Mercurial
comparison third_party/wrk/src/ssl.c @ 186:8cf4ec5e2191 hg-web
Fixed merge conflict.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 23 Jan 2026 22:38:59 -0800 |
| parents | 94705b5986b3 |
| children |
comparison
equal
deleted
inserted
replaced
| 176:fed99fc04e12 | 186:8cf4ec5e2191 |
|---|---|
| 1 // Copyright (C) 2013 - Will Glozer. All rights reserved. | |
| 2 | |
| 3 #include <pthread.h> | |
| 4 | |
| 5 #include <openssl/evp.h> | |
| 6 #include <openssl/err.h> | |
| 7 #include <openssl/ssl.h> | |
| 8 | |
| 9 #include "ssl.h" | |
| 10 | |
| 11 SSL_CTX *ssl_init() { | |
| 12 SSL_CTX *ctx = NULL; | |
| 13 | |
| 14 SSL_load_error_strings(); | |
| 15 SSL_library_init(); | |
| 16 OpenSSL_add_all_algorithms(); | |
| 17 | |
| 18 if ((ctx = SSL_CTX_new(SSLv23_client_method()))) { | |
| 19 SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL); | |
| 20 SSL_CTX_set_verify_depth(ctx, 0); | |
| 21 SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); | |
| 22 SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_CLIENT); | |
| 23 } | |
| 24 | |
| 25 return ctx; | |
| 26 } | |
| 27 | |
| 28 status ssl_connect(connection *c, char *host) { | |
| 29 int r; | |
| 30 SSL_set_fd(c->ssl, c->fd); | |
| 31 SSL_set_tlsext_host_name(c->ssl, host); | |
| 32 if ((r = SSL_connect(c->ssl)) != 1) { | |
| 33 switch (SSL_get_error(c->ssl, r)) { | |
| 34 case SSL_ERROR_WANT_READ: return RETRY; | |
| 35 case SSL_ERROR_WANT_WRITE: return RETRY; | |
| 36 default: return ERROR; | |
| 37 } | |
| 38 } | |
| 39 return OK; | |
| 40 } | |
| 41 | |
| 42 status ssl_close(connection *c) { | |
| 43 SSL_shutdown(c->ssl); | |
| 44 SSL_clear(c->ssl); | |
| 45 return OK; | |
| 46 } | |
| 47 | |
| 48 status ssl_read(connection *c, size_t *n) { | |
| 49 int r; | |
| 50 if ((r = SSL_read(c->ssl, c->buf, sizeof(c->buf))) <= 0) { | |
| 51 switch (SSL_get_error(c->ssl, r)) { | |
| 52 case SSL_ERROR_WANT_READ: return RETRY; | |
| 53 case SSL_ERROR_WANT_WRITE: return RETRY; | |
| 54 default: return ERROR; | |
| 55 } | |
| 56 } | |
| 57 *n = (size_t) r; | |
| 58 return OK; | |
| 59 } | |
| 60 | |
| 61 status ssl_write(connection *c, char *buf, size_t len, size_t *n) { | |
| 62 int r; | |
| 63 if ((r = SSL_write(c->ssl, buf, len)) <= 0) { | |
| 64 switch (SSL_get_error(c->ssl, r)) { | |
| 65 case SSL_ERROR_WANT_READ: return RETRY; | |
| 66 case SSL_ERROR_WANT_WRITE: return RETRY; | |
| 67 default: return ERROR; | |
| 68 } | |
| 69 } | |
| 70 *n = (size_t) r; | |
| 71 return OK; | |
| 72 } | |
| 73 | |
| 74 size_t ssl_readable(connection *c) { | |
| 75 return SSL_pending(c->ssl); | |
| 76 } |