mbedtls/library
Hanno Becker 12f62fb82c Obey bounds of ASN.1 substructures
When parsing a substructure of an ASN.1 structure, no field within
the substructure must exceed the bounds of the substructure.
Concretely, the `end` pointer passed to the ASN.1 parsing routines
must be updated to point to the end of the substructure while parsing
the latter.

This was previously not the case for the routines
- x509_get_attr_type_and_value(),
- mbedtls_x509_get_crt_ext(),
- mbedtls_x509_get_crl_ext().
These functions kept using the end of the parent structure as the
`end` pointer and would hence allow substructure fields to cross
the substructure boundary. This could lead to successful parsing
of ill-formed X.509 CRTs.

This commit fixes this.

Care has to be taken when adapting `mbedtls_x509_get_crt_ext()`
and `mbedtls_x509_get_crl_ext()`, as the underlying function
`mbedtls_x509_get_ext()` returns `0` if no extensions are present
but doesn't set the variable which holds the bounds of the Extensions
structure in case the latter is present. This commit addresses
this by returning early from `mbedtls_x509_get_crt_ext()` and
`mbedtls_x509_get_crl_ext()` if parsing has reached the end of
the input buffer.

The following X.509 parsing tests need to be adapted:
- "TBSCertificate, issuer two inner set datas"
  This test exercises the X.509 CRT parser with a Subject name
  which has two empty `AttributeTypeAndValue` structures.
  This is supposed to fail with `MBEDTLS_ERR_ASN1_OUT_OF_DATA`
  because the parser should attempt to parse the first structure
  and fail because of a lack of data. Previously, it failed to
  obey the (0-length) bounds of the first AttributeTypeAndValue
  structure and would try to interpret the beginning of the second
  AttributeTypeAndValue structure as the first field of the first
  AttributeTypeAndValue structure, returning an UNEXPECTED_TAG error.
- "TBSCertificate, issuer, no full following string"
  This test exercises the parser's behaviour on an AttributeTypeAndValue
  structure which contains more data than expected; it should therefore
  fail with MBEDTLS_ERR_ASN1_LENGTH_MISMATCH. Because of the missing bounds
  check, it previously failed with UNEXPECTED_TAG because it interpreted
  the remaining byte in the first AttributeTypeAndValue structure as the
  first byte in the second AttributeTypeAndValue structure.
- "SubjectAltName repeated"
  This test should exercise two SubjectAltNames extensions in succession,
  but a wrong length values makes the second SubjectAltNames extension appear
  outside of the Extensions structure. With the new bounds in place, this
  therefore fails with a LENGTH_MISMATCH error. This commit adapts the test
  data to put the 2nd SubjectAltNames extension inside the Extensions
  structure, too.
2019-06-04 10:15:09 +01:00
..
.gitignore Split libs with make + general make cleanups 2015-06-25 10:59:56 +02:00
aes.c Add further missing brackets around macro parameters 2019-02-19 17:59:57 +00:00
aesni.c Warn if using a memory sanitizer on AESNI 2018-04-05 15:37:38 +02:00
arc4.c Rename mbedtls_zeroize to mbedtls_platform_zeroize 2018-04-17 10:00:21 -05:00
aria.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
asn1parse.c Rename mbedtls_zeroize to mbedtls_platform_zeroize 2018-04-17 10:00:21 -05:00
asn1write.c Add new function mbedtls_asn1_write_named_bitstring() 2019-02-28 09:36:30 +00:00
base64.c Add comment to integer overflow fix in base64.c 2017-02-15 23:31:07 +02:00
bignum.c Merge remote-tracking branch 'origin/pr/2405' into development 2019-04-05 14:08:49 +01:00
blowfish.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
camellia.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
ccm.c Merge remote-tracking branch 'origin/pr/2092' into development 2019-04-24 11:17:21 +01:00
certs.c Use certificates from data_files and refer them 2019-02-12 15:30:26 +02:00
chacha20.c Improve macro hygiene 2019-02-19 17:59:00 +00:00
chachapoly.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
cipher.c Wrap lines at 80 columns 2019-04-02 10:07:28 -07:00
cipher_wrap.c Wrap lines at 80 columns 2019-04-02 10:07:28 -07:00
cmac.c Merge remote-tracking branch 'public/pr/1390' into development 2018-06-27 10:51:47 +01:00
CMakeLists.txt Force the usage of crypto submodule 2019-05-23 03:01:35 -04:00
ctr_drbg.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
debug.c Merge remote-tracking branch 'origin/pr/1818' into development 2019-03-05 16:27:38 +00:00
des.c Improve macro hygiene 2019-02-19 17:59:00 +00:00
dhm.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
ecdh.c Fix ECDH secret export for Mongomery curves 2019-02-26 16:49:52 +00:00
ecdsa.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
ecjpake.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
ecp.c Merge remote-tracking branch 'origin/pr/2092' into development 2019-04-24 11:17:21 +01:00
ecp_curves.c Improve macro hygiene 2019-02-19 17:59:00 +00:00
entropy.c Rename mbedtls_zeroize to mbedtls_platform_zeroize 2018-04-17 10:00:21 -05:00
entropy_poll.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
error.c Regenerate errors.c 2019-04-30 16:47:36 +01:00
gcm.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
havege.c Improve macro hygiene 2019-02-19 17:59:00 +00:00
hkdf.c Fix issue if salt = NULL and salt_len !=0 in mbedtls_hkdf_extract() 2018-07-23 10:34:47 -07:00
hmac_drbg.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
Makefile Force the usage of crypto submodule 2019-05-23 03:01:35 -04:00
md.c Rename mbedtls_zeroize to mbedtls_platform_zeroize 2018-04-17 10:00:21 -05:00
md2.c Rename mbedtls_zeroize to mbedtls_platform_zeroize 2018-04-17 10:00:21 -05:00
md4.c Add more missing parentheses around macro parameters 2019-02-19 17:59:57 +00:00
md5.c Add further missing brackets around macro parameters 2019-02-19 17:59:57 +00:00
md_wrap.c New MD API: rename functions from _ext to _ret 2018-01-22 11:54:42 +01:00
memory_buffer_alloc.c Fix braces in mbedtls_memory_buffer_alloc_status() 2018-06-12 16:56:04 +01:00
net_sockets.c Merge remote-tracking branch 'public/pr/1198' into development 2018-07-24 17:20:17 +01:00
nist_kw.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
oid.c Add support for RSA PKCSv1.5 signatures using RIPEMD-160 2019-05-06 12:15:17 -04:00
padlock.c Change main license to Apache 2.0 2015-09-04 14:21:07 +02:00
pem.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
pk.c pk: restructure precondition check 2019-02-05 05:09:05 -05:00
pk_wrap.c Fix outdated comment in ecdsa_verify_wrap() 2019-01-29 08:26:15 +00:00
pkcs5.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
pkcs11.c Change main license to Apache 2.0 2015-09-04 14:21:07 +02:00
pkcs12.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
pkparse.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
pkwrite.c Merge development-psa commit 80b5662 into development-psa-merged branch 2019-02-05 06:02:51 -05:00
platform.c Merge remote-tracking branch 'origin/pr/1551' into development 2019-01-30 13:24:55 +00:00
platform_util.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
poly1305.c Improve macro hygiene 2019-02-19 17:59:00 +00:00
ripemd160.c Improve macro hygiene 2019-02-19 17:59:00 +00:00
rsa.c rsa: Enable use of zero-length null output 2019-02-11 03:39:51 -05:00
rsa_internal.c Bignum: Deprecate mbedtls_mpi_is_prime() 2018-10-09 16:36:53 +01:00
sha1.c Add further missing brackets around macro parameters 2019-02-19 17:59:57 +00:00
sha256.c Add further missing brackets around macro parameters 2019-02-19 17:59:57 +00:00
sha512.c Add more missing parentheses around macro parameters 2019-02-19 17:59:57 +00:00
ssl_cache.c Remove peer CRT from cache if !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE 2019-02-26 14:38:09 +00:00
ssl_ciphersuites.c Reduce priority of 3DES ciphersuites 2019-03-01 10:19:27 +01:00
ssl_cli.c ssl_cli.c : add explicit casting to unsigned char 2019-05-23 03:01:35 -04:00
ssl_cookie.c Rename mbedtls_zeroize to mbedtls_platform_zeroize 2018-04-17 10:00:21 -05:00
ssl_srv.c Remove ciphersuite_info from ssl_transform 2019-04-25 12:58:21 +01:00
ssl_ticket.c Fix typo in SSL ticket documentation 2019-02-26 14:38:09 +00:00
ssl_tls.c Fix compile guard for static function in ssl 2019-05-23 03:01:35 -04:00
threading.c Don't declare and define gmtime()-mutex on Windows platforms 2018-09-06 12:09:56 +01:00
timing.c Merge remote-tracking branch 'public/pr/1777' into development-proposed 2018-11-04 18:51:36 +00:00
version.c Fix missing void argument declarations #678 2016-11-04 23:05:56 +01:00
version_features.c Merge remote-tracking branch 'origin/pr/2532' into development 2019-04-16 14:42:11 +01:00
x509.c Obey bounds of ASN.1 substructures 2019-06-04 10:15:09 +01:00
x509_create.c Break overly long line in library/x509_create.c 2018-11-02 10:52:38 +00:00
x509_crl.c Obey bounds of ASN.1 substructures 2019-06-04 10:15:09 +01:00
x509_crt.c Obey bounds of ASN.1 substructures 2019-06-04 10:15:09 +01:00
x509_csr.c Merge development commit 8e76332 into development-psa 2019-01-31 08:20:20 -05:00
x509write_crt.c Add new function mbedtls_asn1_write_named_bitstring() 2019-02-28 09:36:30 +00:00
x509write_csr.c Add new function mbedtls_asn1_write_named_bitstring() 2019-02-28 09:36:30 +00:00
xtea.c Rename mbedtls_zeroize to mbedtls_platform_zeroize 2018-04-17 10:00:21 -05:00