X-Git-Url: https://git.tcpdump.org/libpcap/blobdiff_plain/0f0a435cd7f240ac3641fa02881e665922cb095a..f0363d0cb7fc0e66ac9eac1b6512efe92fce89c5:/sslutils.c diff --git a/sslutils.c b/sslutils.c index c6fb80c5..fba34603 100644 --- a/sslutils.c +++ b/sslutils.c @@ -38,18 +38,28 @@ #include #include "portability.h" + #include "sslutils.h" -#include "pcap/pcap.h" -char ssl_keyfile[PATH_MAX]; //!< file containing the private key in PEM format -char ssl_certfile[PATH_MAX]; //!< file containing the server's certificate in PEM format -char ssl_rootfile[PATH_MAX]; //!< file containing the list of CAs trusted by the client +static const char *ssl_keyfile = ""; //!< file containing the private key in PEM format +static const char *ssl_certfile = ""; //!< file containing the server's certificate in PEM format +static const char *ssl_rootfile = ""; //!< file containing the list of CAs trusted by the client // TODO: a way to set ssl_rootfile from the command line, or an envvar? // TODO: lock? static SSL_CTX *ctx; -static int ssl_init_once(int is_server, int enable_compression, char *errbuf, size_t errbuflen) +void ssl_set_certfile(const char *certfile) +{ + ssl_certfile = certfile; +} + +void ssl_set_keyfile(const char *keyfile) +{ + ssl_keyfile = keyfile; +} + +int ssl_init_once(int is_server, int enable_compression, char *errbuf, size_t errbuflen) { static int inited = 0; if (inited) return 0; @@ -123,26 +133,14 @@ die: return -1; } -void init_ssl_or_die(int is_server, int enable_compression) -{ - char errbuf[PCAP_ERRBUF_SIZE]; - - if (ssl_init_once(is_server, enable_compression, errbuf, sizeof errbuf) < 0) - { - fprintf(stderr, "%s\n", errbuf); - exit(3); - } -} - -SSL *ssl_promotion_rw(int is_server, SOCKET in, SOCKET out, char *errbuf, size_t errbuflen) +SSL *ssl_promotion(int is_server, SOCKET s, char *errbuf, size_t errbuflen) { if (ssl_init_once(is_server, 1, errbuf, errbuflen) < 0) { return NULL; } SSL *ssl = SSL_new(ctx); // TODO: also a DTLS context - SSL_set_rfd(ssl, in); - SSL_set_wfd(ssl, out); + SSL_set_fd(ssl, s); if (is_server) { if (SSL_accept(ssl) <= 0) { @@ -161,14 +159,9 @@ SSL *ssl_promotion_rw(int is_server, SOCKET in, SOCKET out, char *errbuf, size_t return ssl; } -SSL *ssl_promotion(int is_server, SOCKET s, char *errbuf, size_t errbuflen) -{ - return ssl_promotion_rw(is_server, s, s, errbuf, errbuflen); -} - // Same return value as sock_send: // 0 on OK, -1 on error but closed connection (-2). -int ssl_send(SSL *ssl, char const *buffer, size_t size, char *errbuf, size_t errbuflen) +int ssl_send(SSL *ssl, char const *buffer, int size, char *errbuf, size_t errbuflen) { int status = SSL_write(ssl, buffer, size); if (status > 0) @@ -196,7 +189,7 @@ int ssl_send(SSL *ssl, char const *buffer, size_t size, char *errbuf, size_t err } // Returns the number of bytes read, or -1 on syserror, or -2 on SSL error. -int ssl_recv(SSL *ssl, char *buffer, size_t size, char *errbuf, size_t errbuflen) +int ssl_recv(SSL *ssl, char *buffer, int size, char *errbuf, size_t errbuflen) { int status = SSL_read(ssl, buffer, size); if (status <= 0)