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.
This commit is contained in:
Andres Amaya Garcia
2017-08-24 16:48:29 +01:00
committed by Andres Amaya Garcia
parent 8252d7a249
commit 026e95a74d
3 changed files with 40 additions and 0 deletions

View File

@@ -74,6 +74,7 @@
#define MBEDTLS_ASN1_OCTET_STRING 0x04
#define MBEDTLS_ASN1_NULL 0x05
#define MBEDTLS_ASN1_OID 0x06
#define MBEDTLS_ASN1_ENUMERATED 0x0A
#define MBEDTLS_ASN1_UTF8_STRING 0x0C
#define MBEDTLS_ASN1_SEQUENCE 0x10
#define MBEDTLS_ASN1_SET 0x11

View File

@@ -36,6 +36,16 @@
#include <stdint.h>
#define MBEDTLS_ERR_X509_OCSP_INVALID_RESPONSE_STATUS -0x9010 /**< The OCSP response status is invalid */
/* OCSP response status values as defined in RFC 6960 Section 4.2.1 */
#define MBEDTLS_X509_OCSP_RESPONSE_STATUS_SUCCESSFUL 0
#define MBEDTLS_X509_OCSP_RESPONSE_STATUS_MALFORMED_REQ 1
#define MBEDTLS_X509_OCSP_RESPONSE_STATUS_INTERNAL_ERR 2
#define MBEDTLS_X509_OCSP_RESPONSE_STATUS_TRY_LATER 3
#define MBEDTLS_X509_OCSP_RESPONSE_STATUS_SIG_REQUIRED 5
#define MBEDTLS_X509_OCSP_RESPONSE_STATUS_UNAUTHORIZED 6
/**
* \addtogroup x509_module
* \{

View File

@@ -56,6 +56,35 @@ static int x509_ocsp_get_response_status( unsigned char **p,
const unsigned char *end,
uint8_t *resp_status )
{
int ret;
size_t len;
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
MBEDTLS_ASN1_ENUMERATED ) ) != 0 )
{
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
}
if( len != 1 )
return( MBEDTLS_ERR_X509_INVALID_FORMAT +
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
*resp_status = *( *p )++;
/* Ensure the parsed response status is valid */
switch( *resp_status )
{
case MBEDTLS_X509_OCSP_RESPONSE_STATUS_SUCCESSFUL:
case MBEDTLS_X509_OCSP_RESPONSE_STATUS_MALFORMED_REQ:
case MBEDTLS_X509_OCSP_RESPONSE_STATUS_INTERNAL_ERR:
case MBEDTLS_X509_OCSP_RESPONSE_STATUS_TRY_LATER:
case MBEDTLS_X509_OCSP_RESPONSE_STATUS_SIG_REQUIRED:
case MBEDTLS_X509_OCSP_RESPONSE_STATUS_UNAUTHORIZED:
break;
default:
return( MBEDTLS_ERR_X509_OCSP_INVALID_RESPONSE_STATUS );
}
return( 0 );
}