x509_cert_parse.c File Reference

X.509 certificate parsing. More...

#include "core/crypto.h"
#include "pkix/x509_cert_parse.h"
#include "pkix/x509_cert_ext_parse.h"
#include "pkix/x509_key_parse.h"
#include "pkix/x509_sign_parse.h"
#include "encoding/asn1.h"
#include "encoding/oid.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, X509CertInfo *certInfo)
 Parse a X.509 certificate. More...
 
error_t x509ParseCertificateEx (const uint8_t *data, size_t length, X509CertInfo *certInfo, bool_t ignoreUnknown)
 Parse a X.509 certificate. More...
 
error_t x509ParseTbsCertificate (const uint8_t *data, size_t length, size_t *totalLength, X509TbsCertificate *tbsCert, bool_t ignoreUnknown)
 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 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 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 x509ParseGeneralNames (const uint8_t *data, size_t length, X509GeneralName *generalNames, uint_t maxGeneralNames, uint_t *numGeneralNames)
 Parse GeneralNames field. More...
 
error_t x509ParseGeneralName (const uint8_t *data, size_t length, size_t *totalLength, X509GeneralName *generalName)
 Parse GeneralName field. 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 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 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-2024 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
2.4.4

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

◆ x509ParseCertificate()

error_t x509ParseCertificate ( const uint8_t *  data,
size_t  length,
X509CertInfo 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 56 of file x509_cert_parse.c.

◆ x509ParseCertificateEx()

error_t x509ParseCertificateEx ( const uint8_t *  data,
size_t  length,
X509CertInfo certInfo,
bool_t  ignoreUnknown 
)

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
[in]ignoreUnknownIgnore unknown extensions
Returns
Error code

Definition at line 73 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 855 of file x509_cert_parse.c.

◆ x509ParseGeneralNames()

error_t x509ParseGeneralNames ( const uint8_t *  data,
size_t  length,
X509GeneralName generalNames,
uint_t  maxGeneralNames,
uint_t numGeneralNames 
)

Parse GeneralNames field.

Parameters
[in]dataPointer to the ASN.1 structure to parse
[in]lengthLength of the ASN.1 structure
[out]generalNamesArray of GeneralName entries
[in]maxGeneralNamesMaximum number of entries the array can hold
[out]numGeneralNamesActual number of entries in the array
Returns
Error code

Definition at line 805 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 935 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 901 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 1156 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 428 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 535 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 732 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 381 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 481 of file x509_cert_parse.c.

◆ x509ParseTbsCertificate()

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

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
[in]ignoreUnknownIgnore unknown extensions
Returns
Error code

Definition at line 156 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 1021 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 968 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 320 of file x509_cert_parse.c.