AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/nx_secure/src/nx_secure_x509_crl_revocation_check.c
static UINT _nx_secure_x509_crl_parse_entry(const UCHAR *buffer, ULONG length, UINT *bytes_processed,
                                            const UCHAR **serial_number, UINT *serial_number_length)
{
USHORT       tlv_type;
USHORT       tlv_type_class;
ULONG        tlv_length;
const UCHAR *tlv_data;
const UCHAR *current_buffer;
ULONG        header_length;
UINT         status;


    /* Each entry in the list is a sequence containing the serial number, revocation date, and extensions. */
    *bytes_processed = 0;
    current_buffer = buffer;

    /*  First, parse the sequence. */
    status = _nx_secure_x509_asn1_tlv_block_parse(current_buffer, &length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);

    /*  Make sure we parsed the block alright. */
    if (status != 0)
    {
        return(status);
    }

    if (tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
    {
        return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
    }

    *bytes_processed += header_length + tlv_length;
    current_buffer = current_buffer + header_length;
    length = tlv_length;

    /*  Next, parse the serial number. */
    status = _nx_secure_x509_asn1_tlv_block_parse(tlv_data, &length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);

    /*  Make sure we parsed the block alright. */
    if (status != 0)
    {
        return(status);
    }

    /* The serial number is an ASN.1 Integer. */
    if (tlv_type != NX_SECURE_ASN_TAG_INTEGER || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
    {
        return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
    }

    /* Save off the serial number in case someone wants it. */
    *serial_number = tlv_data;
    *serial_number_length = (USHORT)tlv_length;

    /* Don't adjust bytes processed since we handled that above. Just adjust buffer. */
    current_buffer = current_buffer + (tlv_length + header_length);

    /* Parse the "revocationDate" field. */
    status = _nx_secure_x509_asn1_tlv_block_parse(current_buffer, &length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);

    /*  Make sure we parsed the block alright. */
    if (status != 0)
    {
        return(status);
    }

    if ((tlv_type != NX_SECURE_ASN_TAG_UTC_TIME && tlv_type != NX_SECURE_ASN_TAG_GENERALIZED_TIME) || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
    {
        return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
    }

    /* Extensions are optional. Add here when implemented. */

    return(NX_SECURE_X509_SUCCESS);
}
/* Helper function to parse entries in the revokedCertificates list. */
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_secure_x509_crl_parse_entry                     PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Timothy Stapko, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function parses an entry in the revokedCertificates list       */
/*    embedded within an X.509 CRL. Each entry contains the serial number */
/*    of a revoked certificate. This serial number is returned so the     */
/*    caller can compare it to the serial number of the certificate being */
/*    checked for revocation.                                             */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    buffer                                Pointer into CRL data         */
/*    length                                Length of CRL data            */
/*    bytes_processed                       Return bytes parsed           */
/*    serial_number                         Return cert serial number     */
/*    serial_number_length                  Return serial number length   */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    status                                Completion status             */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _nx_secure_x509_asn1_tlv_block_parse  Parse ASN.1 block             */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    _nx_secure_x509_crl_revocation_check  Check revocation in crl       */
/*                                                                        */
/*  RELEASE HISTORY                                                       */
/*                                                                        */
/*    DATE              NAME                      DESCRIPTION             */
/*                                                                        */
/*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
/*  09-30-2020     Timothy Stapko           Modified comment(s),          */
/*                                            resulting in version 6.1    */
/*                                                                        */
/**************************************************************************/
Helper function to parse entries in the revokedCertificates list.
FUNCTION                                               RELEASE

_nx_secure_x509_crl_parse_entry                     PORTABLE C
6.1
AUTHOR

Timothy Stapko, Microsoft Corporation

DESCRIPTION

This function parses an entry in the revokedCertificates list
embedded within an X.509 CRL. Each entry contains the serial number
of a revoked certificate. This serial number is returned so the
caller can compare it to the serial number of the certificate being
checked for revocation.

INPUT

buffer                                Pointer into CRL data
length                                Length of CRL data
bytes_processed                       Return bytes parsed
serial_number                         Return cert serial number
serial_number_length                  Return serial number length

OUTPUT

status                                Completion status

CALLS



CALLED BY

_nx_secure_x509_crl_revocation_check  Check revocation in crl

RELEASE HISTORY

DATE              NAME                      DESCRIPTION

05-19-2020     Timothy Stapko           Initial Version 6.0
09-30-2020     Timothy Stapko           Modified comment(s),
resulting in version 6.1
Helper function to parse entries in the revokedCertificates list . FUNCTION RELEASE _nx_secure_x509_crl_parse_entry PORTABLE C 6 . 1 AUTHOR Timothy Stapko Microsoft Corporation DESCRIPTION This function parses an entry in the revokedCertificates list embedded within an X . 509 CRL . Each entry contains the serial number of a revoked certificate . This serial number is returned so the caller can compare it to the serial number of the certificate being checked for revocation . INPUT buffer Pointer into CRL data length Length of CRL data bytes_processed Return bytes parsed serial_number Return cert serial number serial_number_length Return serial number length OUTPUT status Completion status CALLS CALLED BY _nx_secure_x509_crl_revocation_check Check revocation in crl RELEASE HISTORY DATE NAME DESCRIPTION 05 - 19 - 2020 Timothy Stapko Initial Version 6 . 0 09 - 30 - 2020 Timothy Stapko Modified comment ( s ) resulting in version 6 . 1
static UINT _nx_secure_x509_crl_parse_entry(const UCHAR *buffer, ULONG length, UINT *bytes_processed,
                                            const UCHAR **serial_number, UINT *serial_number_length)
{
USHORT       tlv_type;
USHORT       tlv_type_class;
ULONG        tlv_length;
const UCHAR *tlv_data;
const UCHAR *current_buffer;
ULONG        header_length;
UINT         status;
    *bytes_processed = 0;
    current_buffer = buffer;
    status = _nx_secure_x509_asn1_tlv_block_parse(current_buffer, &length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
    if (status != 0)
    {
        return(status);
    }
    if (tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
    {
        return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
    }
    *bytes_processed += header_length + tlv_length;
    current_buffer = current_buffer + header_length;
    length = tlv_length;
    status = _nx_secure_x509_asn1_tlv_block_parse(tlv_data, &length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
    if (status != 0)
    {
        return(status);
    }
    if (tlv_type != NX_SECURE_ASN_TAG_INTEGER || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
    {
        return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
    }
    *serial_number = tlv_data;
    *serial_number_length = (USHORT)tlv_length;
    current_buffer = current_buffer + (tlv_length + header_length);
    status = _nx_secure_x509_asn1_tlv_block_parse(current_buffer, &length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
    if (status != 0)
    {
        return(status);
    }
    if ((tlv_type != NX_SECURE_ASN_TAG_UTC_TIME && tlv_type != NX_SECURE_ASN_TAG_GENERALIZED_TIME) || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
    {
        return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
    }
    return(NX_SECURE_X509_SUCCESS);
}
static UINT _nx_secure_x509_crl_parse_entry ( const UCHAR * buffer , ULONG length , UINT * bytes_processed , const UCHAR * * serial_number , UINT * serial_number_length ) { USHORT tlv_type ; USHORT tlv_type_class ; ULONG tlv_length ; const UCHAR * tlv_data ; const UCHAR * current_buffer ; ULONG header_length ; UINT status ; * bytes_processed = 0 ; current_buffer = buffer ; status = _nx_secure_x509_asn1_tlv_block_parse ( current_buffer , & length , & tlv_type , & tlv_type_class , & tlv_length , & tlv_data , & header_length ) ; if ( status != 0 ) { return ( status ) ; } if ( tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL ) { return ( NX_SECURE_X509_UNEXPECTED_ASN1_TAG ) ; } * bytes_processed += header_length + tlv_length ; current_buffer = current_buffer + header_length ; length = tlv_length ; status = _nx_secure_x509_asn1_tlv_block_parse ( tlv_data , & length , & tlv_type , & tlv_type_class , & tlv_length , & tlv_data , & header_length ) ; if ( status != 0 ) { return ( status ) ; } if ( tlv_type != NX_SECURE_ASN_TAG_INTEGER || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL ) { return ( NX_SECURE_X509_UNEXPECTED_ASN1_TAG ) ; } * serial_number = tlv_data ; * serial_number_length = ( USHORT ) tlv_length ; current_buffer = current_buffer + ( tlv_length + header_length ) ; status = _nx_secure_x509_asn1_tlv_block_parse ( current_buffer , & length , & tlv_type , & tlv_type_class , & tlv_length , & tlv_data , & header_length ) ; if ( status != 0 ) { return ( status ) ; } if ( ( tlv_type != NX_SECURE_ASN_TAG_UTC_TIME && tlv_type != NX_SECURE_ASN_TAG_GENERALIZED_TIME ) || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL ) { return ( NX_SECURE_X509_UNEXPECTED_ASN1_TAG ) ; } return ( NX_SECURE_X509_SUCCESS ) ; }
Helper function to parse entries in the revokedCertificates list.
Helper function to parse entries in the revokedCertificates list .
/* Each entry in the list is a sequence containing the serial number, revocation date, and extensions. */ /*  First, parse the sequence. */ /*  Make sure we parsed the block alright. */ /*  Next, parse the serial number. */ /*  Make sure we parsed the block alright. */ /* The serial number is an ASN.1 Integer. */ /* Save off the serial number in case someone wants it. */ /* Don't adjust bytes processed since we handled that above. Just adjust buffer. */ /* Parse the "revocationDate" field. */ /*  Make sure we parsed the block alright. */ /* Extensions are optional. Add here when implemented. */