Skip to content

Commit d4a90e8

Browse files
committed
Fix wolfSSL_ASN1_TIME_to_generalizedtime with UTC time
1 parent 5efa82a commit d4a90e8

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/ssl_asn1.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3510,14 +3510,17 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_to_generalizedtime(WOLFSSL_ASN1_TIME *t,
35103510
if (ret != NULL) {
35113511
/* Set the ASN.1 type and length of string. */
35123512
ret->type = V_ASN1_GENERALIZEDTIME;
3513-
ret->length = ASN_GENERALIZED_TIME_SIZE;
35143513

35153514
if (t->type == V_ASN1_GENERALIZEDTIME) {
3515+
ret->length = ASN_GENERALIZED_TIME_SIZE;
3516+
35163517
/* Just copy as data already appropriately formatted. */
35173518
XMEMCPY(ret->data, t->data, ASN_GENERALIZED_TIME_SIZE);
35183519
}
35193520
else {
35203521
/* Convert UTC TIME to GENERALIZED TIME. */
3522+
ret->length = t->length + 2; /* Add two extra year digits */
3523+
35213524
if (t->data[0] >= '5') {
35223525
/* >= 50 is 1900s. */
35233526
ret->data[0] = '1'; ret->data[1] = '9';
@@ -3527,7 +3530,7 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_to_generalizedtime(WOLFSSL_ASN1_TIME *t,
35273530
ret->data[0] = '2'; ret->data[1] = '0';
35283531
}
35293532
/* Append rest of the data as it is the same. */
3530-
XMEMCPY(&ret->data[2], t->data, ASN_UTC_TIME_SIZE);
3533+
XMEMCPY(&ret->data[2], t->data, t->length);
35313534
}
35323535

35333536
/* Check for pointer to return result through. */

0 commit comments

Comments
 (0)