-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssl_utils.cpp
More file actions
31 lines (28 loc) · 799 Bytes
/
Copy pathssl_utils.cpp
File metadata and controls
31 lines (28 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "ssl_utils.h"
SSL_CTX* newSSLContext()
{ const SSL_METHOD *method;
SSL_CTX *ctx;
OpenSSL_add_all_algorithms();
SSL_load_error_strings();
SSL_library_init();
method = TLSv1_2_method();
ctx = SSL_CTX_new(method);
if ( ctx == NULL )
{
ERR_print_errors_fp(stderr);
exit(1);
}
return ctx;
}
void loadPrivateAndPublicKeys(SSL_CTX* ctx, char* cert, char* key)
{
if ( SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0 || SSL_CTX_use_PrivateKey_file(ctx, key, SSL_FILETYPE_PEM) <= 0 )
{
ERR_print_errors_fp(stderr);
exit(1);
}
if ( !SSL_CTX_check_private_key(ctx) ){
fprintf(stderr, "Private key does not match the public certificate\n");
exit(1);
}
}