mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-03 20:54:41 +02:00
Merge pull request #4288 from julek-wolfssl/get-date-from-cert
Add a test/example for parsing the date from a certificate
This commit is contained in:
@@ -15373,6 +15373,12 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void)
|
|||||||
#else
|
#else
|
||||||
DecodedCert cert[1];
|
DecodedCert cert[1];
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef NO_ASN_TIME
|
||||||
|
struct tm timearg;
|
||||||
|
const byte* date;
|
||||||
|
byte dateFormat;
|
||||||
|
int dateLength;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
|
DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
|
||||||
@@ -15748,15 +15754,28 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void)
|
|||||||
#ifdef sizeof
|
#ifdef sizeof
|
||||||
#undef sizeof
|
#undef sizeof
|
||||||
#endif
|
#endif
|
||||||
|
InitDecodedCert(cert, tmp, (word32)bytes, NULL);
|
||||||
|
|
||||||
InitDecodedCert(cert, tmp, (word32)bytes, 0);
|
ret = ParseCert(cert, CERT_TYPE, NO_VERIFY, NULL);
|
||||||
|
|
||||||
ret = ParseCert(cert, CERT_TYPE, NO_VERIFY, 0);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
FreeDecodedCert(cert);
|
FreeDecodedCert(cert);
|
||||||
ERROR_OUT(-7942, exit_rsa);
|
ERROR_OUT(-7942, exit_rsa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NO_ASN_TIME
|
||||||
|
ret = wc_GetDateInfo(cert->afterDate, cert->afterDateLen, &date,
|
||||||
|
&dateFormat, &dateLength);
|
||||||
|
if (ret != 0) {
|
||||||
|
FreeDecodedCert(cert);
|
||||||
|
ERROR_OUT(-7943, exit_rsa);
|
||||||
|
}
|
||||||
|
ret = wc_GetDateAsCalendarTime(date, dateLength, dateFormat, &timearg);
|
||||||
|
if (ret != 0) {
|
||||||
|
FreeDecodedCert(cert);
|
||||||
|
ERROR_OUT(-7944, exit_rsa);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
FreeDecodedCert(cert);
|
FreeDecodedCert(cert);
|
||||||
#endif /* WOLFSSL_TEST_CERT */
|
#endif /* WOLFSSL_TEST_CERT */
|
||||||
|
|
||||||
@@ -15779,7 +15798,7 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void)
|
|||||||
if (!file) {
|
if (!file) {
|
||||||
err_sys("can't open ./certs/client-keyPub.der, "
|
err_sys("can't open ./certs/client-keyPub.der, "
|
||||||
"Please run from wolfSSL home dir", -40);
|
"Please run from wolfSSL home dir", -40);
|
||||||
ERROR_OUT(-7943, exit_rsa);
|
ERROR_OUT(-7945, exit_rsa);
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = XFREAD(tmp, 1, FOURK_BUF, file);
|
bytes = XFREAD(tmp, 1, FOURK_BUF, file);
|
||||||
@@ -15788,13 +15807,13 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void)
|
|||||||
|
|
||||||
ret = wc_InitRsaKey(keypub, HEAP_HINT);
|
ret = wc_InitRsaKey(keypub, HEAP_HINT);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ERROR_OUT(-7944, exit_rsa);
|
ERROR_OUT(-7946, exit_rsa);
|
||||||
}
|
}
|
||||||
idx = 0;
|
idx = 0;
|
||||||
|
|
||||||
ret = wc_RsaPublicKeyDecode(tmp, &idx, keypub, (word32)bytes);
|
ret = wc_RsaPublicKeyDecode(tmp, &idx, keypub, (word32)bytes);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ERROR_OUT(-7945, exit_rsa);
|
ERROR_OUT(-7947, exit_rsa);
|
||||||
}
|
}
|
||||||
#endif /* WOLFSSL_CERT_EXT */
|
#endif /* WOLFSSL_CERT_EXT */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user