Skip to content

Commit 26b474c

Browse files
romanmichalvasko
authored andcommitted
session wrapper UPDATE exp time from cert getter
1 parent a093712 commit 26b474c

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/session_mbedtls.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,3 +1883,25 @@ nc_server_tls_set_cipher_suites_wrap(void *tls_cfg, void *cipher_suites)
18831883
{
18841884
mbedtls_ssl_conf_ciphersuites(tls_cfg, cipher_suites);
18851885
}
1886+
1887+
time_t
1888+
nc_tls_get_cert_exp_time_wrap(void *cert)
1889+
{
1890+
struct tm t = {0};
1891+
mbedtls_x509_time *valid_to;
1892+
1893+
valid_to = &((mbedtls_x509_crt *)cert)->valid_to;
1894+
1895+
t.tm_sec = valid_to->sec;
1896+
t.tm_min = valid_to->min;
1897+
t.tm_hour = valid_to->hour;
1898+
1899+
t.tm_mday = valid_to->day;
1900+
t.tm_mon = valid_to->mon - 1;
1901+
t.tm_year = valid_to->year - 1900;
1902+
1903+
/* let system figure out the DST */
1904+
t.tm_isdst = -1;
1905+
1906+
return timegm(&t);
1907+
}

src/session_openssl.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,3 +1432,20 @@ nc_server_tls_set_cipher_suites_wrap(void *tls_cfg, void *cipher_suites)
14321432
/* set for TLS1.3 */
14331433
SSL_CTX_set_ciphersuites(tls_cfg, cipher_suites);
14341434
}
1435+
1436+
time_t
1437+
nc_tls_get_cert_exp_time_wrap(void *cert)
1438+
{
1439+
int r;
1440+
struct tm t = {0};
1441+
1442+
r = ASN1_TIME_to_tm(X509_get0_notAfter(cert), &t);
1443+
if (!r) {
1444+
return -1;
1445+
}
1446+
1447+
/* let system figure out the DST */
1448+
t.tm_isdst = -1;
1449+
1450+
return timegm(&t);
1451+
}

src/session_wrapper.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,4 +724,13 @@ int nc_tls_append_cipher_suite_wrap(struct nc_server_tls_opts *opts, const char
724724
*/
725725
void nc_server_tls_set_cipher_suites_wrap(void *tls_cfg, void *cipher_suites);
726726

727+
/**
728+
* @brief Get the certificate's expiration time.
729+
*
730+
* @param[in] cert Certificate.
731+
*
732+
* @return Calendar time of the expiration (it is in GMT) or -1 on error.
733+
*/
734+
time_t nc_tls_get_cert_exp_time_wrap(void *cert);
735+
727736
#endif

0 commit comments

Comments
 (0)