diff --git a/tests/data_files/Makefile b/tests/data_files/Makefile index 14cf5ae8da..8ec84c1049 100644 --- a/tests/data_files/Makefile +++ b/tests/data_files/Makefile @@ -556,8 +556,8 @@ authorityKeyId_subjectKeyId.crt.der: authorityKeyId_no_keyid.crt.der: $(OPENSSL) req -x509 -nodes -days 7300 -key server2.key -outform DER -out $@ -config authorityKeyId_subjectKeyId.conf -extensions 'v3_req_authorityKeyId_no_keyid' -authorityKeyId_no_issuer_serial.crt.der: - $(OPENSSL) req -x509 -nodes -days 7300 -key server2.key -outform DER -out $@ -config authorityKeyId_subjectKeyId.conf -extensions 'v3_req_authorityKeyId_no_issuer_serial' +authorityKeyId_no_authorityKeyId.crt.der: + $(OPENSSL) req -x509 -nodes -days 7300 -key server2.key -outform DER -out $@ -config authorityKeyId_subjectKeyId.conf -extensions 'v3_req_no_authorityKeyId' authorityKeyId_empty.crt.der: $(OPENSSL) req -x509 -nodes -days 7300 -key server2.key -outform DER -out $@ -config authorityKeyId_subjectKeyId.conf -extensions 'v3_req_authorityKeyId_empty' diff --git a/tests/data_files/authorityKeyId_no_authorityKeyId.crt.der b/tests/data_files/authorityKeyId_no_authorityKeyId.crt.der new file mode 100644 index 0000000000..452d9d135d Binary files /dev/null and b/tests/data_files/authorityKeyId_no_authorityKeyId.crt.der differ diff --git a/tests/data_files/authorityKeyId_no_issuer_serial.crt.der b/tests/data_files/authorityKeyId_no_issuer_serial.crt.der deleted file mode 100644 index 19c3c4976c..0000000000 Binary files a/tests/data_files/authorityKeyId_no_issuer_serial.crt.der and /dev/null differ diff --git a/tests/data_files/authorityKeyId_subjectKeyId.conf b/tests/data_files/authorityKeyId_subjectKeyId.conf index 7237724c1f..94ab20e15b 100644 --- a/tests/data_files/authorityKeyId_subjectKeyId.conf +++ b/tests/data_files/authorityKeyId_subjectKeyId.conf @@ -12,7 +12,7 @@ authorityKeyIdentifier = keyid:always,issuer:always [v3_req_authorityKeyId_no_keyid] subjectKeyIdentifier = hash authorityKeyIdentifier = issuer:always -[v3_req_authorityKeyId_no_issuer_serial] +[v3_req_no_authorityKeyId] subjectKeyIdentifier = hash [v3_req_authorityKeyId_empty] subjectKeyIdentifier = hash diff --git a/tests/suites/test_suite_x509parse.data b/tests/suites/test_suite_x509parse.data index 365a58c548..e6d2c534d3 100644 --- a/tests/suites/test_suite_x509parse.data +++ b/tests/suites/test_suite_x509parse.data @@ -3309,7 +3309,7 @@ X509 CRT parse Subject Key Id - Wrong OCTET_STRING tag depends_on:MBEDTLS_MD_CAN_SHA256:MBEDTLS_RSA_C x509_crt_parse_subjectkeyid:"data_files/authorityKeyId_subjectKeyId_tag_malformed.crt.der":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS+MBEDTLS_ERR_ASN1_UNEXPECTED_TAG -X509 CRT parse Subject Key Id - Wrong OCTET_STRING tag +X509 CRT parse Subject Key Id - Wrong OCTET_STRING length depends_on:MBEDTLS_MD_CAN_SHA256:MBEDTLS_RSA_C x509_crt_parse_subjectkeyid:"data_files/authorityKeyId_subjectKeyId_tag_len_malformed.crt.der":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS+MBEDTLS_ERR_ASN1_LENGTH_MISMATCH @@ -3321,9 +3321,9 @@ X509 CRT parse Authority Key Id - Correct Authority Key ID (no keyid) depends_on:MBEDTLS_MD_CAN_SHA256:MBEDTLS_RSA_C x509_crt_parse_authoritykeyid:"data_files/authorityKeyId_no_keyid.crt.der":"":"NL/PolarSSL/PolarSSL Test CA/":"7581F2D168FE33F964F0AE5FE884FAD3C55F24DA":0 -X509 CRT parse Authority Key Id - Correct Authority Key ID (no issuer and serial) +X509 CRT parse Authority Key Id - no Authority Key ID depends_on:MBEDTLS_MD_CAN_SHA256:MBEDTLS_RSA_C -x509_crt_parse_authoritykeyid:"data_files/authorityKeyId_no_issuer_serial.crt.der":"A505E864B8DCDF600F50124D60A864AF4D8B4393":"":"":0 +x509_crt_parse_authoritykeyid:"data_files/authorityKeyId_no_authorityKeyId.crt.der":"":"":"":0 X509 CRT parse Authority Key Id - Correct Authority Key ID (empty) depends_on:MBEDTLS_MD_CAN_SHA256:MBEDTLS_RSA_C @@ -3345,11 +3345,11 @@ X509 CRT parse Authority Key Id - Wrong KeyId Tag Length depends_on:MBEDTLS_MD_CAN_SHA256:MBEDTLS_RSA_C x509_crt_parse_authoritykeyid:"data_files/authorityKeyId_subjectKeyId_keyid_tag_len_malformed.crt.der":"":"":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS+MBEDTLS_ERR_ASN1_INVALID_LENGTH -X509 CRT parse Authority Key Id - Wrong Issuer Tag 1 +X509 CRT parse Authority Key Id - Wrong Issuer Tag depends_on:MBEDTLS_MD_CAN_SHA256:MBEDTLS_RSA_C x509_crt_parse_authoritykeyid:"data_files/authorityKeyId_subjectKeyId_issuer_tag1_malformed.crt.der":"":"":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS+MBEDTLS_ERR_ASN1_UNEXPECTED_TAG -X509 CRT parse Authority Key Id - Wrong Issuer Tag 2 +X509 CRT parse Authority Key Id - Wrong DirectoryName tag in issuer field depends_on:MBEDTLS_MD_CAN_SHA256:MBEDTLS_RSA_C x509_crt_parse_authoritykeyid:"data_files/authorityKeyId_subjectKeyId_issuer_tag2_malformed.crt.der":"":"":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS+MBEDTLS_ERR_ASN1_UNEXPECTED_TAG diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function index 4c938b3e4e..7163632a89 100644 --- a/tests/suites/test_suite_x509parse.function +++ b/tests/suites/test_suite_x509parse.function @@ -1549,7 +1549,7 @@ exit: } /* END_CASE */ -/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ +/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */ void x509_crt_parse_subjectkeyid(char *file, data_t *subjectKeyId, int ref_ret) { mbedtls_x509_crt crt; @@ -1572,7 +1572,7 @@ exit: } /* END_CASE */ -/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ +/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */ void x509_crt_parse_authoritykeyid(char *file, data_t* keyId, char *authorityKeyId_issuer, @@ -1592,15 +1592,19 @@ void x509_crt_parse_authoritykeyid(char *file, if (ref_ret == 0) { /* KeyId test */ - if (crt.authority_key_id.keyIdentifier.len > 0) + if (keyId->len > 0) { TEST_EQUAL(crt.authority_key_id.keyIdentifier.tag, MBEDTLS_ASN1_OCTET_STRING); TEST_EQUAL(memcmp(crt.authority_key_id.keyIdentifier.p, keyId->x, keyId->len), 0); TEST_EQUAL(crt.authority_key_id.keyIdentifier.len, keyId->len); + } else { + TEST_EQUAL(crt.authority_key_id.keyIdentifier.tag, 0); + TEST_EQUAL(crt.authority_key_id.keyIdentifier.len, 0); } + /* Issuer test */ - if (crt.authority_key_id.authorityCertIssuer.buf.len > 0) + if (strlen(authorityKeyId_issuer) > 0) { mbedtls_x509_sequence *issuerPtr = &crt.authority_key_id.authorityCertIssuer; @@ -1621,13 +1625,16 @@ void x509_crt_parse_authoritykeyid(char *file, } /* Serial test */ - if (crt.authority_key_id.authorityCertSerialNumber.len > 0) + if (serial->len > 0) { TEST_EQUAL(crt.authority_key_id.authorityCertSerialNumber.tag, MBEDTLS_ASN1_INTEGER); TEST_EQUAL(memcmp(crt.authority_key_id.authorityCertSerialNumber.p, serial->x, serial->len), 0); TEST_EQUAL(crt.authority_key_id.authorityCertSerialNumber.len, serial->len); + } else { + TEST_EQUAL(crt.authority_key_id.authorityCertSerialNumber.tag, 0); + TEST_EQUAL(crt.authority_key_id.authorityCertSerialNumber.len, 0); } } else {