12
12
#include < logging/logging.h>
13
13
#include < client/udaClientHostList.h>
14
14
15
+ #include " utils.h"
16
+
15
17
static bool g_sslDisabled = true ; // Default state is not SSL authentication
16
18
static int g_sslProtocol = 0 ; // The default server host name has the SSL protocol name prefix or
17
19
static int g_sslSocket = -1 ;
@@ -51,9 +53,7 @@ static void init_ssl_library()
51
53
UDA_LOG (UDA_LOG_DEBUG, " Prior SSL initialisation\n " );
52
54
return ;
53
55
}
54
- SSL_library_init ();
55
- SSL_load_error_strings ();
56
- OpenSSL_add_ssl_algorithms ();
56
+ OPENSSL_init_ssl (OPENSSL_INIT_SSL_DEFAULT, nullptr );
57
57
#ifdef _WIN32
58
58
if (getenv (" UDA_SSL_INITIALISED" ) == nullptr ) {
59
59
_putenv_s (" UDA_SSL_INITIALISED" , " 1" );
@@ -84,7 +84,6 @@ void closeUdaClientSSL()
84
84
if (ctx != nullptr ) {
85
85
SSL_CTX_free (ctx);
86
86
}
87
- EVP_cleanup ();
88
87
g_ssl = nullptr ;
89
88
g_ctx = nullptr ;
90
89
#ifdef _WIN32
@@ -272,10 +271,10 @@ int configureUdaClientSSLContext(const HostData* host)
272
271
UDA_THROW_ERROR (999 , " Unable to parse client certificate [%s] to verify certificate validity" );
273
272
}
274
273
275
- const ASN1_TIME* before = X509_get_notBefore (clientCert);
276
- const ASN1_TIME* after = X509_get_notAfter (clientCert);
274
+ const ASN1_TIME* before = X509_getm_notBefore (clientCert);
275
+ const ASN1_TIME* after = X509_getm_notAfter (clientCert);
277
276
278
- char work[X509STRINGSIZE ];
277
+ char work[X509_STRING_SIZE ];
279
278
UDA_LOG (UDA_LOG_DEBUG, " Client X509 subject: %s\n " ,
280
279
X509_NAME_oneline (X509_get_subject_name (clientCert), work, sizeof (work)));
281
280
UDA_LOG (UDA_LOG_DEBUG, " Client X509 issuer: %s\n " ,
@@ -284,31 +283,22 @@ int configureUdaClientSSLContext(const HostData* host)
284
283
time_t current_time = time (nullptr );
285
284
char * c_time_string = ctime (¤t_time);
286
285
287
- int rc = 0 , count = 0 ;
288
- BIO* b = BIO_new (BIO_s_mem ());
289
- if (b && ASN1_TIME_print (b, before)) {
290
- count = BIO_read (b, work, X509STRINGSIZE - 1 );
291
- BIO_free (b);
292
- }
293
- work[count] = ' \0 ' ;
294
- UDA_LOG (UDA_LOG_DEBUG, " Client X509 not before: %s\n " , work);
286
+ std::string before_string = to_string (before);
287
+
288
+ UDA_LOG (UDA_LOG_DEBUG, " Client X509 not before: %s\n " , before_string.c_str ());
289
+ int rc = 0 ;
295
290
if ((rc = X509_cmp_time (before, ¤t_time)) >= 0 ) {
296
291
// Not Before is after Now!
297
292
X509_free (clientCert);
298
293
UDA_LOG (UDA_LOG_DEBUG, " Current Time : %s\n " , c_time_string);
299
294
UDA_LOG (UDA_LOG_DEBUG, " Client X509 not before date is before the current date!\n " );
300
- UDA_LOG (UDA_LOG_DEBUG, " The client SSL/x509 certificate is Not Valid - the Vaidity Date is in the future!\n " );
301
- UDA_THROW_ERROR (999 , " The client SSL/x509 certificate is Not Valid - the Vaidity Date is in the future" );
295
+ UDA_LOG (UDA_LOG_DEBUG, " The client SSL/x509 certificate is Not Valid - the Validity Date is in the future!\n " );
296
+ UDA_THROW_ERROR (999 , " The client SSL/x509 certificate is Not Valid - the Validity Date is in the future" );
302
297
}
303
298
304
- count = 0 ;
305
- b = BIO_new (BIO_s_mem ());
306
- if (b && ASN1_TIME_print (b, after)) {
307
- count = BIO_read (b, work, X509STRINGSIZE - 1 );
308
- BIO_free (b);
309
- }
310
- work[count] = ' \0 ' ;
311
- UDA_LOG (UDA_LOG_DEBUG, " Client X509 not after : %s\n " , work);
299
+ std::string after_string = to_string (after);
300
+
301
+ UDA_LOG (UDA_LOG_DEBUG, " Client X509 not after : %s\n " , after_string.c_str ());
312
302
if ((rc = X509_cmp_time (after, ¤t_time)) <= 0 ) {// Not After is before Now!
313
303
X509_free (clientCert);
314
304
UDA_LOG (UDA_LOG_DEBUG, " Current Time : %s\n " , c_time_string);
@@ -319,7 +309,7 @@ int configureUdaClientSSLContext(const HostData* host)
319
309
X509_free (clientCert);
320
310
321
311
UDA_LOG (UDA_LOG_DEBUG, " Current Time : %s\n " , c_time_string);
322
- UDA_LOG (UDA_LOG_DEBUG, " Cient certificate date validity checked but not validated \n " );
312
+ UDA_LOG (UDA_LOG_DEBUG, " Client certificate date validity checked but not validated \n " );
323
313
324
314
return 0 ;
325
315
}
@@ -393,7 +383,7 @@ int startUdaClientSSL()
393
383
}
394
384
395
385
// Get the Server certificate and verify
396
- X509* peer = SSL_get_peer_certificate (g_ssl);
386
+ X509* peer = SSL_get1_peer_certificate (g_ssl);
397
387
398
388
if (peer != nullptr ) {
399
389
@@ -407,7 +397,7 @@ int startUdaClientSSL()
407
397
408
398
// Server's details - not required apart from logging
409
399
410
- char work[X509STRINGSIZE ];
400
+ char work[X509_STRING_SIZE ];
411
401
UDA_LOG (UDA_LOG_DEBUG, " Server certificate verified\n " );
412
402
UDA_LOG (UDA_LOG_DEBUG, " X509 subject: %s\n " ,
413
403
X509_NAME_oneline (X509_get_subject_name (peer), work, sizeof (work)));
@@ -416,20 +406,15 @@ int startUdaClientSSL()
416
406
417
407
// Verify Date validity
418
408
419
- const ASN1_TIME* before = X509_get_notBefore (peer);
420
- const ASN1_TIME* after = X509_get_notAfter (peer);
409
+ const ASN1_TIME* before = X509_getm_notBefore (peer);
410
+ const ASN1_TIME* after = X509_getm_notAfter (peer);
421
411
422
412
time_t current_time = time (nullptr );
423
413
char * c_time_string = ctime (¤t_time);
424
414
425
- int count = 0 ;
426
- BIO* b = BIO_new (BIO_s_mem ());
427
- if (b && ASN1_TIME_print (b, before)) {
428
- count = BIO_read (b, work, X509STRINGSIZE - 1 );
429
- BIO_free (b);
430
- }
431
- work[count] = ' \0 ' ;
432
- UDA_LOG (UDA_LOG_DEBUG, " Server X509 not before: %s\n " , work);
415
+ std::string before_string = to_string (before);
416
+
417
+ UDA_LOG (UDA_LOG_DEBUG, " Server X509 not before: %s\n " , before_string.c_str ());
433
418
if ((rc = X509_cmp_time (before, ¤t_time)) >= 0 ) {// Not Before is after Now!
434
419
X509_free (peer);
435
420
UDA_LOG (UDA_LOG_DEBUG, " Current Time : %s\n " , c_time_string);
@@ -439,14 +424,9 @@ int startUdaClientSSL()
439
424
UDA_THROW_ERROR (999 , " The Server's SSL/x509 certificate is Not Valid - the Vaidity Date is in the future" );
440
425
}
441
426
442
- count = 0 ;
443
- b = BIO_new (BIO_s_mem ());
444
- if (b && ASN1_TIME_print (b, after)) {
445
- count = BIO_read (b, work, X509STRINGSIZE - 1 );
446
- BIO_free (b);
447
- }
448
- work[count] = ' \0 ' ;
449
- UDA_LOG (UDA_LOG_DEBUG, " Server X509 not after : %s\n " , work);
427
+ std::string after_string = to_string (after);
428
+
429
+ UDA_LOG (UDA_LOG_DEBUG, " Server X509 not after : %s\n " , after_string.c_str ());
450
430
if ((rc = X509_cmp_time (after, ¤t_time)) <= 0 ) {// Not After is before Now!
451
431
X509_free (peer);
452
432
UDA_LOG (UDA_LOG_DEBUG, " Current Time : %s\n " , c_time_string);
0 commit comments