From ecf449dfe0eb59183442c8547431efdc4be506a2 Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Thu, 5 May 2022 15:07:59 -0600 Subject: [PATCH 1/4] Refactor wolfSSL_ASN1_TIME_adj to use GetUnformattedTimeString (new API) --- src/ssl.c | 65 ++++++------------------------ wolfcrypt/src/asn.c | 88 +++++++++++++++++++++++++---------------- wolfssl/wolfcrypt/asn.h | 4 +- 3 files changed, 69 insertions(+), 88 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index 5260c1155..c1d02bdb6 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -45308,18 +45308,11 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_adj(WOLFSSL_ASN1_TIME *s, time_t t, int offset_day, long offset_sec) { const time_t sec_per_day = 24*60*60; - struct tm* ts = NULL; - struct tm* tmpTime; time_t t_adj = 0; time_t offset_day_sec = 0; -#if defined(NEED_TMP_TIME) - struct tm tmpTimeStorage; - - tmpTime = &tmpTimeStorage; -#else - tmpTime = NULL; -#endif - (void)tmpTime; + char utc_str_buf[MAX_TIME_STRING_SZ] = {0}; + char* utc_str = utc_str_buf; + int time_get; WOLFSSL_ENTER("wolfSSL_ASN1_TIME_adj"); @@ -45333,54 +45326,18 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_adj(WOLFSSL_ASN1_TIME *s, time_t t, /* compute GMT time with offset */ offset_day_sec = offset_day * sec_per_day; t_adj = t + offset_day_sec + offset_sec; - ts = (struct tm *)XGMTIME(&t_adj, tmpTime); - if (ts == NULL){ - WOLFSSL_MSG("failed to get time data."); + + /* Get UTC Time */ + time_get = GetUnformattedTimeString(&t_adj, (byte*) utc_str, + sizeof(utc_str_buf)); + if (time_get <= 0) { wolfSSL_ASN1_TIME_free(s); return NULL; } - /* create ASN1 time notation */ - /* UTC Time */ - if (ts->tm_year >= 50 && ts->tm_year < 150){ - char utc_str[ASN_UTC_TIME_SIZE]; - int utc_year = 0,utc_mon,utc_day,utc_hour,utc_min,utc_sec; - - if (ts->tm_year >= 50 && ts->tm_year < 100){ - utc_year = ts->tm_year; - } else if (ts->tm_year >= 100 && ts->tm_year < 150){ - utc_year = ts->tm_year - 100; - } - utc_mon = ts->tm_mon + 1; - utc_day = ts->tm_mday; - utc_hour = ts->tm_hour; - utc_min = ts->tm_min; - utc_sec = ts->tm_sec; - XSNPRINTF((char *)utc_str, sizeof(utc_str), - "%02d%02d%02d%02d%02d%02dZ", - utc_year, utc_mon, utc_day, utc_hour, utc_min, utc_sec); - if (wolfSSL_ASN1_TIME_set_string(s, utc_str) != WOLFSSL_SUCCESS) { - wolfSSL_ASN1_TIME_free(s); - return NULL; - } - /* GeneralizedTime */ - } else { - char gt_str[ASN_GENERALIZED_TIME_MAX]; - int gt_year,gt_mon,gt_day,gt_hour,gt_min,gt_sec; - - gt_year = ts->tm_year + 1900; - gt_mon = ts->tm_mon + 1; - gt_day = ts->tm_mday; - gt_hour = ts->tm_hour; - gt_min = ts->tm_min; - gt_sec = ts->tm_sec; - XSNPRINTF((char *)gt_str, sizeof(gt_str), - "%4d%02d%02d%02d%02d%02dZ", - gt_year, gt_mon, gt_day, gt_hour, gt_min,gt_sec); - if (wolfSSL_ASN1_TIME_set_string(s, gt_str) != WOLFSSL_SUCCESS) { - wolfSSL_ASN1_TIME_free(s); - return NULL; - } + if (wolfSSL_ASN1_TIME_set_string(s, utc_str) != WOLFSSL_SUCCESS) { + wolfSSL_ASN1_TIME_free(s); + return NULL; } return s; diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 869984e12..207321ce7 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -12192,19 +12192,60 @@ int GetTimeString(byte* date, int format, char* buf, int len) #endif /* OPENSSL_ALL || WOLFSSL_MYSQL_COMPATIBLE || WOLFSSL_NGINX || WOLFSSL_HAPROXY */ -#if !defined(NO_ASN_TIME) && defined(HAVE_PKCS7) - +#if !defined(NO_ASN_TIME) && !defined(USER_TIME) && \ + !defined(TIME_OVERRIDES) && (defined(OPENSSL_EXTRA) || defined(HAVE_PKCS7)) /* Set current time string, either UTC or GeneralizedTime. * (void*) tm should be a pointer to time_t, output is placed in buf. * * Return time string length placed in buf on success, negative on error */ int GetAsnTimeString(void* currTime, byte* buf, word32 len) +{ + byte* data_ptr = buf; + byte uf_time[ASN_GENERALIZED_TIME_SIZE] = {0}; + word32 data_len = 0; + + WOLFSSL_ENTER("GetAsnTimeString"); + + if (buf == NULL || len == 0) + return BAD_FUNC_ARG; + + data_len = GetUnformattedTimeString(currTime, uf_time, len); + /* ensure room to add 2 bytes (ASN type and length) before proceeding */ + if (len < data_len + 2) + return BUFFER_E; + if(data_len <= 0) + return ASN_TIME_E; + + /* Increment by 1 for ASN type */ + data_len++; + + if (data_len == ASN_UTC_TIME_SIZE) { + /* increment data_len for ASN length byte after adding the data_ptr */ + *data_ptr = (byte) ASN_UTC_TIME; data_ptr++; data_len++; + /* -1 below excludes null terminator */ + *data_ptr = (byte) ASN_UTC_TIME_SIZE - 1; data_ptr++; + XMEMCPY(data_ptr,(byte *)uf_time, ASN_UTC_TIME_SIZE - 1); + } else if (data_len == ASN_GENERALIZED_TIME_SIZE) { + /* increment data_len for ASN length byte after adding the data_ptr */ + *data_ptr = (byte) ASN_GENERALIZED_TIME; data_ptr++; data_len++; + /* -1 below excludes null terminator */ + *data_ptr = (byte) ASN_GENERALIZED_TIME_SIZE - 1; data_ptr++; + XMEMCPY(data_ptr,(byte *)uf_time, ASN_GENERALIZED_TIME_SIZE - 1); + } else { + WOLFSSL_MSG("Invalid time size returned"); + return ASN_TIME_E; + } + + return data_len; +} + +/* return just the raw time string */ +int GetUnformattedTimeString(void* currTime, byte* buf, word32 len) { struct tm* ts = NULL; struct tm* tmpTime = NULL; - byte* data_ptr = buf; - word32 data_len = 0; int year, mon, day, hour, mini, sec; + int ret_bytes_len = 0; #if defined(NEED_TMP_TIME) struct tm tmpTimeStorage; tmpTime = &tmpTimeStorage; @@ -12212,7 +12253,7 @@ int GetAsnTimeString(void* currTime, byte* buf, word32 len) (void)tmpTime; #endif - WOLFSSL_ENTER("SetAsnTimeString"); + WOLFSSL_ENTER("GetTimeString"); if (buf == NULL || len == 0) return BAD_FUNC_ARG; @@ -12228,12 +12269,6 @@ int GetAsnTimeString(void* currTime, byte* buf, word32 len) if (ts->tm_year >= 50 && ts->tm_year < 150) { /* UTC Time */ - char utc_str[ASN_UTC_TIME_SIZE]; - data_len = ASN_UTC_TIME_SIZE - 1 + 2; - - if (len < data_len) - return BUFFER_E; - if (ts->tm_year >= 50 && ts->tm_year < 100) { year = ts->tm_year; } else if (ts->tm_year >= 100 && ts->tm_year < 150) { @@ -12248,40 +12283,27 @@ int GetAsnTimeString(void* currTime, byte* buf, word32 len) hour = ts->tm_hour; mini = ts->tm_min; sec = ts->tm_sec; - XSNPRINTF((char *)utc_str, ASN_UTC_TIME_SIZE, - "%02d%02d%02d%02d%02d%02dZ", year, mon, day, hour, mini, sec); - *data_ptr = (byte) ASN_UTC_TIME; data_ptr++; - /* -1 below excludes null terminator */ - *data_ptr = (byte) ASN_UTC_TIME_SIZE - 1; data_ptr++; - XMEMCPY(data_ptr,(byte *)utc_str, ASN_UTC_TIME_SIZE - 1); - + ret_bytes_len = XSNPRINTF((char *)buf, len, + "%02d%02d%02d%02d%02d%02dZ", year, mon, day, + hour, mini, sec); } else { /* GeneralizedTime */ - char gt_str[ASN_GENERALIZED_TIME_SIZE]; - data_len = ASN_GENERALIZED_TIME_SIZE - 1 + 2; - - if (len < data_len) - return BUFFER_E; - year = ts->tm_year + 1900; mon = ts->tm_mon + 1; day = ts->tm_mday; hour = ts->tm_hour; mini = ts->tm_min; sec = ts->tm_sec; - XSNPRINTF((char *)gt_str, ASN_GENERALIZED_TIME_SIZE, - "%4d%02d%02d%02d%02d%02dZ", year, mon, day, hour, mini, sec); - *data_ptr = (byte) ASN_GENERALIZED_TIME; data_ptr++; - /* -1 below excludes null terminator */ - *data_ptr = (byte) ASN_GENERALIZED_TIME_SIZE - 1; data_ptr++; - XMEMCPY(data_ptr,(byte *)gt_str, ASN_GENERALIZED_TIME_SIZE - 1); + ret_bytes_len = XSNPRINTF((char *)buf, len, + "%4d%02d%02d%02d%02d%02dZ", year, mon, day, + hour, mini, sec); } - return data_len; + return ret_bytes_len; } -#endif /* !NO_ASN_TIME && HAVE_PKCS7 */ - +#endif /* !NO_ASN_TIME && !USER_TIME && !TIME_OVERRIDES && + * (OPENSSL_EXTRA || HAVE_PKCS7) */ #if defined(USE_WOLF_VALIDDATE) diff --git a/wolfssl/wolfcrypt/asn.h b/wolfssl/wolfcrypt/asn.h index 723b37c3a..c0abf71c3 100644 --- a/wolfssl/wolfcrypt/asn.h +++ b/wolfssl/wolfcrypt/asn.h @@ -1894,7 +1894,9 @@ typedef struct tm wolfssl_tm; defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) WOLFSSL_LOCAL int GetTimeString(byte* date, int format, char* buf, int len); #endif -#if !defined(NO_ASN_TIME) && defined(HAVE_PKCS7) +#if !defined(NO_ASN_TIME) && !defined(USER_TIME) && \ + !defined(TIME_OVERRIDES) && (defined(OPENSSL_EXTRA) || defined(HAVE_PKCS7)) +WOLFSSL_LOCAL int GetUnformattedTimeString(void* currTime, byte* buf, word32 len); WOLFSSL_LOCAL int GetAsnTimeString(void* currTime, byte* buf, word32 len); #endif WOLFSSL_LOCAL int ExtractDate(const unsigned char* date, unsigned char format, From 3e1ba5d4d47cf8650d52514223a32e5795536fa9 Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Fri, 6 May 2022 07:50:39 -0600 Subject: [PATCH 2/4] Implement peer review feedback and leave some breadcrumbs in the event of future updates --- wolfcrypt/src/asn.c | 14 ++++++++++---- wolfssl/wolfcrypt/asn.h | 9 +++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 207321ce7..48bc23e2d 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -12211,12 +12211,18 @@ int GetAsnTimeString(void* currTime, byte* buf, word32 len) data_len = GetUnformattedTimeString(currTime, uf_time, len); /* ensure room to add 2 bytes (ASN type and length) before proceeding */ - if (len < data_len + 2) - return BUFFER_E; - if(data_len <= 0) + if(data_len <= 0) { return ASN_TIME_E; + } else if (len < data_len + 2) { + return BUFFER_E; + } - /* Increment by 1 for ASN type */ + /* Increment by 1 for ASN type, it is critical that this increment occur + * prior to the check on data_len being ASN_UTC_TIME_SIZE or + * ASN_GENERALIZED_TIME_SIZE since GetUnformattedTimeString returns the + * length without NULL terminator + * (IE 13 instead of 14 for ASN_UTC_TIME_SIZE) This logic WILL NEED updated + * if ASN_UTC_TIME_SIZE or ASN_GENERALIZED_TIME_SIZE are ever modified */ data_len++; if (data_len == ASN_UTC_TIME_SIZE) { diff --git a/wolfssl/wolfcrypt/asn.h b/wolfssl/wolfcrypt/asn.h index c0abf71c3..17239d87e 100644 --- a/wolfssl/wolfcrypt/asn.h +++ b/wolfssl/wolfcrypt/asn.h @@ -156,8 +156,13 @@ enum ASN_Tags { ASN_ASYMKEY_PUBKEY = 0x01, }; -#define ASN_UTC_TIME_SIZE 14 -#define ASN_GENERALIZED_TIME_SIZE 16 +/* NOTE: If ASN_UTC_TIME_SIZE or ASN_GENERALIZED_TIME_SIZE are ever modified + * one needs to update the logic in asn.c function GetAsnTimeString() + * which depends on the size 14 and/or 16 to determine which format to + * place in the "buf" (output) + */ +#define ASN_UTC_TIME_SIZE 14 /* Read note above before modifying */ +#define ASN_GENERALIZED_TIME_SIZE 16 /* Read note above before modifying */ #define ASN_GENERALIZED_TIME_MAX 68 #ifdef WOLFSSL_ASN_TEMPLATE From ef89e2e6376f29a960430ec6021e0f7a95b87f79 Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Fri, 6 May 2022 08:18:14 -0600 Subject: [PATCH 3/4] Rename utc_str[_buf] -> time_str[_buf] (semantic change) --- src/ssl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index c1d02bdb6..0635a8662 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -45310,8 +45310,8 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_adj(WOLFSSL_ASN1_TIME *s, time_t t, const time_t sec_per_day = 24*60*60; time_t t_adj = 0; time_t offset_day_sec = 0; - char utc_str_buf[MAX_TIME_STRING_SZ] = {0}; - char* utc_str = utc_str_buf; + char time_str_buf[MAX_TIME_STRING_SZ] = {0}; + char* time_str = time_str_buf; int time_get; WOLFSSL_ENTER("wolfSSL_ASN1_TIME_adj"); @@ -45328,14 +45328,14 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_adj(WOLFSSL_ASN1_TIME *s, time_t t, t_adj = t + offset_day_sec + offset_sec; /* Get UTC Time */ - time_get = GetUnformattedTimeString(&t_adj, (byte*) utc_str, - sizeof(utc_str_buf)); + time_get = GetUnformattedTimeString(&t_adj, (byte*) time_str, + sizeof(time_str_buf)); if (time_get <= 0) { wolfSSL_ASN1_TIME_free(s); return NULL; } - if (wolfSSL_ASN1_TIME_set_string(s, utc_str) != WOLFSSL_SUCCESS) { + if (wolfSSL_ASN1_TIME_set_string(s, time_str) != WOLFSSL_SUCCESS) { wolfSSL_ASN1_TIME_free(s); return NULL; } From 3e774be88c8dfe0c87d946402088879e04d9043d Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 6 May 2022 10:54:35 -0700 Subject: [PATCH 4/4] Minor text and formatting cleanups. --- src/ssl.c | 13 ++++--- wolfcrypt/src/asn.c | 76 ++++++++++++++++++++++------------------- wolfssl/wolfcrypt/asn.h | 2 +- 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index 0635a8662..92b8011f8 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -45310,15 +45310,14 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_adj(WOLFSSL_ASN1_TIME *s, time_t t, const time_t sec_per_day = 24*60*60; time_t t_adj = 0; time_t offset_day_sec = 0; - char time_str_buf[MAX_TIME_STRING_SZ] = {0}; - char* time_str = time_str_buf; + char time_str[MAX_TIME_STRING_SZ]; int time_get; WOLFSSL_ENTER("wolfSSL_ASN1_TIME_adj"); - if (s == NULL){ + if (s == NULL) { s = wolfSSL_ASN1_TIME_new(); - if (s == NULL){ + if (s == NULL) { return NULL; } } @@ -45327,9 +45326,9 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_adj(WOLFSSL_ASN1_TIME *s, time_t t, offset_day_sec = offset_day * sec_per_day; t_adj = t + offset_day_sec + offset_sec; - /* Get UTC Time */ - time_get = GetUnformattedTimeString(&t_adj, (byte*) time_str, - sizeof(time_str_buf)); + /* Get time string as either UTC or GeneralizedTime */ + time_get = GetFormattedTime(&t_adj, (byte*)time_str, + (word32)sizeof(time_str)); if (time_get <= 0) { wolfSSL_ASN1_TIME_free(s); return NULL; diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 48bc23e2d..d60bf02e9 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -12201,7 +12201,7 @@ int GetTimeString(byte* date, int format, char* buf, int len) int GetAsnTimeString(void* currTime, byte* buf, word32 len) { byte* data_ptr = buf; - byte uf_time[ASN_GENERALIZED_TIME_SIZE] = {0}; + byte uf_time[ASN_GENERALIZED_TIME_SIZE]; word32 data_len = 0; WOLFSSL_ENTER("GetAsnTimeString"); @@ -12209,49 +12209,51 @@ int GetAsnTimeString(void* currTime, byte* buf, word32 len) if (buf == NULL || len == 0) return BAD_FUNC_ARG; - data_len = GetUnformattedTimeString(currTime, uf_time, len); - /* ensure room to add 2 bytes (ASN type and length) before proceeding */ - if(data_len <= 0) { + XMEMSET(uf_time, 0, sizeof(uf_time)); + /* GetFormattedTime returns length with null terminator */ + data_len = GetFormattedTime(currTime, uf_time, len); + if (data_len <= 0) { return ASN_TIME_E; - } else if (len < data_len + 2) { + } + /* ensure room to add 2 bytes (ASN type and length) before proceeding */ + else if (len < data_len + 2) { return BUFFER_E; } - /* Increment by 1 for ASN type, it is critical that this increment occur - * prior to the check on data_len being ASN_UTC_TIME_SIZE or - * ASN_GENERALIZED_TIME_SIZE since GetUnformattedTimeString returns the - * length without NULL terminator - * (IE 13 instead of 14 for ASN_UTC_TIME_SIZE) This logic WILL NEED updated - * if ASN_UTC_TIME_SIZE or ASN_GENERALIZED_TIME_SIZE are ever modified */ - data_len++; - - if (data_len == ASN_UTC_TIME_SIZE) { + if (data_len == ASN_UTC_TIME_SIZE-1) { /* increment data_len for ASN length byte after adding the data_ptr */ - *data_ptr = (byte) ASN_UTC_TIME; data_ptr++; data_len++; + *data_ptr = (byte)ASN_UTC_TIME; data_ptr++; data_len++; /* -1 below excludes null terminator */ - *data_ptr = (byte) ASN_UTC_TIME_SIZE - 1; data_ptr++; - XMEMCPY(data_ptr,(byte *)uf_time, ASN_UTC_TIME_SIZE - 1); - } else if (data_len == ASN_GENERALIZED_TIME_SIZE) { + *data_ptr = (byte)ASN_UTC_TIME_SIZE - 1; data_ptr++; data_len++; + XMEMCPY(data_ptr, (byte *)uf_time, ASN_UTC_TIME_SIZE - 1); + *data_ptr += ASN_UTC_TIME_SIZE - 1; + } + else if (data_len == ASN_GENERALIZED_TIME_SIZE-1) { /* increment data_len for ASN length byte after adding the data_ptr */ - *data_ptr = (byte) ASN_GENERALIZED_TIME; data_ptr++; data_len++; + *data_ptr = (byte)ASN_GENERALIZED_TIME; data_ptr++; data_len++; /* -1 below excludes null terminator */ - *data_ptr = (byte) ASN_GENERALIZED_TIME_SIZE - 1; data_ptr++; - XMEMCPY(data_ptr,(byte *)uf_time, ASN_GENERALIZED_TIME_SIZE - 1); - } else { + *data_ptr = (byte)ASN_GENERALIZED_TIME_SIZE - 1; data_ptr++; data_len++; + XMEMCPY(data_ptr, (byte*)uf_time, ASN_GENERALIZED_TIME_SIZE - 1); + *data_ptr += ASN_GENERALIZED_TIME_SIZE - 1; + } + else { WOLFSSL_MSG("Invalid time size returned"); return ASN_TIME_E; } + /* append null terminator */ + *data_ptr = 0; + /* return length without null terminator */ return data_len; } -/* return just the raw time string */ -int GetUnformattedTimeString(void* currTime, byte* buf, word32 len) +/* return just the time string as either UTC or Generalized Time*/ +int GetFormattedTime(void* currTime, byte* buf, word32 len) { struct tm* ts = NULL; struct tm* tmpTime = NULL; int year, mon, day, hour, mini, sec; - int ret_bytes_len = 0; + int ret; #if defined(NEED_TMP_TIME) struct tm tmpTimeStorage; tmpTime = &tmpTimeStorage; @@ -12259,13 +12261,13 @@ int GetUnformattedTimeString(void* currTime, byte* buf, word32 len) (void)tmpTime; #endif - WOLFSSL_ENTER("GetTimeString"); + WOLFSSL_ENTER("GetFormattedTime"); if (buf == NULL || len == 0) return BAD_FUNC_ARG; ts = (struct tm *)XGMTIME((time_t*)currTime, tmpTime); - if (ts == NULL){ + if (ts == NULL) { WOLFSSL_MSG("failed to get time data."); return ASN_TIME_E; } @@ -12277,7 +12279,8 @@ int GetUnformattedTimeString(void* currTime, byte* buf, word32 len) /* UTC Time */ if (ts->tm_year >= 50 && ts->tm_year < 100) { year = ts->tm_year; - } else if (ts->tm_year >= 100 && ts->tm_year < 150) { + } + else if (ts->tm_year >= 100 && ts->tm_year < 150) { year = ts->tm_year - 100; } else { @@ -12289,10 +12292,11 @@ int GetUnformattedTimeString(void* currTime, byte* buf, word32 len) hour = ts->tm_hour; mini = ts->tm_min; sec = ts->tm_sec; - ret_bytes_len = XSNPRINTF((char *)buf, len, - "%02d%02d%02d%02d%02d%02dZ", year, mon, day, - hour, mini, sec); - } else { + ret = XSNPRINTF((char*)buf, len, + "%02d%02d%02d%02d%02d%02dZ", year, mon, day, + hour, mini, sec); + } + else { /* GeneralizedTime */ year = ts->tm_year + 1900; mon = ts->tm_mon + 1; @@ -12300,12 +12304,12 @@ int GetUnformattedTimeString(void* currTime, byte* buf, word32 len) hour = ts->tm_hour; mini = ts->tm_min; sec = ts->tm_sec; - ret_bytes_len = XSNPRINTF((char *)buf, len, - "%4d%02d%02d%02d%02d%02dZ", year, mon, day, - hour, mini, sec); + ret = XSNPRINTF((char*)buf, len, + "%4d%02d%02d%02d%02d%02dZ", year, mon, day, + hour, mini, sec); } - return ret_bytes_len; + return ret; } #endif /* !NO_ASN_TIME && !USER_TIME && !TIME_OVERRIDES && diff --git a/wolfssl/wolfcrypt/asn.h b/wolfssl/wolfcrypt/asn.h index 17239d87e..7838fe9de 100644 --- a/wolfssl/wolfcrypt/asn.h +++ b/wolfssl/wolfcrypt/asn.h @@ -1901,7 +1901,7 @@ WOLFSSL_LOCAL int GetTimeString(byte* date, int format, char* buf, int len); #endif #if !defined(NO_ASN_TIME) && !defined(USER_TIME) && \ !defined(TIME_OVERRIDES) && (defined(OPENSSL_EXTRA) || defined(HAVE_PKCS7)) -WOLFSSL_LOCAL int GetUnformattedTimeString(void* currTime, byte* buf, word32 len); +WOLFSSL_LOCAL int GetFormattedTime(void* currTime, byte* buf, word32 len); WOLFSSL_LOCAL int GetAsnTimeString(void* currTime, byte* buf, word32 len); #endif WOLFSSL_LOCAL int ExtractDate(const unsigned char* date, unsigned char format,