mbedtls/tests/suites
Hanno Becker 19557c2078 Always return a high-level error code from X.509 module
Some functions within the X.509 module return an ASN.1 low level
error code where instead this error code should be wrapped by a
high-level X.509 error code as in the bulk of the module.

Specifically, the following functions are affected:
- mbedtls_x509_get_ext()
- x509_get_version()
- x509_get_uid()

This commit modifies these functions to always return an
X.509 high level error code.

Care has to be taken when adapting `mbetls_x509_get_ext()`:
Currently, the callers `mbedtls_x509_crt_ext()` treat the
return code `MBEDTLS_ERR_ASN1_UNEXPECTED_TAG` specially to
gracefully detect and continue if the extension structure is not
present. Wrapping the ASN.1 error with
`MBEDTLS_ERR_X509_INVALID_EXTENSIONS` and adapting the check
accordingly would mean that an unexpected tag somewhere
down the extension parsing would be ignored by the caller.

The way out of this is the following: Luckily, the extension
structure is always the last field in the surrounding structure,
so if there is some data remaining, it must be an Extension
structure, so we don't need to deal with a tag mismatch gracefully
in the first place.

We may therefore wrap the return code from the initial call to
`mbedtls_asn1_get_tag()` in `mbedtls_x509_get_ext()` by
`MBEDTLS_ERR_X509_INVALID_EXTENSIONS` and simply remove
the special treatment of `MBEDTLS_ERR_ASN1_UNEXPECTED_TAG`
in the callers `x509_crl_get_ext()` and `x509_crt_get_ext()`.

This renders `mbedtls_x509_get_ext()` unsuitable if it ever
happened that an Extension structure is optional and does not
occur at the end of its surrounding structure, but for CRTs
and CRLs, it's fine.

The following tests need to be adapted:
- "TBSCertificate v3, issuerID wrong tag"
  The issuerID is optional, so if we look for its presence
  but find a different tag, we silently continue and try
  parsing the subjectID, and then the extensions. The tag '00'
  used in this test doesn't match either of these, and the
  previous code would hence return LENGTH_MISMATCH after
  unsucessfully trying issuerID, subjectID and Extensions.
  With the new code, any data remaining after issuerID and
  subjectID _must_ be Extension data, so we fail with
  UNEXPECTED_TAG when trying to parse the Extension data.
- "TBSCertificate v3, UIDs, invalid length"
  The test hardcodes the expectation of
  MBEDTLS_ERR_ASN1_INVALID_LENGTH, which needs to be
  wrapped in MBEDTLS_ERR_X509_INVALID_FORMAT now.

Fixes #2431.
2019-06-04 14:03:27 +01:00
..
helpers.function Fix resource leak of file desc in test code 2018-11-26 21:29:29 +00:00
main_test.function Merge branch 'pr_1025' into development 2017-11-28 18:23:53 +01:00
test_suite_aes.cbc.data
test_suite_aes.cfb.data
test_suite_aes.ecb.data
test_suite_aes.function
test_suite_aes.rest.data
test_suite_arc4.data
test_suite_arc4.function
test_suite_asn1write.data
test_suite_asn1write.function Add dependency of mbedtls_asn1_write_len() test on ASN.1 parsing 2018-10-16 13:54:37 +01:00
test_suite_base64.data
test_suite_base64.function
test_suite_blowfish.data
test_suite_blowfish.function
test_suite_camellia.data
test_suite_camellia.function
test_suite_ccm.data Test AD too long only when CCM_ALT not defined 2018-12-19 14:14:58 +02:00
test_suite_ccm.function
test_suite_cipher.aes.data Fix after PR comments 2018-06-21 14:03:14 +03:00
test_suite_cipher.arc4.data Add tests for "return plaintext data faster on unpadded decryption" 2018-03-29 08:43:30 -04:00
test_suite_cipher.blowfish.data Add tests for "return plaintext data faster on unpadded decryption" 2018-03-29 08:43:30 -04:00
test_suite_cipher.camellia.data Add tests for "return plaintext data faster on unpadded decryption" 2018-03-29 08:43:30 -04:00
test_suite_cipher.ccm.data
test_suite_cipher.des.data Add tests for "return plaintext data faster on unpadded decryption" 2018-03-29 08:43:30 -04:00
test_suite_cipher.function Fix errors in AEAD test function 2019-03-14 11:00:58 +02:00
test_suite_cipher.gcm.data Add tests for "return plaintext data faster on unpadded decryption" 2018-03-29 08:43:30 -04:00
test_suite_cipher.null.data Add tests for "return plaintext data faster on unpadded decryption" 2018-03-29 08:43:30 -04:00
test_suite_cipher.padding.data fix bug in get_one_and_zeros_padding() 2017-12-23 23:40:08 +01:00
test_suite_cmac.data
test_suite_cmac.function
test_suite_ctr_drbg.data
test_suite_ctr_drbg.function CTR_DRBG: add mbedtls_ctr_drbg_update_ret 2018-09-13 22:19:31 +02:00
test_suite_debug.data Tests: add omitted dependency on MBEDTLS_ECDSA_C in test_suite_debug 2018-03-05 13:20:31 +01:00
test_suite_debug.function
test_suite_des.data
test_suite_des.function
test_suite_dhm.data tests: dhm: Rename Hallman to Hellman 2018-07-06 14:28:45 +01:00
test_suite_dhm.function
test_suite_ecdh.data Add test case for ecdh_get_params with mismatching group 2019-02-21 18:17:05 +01:00
test_suite_ecdh.function Fix too small buffer in a test 2019-02-22 11:30:14 +01:00
test_suite_ecdsa.data Add tests for invalid private parameters in mbedtls_ecdsa_sign() 2017-11-17 17:09:31 +00:00
test_suite_ecdsa.function Add missing return value check in ECDSA test suite 2018-10-17 14:00:59 +01:00
test_suite_ecjpake.data
test_suite_ecjpake.function
test_suite_ecp.data
test_suite_ecp.function
test_suite_entropy.data
test_suite_entropy.function
test_suite_error.data
test_suite_error.function
test_suite_gcm.aes128_de.data
test_suite_gcm.aes128_en.data
test_suite_gcm.aes192_de.data
test_suite_gcm.aes192_en.data
test_suite_gcm.aes256_de.data
test_suite_gcm.aes256_en.data
test_suite_gcm.camellia.data
test_suite_gcm.function Fix multiple quality issues in the source 2018-06-08 11:14:43 +01:00
test_suite_hmac_drbg.function Change mbedtls_entropy_func in tests to mbedtls_test_entropy_func 2018-01-24 20:05:45 +00:00
test_suite_hmac_drbg.misc.data
test_suite_hmac_drbg.no_reseed.data
test_suite_hmac_drbg.nopr.data
test_suite_hmac_drbg.pr.data
test_suite_md.data Allow comments in test data files 2017-10-06 11:58:50 +01:00
test_suite_md.function
test_suite_mdx.data Allow comments in test data files 2017-10-06 11:58:50 +01:00
test_suite_mdx.function New MD API: rename functions from _ext to _ret 2018-01-22 11:54:42 +01:00
test_suite_memory_buffer_alloc.data Test corner case uses of memory_buffer_alloc.c 2018-01-23 19:37:44 +00:00
test_suite_memory_buffer_alloc.function Test corner case uses of memory_buffer_alloc.c 2018-01-23 19:37:44 +00:00
test_suite_mpi.data Add non-regression test for buffer overflow 2019-03-06 14:00:39 +00:00
test_suite_mpi.function Add non-regression test for buffer overflow 2019-03-06 14:00:39 +00:00
test_suite_pem.data
test_suite_pem.function
test_suite_pk.data Fix depends_on:pk_alg in test suites 2018-03-05 12:58:51 +01:00
test_suite_pk.function Merge remote-tracking branch 'upstream-restricted/pr/460' into mbedtls-2.7-restricted-proposed 2018-03-13 17:24:33 +01:00
test_suite_pkcs1_v15.data Add tests for PKCS#1 v1.5 decoding 2018-10-08 11:49:15 +02:00
test_suite_pkcs1_v15.function Add tests for PKCS#1 v1.5 decoding 2018-10-08 11:49:15 +02:00
test_suite_pkcs1_v21.data RSA PSS: fix first byte check for keys of size 8N+1 2017-10-19 15:23:49 +02:00
test_suite_pkcs1_v21.function Adapt uses of mbedtls_rsa_complete to removed PRNG argument 2017-10-10 16:56:22 +01:00
test_suite_pkcs5.data tests/pkcs5/pbkdf2_hmac: add unit tests for additional SHA algorithms 2018-02-08 17:18:19 +08:00
test_suite_pkcs5.function Fix test dependencies of pkcs5 pbs2 on asn1 parse 2018-03-27 21:25:55 +01:00
test_suite_pkparse.data Change test dependencies to RC4 from DES 2018-07-27 17:33:34 +01:00
test_suite_pkparse.function Remove redundant dependency 2018-03-06 23:35:14 +01:00
test_suite_pkwrite.data
test_suite_pkwrite.function Add dependency of pkwrite test suite on pkparse module 2018-10-16 13:54:08 +01:00
test_suite_rsa.data Merge branch 'development' into iotssl-247 2018-01-15 11:31:34 +00:00
test_suite_rsa.function Yet another dependency issue (PKCS1_V15) 2018-03-13 13:44:45 +01:00
test_suite_shax.data Allow comments in test data files 2017-10-06 11:58:50 +01:00
test_suite_shax.function New MD API: rename functions from _ext to _ret 2018-01-22 11:54:42 +01:00
test_suite_ssl.data Add test case calling ssl_set_hostname twice 2017-10-06 11:58:50 +01:00
test_suite_ssl.function Fix multiple quality issues in the source 2018-06-08 11:14:43 +01:00
test_suite_timing.data Reduce the timing tests complexity 2019-01-29 12:54:10 +01:00
test_suite_timing.function Correct code formatting in the timing test suites 2019-02-05 10:03:31 +01:00
test_suite_version.data Update library version to 2.7.10 2019-03-19 16:18:43 +00:00
test_suite_version.function Fix some test deps 2018-03-27 23:18:13 +02:00
test_suite_x509parse.data Always return a high-level error code from X.509 module 2019-06-04 14:03:27 +01:00
test_suite_x509parse.function Add test cases exercising successful verification of MD2/MD4/MD5 CRT 2019-06-03 16:22:10 +01:00
test_suite_x509write.data Add tests for (named) bitstring to suite_asn1write 2019-02-11 21:10:55 +00:00
test_suite_x509write.function Add tests for (named) bitstring to suite_asn1write 2019-02-11 21:10:55 +00:00
test_suite_xtea.data
test_suite_xtea.function