Commit Graph

5524 Commits

Author SHA1 Message Date
Andres Amaya Garcia
07baaf1538 Add missing dependency to test x509_ocsp_response_verify 2018-04-18 09:31:19 -05:00
Andres Amaya Garcia
2de06106c2 Add missing preprocessor guard around mbedtls_x509_ocsp_response_parse_file() 2018-04-18 09:30:55 -05:00
Andres Amaya Garcia
3879f00c46 Add OCSP resp test for future revocation time 2018-03-21 09:44:41 +00:00
Andres Amaya Garcia
bb7f08c7ff Fix out-of-date docs for MBEDTLS_X509_OCSP_PARSE_C 2018-03-20 19:33:06 +00:00
Andres Amaya Garcia
87e1f2604c Add dependencies to test_suite_x509parse_ocsp.data 2018-03-20 19:30:59 +00:00
Andres Amaya Garcia
926a14b0dc Fix unused warnings in OCSP issuer checks when x509 ext absent 2018-03-20 19:30:18 +00:00
Andres Amaya Garcia
c502d3c9f4 Add OCSP response issuer verification tests 2018-03-15 22:44:21 +00:00
Andres Amaya Garcia
75d24d8e35 Fail when ExtendedKeyUsage extension not present
The existing Mbed TLS API to check whether the ExtendedKeyUsage
extension allows an operation. However, this API succeeds when the
extension is not present in the certificate. In the case of authorised
signers for OCSP responses, the certificate MUST have the extension AND
the OCSPSigning field set to be accepted.

This commit creates the new function
mbedtls_x509_crt_check_extended_key_usage_ext() which is a version of
mbedtls_x509_crt_check_extended_key_usage() that returns an error code
if the extension is not present in the certificate in question.
2018-03-15 21:52:46 +00:00
Andres Amaya Garcia
9830d19bf8 Add test with unknown, good and revoked responses 2018-03-15 19:08:20 +00:00
Andres Amaya Garcia
f53276a6bd Add OCSP resp test with unknown cert status 2018-03-07 10:53:03 +00:00
Andres Amaya Garcia
53a3226a2d Remove uneccessary bracketing 2018-03-07 10:52:04 +00:00
Andres Amaya Garcia
10242ac88b Remove parent checks based on OCSP resp DN hash
Remove the parental check between two certificates using the issuer's
DN hash because the parent subject and a cert's issuer DN can be
syntactically different, but still be the parent.
2018-03-07 10:50:06 +00:00
Andres Amaya Garcia
b9590e3647 Add OCSP resp test for revoked cert 2018-03-06 22:09:19 +00:00
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