Mercurial
comparison seobeo/s_ssl.c @ 96:70401cf61e97
[Seobeo] Added logging.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Fri, 02 Jan 2026 19:16:17 -0800 |
| parents | 6626ec933933 |
| children |
comparison
equal
deleted
inserted
replaced
| 95:b51f8cce9170 | 96:70401cf61e97 |
|---|---|
| 15 | 15 |
| 16 int Seobeo_SSL_Setup_Client(Seobeo_Handle *p_handle, const char *host, int socket_fd) | 16 int Seobeo_SSL_Setup_Client(Seobeo_Handle *p_handle, const char *host, int socket_fd) |
| 17 { | 17 { |
| 18 if (!p_handle) return -1; | 18 if (!p_handle) return -1; |
| 19 | 19 |
| 20 printf("USE SSL\n\n"); | 20 Seobeo_Log(SEOBEO_INFO, "Using SSL/TLS encryption\n"); |
| 21 Seobeo_Web_SSL_Init(); | 21 Seobeo_Web_SSL_Init(); |
| 22 p_handle->ssl_ctx = SSL_CTX_new(TLS_client_method()); | 22 p_handle->ssl_ctx = SSL_CTX_new(TLS_client_method()); |
| 23 if (!p_handle->ssl_ctx) | 23 if (!p_handle->ssl_ctx) |
| 24 { | 24 { |
| 25 fprintf(stderr, "SSL_CTX_new failed\n"); | 25 Seobeo_Log(SEOBEO_ERROR, "SSL_CTX_new failed\n"); |
| 26 ERR_print_errors_fp(stderr); | 26 ERR_print_errors_fp(stderr); |
| 27 return -1; | 27 return -1; |
| 28 } | 28 } |
| 29 | 29 |
| 30 SSL_CTX_set_default_verify_paths(p_handle->ssl_ctx); | 30 SSL_CTX_set_default_verify_paths(p_handle->ssl_ctx); |
| 31 | 31 |
| 32 p_handle->ssl = SSL_new(p_handle->ssl_ctx); | 32 p_handle->ssl = SSL_new(p_handle->ssl_ctx); |
| 33 if (!p_handle->ssl) | 33 if (!p_handle->ssl) |
| 34 { | 34 { |
| 35 fprintf(stderr, "SSL_new failed\n"); | 35 Seobeo_Log(SEOBEO_ERROR, "SSL_new failed\n"); |
| 36 ERR_print_errors_fp(stderr); | 36 ERR_print_errors_fp(stderr); |
| 37 SSL_CTX_free(p_handle->ssl_ctx); | 37 SSL_CTX_free(p_handle->ssl_ctx); |
| 38 p_handle->ssl_ctx = NULL; | 38 p_handle->ssl_ctx = NULL; |
| 39 return -1; | 39 return -1; |
| 40 } | 40 } |
| 45 // Blocking for TLS handshake | 45 // Blocking for TLS handshake |
| 46 fcntl(socket_fd, F_SETFL, 0); | 46 fcntl(socket_fd, F_SETFL, 0); |
| 47 | 47 |
| 48 if (SSL_connect(p_handle->ssl) != 1) | 48 if (SSL_connect(p_handle->ssl) != 1) |
| 49 { | 49 { |
| 50 fprintf(stderr, "SSL_connect failed\n"); | 50 Seobeo_Log(SEOBEO_ERROR, "SSL_connect failed\n"); |
| 51 ERR_print_errors_fp(stderr); | 51 ERR_print_errors_fp(stderr); |
| 52 SSL_free(p_handle->ssl); | 52 SSL_free(p_handle->ssl); |
| 53 SSL_CTX_free(p_handle->ssl_ctx); | 53 SSL_CTX_free(p_handle->ssl_ctx); |
| 54 p_handle->ssl = NULL; | 54 p_handle->ssl = NULL; |
| 55 p_handle->ssl_ctx = NULL; | 55 p_handle->ssl_ctx = NULL; |
| 124 void Seobeo_Web_SSL_Init() {} | 124 void Seobeo_Web_SSL_Init() {} |
| 125 void Seobeo_Web_SSL_Cleanup(void) {} | 125 void Seobeo_Web_SSL_Cleanup(void) {} |
| 126 int Seobeo_SSL_Setup_Client(Seobeo_Handle *p_handle, const char *host, int socket_fd) | 126 int Seobeo_SSL_Setup_Client(Seobeo_Handle *p_handle, const char *host, int socket_fd) |
| 127 { | 127 { |
| 128 (void)p_handle; (void)host; (void)socket_fd; | 128 (void)p_handle; (void)host; (void)socket_fd; |
| 129 fprintf(stderr, "SSL support not compiled in\n"); | 129 Seobeo_Log(SEOBEO_WARNING, "SSL support not compiled in\n"); |
| 130 return -1; | 130 return -1; |
| 131 } | 131 } |
| 132 void Seobeo_SSL_Cleanup(Seobeo_Handle *p_handle) { (void)p_handle; } | 132 void Seobeo_SSL_Cleanup(Seobeo_Handle *p_handle) { (void)p_handle; } |
| 133 int32 Seobeo_SSL_Write(Seobeo_Handle *p_handle, const uint8 *data, uint32 length) | 133 int32 Seobeo_SSL_Write(Seobeo_Handle *p_handle, const uint8 *data, uint32 length) |
| 134 { | 134 { |