Add log_ssl() and some cleanups

This commit is contained in:
2016-08-09 00:31:49 +03:00
parent 94e0e140b4
commit 5f67602e8e
4 changed files with 22 additions and 26 deletions

17
rmps.c
View File

@@ -6,10 +6,7 @@
#include <sys/stat.h>
#include <fcntl.h>
/* included for openssl and sockets */
#include <sys/socket.h>
#include <arpa/inet.h>
#include <resolv.h>
/* included for openssl */
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -233,21 +230,17 @@ static SSL_CTX* init_server_ctx(const char *cipherlist)
void load_certificates(SSL_CTX* ctx, const char *certfile,
const char *keyfile, const char *cafile)
{
long ssl_errnum;
char ssl_errstr[2048];
/* set the local certificate from certfile */
if (SSL_CTX_use_certificate_file(ctx, certfile, SSL_FILETYPE_PEM) <= 0) {
ssl_errnum = ERR_get_error();
ERR_error_string_n(ssl_errnum, ssl_errstr, sizeof(ssl_errstr));
log_trace(ERROR, "Failed to load certfile! SSL error below:\n%s", ssl_errstr);
log_trace(ERROR, "Failed to load certfile! SSL error below:");
log_ssl();
log_trace(INFO, "RMPS failed to start, shutting down...");
atexit(cleanup);
}
/* set the private key from KeyFile (may be the same as CertFile) */
if (SSL_CTX_use_PrivateKey_file(ctx, keyfile, SSL_FILETYPE_PEM) <= 0) {
ssl_errnum = ERR_get_error();
ERR_error_string_n(ssl_errnum, ssl_errstr, sizeof(ssl_errstr));
log_trace(ERROR, "Failed to load keyfile! SSL error below:\n%s", ssl_errstr);
log_trace(ERROR, "Failed to load keyfile! SSL error below:");
log_ssl();
log_trace(INFO, "RMPS failed to start, shutting down...");
atexit(cleanup);
}