x509_cert_parse.c File Reference

X.509 certificate parsing. More...

#include "core/crypto.h"
#include "pkix/x509_cert_parse.h"
#include "pkix/x509_key_parse.h"
#include "encoding/asn1.h"
#include "encoding/oid.h"
#include "pkc/rsa.h"
#include "pkc/dsa.h"
#include "ecc/ecdsa.h"
#include "hash/md5.h"
#include "hash/sha1.h"
#include "hash/sha224.h"
#include "hash/sha256.h"
#include "hash/sha384.h"
#include "hash/sha512.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t x509ParseCertificate (const uint8_t *data, size_t length, X509CertificateInfo *certInfo)
 Parse a X.509 certificate. More...
 
error_t x509ParseTbsCertificate (const uint8_t *data, size_t length, size_t *totalLength, X509TbsCertificate *tbsCert)
 Parse TBSCertificate structure. More...
 
error_t x509ParseVersion (const uint8_t *data, size_t length, size_t *totalLength, X509Version *version)
 Parse Version field. More...
 
error_t x509ParseSerialNumber (const uint8_t *data, size_t length, size_t *totalLength, X509SerialNumber *serialNumber)
 Parse SerialNumber field. More...
 
error_t x509ParseName (const uint8_t *data, size_t length, size_t *totalLength, X509Name *name)
 Parse Name structure. More...
 
error_t x509ParseNameAttribute (const uint8_t *data, size_t length, size_t *totalLength, X509NameAttribute *nameAttribute)
 Parse name attribute. More...
 
error_t x509ParseValidity (const uint8_t *data, size_t length, size_t *totalLength, X509Validity *validity)
 Parse Validity structure. More...
 
error_t x509ParseTime (const uint8_t *data, size_t length, size_t *totalLength, DateTime *dateTime)
 Parse UTCTime or GeneralizedTime field. More...
 
error_t x509ParseIssuerUniqueId (const uint8_t *data, size_t length, size_t *totalLength)
 Parse IssuerUniqueID structure. More...
 
error_t x509ParseSubjectUniqueId (const uint8_t *data, size_t length, size_t *totalLength)
 Parse SubjectUniqueID structure. More...
 
error_t x509ParseExtensions (const uint8_t *data, size_t length, size_t *totalLength, X509Extensions *extensions)
 Parse X.509 certificate extensions. More...
 
error_t x509ParseExtension (const uint8_t *data, size_t length, size_t *totalLength, X509Extension *extension)
 Parse X.509 certificate extension. More...
 
error_t x509ParseBasicConstraints (bool_t critical, const uint8_t *data, size_t length, X509BasicConstraints *basicConstraints)
 Parse BasicConstraints extension. More...
 
error_t x509ParseNameConstraints (bool_t critical, const uint8_t *data, size_t length, X509NameConstraints *nameConstraints)
 Parse NameConstraints extension. More...
 
error_t x509ParsePolicyConstraints (bool_t critical, const uint8_t *data, size_t length)
 Parse PolicyConstraints extension. More...
 
error_t x509ParsePolicyMappings (bool_t critical, const uint8_t *data, size_t length)
 Parse PolicyMappings extension. More...
 
error_t x509ParseInhibitAnyPolicy (bool_t critical, const uint8_t *data, size_t length)
 Parse InhibitAnyPolicy extension. More...
 
error_t x509ParseKeyUsage (bool_t critical, const uint8_t *data, size_t length, X509KeyUsage *keyUsage)
 Parse KeyUsage extension. More...
 
error_t x509ParseExtendedKeyUsage (bool_t critical, const uint8_t *data, size_t length, X509ExtendedKeyUsage *extKeyUsage)
 Parse ExtendedKeyUsage extension. More...
 
error_t x509ParseSubjectAltName (bool_t critical, const uint8_t *data, size_t length, X509SubjectAltName *subjectAltName)
 Parse SubjectAltName extension. More...
 
error_t x509ParseGeneralSubtrees (const uint8_t *data, size_t length)
 Parse GeneralSubtrees field. More...
 
error_t x509ParseGeneralSubtree (const uint8_t *data, size_t length, size_t *totalLength, X509GeneralName *generalName)
 Parse GeneralSubtree field. More...
 
error_t x509ParseGeneralName (const uint8_t *data, size_t length, size_t *totalLength, X509GeneralName *generalName)
 Parse GeneralName field. More...
 
error_t x509ParseSubjectKeyId (bool_t critical, const uint8_t *data, size_t length, X509SubjectKeyId *subjectKeyId)
 Parse SubjectKeyIdentifier extension. More...
 
error_t x509ParseAuthorityKeyId (bool_t critical, const uint8_t *data, size_t length, X509AuthorityKeyId *authKeyId)
 Parse AuthorityKeyIdentifier extension. More...
 
error_t x509ParseNsCertType (bool_t critical, const uint8_t *data, size_t length, X509NsCertType *nsCertType)
 Parse NetscapeCertType extension. More...
 
error_t x509ParseSignatureAlgo (const uint8_t *data, size_t length, size_t *totalLength, X509SignatureAlgoId *signatureAlgo)
 Parse SignatureAlgorithm structure. More...
 
error_t x509ParseSignatureValue (const uint8_t *data, size_t length, size_t *totalLength, X509SignatureValue *signatureValue)
 Parse SignatureValue field. More...
 
error_t x509ParseInt (const uint8_t *data, size_t length, uint_t *value)
 Convert string to integer. More...
 

Detailed Description

X.509 certificate parsing.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCrypto Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.6

Definition in file x509_cert_parse.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file x509_cert_parse.c.

Function Documentation

◆ x509ParseAuthorityKeyId()

error_t x509ParseAuthorityKeyId ( bool_t  critical,
const uint8_t *  data,
size_t  length,
X509AuthorityKeyId authKeyId 
)

Parse AuthorityKeyIdentifier extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]authKeyIdInformation resulting from the parsing process
Returns
Error code

Definition at line 1912 of file x509_cert_parse.c.

◆ x509ParseBasicConstraints()

error_t x509ParseBasicConstraints ( bool_t  critical,
const uint8_t *  data,
size_t  length,
X509BasicConstraints basicConstraints 
)

Parse BasicConstraints extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]basicConstraintsInformation resulting from the parsing process
Returns
Error code

Definition at line 1233 of file x509_cert_parse.c.

◆ x509ParseCertificate()

error_t x509ParseCertificate ( const uint8_t *  data,
size_t  length,
X509CertificateInfo certInfo 
)

Parse a X.509 certificate.

Parameters
[in]dataPointer to the X.509 certificate to parse
[in]lengthLength of the X.509 certificate
[out]certInfoInformation resulting from the parsing process
Returns
Error code

Definition at line 63 of file x509_cert_parse.c.

◆ x509ParseExtendedKeyUsage()

error_t x509ParseExtendedKeyUsage ( bool_t  critical,
const uint8_t *  data,
size_t  length,
X509ExtendedKeyUsage extKeyUsage 
)

Parse ExtendedKeyUsage extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]extKeyUsageInformation resulting from the parsing process
Returns
Error code

Definition at line 1573 of file x509_cert_parse.c.

◆ x509ParseExtension()

error_t x509ParseExtension ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509Extension extension 
)

Parse X.509 certificate extension.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]extensionInformation resulting from the parsing process
Returns
Error code

Definition at line 1146 of file x509_cert_parse.c.

◆ x509ParseExtensions()

error_t x509ParseExtensions ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509Extensions extensions 
)

Parse X.509 certificate extensions.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]extensionsInformation resulting from the parsing process
Returns
Error code

Definition at line 947 of file x509_cert_parse.c.

◆ x509ParseGeneralName()

error_t x509ParseGeneralName ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509GeneralName generalName 
)

Parse GeneralName field.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]generalNameInformation resulting from the parsing process
Returns
Error code

Definition at line 1829 of file x509_cert_parse.c.

◆ x509ParseGeneralSubtree()

error_t x509ParseGeneralSubtree ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509GeneralName generalName 
)

Parse GeneralSubtree field.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]generalNameInformation resulting from the parsing process
Returns
Error code

Definition at line 1796 of file x509_cert_parse.c.

◆ x509ParseGeneralSubtrees()

error_t x509ParseGeneralSubtrees ( const uint8_t *  data,
size_t  length 
)

Parse GeneralSubtrees field.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
Returns
Error code

Definition at line 1762 of file x509_cert_parse.c.

◆ x509ParseInhibitAnyPolicy()

error_t x509ParseInhibitAnyPolicy ( bool_t  critical,
const uint8_t *  data,
size_t  length 
)

Parse InhibitAnyPolicy extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
Returns
Error code

Definition at line 1484 of file x509_cert_parse.c.

◆ x509ParseInt()

error_t x509ParseInt ( const uint8_t *  data,
size_t  length,
uint_t value 
)

Convert string to integer.

Parameters
[in]dataString containing the representation of an integral number
[in]lengthLength of the string
[out]valueOn success, the function returns the converted integral number
Returns
Error code

Definition at line 2140 of file x509_cert_parse.c.

◆ x509ParseIssuerUniqueId()

error_t x509ParseIssuerUniqueId ( const uint8_t *  data,
size_t  length,
size_t *  totalLength 
)

Parse IssuerUniqueID structure.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
Returns
Error code

Definition at line 840 of file x509_cert_parse.c.

◆ x509ParseKeyUsage()

error_t x509ParseKeyUsage ( bool_t  critical,
const uint8_t *  data,
size_t  length,
X509KeyUsage keyUsage 
)

Parse KeyUsage extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]keyUsageInformation resulting from the parsing process
Returns
Error code

Definition at line 1504 of file x509_cert_parse.c.

◆ x509ParseName()

error_t x509ParseName ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509Name name 
)

Parse Name structure.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]nameInformation resulting from the parsing process
Returns
Error code

Definition at line 417 of file x509_cert_parse.c.

◆ x509ParseNameAttribute()

error_t x509ParseNameAttribute ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509NameAttribute nameAttribute 
)

Parse name attribute.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]nameAttributeInformation resulting from the parsing process
Returns
Error code

Definition at line 587 of file x509_cert_parse.c.

◆ x509ParseNameConstraints()

error_t x509ParseNameConstraints ( bool_t  critical,
const uint8_t *  data,
size_t  length,
X509NameConstraints nameConstraints 
)

Parse NameConstraints extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]nameConstraintsInformation resulting from the parsing process
Returns
Error code

Definition at line 1324 of file x509_cert_parse.c.

◆ x509ParseNsCertType()

error_t x509ParseNsCertType ( bool_t  critical,
const uint8_t *  data,
size_t  length,
X509NsCertType nsCertType 
)

Parse NetscapeCertType extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]nsCertTypeInformation resulting from the parsing process
Returns
Error code

Definition at line 1974 of file x509_cert_parse.c.

◆ x509ParsePolicyConstraints()

error_t x509ParsePolicyConstraints ( bool_t  critical,
const uint8_t *  data,
size_t  length 
)

Parse PolicyConstraints extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
Returns
Error code

Definition at line 1419 of file x509_cert_parse.c.

◆ x509ParsePolicyMappings()

error_t x509ParsePolicyMappings ( bool_t  critical,
const uint8_t *  data,
size_t  length 
)

Parse PolicyMappings extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
Returns
Error code

Definition at line 1452 of file x509_cert_parse.c.

◆ x509ParseSerialNumber()

error_t x509ParseSerialNumber ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509SerialNumber serialNumber 
)

Parse SerialNumber field.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]serialNumberInformation resulting from the parsing process
Returns
Error code

Definition at line 369 of file x509_cert_parse.c.

◆ x509ParseSignatureAlgo()

error_t x509ParseSignatureAlgo ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509SignatureAlgoId signatureAlgo 
)

Parse SignatureAlgorithm structure.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]signatureAlgoInformation resulting from the parsing process
Returns
Error code

Definition at line 2028 of file x509_cert_parse.c.

◆ x509ParseSignatureValue()

error_t x509ParseSignatureValue ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509SignatureValue signatureValue 
)

Parse SignatureValue field.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]signatureValueInformation resulting from the parsing process
Returns
Error code

Definition at line 2094 of file x509_cert_parse.c.

◆ x509ParseSubjectAltName()

error_t x509ParseSubjectAltName ( bool_t  critical,
const uint8_t *  data,
size_t  length,
X509SubjectAltName subjectAltName 
)

Parse SubjectAltName extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]subjectAltNameInformation resulting from the parsing process
Returns
Error code

Definition at line 1690 of file x509_cert_parse.c.

◆ x509ParseSubjectKeyId()

error_t x509ParseSubjectKeyId ( bool_t  critical,
const uint8_t *  data,
size_t  length,
X509SubjectKeyId subjectKeyId 
)

Parse SubjectKeyIdentifier extension.

Parameters
[in]criticalCritical extension flag
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]subjectKeyIdInformation resulting from the parsing process
Returns
Error code

Definition at line 1875 of file x509_cert_parse.c.

◆ x509ParseSubjectUniqueId()

error_t x509ParseSubjectUniqueId ( const uint8_t *  data,
size_t  length,
size_t *  totalLength 
)

Parse SubjectUniqueID structure.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
Returns
Error code

Definition at line 893 of file x509_cert_parse.c.

◆ x509ParseTbsCertificate()

error_t x509ParseTbsCertificate ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509TbsCertificate tbsCert 
)

Parse TBSCertificate structure.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]tbsCertInformation resulting from the parsing process
Returns
Error code

Definition at line 145 of file x509_cert_parse.c.

◆ x509ParseTime()

error_t x509ParseTime ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
DateTime dateTime 
)

Parse UTCTime or GeneralizedTime field.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]dateTimedate resulting from the parsing process
Returns
Error code

Definition at line 709 of file x509_cert_parse.c.

◆ x509ParseValidity()

error_t x509ParseValidity ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509Validity validity 
)

Parse Validity structure.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]validityInformation resulting from the parsing process
Returns
Error code

Definition at line 656 of file x509_cert_parse.c.

◆ x509ParseVersion()

error_t x509ParseVersion ( const uint8_t *  data,
size_t  length,
size_t *  totalLength,
X509Version version 
)

Parse Version field.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]totalLengthNumber of bytes that have been parsed
[out]versionInformation resulting from the parsing process
Returns
Error code

Definition at line 308 of file x509_cert_parse.c.