Commit Graph

5511 Commits

Author SHA1 Message Date
Andres Amaya Garcia
dfcb97ba90 Fix typos and dependencies Makefile for certs and resps for OCSP 2018-03-06 22:04:45 +00:00
Andres Amaya Garcia
d0fa371729 Add OCSP resp tests for producedAt nextUpdate thisUpdate
Modify the existing tests for producedAt as in reality it was testing
also for an invalid thisUpdate value. Also add tests for each of the
components independently. That is, a different response for each case:
    * future producedAt
    * expired nextUpdate
    * future thisUpdate
    * future producedAt and thisUpdate
2018-03-06 21:28:54 +00:00
Andres Amaya Garcia
b61d90202f Add OCSP resp test for cert not in SingleResponse 2018-03-06 20:25:44 +00:00
Andres Amaya Garcia
12f8f6ab78 Add OCSP resp signature verification failure test 2018-03-06 20:18:22 +00:00
Andres Amaya Garcia
afc70657c2 Add invalid arg and issuer tests for OCSP Resp vfy 2018-03-01 22:15:28 +00:00
Andres Amaya Garcia
1182bd1709 Add OCSP Resp verify test for invalid producedAt 2018-03-01 22:14:15 +00:00
Andres Amaya Garcia
244579388e Add OCSP response verify test for failed status 2018-02-15 21:50:09 +00:00
Andres Amaya Garcia
9be9b509aa Add test function for mbedtls_x509_ocsp_response_verify() 2018-02-15 21:49:12 +00:00
Andres Amaya Garcia
5e92c529f6 Rename OCSP response verify function 2018-01-18 22:03:29 +00:00
Andres Amaya Garcia
2acb20260c Add func to generate string from resp verify flags
The function mbedtls_x509_ocsp_response_verify_info() was added, which
is similar to mbedtls_x509_crt_verify_info() but for OCSP responses
instead of certificates. To avoid code duplication, both of these
functions actually call a new function mbedtls_x509_verify_info() in
x509.h with their specific flags and strings in an array of struct
mbedtls_x509_info_string.
2018-01-18 22:03:29 +00:00
Andres Amaya Garcia
425644af0f Move flag defs for OCSP response vrfy to x509.h 2018-01-18 22:03:29 +00:00
Andres Amaya Garcia
fbe751f532 Ensure that x509_ocsp_is_issuer sets issuer var
Ensure that the internal function x509_ocsp_is_issuer() sets the in/out
issuer pointer to NULL when the supplied certificate is not the issuer
of the OCSP response.
2018-01-18 22:03:29 +00:00
Andres Amaya Garcia
94fe8c196e Finish OCSP response verification
Complete the code that implements the checks between the relationship
between the requested certificate and the OCSP response issuer as part
of the verification process. The checks essentially use the information
in the OCSP response and the supplied certificate chains to:

    * Check whether the issuer is the parent of the requested cert

failing that, we check that

    * There is a parent for the issuer in one of the supplied cert
      chains
    * The issuer's parent is also the parent of the requested cert

If either of the two checks succeeds, we accept this verification step.
2018-01-18 22:03:29 +00:00
Andres Amaya Garcia
6aa52ffc56 OCSP add helpers to check if cert is parent of
Add two helper functions to x509_ocspc. to check whether a certificate
is the parent of another certificate. The functions were mostly due to
@mpg.
2018-01-18 22:03:29 +00:00
Andres Amaya Garcia
ea6071c4db Fix typo in comment in library/x509_ocsp.c 2018-01-18 22:03:29 +00:00
Andres Amaya Garcia
6ea49d30b8 Check OCSPSigning ExtKeyUsage from response issuer
Ensure that when the OCSP response issuer is not the parent of the cert
whose status was requested the issuer has OCSPSigning enabled in the
extended key usage X.509 extension.
2018-01-18 22:03:29 +00:00
Andres Amaya Garcia
d48a4a62dd Idenfity relationship between OCSP issuer and cert
Add code to identify the relationship between the OCSP request issuer
certificate and the certificate whose status was requested. According
to RFC 6960 Section 4.2.2.2 the OCSP response issuer can be:

 1. A locally configured signing authority.
    - This has not been implemented at this stage
 2. The certificate of the CA that issued the certificate in question
 3. A certificate that includes the value of id-kp-OCSPSigning in an
    extended key usage extension and is issued by the CA that issued
    the certificate in question

Note that at this stage the relationship between the certificates has
only been validated based on the information supplied within the OCSP
response.
2018-01-18 22:03:29 +00:00
Andres Amaya Garcia
9dc28c0357 Add skeleton code to verify SingleResponse vs cert
Add skeleton code that will be filled in with functionality that
verifies a SingleResponse given the OCSP response issuer and the
requested certificate. Also, helper functions have been added to
x509_ocsp.c to find the parent of the requested certificate's status by
using the information in the OCSP SingleResponse supplied.
2018-01-18 22:03:28 +00:00
Andres Amaya Garcia
c239f478b7 Store raw SubjectPublicKeyInfo when parsing cert
Modify the x509_crt.c and pkparse.c slightly so that the certificate
parsing (and mbedtls_x509_crt) keeps a pointer to the raw DER structure
containing the SubjectPublicKeyInfo. This improves the efficiency of
the OCSP response verification because we have to take the hash of the
certificate's key.
2018-01-18 22:03:28 +00:00
Andres Amaya Garcia
65d8144b22 Verify OCSP status in SingleResponse 2018-01-18 22:03:28 +00:00
Andres Amaya Garcia
cf1e28f77a Verify OCSP response SingleResponse timestamps
Add code to verify the thisUpdate and nextUpdate fields of the
SingleResponse.
2018-01-18 22:03:28 +00:00
Andres Amaya Garcia
02d7ddcfcc Add verification for each OCSP SingleResponse
Add code that loops through every requested certificate and finds out
the corresponding SingleResponse in the OCSP response. This code is the
skeleton for the verification of each SingleResponse. However, at this
stage the verification code is very minimal.
2018-01-18 22:03:28 +00:00
Andres Amaya Garcia
07a934c0a0 Add OCSP response signature verification
The signature is calculated over the hash of the DER encoded
ResponseData as per RFC 6960.
2018-01-18 22:03:28 +00:00
Andres Amaya Garcia
9b0136dcb9 Finish OCSP response issuer finding function
The function follows RFC 6960 and uses either the responder's name or
the responder's hash of their key as available in the OCSP response to
locate the correct issuer certificate.

To avoid code duplication, some functionality from x509_crt.c module
was moved to x509.c and made public in x509.h.
2018-01-18 22:03:28 +00:00
Andres Amaya Garcia
eb00356168 Add skeleton code to find OCSP response issuer
Add the main skeleton code of a function
x509_ocsp_find_response_issuer_crt() that traverses  the certs field in
the OCSP response and other user supplied certificates to find the OCSP
response's issuer. At the momment, the helper function is unimplemented
2018-01-18 22:03:28 +00:00
Andres Amaya Garcia
016dda5a7f Add main OCSP response verification function
Add the main OCSP response verification function
mbedtls_x509_ocsp_verify_response() to the header file x509_ocsp.h and
a simple definition to x509_ocsp.c. At this stage, the verification
function only checks the response status and the timestamp and sets the
verification flags accordingly.

Also, new verification errors and flags are added as macros. These
values will be used in subsequent commits.
2018-01-18 22:03:26 +00:00
Andres Amaya Garcia
6a6011043b Rework mbedtls_x509_ocsp_response_info()
Rework the function mbedtls_x509_ocsp_response_info() to ensure that
it follows the example of similar functions in other X.509 components.
That is, the function should return the number of bytes written to the
provided buffer and in case of error return a negative value.
2018-01-18 22:01:44 +00:00
Andres Amaya Garcia
22b7c1745f Rename x509_ocsp_response functions to fit pattern
Rename the following functions in x509_ocsp.h and x509_ocsp.c to fit
the calling convention in other X.509 components (e.g CRL and CRT):

* mbedtls_x509_ocsp_parse_response -> mbedtls_x509_ocsp_response_parse
* mbedtls_x509_ocsp_parse_response_file -> mbedtls_x509_ocsp_response_parse_file
2018-01-18 19:45:30 +00:00
Andres Amaya Garcia
b3b380d700 Run generate_features.pl and generate_visualc_files.pl 2018-01-18 19:45:30 +00:00
Andres Amaya Garcia
f49c82717c Increase DER OCSP response buffer len to place larger test data 2018-01-18 19:45:30 +00:00
Andres Amaya Garcia
2868fad4af Add signature and certs tests for OCSP parsing 2018-01-18 19:45:30 +00:00
Andres Amaya Garcia
49afce56a0 Fix spacing around + in test_suite_x509parse_ocsp.data 2018-01-18 19:45:30 +00:00
Andres Amaya Garcia
7283253073 Use more specific error code when parsing GenTime
Return a mores specific error code MBEDTLS_ERR_X509_INVALID_DATE +
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG instead of simply
MBEDTLS_ERR_X509_INVALID_DATE to help debugging.
2018-01-18 19:45:29 +00:00
Andres Amaya Garcia
2fbc131d8c Update comments in OCSP code and add missing checks 2018-01-18 19:45:29 +00:00
Andres Amaya Garcia
bb0ed5770f Remove debugging code from x509parse_ocsp test suite 2018-01-18 19:45:29 +00:00
Andres Amaya Garcia
da29b86513 Add negative tests for OCSP ResponseData 2018-01-18 19:45:29 +00:00
Andres Amaya Garcia
8df18f0caa Remove SHA1 from the list of dependencies for OCSP 2018-01-18 19:45:29 +00:00
Andres Amaya Garcia
a5487f5620 Add test suite for x509ocsp parsing
This commit only adds the test code for
mbedtls_x509_ocsp_parse_response() and an initial set of negative tests

So far, the tests introduced are manually crafted malicious OCSP
responses that tests several error conditions in the initial part of
the response structure including the response status, producedAt date,
ResponderID, part of the tsbResponseData, etc.
2018-01-18 19:45:29 +00:00
Andres Amaya Garcia
84038e81b0 Fix parsing of RevocationInfo
Remove double parsing of the SEQUENCE tag that encloses the
RevocationInfo ASN.1 structure in an OCSP response.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
f7a5ddf682 Fix init of OCSP response struct 2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
ee0b017085 Track OCSP ResponseData to facilitate verification 2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
b2ed34208d Fix typo in ocsp struct field name 2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
f43bc1077c OCSP parser rejects ResponseBytes on failure
Improve the OCSP parsing code so that it rejects OCSP responses that
have a failure code value in ResponseStatus but contain ResponseBytes.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
7bb5a85276 Factor OCSP code to parse hashes in response
Factor common code into a new function x509_ocsp_get_md(). The function
takes in a pointer to the DER-encoded buffer, parses the octet string
containing some hash value and then checks that the length corresponds
to the expected length for each md algorithm.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
4098d859fc Fix documentation spacing in x509.h 2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
fc3afe5c6b Ensure that the responseType is OCSP Basic
The responseType indicates a large portion of the syntax of an OCSP
response message. At this stage we only support OCSP Basic, so this
change ensure that the parser returns a failure code if the
responseType does not match the OID id-pkix-ocsp-basic.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
b85378efb3 Add missing dependencies to x509_ocsp.c
Add missing dependency checks to check_config.h and documentation to
config.h. Note that SHA-1 is required for OCSP as RFC 6960 Section
4.4.2 specifies that the ResponderID byKey is the SHA-1 hash of the
responder's public key. That is, without SHA-1 we might not be able to
tell who signed the OCSP response.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
1c0aac06f7 Make input buf const in mbedtls_x509_ocsp_parse_response()
Make the input buffer const in the function
mbedtls_x509_ocsp_parse_response() to follow the same coding pattern as
in mbedtls_x509_crt_parse().
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
462eb3bf1f Fix doxygen warnings in x509_ocsp.h
Fix copy-paste errors in doxygen documentation that were causing
warnings due to variable names not matching the function definition.
2017-11-11 12:49:19 +00:00
Andres Amaya Garcia
26d32e49f8 Call correct free on OCSP response_id after fail
Assign the type of response_id used in the OCSP response ID is recorded
before the actual ID is initialised. In this way, if the initialisation
call to a Name ID fails, the function mbedtls_x509_ocsp_response_free()
calls the correct free() function on the response ID avoiding potential
memory leaks.
2017-11-11 12:49:19 +00:00