mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-03 12:44:45 +02:00
Minor text and formatting cleanups.
This commit is contained in:
13
src/ssl.c
13
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;
|
const time_t sec_per_day = 24*60*60;
|
||||||
time_t t_adj = 0;
|
time_t t_adj = 0;
|
||||||
time_t offset_day_sec = 0;
|
time_t offset_day_sec = 0;
|
||||||
char time_str_buf[MAX_TIME_STRING_SZ] = {0};
|
char time_str[MAX_TIME_STRING_SZ];
|
||||||
char* time_str = time_str_buf;
|
|
||||||
int time_get;
|
int time_get;
|
||||||
|
|
||||||
WOLFSSL_ENTER("wolfSSL_ASN1_TIME_adj");
|
WOLFSSL_ENTER("wolfSSL_ASN1_TIME_adj");
|
||||||
|
|
||||||
if (s == NULL){
|
if (s == NULL) {
|
||||||
s = wolfSSL_ASN1_TIME_new();
|
s = wolfSSL_ASN1_TIME_new();
|
||||||
if (s == NULL){
|
if (s == NULL) {
|
||||||
return 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;
|
offset_day_sec = offset_day * sec_per_day;
|
||||||
t_adj = t + offset_day_sec + offset_sec;
|
t_adj = t + offset_day_sec + offset_sec;
|
||||||
|
|
||||||
/* Get UTC Time */
|
/* Get time string as either UTC or GeneralizedTime */
|
||||||
time_get = GetUnformattedTimeString(&t_adj, (byte*) time_str,
|
time_get = GetFormattedTime(&t_adj, (byte*)time_str,
|
||||||
sizeof(time_str_buf));
|
(word32)sizeof(time_str));
|
||||||
if (time_get <= 0) {
|
if (time_get <= 0) {
|
||||||
wolfSSL_ASN1_TIME_free(s);
|
wolfSSL_ASN1_TIME_free(s);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@@ -12201,7 +12201,7 @@ int GetTimeString(byte* date, int format, char* buf, int len)
|
|||||||
int GetAsnTimeString(void* currTime, byte* buf, word32 len)
|
int GetAsnTimeString(void* currTime, byte* buf, word32 len)
|
||||||
{
|
{
|
||||||
byte* data_ptr = buf;
|
byte* data_ptr = buf;
|
||||||
byte uf_time[ASN_GENERALIZED_TIME_SIZE] = {0};
|
byte uf_time[ASN_GENERALIZED_TIME_SIZE];
|
||||||
word32 data_len = 0;
|
word32 data_len = 0;
|
||||||
|
|
||||||
WOLFSSL_ENTER("GetAsnTimeString");
|
WOLFSSL_ENTER("GetAsnTimeString");
|
||||||
@@ -12209,49 +12209,51 @@ int GetAsnTimeString(void* currTime, byte* buf, word32 len)
|
|||||||
if (buf == NULL || len == 0)
|
if (buf == NULL || len == 0)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
data_len = GetUnformattedTimeString(currTime, uf_time, len);
|
XMEMSET(uf_time, 0, sizeof(uf_time));
|
||||||
/* ensure room to add 2 bytes (ASN type and length) before proceeding */
|
/* GetFormattedTime returns length with null terminator */
|
||||||
if(data_len <= 0) {
|
data_len = GetFormattedTime(currTime, uf_time, len);
|
||||||
|
if (data_len <= 0) {
|
||||||
return ASN_TIME_E;
|
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;
|
return BUFFER_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Increment by 1 for ASN type, it is critical that this increment occur
|
if (data_len == ASN_UTC_TIME_SIZE-1) {
|
||||||
* 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) {
|
|
||||||
/* increment data_len for ASN length byte after adding the data_ptr */
|
/* 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 */
|
/* -1 below excludes null terminator */
|
||||||
*data_ptr = (byte) ASN_UTC_TIME_SIZE - 1; data_ptr++;
|
*data_ptr = (byte)ASN_UTC_TIME_SIZE - 1; data_ptr++; data_len++;
|
||||||
XMEMCPY(data_ptr,(byte *)uf_time, ASN_UTC_TIME_SIZE - 1);
|
XMEMCPY(data_ptr, (byte *)uf_time, ASN_UTC_TIME_SIZE - 1);
|
||||||
} else if (data_len == ASN_GENERALIZED_TIME_SIZE) {
|
*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 */
|
/* 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 */
|
/* -1 below excludes null terminator */
|
||||||
*data_ptr = (byte) ASN_GENERALIZED_TIME_SIZE - 1; data_ptr++;
|
*data_ptr = (byte)ASN_GENERALIZED_TIME_SIZE - 1; data_ptr++; data_len++;
|
||||||
XMEMCPY(data_ptr,(byte *)uf_time, ASN_GENERALIZED_TIME_SIZE - 1);
|
XMEMCPY(data_ptr, (byte*)uf_time, ASN_GENERALIZED_TIME_SIZE - 1);
|
||||||
} else {
|
*data_ptr += ASN_GENERALIZED_TIME_SIZE - 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
WOLFSSL_MSG("Invalid time size returned");
|
WOLFSSL_MSG("Invalid time size returned");
|
||||||
return ASN_TIME_E;
|
return ASN_TIME_E;
|
||||||
}
|
}
|
||||||
|
/* append null terminator */
|
||||||
|
*data_ptr = 0;
|
||||||
|
|
||||||
|
/* return length without null terminator */
|
||||||
return data_len;
|
return data_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return just the raw time string */
|
/* return just the time string as either UTC or Generalized Time*/
|
||||||
int GetUnformattedTimeString(void* currTime, byte* buf, word32 len)
|
int GetFormattedTime(void* currTime, byte* buf, word32 len)
|
||||||
{
|
{
|
||||||
struct tm* ts = NULL;
|
struct tm* ts = NULL;
|
||||||
struct tm* tmpTime = NULL;
|
struct tm* tmpTime = NULL;
|
||||||
int year, mon, day, hour, mini, sec;
|
int year, mon, day, hour, mini, sec;
|
||||||
int ret_bytes_len = 0;
|
int ret;
|
||||||
#if defined(NEED_TMP_TIME)
|
#if defined(NEED_TMP_TIME)
|
||||||
struct tm tmpTimeStorage;
|
struct tm tmpTimeStorage;
|
||||||
tmpTime = &tmpTimeStorage;
|
tmpTime = &tmpTimeStorage;
|
||||||
@@ -12259,13 +12261,13 @@ int GetUnformattedTimeString(void* currTime, byte* buf, word32 len)
|
|||||||
(void)tmpTime;
|
(void)tmpTime;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
WOLFSSL_ENTER("GetTimeString");
|
WOLFSSL_ENTER("GetFormattedTime");
|
||||||
|
|
||||||
if (buf == NULL || len == 0)
|
if (buf == NULL || len == 0)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
ts = (struct tm *)XGMTIME((time_t*)currTime, tmpTime);
|
ts = (struct tm *)XGMTIME((time_t*)currTime, tmpTime);
|
||||||
if (ts == NULL){
|
if (ts == NULL) {
|
||||||
WOLFSSL_MSG("failed to get time data.");
|
WOLFSSL_MSG("failed to get time data.");
|
||||||
return ASN_TIME_E;
|
return ASN_TIME_E;
|
||||||
}
|
}
|
||||||
@@ -12277,7 +12279,8 @@ int GetUnformattedTimeString(void* currTime, byte* buf, word32 len)
|
|||||||
/* UTC Time */
|
/* UTC Time */
|
||||||
if (ts->tm_year >= 50 && ts->tm_year < 100) {
|
if (ts->tm_year >= 50 && ts->tm_year < 100) {
|
||||||
year = ts->tm_year;
|
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;
|
year = ts->tm_year - 100;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -12289,10 +12292,11 @@ int GetUnformattedTimeString(void* currTime, byte* buf, word32 len)
|
|||||||
hour = ts->tm_hour;
|
hour = ts->tm_hour;
|
||||||
mini = ts->tm_min;
|
mini = ts->tm_min;
|
||||||
sec = ts->tm_sec;
|
sec = ts->tm_sec;
|
||||||
ret_bytes_len = XSNPRINTF((char *)buf, len,
|
ret = XSNPRINTF((char*)buf, len,
|
||||||
"%02d%02d%02d%02d%02d%02dZ", year, mon, day,
|
"%02d%02d%02d%02d%02d%02dZ", year, mon, day,
|
||||||
hour, mini, sec);
|
hour, mini, sec);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* GeneralizedTime */
|
/* GeneralizedTime */
|
||||||
year = ts->tm_year + 1900;
|
year = ts->tm_year + 1900;
|
||||||
mon = ts->tm_mon + 1;
|
mon = ts->tm_mon + 1;
|
||||||
@@ -12300,12 +12304,12 @@ int GetUnformattedTimeString(void* currTime, byte* buf, word32 len)
|
|||||||
hour = ts->tm_hour;
|
hour = ts->tm_hour;
|
||||||
mini = ts->tm_min;
|
mini = ts->tm_min;
|
||||||
sec = ts->tm_sec;
|
sec = ts->tm_sec;
|
||||||
ret_bytes_len = XSNPRINTF((char *)buf, len,
|
ret = XSNPRINTF((char*)buf, len,
|
||||||
"%4d%02d%02d%02d%02d%02dZ", year, mon, day,
|
"%4d%02d%02d%02d%02d%02dZ", year, mon, day,
|
||||||
hour, mini, sec);
|
hour, mini, sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret_bytes_len;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !NO_ASN_TIME && !USER_TIME && !TIME_OVERRIDES &&
|
#endif /* !NO_ASN_TIME && !USER_TIME && !TIME_OVERRIDES &&
|
||||||
|
@@ -1901,7 +1901,7 @@ WOLFSSL_LOCAL int GetTimeString(byte* date, int format, char* buf, int len);
|
|||||||
#endif
|
#endif
|
||||||
#if !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
|
#if !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
|
||||||
!defined(TIME_OVERRIDES) && (defined(OPENSSL_EXTRA) || defined(HAVE_PKCS7))
|
!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);
|
WOLFSSL_LOCAL int GetAsnTimeString(void* currTime, byte* buf, word32 len);
|
||||||
#endif
|
#endif
|
||||||
WOLFSSL_LOCAL int ExtractDate(const unsigned char* date, unsigned char format,
|
WOLFSSL_LOCAL int ExtractDate(const unsigned char* date, unsigned char format,
|
||||||
|
Reference in New Issue
Block a user