@@ -13752,11 +13752,34 @@ static int CopyREQAttributes(WOLFSSL_X509* x509, DecodedCert* dCert)
1375213752}
1375313753#endif /* WOLFSSL_CERT_REQ */
1375413754
13755+ /* Copy an ASN-encoded date (type + length + data) into a WOLFSSL_ASN1_TIME.
13756+ * srcDate: ASN date buffer where [0]=type, [1]=length, [2..]=date bytes.
13757+ * srcDateLen: total length of srcDate (0 means no date present). */
13758+ static void CopyDateToASN1_TIME(const byte* srcDate, int srcDateLen,
13759+ WOLFSSL_ASN1_TIME* dst)
13760+ {
13761+ if (srcDateLen >= 2) {
13762+ /* Clamp the date length to the maximum allowed size.
13763+ * This needs to match the size of WOLFSSL_ASN1_TIME minus the
13764+ * the type and length fields. */
13765+ const int maxSz = CTC_DATE_SIZE - 2;
13766+ const int copySz = (int)min(srcDate[1], maxSz);
13767+ dst->type = srcDate[0];
13768+ dst->length = copySz;
13769+ XMEMCPY(dst->data, &srcDate[2], copySz);
13770+ }
13771+ else {
13772+ dst->length = 0;
13773+ }
13774+ }
13775+
1375513776/* Copy parts X509 needs from Decoded cert, 0 on success */
1375613777int CopyDecodedToX509(WOLFSSL_X509* x509, DecodedCert* dCert)
1375713778{
1375813779 int ret = 0;
13780+ #ifdef WOLFSSL_SEP
1375913781 int minSz;
13782+ #endif
1376013783
1376113784 if (x509 == NULL || dCert == NULL ||
1376213785 dCert->subjectCNLen < 0)
@@ -13829,22 +13852,10 @@ int CopyDecodedToX509(WOLFSSL_X509* x509, DecodedCert* dCert)
1382913852 x509->hwSerialNumSz = 0;
1383013853#endif /* WOLFSSL_SEP */
1383113854
13832- if (dCert->beforeDateLen > 0) {
13833- minSz = (int)min(dCert->beforeDate[1], MAX_DATE_SZ);
13834- x509->notBefore.type = dCert->beforeDate[0];
13835- x509->notBefore.length = minSz;
13836- XMEMCPY(x509->notBefore.data, &dCert->beforeDate[2], minSz);
13837- }
13838- else
13839- x509->notBefore.length = 0;
13840- if (dCert->afterDateLen > 0) {
13841- minSz = (int)min(dCert->afterDate[1], MAX_DATE_SZ);
13842- x509->notAfter.type = dCert->afterDate[0];
13843- x509->notAfter.length = minSz;
13844- XMEMCPY(x509->notAfter.data, &dCert->afterDate[2], minSz);
13845- }
13846- else
13847- x509->notAfter.length = 0;
13855+ CopyDateToASN1_TIME(dCert->beforeDate, dCert->beforeDateLen,
13856+ &x509->notBefore);
13857+ CopyDateToASN1_TIME(dCert->afterDate, dCert->afterDateLen,
13858+ &x509->notAfter);
1384813859
1384913860 if (dCert->publicKey != NULL && dCert->pubKeySize != 0) {
1385013861 x509->pubKey.buffer = (byte*)XMALLOC(
@@ -14226,29 +14237,10 @@ int CopyDecodedAcertToX509(WOLFSSL_X509_ACERT* x509, DecodedAcert* dAcert)
1422614237 }
1422714238
1422814239 /* Copy before and after dates. */
14229- {
14230- int minSz = 0;
14231-
14232- if (dAcert->beforeDateLen > 0) {
14233- minSz = (int)min(dAcert->beforeDate[1], MAX_DATE_SZ);
14234- x509->notBefore.type = dAcert->beforeDate[0];
14235- x509->notBefore.length = minSz;
14236- XMEMCPY(x509->notBefore.data, &dAcert->beforeDate[2], minSz);
14237- }
14238- else {
14239- x509->notBefore.length = 0;
14240- }
14241-
14242- if (dAcert->afterDateLen > 0) {
14243- minSz = (int)min(dAcert->afterDate[1], MAX_DATE_SZ);
14244- x509->notAfter.type = dAcert->afterDate[0];
14245- x509->notAfter.length = minSz;
14246- XMEMCPY(x509->notAfter.data, &dAcert->afterDate[2], minSz);
14247- }
14248- else {
14249- x509->notAfter.length = 0;
14250- }
14251- }
14240+ CopyDateToASN1_TIME(dAcert->beforeDate, dAcert->beforeDateLen,
14241+ &x509->notBefore);
14242+ CopyDateToASN1_TIME(dAcert->afterDate, dAcert->afterDateLen,
14243+ &x509->notAfter);
1425214244
1425314245 /* Copy the signature. */
1425414246 if (dAcert->signature != NULL && dAcert->sigLength != 0 &&
0 commit comments