@@ -13743,11 +13743,34 @@ static int CopyREQAttributes(WOLFSSL_X509* x509, DecodedCert* dCert)
1374313743}
1374413744#endif /* WOLFSSL_CERT_REQ */
1374513745
13746+ /* Copy an ASN-encoded date (type + length + data) into a WOLFSSL_ASN1_TIME.
13747+ * srcDate: ASN date buffer where [0]=type, [1]=length, [2..]=date bytes.
13748+ * srcDateLen: total length of srcDate (0 means no date present). */
13749+ static void CopyDateToASN1_TIME(const byte* srcDate, int srcDateLen,
13750+ WOLFSSL_ASN1_TIME* dst)
13751+ {
13752+ if (srcDateLen >= 2) {
13753+ /* Clamp the date length to the maximum allowed size.
13754+ * This needs to match the size of WOLFSSL_ASN1_TIME minus the
13755+ * the type and length fields. */
13756+ const int maxSz = CTC_DATE_SIZE - 2;
13757+ const int copySz = (int)min(srcDate[1], maxSz);
13758+ dst->type = srcDate[0];
13759+ dst->length = copySz;
13760+ XMEMCPY(dst->data, &srcDate[2], copySz);
13761+ }
13762+ else {
13763+ dst->length = 0;
13764+ }
13765+ }
13766+
1374613767/* Copy parts X509 needs from Decoded cert, 0 on success */
1374713768int CopyDecodedToX509(WOLFSSL_X509* x509, DecodedCert* dCert)
1374813769{
1374913770 int ret = 0;
13771+ #ifdef WOLFSSL_SEP
1375013772 int minSz;
13773+ #endif
1375113774
1375213775 if (x509 == NULL || dCert == NULL ||
1375313776 dCert->subjectCNLen < 0)
@@ -13820,22 +13843,10 @@ int CopyDecodedToX509(WOLFSSL_X509* x509, DecodedCert* dCert)
1382013843 x509->hwSerialNumSz = 0;
1382113844#endif /* WOLFSSL_SEP */
1382213845
13823- if (dCert->beforeDateLen > 0) {
13824- minSz = (int)min(dCert->beforeDate[1], MAX_DATE_SZ);
13825- x509->notBefore.type = dCert->beforeDate[0];
13826- x509->notBefore.length = minSz;
13827- XMEMCPY(x509->notBefore.data, &dCert->beforeDate[2], minSz);
13828- }
13829- else
13830- x509->notBefore.length = 0;
13831- if (dCert->afterDateLen > 0) {
13832- minSz = (int)min(dCert->afterDate[1], MAX_DATE_SZ);
13833- x509->notAfter.type = dCert->afterDate[0];
13834- x509->notAfter.length = minSz;
13835- XMEMCPY(x509->notAfter.data, &dCert->afterDate[2], minSz);
13836- }
13837- else
13838- x509->notAfter.length = 0;
13846+ CopyDateToASN1_TIME(dCert->beforeDate, dCert->beforeDateLen,
13847+ &x509->notBefore);
13848+ CopyDateToASN1_TIME(dCert->afterDate, dCert->afterDateLen,
13849+ &x509->notAfter);
1383913850
1384013851 if (dCert->publicKey != NULL && dCert->pubKeySize != 0) {
1384113852 x509->pubKey.buffer = (byte*)XMALLOC(
@@ -14217,29 +14228,10 @@ int CopyDecodedAcertToX509(WOLFSSL_X509_ACERT* x509, DecodedAcert* dAcert)
1421714228 }
1421814229
1421914230 /* Copy before and after dates. */
14220- {
14221- int minSz = 0;
14222-
14223- if (dAcert->beforeDateLen > 0) {
14224- minSz = (int)min(dAcert->beforeDate[1], MAX_DATE_SZ);
14225- x509->notBefore.type = dAcert->beforeDate[0];
14226- x509->notBefore.length = minSz;
14227- XMEMCPY(x509->notBefore.data, &dAcert->beforeDate[2], minSz);
14228- }
14229- else {
14230- x509->notBefore.length = 0;
14231- }
14232-
14233- if (dAcert->afterDateLen > 0) {
14234- minSz = (int)min(dAcert->afterDate[1], MAX_DATE_SZ);
14235- x509->notAfter.type = dAcert->afterDate[0];
14236- x509->notAfter.length = minSz;
14237- XMEMCPY(x509->notAfter.data, &dAcert->afterDate[2], minSz);
14238- }
14239- else {
14240- x509->notAfter.length = 0;
14241- }
14242- }
14231+ CopyDateToASN1_TIME(dAcert->beforeDate, dAcert->beforeDateLen,
14232+ &x509->notBefore);
14233+ CopyDateToASN1_TIME(dAcert->afterDate, dAcert->afterDateLen,
14234+ &x509->notAfter);
1424314235
1424414236 /* Copy the signature. */
1424514237 if (dAcert->signature != NULL && dAcert->sigLength != 0 &&
0 commit comments