Skip to content

Commit

Permalink
Fix wolfSSL_ASN1_TIME_to_generalizedtime with UTC time
Browse files Browse the repository at this point in the history
  • Loading branch information
embhorn committed Jun 18, 2024
1 parent 5efa82a commit d4a90e8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ssl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3510,14 +3510,17 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_to_generalizedtime(WOLFSSL_ASN1_TIME *t,
if (ret != NULL) {
/* Set the ASN.1 type and length of string. */
ret->type = V_ASN1_GENERALIZEDTIME;
ret->length = ASN_GENERALIZED_TIME_SIZE;

if (t->type == V_ASN1_GENERALIZEDTIME) {
ret->length = ASN_GENERALIZED_TIME_SIZE;

/* Just copy as data already appropriately formatted. */
XMEMCPY(ret->data, t->data, ASN_GENERALIZED_TIME_SIZE);
}
else {
/* Convert UTC TIME to GENERALIZED TIME. */
ret->length = t->length + 2; /* Add two extra year digits */

if (t->data[0] >= '5') {
/* >= 50 is 1900s. */
ret->data[0] = '1'; ret->data[1] = '9';
Expand All @@ -3527,7 +3530,7 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_to_generalizedtime(WOLFSSL_ASN1_TIME *t,
ret->data[0] = '2'; ret->data[1] = '0';
}
/* Append rest of the data as it is the same. */
XMEMCPY(&ret->data[2], t->data, ASN_UTC_TIME_SIZE);
XMEMCPY(&ret->data[2], t->data, t->length);
}

/* Check for pointer to return result through. */
Expand Down

0 comments on commit d4a90e8

Please sign in to comment.