From 8c5c5defbf0f4b7536abfb41d6b1b6a24577672a Mon Sep 17 00:00:00 2001 From: Ooohui Date: Tue, 10 Dec 2024 20:39:42 +0800 Subject: [PATCH 10/10] Rename get time cmd Cherry-picked from: https://gitcode.com/openHiTLS/openhitls/merge_requests/97 --- include/pki/hitls_pki.h | 22 ++++++++++--------- pki/x509_cert/src/hitls_x509_cert.c | 4 ++-- .../pki/cert/test_suite_sdv_x509_cert.c | 4 ++-- .../pki/common/test_suite_sdv_common.c | 4 ++-- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/pki/hitls_pki.h b/include/pki/hitls_pki.h index a570e6d..de21f07 100644 --- a/include/pki/hitls_pki.h +++ b/include/pki/hitls_pki.h @@ -77,8 +77,8 @@ typedef enum { HITLS_X509_GET_SUBJECT_DN_STR, /** Get the subject distinguished name as a formatted string */ HITLS_X509_GET_ISSUER_DN_STR, /** Get the issuer distinguished name as a formatted string */ HITLS_X509_GET_SERIALNUM_STR, /** Get the serial number as a string */ - HITLS_X509_GET_BEFORE_TIME, /** Get the validity start time as a string */ - HITLS_X509_GET_AFTER_TIME, /** Get the validity end time as a string */ + HITLS_X509_GET_BEFORE_TIME_STR, /** Get the validity start time as a string */ + HITLS_X509_GET_AFTER_TIME_STR, /** Get the validity end time as a string */ HITLS_X509_GET_SUBJECT_DN, /** Get the list of subject distinguished name components. Note: The list is read-only and should not be modified. */ HITLS_X509_GET_ISSUER_DN, /** Get the list of issuer distinguished name components. @@ -86,6 +86,8 @@ typedef enum { HITLS_X509_GET_VERSION, /** Get the version from cert or crl. */ HITLS_X509_GET_REVOKELIST, /** Get the certficate revoke list from the crl. */ HITLS_X509_GET_SERIALNUM, /** Get the serial number of the cert. */ + HITLS_X509_GET_BEFORE_TIME, /** Get the validity start time */ + HITLS_X509_GET_AFTER_TIME, /** Get the validity end time */ HITLS_X509_SET_VERSION = 0x0200, /** Set the version for the cert. */ HITLS_X509_SET_SERIALNUM, /** Set the serial number for the cert, the length range is 1 to 20. */ @@ -93,7 +95,7 @@ typedef enum { HITLS_X509_SET_AFTER_TIME, /** Set the after time for the cert. */ HITLS_X509_SET_PUBKEY, /** Set the public key for the cert/csr. */ HITLS_X509_SET_SUBJECT_DN, /** Set the subject name list. */ - HITLS_X509_SET_ISSUER_DN, /** Set the issuer name list. */ + HITLS_X509_SET_ISSUER_DN, /** Set the issuer name list. */ HITLS_X509_SET_CSR_EXT, /** Replace the cert's ext with csr's */ HITLS_X509_ADD_SUBJECT_NAME, /** Add the subject name for the cert/csr. */ HITLS_X509_CRL_ADD_REVOKED_CERT, /** Add the revoke cert to crl. */ @@ -103,13 +105,13 @@ typedef enum { HITLS_X509_EXT_KU_CERTSIGN, /** Check if certificate signing usage is set in key usage extension */ HITLS_X509_EXT_KU_KEYAGREEMENT, /** Check if key agreement usage is set in key usage extension */ - HITLS_X509_EXT_SET_SKI = 0x0400, /** Set the subject key identifier extension. */ - HITLS_X509_EXT_SET_AKI, /** Set the authority key identifier extension. */ - HITLS_X509_EXT_SET_KUSAGE, /** Set the key usage extension. */ - HITLS_X509_EXT_SET_SAN, /** Set the subject alternative name extension. */ - HITLS_X509_EXT_SET_BCONS, /** Set the basic constraints extension. */ - HITLS_X509_EXT_SET_EXKUSAGE, /** Set the extended key usage extension. */ - HITLS_X509_EXT_SET_CRLNUMBER, /** Set the crlnumber extension. */ + HITLS_X509_EXT_SET_SKI = 0x0400, /** Set the subject key identifier extension. */ + HITLS_X509_EXT_SET_AKI, /** Set the authority key identifier extension. */ + HITLS_X509_EXT_SET_KUSAGE, /** Set the key usage extension. */ + HITLS_X509_EXT_SET_SAN, /** Set the subject alternative name extension. */ + HITLS_X509_EXT_SET_BCONS, /** Set the basic constraints extension. */ + HITLS_X509_EXT_SET_EXKUSAGE, /** Set the extended key usage extension. */ + HITLS_X509_EXT_SET_CRLNUMBER, /** Set the crlnumber extension. */ HITLS_X509_EXT_GET_SKI = 0x0500, /** Get Subject Key Identifier from extensions. Note: Kid is a shallow copy. */ diff --git a/pki/x509_cert/src/hitls_x509_cert.c b/pki/x509_cert/src/hitls_x509_cert.c index 707341b..38316c5 100644 --- a/pki/x509_cert/src/hitls_x509_cert.c +++ b/pki/x509_cert/src/hitls_x509_cert.c @@ -616,9 +616,9 @@ static int32_t X509_CertGetCtrl(HITLS_X509_Cert *cert, int32_t cmd, void *val, i return X509_GetSerialNumStr(cert, val); case HITLS_X509_GET_SERIALNUM: return HITLS_X509_GetSerial(&cert->tbs.serialNum, val, valLen); - case HITLS_X509_GET_BEFORE_TIME: + case HITLS_X509_GET_BEFORE_TIME_STR: return X509_GetAsn1BslTimeStr(cert, val, HITLS_X509_BEFORE_TIME); - case HITLS_X509_GET_AFTER_TIME: + case HITLS_X509_GET_AFTER_TIME_STR: return X509_GetAsn1BslTimeStr(cert, val, HITLS_X509_AFTER_TIME); default: BSL_ERR_PUSH_ERROR(HITLS_X509_ERR_INVALID_PARAM); diff --git a/testcode/sdv/testcase/pki/cert/test_suite_sdv_x509_cert.c b/testcode/sdv/testcase/pki/cert/test_suite_sdv_x509_cert.c index 51ae228..3d9dd6a 100644 --- a/testcode/sdv/testcase/pki/cert/test_suite_sdv_x509_cert.c +++ b/testcode/sdv/testcase/pki/cert/test_suite_sdv_x509_cert.c @@ -483,12 +483,12 @@ void SDV_X509_CERT_CTRL_FUNC_TC002(char *path, char *expectedSerialNum, char *ex ASSERT_EQ(serialNum.dataLen, strlen(expectedSerialNum)); ASSERT_EQ(strcmp((char *)serialNum.data, expectedSerialNum), 0); - ASSERT_EQ(HITLS_X509_CertCtrl(cert, HITLS_X509_GET_BEFORE_TIME, &beforeTime, sizeof(BSL_Buffer)), 0); + ASSERT_EQ(HITLS_X509_CertCtrl(cert, HITLS_X509_GET_BEFORE_TIME_STR, &beforeTime, sizeof(BSL_Buffer)), 0); ASSERT_NE(beforeTime.data, NULL); ASSERT_EQ(beforeTime.dataLen, strlen(expectedBeforeTime)); ASSERT_EQ(strcmp((char *)beforeTime.data, expectedBeforeTime), 0); - ASSERT_EQ(HITLS_X509_CertCtrl(cert, HITLS_X509_GET_AFTER_TIME, &afterTime, sizeof(BSL_Buffer)), 0); + ASSERT_EQ(HITLS_X509_CertCtrl(cert, HITLS_X509_GET_AFTER_TIME_STR, &afterTime, sizeof(BSL_Buffer)), 0); ASSERT_NE(afterTime.data, NULL); ASSERT_EQ (afterTime.dataLen, strlen(expectedAfterTime)); ASSERT_EQ(strcmp((char *)afterTime.data, expectedAfterTime), 0); diff --git a/testcode/sdv/testcase/pki/common/test_suite_sdv_common.c b/testcode/sdv/testcase/pki/common/test_suite_sdv_common.c index 792ab2d..e741064 100644 --- a/testcode/sdv/testcase/pki/common/test_suite_sdv_common.c +++ b/testcode/sdv/testcase/pki/common/test_suite_sdv_common.c @@ -194,8 +194,8 @@ void SDV_HITLS_X509_CtrlCert_TC001(void) ASSERT_EQ(HITLS_X509_CertCtrl(&cert, HITLS_X509_GET_SUBJECT_DN_STR, NULL, 0), HITLS_X509_ERR_INVALID_PARAM); ASSERT_EQ(HITLS_X509_CertCtrl(&cert, HITLS_X509_GET_ISSUER_DN_STR, NULL, 0), HITLS_X509_ERR_INVALID_PARAM); ASSERT_EQ(HITLS_X509_CertCtrl(&cert, HITLS_X509_GET_SERIALNUM, NULL, 0), HITLS_X509_ERR_INVALID_PARAM); - ASSERT_EQ(HITLS_X509_CertCtrl(&cert, HITLS_X509_GET_BEFORE_TIME, NULL, 0), HITLS_X509_ERR_INVALID_PARAM); - ASSERT_EQ(HITLS_X509_CertCtrl(&cert, HITLS_X509_GET_AFTER_TIME, NULL, 0), HITLS_X509_ERR_INVALID_PARAM); + ASSERT_EQ(HITLS_X509_CertCtrl(&cert, HITLS_X509_GET_BEFORE_TIME_STR, NULL, 0), HITLS_X509_ERR_INVALID_PARAM); + ASSERT_EQ(HITLS_X509_CertCtrl(&cert, HITLS_X509_GET_AFTER_TIME_STR, NULL, 0), HITLS_X509_ERR_INVALID_PARAM); exit: BSL_GLOBAL_DeInit(); } -- 2.42.0.windows.2