Commit Graph

2754 Commits

Author SHA1 Message Date
Andres Amaya Garcia
fec7119fc8 Add wrapper for parsing time in X.509
Add a wrapper around the function mbedtls_x509_get_time() to ensure
that only GeneralizedTime tags are parsed. This is necesary for
parsing OCSP responses as the RFC 6960 demands that all time-related
components be in GeneralizedTime format.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
28e015bb9f Add information string for OCSP ResponderID 2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
4bbe7d548d Parse ResponderID structure in OCSP response
Populate the function x509_ocsp_get_responder_id() with code that
parses the following X.509 structure:

   ResponderID ::= CHOICE {
      byName               [1] Name,
      byKey                [2] KeyHash }

   KeyHash ::= OCTET STRING -- SHA-1 hash of responder's public key
   (excluding the tag and length fields)

Note that here the name is parsed by the helper function
mbedtls_x509_get_name() and the KeyHash's bounds are checked but we
do not ensure that the hash is of the correct length.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
a86467b6b3 Add informational string for OCSP response version 2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
a7598705bf Parse the OCSP response version 2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
4775cd3827 Parse top-level OCSP ResponseData
Populate the function x509_ocsp_get_response_data() with code that
parses the following ASN.1 structure:

   ResponseData ::= SEQUENCE {
      version              [0] EXPLICIT Version DEFAULT v1,
      responderID              ResponderID,
      producedAt               GeneralizedTime,
      responses                SEQUENCE OF SingleResponse,
      responseExtensions   [1] EXPLICIT Extensions OPTIONAL }

x509_ocsp_get_response_data() will parse the top-level SEQUENCE and the
two EXPLICIT tags. It delegates the parsing of the individual
subcomponents to x509_ocsp_get_version(), x509_ocsp_get_responder_id(),
x509_ocsp_get_generalized_time(), x509_ocsp_get_responses() and
x509_ocsp_get_extensions().
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
8f1e390a36 Parse top-level components of BasicOCSPResponse
Populate the function x509_ocsp_get_response() that parses the top
level components of the following ASN.1 structure:

   BasicOCSPResponse       ::= SEQUENCE {
      tbsResponseData      ResponseData,
      signatureAlgorithm   AlgorithmIdentifier,
      signature            BIT STRING,
      certs            [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }

The top-level components correspond to the main SEQUENCE and the
EXPLICIT tag.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
d4c37efeac Add informational string for OCSP response type 2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
f4d32f695f Parse OCSP ResponseType OID
Parse the OCSP ResponseType OID contained in the ResponseBytes.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
cd5d0aaa59 Add missing id-pkix-ocsp-basic OID for OCSP
Add missing id-pkix-ocsp-basic OID for ResponseType from RFC 6960
Section 4.2.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
26db5fbe9b Parse ResponseBytes top-level from OCSP response
The added code removed the SEQUENCE component from the following ASN.1
structure:

   ResponseBytes ::=       SEQUENCE {
       responseType   OBJECT IDENTIFIER,
       response       OCTET STRING }

The parsing for responseType and response is delegated to
x509_ocsp_get_response_type() and x509_ocsp_get_response() respectively.
2017-11-11 12:44:26 +00:00
Andres Amaya Garcia
5f72ea8757 Document the general idea of the code in x509_ocsp.c 2017-11-11 12:44:26 +00:00
Andres Amaya Garcia
5ebc241bd4 Add informational string for OCSP response status 2017-11-11 12:44:26 +00:00
Andres Amaya Garcia
026e95a74d Parse the OCSP response status
Populate the function x509_ocsp_get_response_status() that parses the
OCSPResponseStatus:

   OCSPResponseStatus ::= ENUMERATED {
       successful            (0),  -- Response has valid confirmations
       malformedRequest      (1),  -- Illegal confirmation request
       internalError         (2),  -- Internal error in issuer
       tryLater              (3),  -- Try again later
                                   -- (4) is not used
       sigRequired           (5),  -- Must sign the request
       unauthorized          (6)   -- Request unauthorized
   }

The function writes the value into the resp_status field of the
mbedtls_x509_ocsp_response struct.
2017-11-11 12:44:26 +00:00
Andres Amaya Garcia
8252d7a249 Add OCSP parser doxygen docs and placeholder funcs
Add OCSP parser doxygen comments to x509_ocsp.h and placeholder init
and free functions that will be populated later in the development of
the feature
2017-11-11 12:44:26 +00:00
Andres Amaya Garcia
6def89e84e Parse the OCSPResponse top level components
Add parsing for the OCSPResponse top level components:

   OCSPResponse ::= SEQUENCE {
      responseStatus         OCSPResponseStatus,
      responseBytes          [0] EXPLICIT ResponseBytes OPTIONAL }

The added code does the following:

    1. Parse the top level SEQUENCE
    2. Call x509_ocsp_get_response_status() which will parse the
       responseStatus in the future
    3. If there is any data left in the buffer, parses the EXPLICIT
       tag and calls x509_ocsp_get_response_bytes() which will parse
       the responseBytes in the future

At this stage, the main framework for the code is being set up. The idea
is that each function will parse the top level components of the ASN1
objects and hand over the parsing of each of the individual
sub-components to other functions. Also, note that each function its
responsible for checking that:

    1. At the begining, there is enough space in the buffer p to parse
       whatever is being processed before end.
    2. Prior to returning, the length specified in the ASN1 encoding
       matches the number of bytes consumed from the buffer p.
    3. The lengths of any intermediate sub-components (such as EXPLICIT
       tags) parsed matches the number of bytes consumed by the called
       functions x509_ocsp_get_*().
2017-11-11 12:44:26 +00:00
Andres Amaya Garcia
22b1db8a4c Add OCSP parsing files as part of the X509 module
OCSP by itself is a protocol between an OCSP responder and a client.
The protocol messages are encoded in X.509 format, so I have created
the place-holder files x509_ocsp.c and x509_ocsp.h that will contain
the X.509 parser and verification for OCSP messages.
2017-11-11 12:44:26 +00:00
Andres Amaya Garcia
4cfdb54e2c Add bounds check for OCSP nocheck parsing in X509 2017-11-11 12:43:16 +00:00
Andres Amaya Garcia
94be1592f4 Skip parsing unknown accessLocation in authInfoAcc 2017-11-11 12:43:16 +00:00
Andres Amaya Garcia
28681c6afd Parse NULL asn1 octet string in OCSP nocheck ext 2017-11-11 12:43:16 +00:00
Andres Amaya Garcia
998013caab Improve comments for OCSP no-check X509 extension 2017-11-11 12:43:16 +00:00
Andres Amaya Garcia
2c8546f8ad Print URI up to 127 characters in x509_crt.c 2017-11-11 12:43:16 +00:00
Andres Amaya Garcia
a05c5edebc Wrap lines at 79 chars long in x509_crt.c 2017-11-11 12:43:16 +00:00
Andres Amaya Garcia
23875e3297 Remove old TODO comments from x509_crt.c 2017-11-11 12:43:16 +00:00
Andres Amaya Garcia
994a028465 Free authority info access data in x509_crt struct 2017-11-11 12:43:16 +00:00
Andres Amaya Garcia
4e075e4f5c Add support for OCSP noCheck X509 extension 2017-11-11 12:43:16 +00:00
Andres Amaya Garcia
d6700fd019 Add support for AuthorityInfoAccess X509 extension 2017-11-11 12:43:16 +00:00
Andres Amaya Garcia
735b37eeef Correctly handle leap year in x509_date_is_valid()
This patch ensures that invalid dates on leap years with 100 or 400
years intervals are handled correctly.
2017-10-12 23:21:37 +01:00
Ron Eldor
73a381772b Parse Signature Algorithm ext when renegotiating
Signature algorithm extension was skipped when renegotiation was in
progress, causing the signature algorithm not to be known when
renegotiating, and failing the handshake. Fix removes the renegotiation
step check before parsing the extension.
2017-10-12 23:21:37 +01:00
Andres Amaya Garcia
bd9d42c236 Fix typo and bracketing in macro args 2017-10-12 23:21:37 +01:00
Andres Amaya Garcia
6bce9cb5ac Always print gmt_unix_time in TLS client
Change ssl_parse_server_hello() so that the parsed first four random
bytes from the ServerHello message are printed by the TLS client as
a Unix timestamp regardless of whether MBEDTLS_DEBUG_C is defined. The
debug message will only be printed if debug_level is 3 or higher.

Unconditionally enabling the debug print enabled testing of this value.
2017-10-06 11:59:13 +01:00
Hanno Becker
1a9a51c7cf Enhance documentation of ssl_write_hostname_ext, adapt ChangeLog.
Add a reference to the relevant RFC, adapt ChangeLog.
2017-10-06 11:58:50 +01:00
Hanno Becker
947194e7cf Make mbedtls_ssl_set_hostname safe to be called multiple times
Zeroize and free previously set hostnames before overwriting
them. Also, allow clearance of hostname by providing NULL parameter.
2017-10-06 11:58:50 +01:00
Andres Amaya Garcia
01692531c6 Document code silently discarding invalid records 2017-09-14 20:20:31 +01:00
Andres Amaya Garcia
2fad94b193 Dont send alert on invalid DTLS record type
Do not send fatal alerts when receiving a record with an invalid header
while running DTLS as this is not compliant behaviour.
2017-09-14 20:18:37 +01:00
Simon Butcher
72ea31b026 Update version number to 2.6.0 2017-08-10 11:51:16 +01:00
Simon Butcher
a55e084bce Fix naked call to time() with platform call
In ssl_cache.c a call to time() was being made instead of it's platform
equivalent.
2017-07-28 23:46:43 +01:00
Hanno Becker
61937d4a83 Rename time and index parameter to avoid name conflict.
As noted in #557, several functions use 'index' resp. 'time'
as parameter names in their declaration and/or definition, causing name
conflicts with the functions in the C standard library of the same
name some compilers warn about.

This commit renames the arguments accordingly.
2017-07-28 22:28:08 +01:00
Andres AG
2e3ddfac5f Prevent signed integer overflow in CSR parsing
Modify the function mbedtls_x509_csr_parse_der() so that it checks the
parsed CSR version integer before it increments the value. This prevents
a potential signed integer overflow, as these have undefined behaviour
in the C standard.
2017-07-27 21:44:34 +01:00
Andres AG
80164741e1 Fix potential integer overflow parsing DER CRT
This patch prevents a potential signed integer overflow during the
certificate version verification checks.
2017-07-27 21:44:34 +01:00
Andres AG
4f753c1186 Fix potential integer overflow parsing DER CRL
This patch prevents a potential signed integer overflow during the
CRL version verification checks.
2017-07-27 21:44:34 +01:00
Gilles Peskine
683ac27b0f Checked names 2017-07-27 21:44:33 +01:00
Simon Butcher
a95d630197 Fix platform setup/teardown feature and comments
Fixed the platform setup/teardown feature, by fixing it for doxygen and adding it
as a feature  in 'version_features.c'.
2017-07-27 21:44:33 +01:00
Andres Amaya Garcia
d91f99f868 Rename macro SETUP_ALT to SETUP_TEARDOWN_ALT
Rename the macro MBEDTLS_PLATFORM_SETUP_ALT to
MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT to make the name more descriptive
as this macro enables/disables both functions.
2017-07-27 21:44:33 +01:00
Andres Amaya Garcia
3c8a39d28a Remove internal functions from setup API 2017-07-27 21:44:33 +01:00
Andres Amaya Garcia
2a6f39cb63 Add library setup and teardown APIs
Add the following two functions to allow platform setup and teardown
operations for the full library to be hooked in:

* mbedtls_platform_setup()
* mbedtls_platform_teardown()

An mbedtls_platform_context C structure is also added and two internal
functions that are called by the corresponding setup and teardown
functions above:

* mbedtls_internal_platform_setup()
* mbedtls_internal_plartform_teardown()

Finally, the macro MBEDTLS_PLATFORM_SETUP_ALT is also added to allow
mbedtls_platform_context and internal function to be overriden by the
user as needed for a platform.
2017-07-27 21:44:33 +01:00
Hanno Becker
bedc2050b6 Export mbedtls_aes_(en/de)crypt to retain for API compatibility
The commit f5bf7189d3 made the AES
functions mbedtls_aes_encrypt and mbedtls_aes_decrypt static, changing
the library's API.

This commit reverts this.
2017-07-27 21:44:33 +01:00
Hanno Becker
639ce56b6a Undo API change from SHA1 deprecation
The previous commit bd5ceee484 removed
the definition of the global constants
- mbedtls_test_ca_crt_rsa_len,
- mbedtls_test_cli_crt_rsa_len,
- mbedtls_test_ca_crt_rsa, and
- mbedtls_test_cli_crt_rsa.
This commit restores these to maintain ABI compatibility.

Further, it was noticed that without SHA256_C being enabled the
previous code failed to compile because because the SHA1 resp. SHA256
certificates were only defined when the respective SHAXXX_C options
were set, but the emission of the global variable mbedtls_test_ca_crt
was unconditionally defined through the SHA256
certificate. Previously, the RSA SHA1 certificate was unconditionally
defined and used for that.

As a remedy, this commit makes sure some RSA certificate is defined
and exported through the following rule:
1. If SHA256_C is active, define an RSA SHA256 certificate and export
   it as mbedtls_test_ca_crt. Also, define SHA1 certificates only if
   SHA1_C is set.
2. If SHA256_C is not set, always define SHA1 certificate and export
   it as mbedtls_test_ca_crt.
2017-07-27 21:44:33 +01:00
Hanno Becker
d300a5734a Undo API change
The previous commit b3e6872c93 changed
to public functions from ssl_ciphersuite.h to static inline. This
commit reverts this change.
2017-07-27 21:44:33 +01:00
Ron Eldor
7269fee0b6 Check return code of mbedtls_mpi_fill_random
Add MBEDTLS_MPI_CHK to check for error value of mbedtls_mpi_fill_random.
Reported and fix suggested by guidovranken in #740
2017-07-27 21:44:33 +01:00