2013-04-07 22:00:46 +02:00
|
|
|
/**
|
|
|
|
* \file oid.c
|
|
|
|
*
|
|
|
|
* \brief Object Identifier (OID) database
|
|
|
|
*
|
2020-08-07 13:07:28 +02:00
|
|
|
* Copyright The Mbed TLS Contributors
|
2015-09-04 14:21:07 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2013-04-07 22:00:46 +02:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2013-04-07 22:00:46 +02:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-04-07 22:00:46 +02:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2013-04-07 22:00:46 +02:00
|
|
|
*/
|
|
|
|
|
2020-06-03 01:43:33 +02:00
|
|
|
#include "common.h"
|
2013-04-07 22:00:46 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_OID_C)
|
2013-04-07 22:00:46 +02:00
|
|
|
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/oid.h"
|
|
|
|
#include "mbedtls/rsa.h"
|
2019-11-22 14:21:35 +01:00
|
|
|
#include "mbedtls/error.h"
|
2023-02-13 10:04:28 +01:00
|
|
|
#include "mbedtls/pk.h"
|
2013-04-07 22:00:46 +02:00
|
|
|
|
2015-02-06 14:43:58 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/platform.h"
|
2015-01-30 11:54:04 +01:00
|
|
|
|
2013-08-15 14:22:17 +02:00
|
|
|
/*
|
|
|
|
* Macro to automatically add the size of #define'd OIDs
|
|
|
|
*/
|
2015-04-08 12:49:31 +02:00
|
|
|
#define ADD_LEN(s) s, MBEDTLS_OID_SIZE(s)
|
2013-08-15 14:22:17 +02:00
|
|
|
|
2018-12-11 20:55:56 +01:00
|
|
|
/*
|
|
|
|
* Macro to generate mbedtls_oid_descriptor_t
|
|
|
|
*/
|
2020-10-09 10:19:39 +02:00
|
|
|
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
2018-12-11 20:55:56 +01:00
|
|
|
#define OID_DESCRIPTOR(s, name, description) { ADD_LEN(s), name, description }
|
|
|
|
#define NULL_OID_DESCRIPTOR { NULL, 0, NULL, NULL }
|
|
|
|
#else
|
|
|
|
#define OID_DESCRIPTOR(s, name, description) { ADD_LEN(s) }
|
|
|
|
#define NULL_OID_DESCRIPTOR { NULL, 0 }
|
|
|
|
#endif
|
|
|
|
|
2013-06-28 17:20:22 +02:00
|
|
|
/*
|
|
|
|
* Macro to generate an internal function for oid_XXX_from_asn1() (used by
|
|
|
|
* the other functions)
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#define FN_OID_TYPED_FROM_ASN1(TYPE_T, NAME, LIST) \
|
|
|
|
static const TYPE_T *oid_ ## NAME ## _from_asn1( \
|
|
|
|
const mbedtls_asn1_buf *oid) \
|
2018-10-15 13:01:35 +02:00
|
|
|
{ \
|
|
|
|
const TYPE_T *p = (LIST); \
|
|
|
|
const mbedtls_oid_descriptor_t *cur = \
|
|
|
|
(const mbedtls_oid_descriptor_t *) p; \
|
2023-01-11 14:50:10 +01:00
|
|
|
if (p == NULL || oid == NULL) return NULL; \
|
|
|
|
while (cur->asn1 != NULL) { \
|
|
|
|
if (cur->asn1_len == oid->len && \
|
|
|
|
memcmp(cur->asn1, oid->p, oid->len) == 0) { \
|
|
|
|
return p; \
|
2018-10-15 13:01:35 +02:00
|
|
|
} \
|
|
|
|
p++; \
|
|
|
|
cur = (const mbedtls_oid_descriptor_t *) p; \
|
|
|
|
} \
|
2023-01-11 14:50:10 +01:00
|
|
|
return NULL; \
|
2018-10-15 13:01:35 +02:00
|
|
|
}
|
2013-06-28 16:51:52 +02:00
|
|
|
|
2020-10-09 10:19:39 +02:00
|
|
|
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
2013-06-28 17:20:22 +02:00
|
|
|
/*
|
|
|
|
* Macro to generate a function for retrieving a single attribute from the
|
2015-04-08 12:49:31 +02:00
|
|
|
* descriptor of an mbedtls_oid_descriptor_t wrapper.
|
2013-06-28 17:20:22 +02:00
|
|
|
*/
|
|
|
|
#define FN_OID_GET_DESCRIPTOR_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
|
2023-01-11 14:50:10 +01:00
|
|
|
int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1) \
|
|
|
|
{ \
|
|
|
|
const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid); \
|
|
|
|
if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND; \
|
|
|
|
*ATTR1 = data->descriptor.ATTR1; \
|
|
|
|
return 0; \
|
|
|
|
}
|
2020-10-09 10:19:39 +02:00
|
|
|
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
2013-06-28 17:20:22 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Macro to generate a function for retrieving a single attribute from an
|
2015-04-08 12:49:31 +02:00
|
|
|
* mbedtls_oid_descriptor_t wrapper.
|
2013-06-28 17:20:22 +02:00
|
|
|
*/
|
|
|
|
#define FN_OID_GET_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \
|
2023-01-11 14:50:10 +01:00
|
|
|
int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1) \
|
|
|
|
{ \
|
|
|
|
const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid); \
|
|
|
|
if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND; \
|
|
|
|
*ATTR1 = data->ATTR1; \
|
|
|
|
return 0; \
|
|
|
|
}
|
2013-06-28 17:20:22 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Macro to generate a function for retrieving two attributes from an
|
2015-04-08 12:49:31 +02:00
|
|
|
* mbedtls_oid_descriptor_t wrapper.
|
2013-06-28 17:20:22 +02:00
|
|
|
*/
|
|
|
|
#define FN_OID_GET_ATTR2(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1, \
|
|
|
|
ATTR2_TYPE, ATTR2) \
|
2023-01-11 14:50:10 +01:00
|
|
|
int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, \
|
|
|
|
ATTR2_TYPE * ATTR2) \
|
|
|
|
{ \
|
|
|
|
const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid); \
|
|
|
|
if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND; \
|
|
|
|
*(ATTR1) = data->ATTR1; \
|
|
|
|
*(ATTR2) = data->ATTR2; \
|
|
|
|
return 0; \
|
|
|
|
}
|
2013-06-28 17:20:22 +02:00
|
|
|
|
2013-06-28 18:05:35 +02:00
|
|
|
/*
|
|
|
|
* Macro to generate a function for retrieving the OID based on a single
|
2015-04-08 12:49:31 +02:00
|
|
|
* attribute from a mbedtls_oid_descriptor_t wrapper.
|
2013-06-28 18:05:35 +02:00
|
|
|
*/
|
|
|
|
#define FN_OID_GET_OID_BY_ATTR1(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1) \
|
2023-01-11 14:50:10 +01:00
|
|
|
int FN_NAME(ATTR1_TYPE ATTR1, const char **oid, size_t *olen) \
|
|
|
|
{ \
|
|
|
|
const TYPE_T *cur = (LIST); \
|
|
|
|
while (cur->descriptor.asn1 != NULL) { \
|
|
|
|
if (cur->ATTR1 == (ATTR1)) { \
|
|
|
|
*oid = cur->descriptor.asn1; \
|
|
|
|
*olen = cur->descriptor.asn1_len; \
|
|
|
|
return 0; \
|
|
|
|
} \
|
|
|
|
cur++; \
|
|
|
|
} \
|
|
|
|
return MBEDTLS_ERR_OID_NOT_FOUND; \
|
|
|
|
}
|
2013-06-28 18:05:35 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Macro to generate a function for retrieving the OID based on two
|
2015-04-08 12:49:31 +02:00
|
|
|
* attributes from a mbedtls_oid_descriptor_t wrapper.
|
2013-06-28 18:05:35 +02:00
|
|
|
*/
|
|
|
|
#define FN_OID_GET_OID_BY_ATTR2(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1, \
|
|
|
|
ATTR2_TYPE, ATTR2) \
|
2023-01-11 14:50:10 +01:00
|
|
|
int FN_NAME(ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid, \
|
|
|
|
size_t *olen) \
|
|
|
|
{ \
|
|
|
|
const TYPE_T *cur = (LIST); \
|
|
|
|
while (cur->descriptor.asn1 != NULL) { \
|
|
|
|
if (cur->ATTR1 == (ATTR1) && cur->ATTR2 == (ATTR2)) { \
|
|
|
|
*oid = cur->descriptor.asn1; \
|
|
|
|
*olen = cur->descriptor.asn1_len; \
|
|
|
|
return 0; \
|
|
|
|
} \
|
|
|
|
cur++; \
|
|
|
|
} \
|
|
|
|
return MBEDTLS_ERR_OID_NOT_FOUND; \
|
|
|
|
}
|
2013-06-28 18:05:35 +02:00
|
|
|
|
2013-04-07 22:00:46 +02:00
|
|
|
/*
|
|
|
|
* For X520 attribute types
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_oid_descriptor_t descriptor;
|
2013-04-07 22:00:46 +02:00
|
|
|
const char *short_name;
|
|
|
|
} oid_x520_attr_t;
|
|
|
|
|
|
|
|
static const oid_x520_attr_t oid_x520_attr_type[] =
|
|
|
|
{
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_CN, "id-at-commonName", "Common Name"),
|
2013-04-07 22:00:46 +02:00
|
|
|
"CN",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_COUNTRY, "id-at-countryName", "Country"),
|
2013-04-07 22:00:46 +02:00
|
|
|
"C",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_LOCALITY, "id-at-locality", "Locality"),
|
2013-04-07 22:00:46 +02:00
|
|
|
"L",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_STATE, "id-at-state", "State"),
|
2013-04-07 22:00:46 +02:00
|
|
|
"ST",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_ORGANIZATION, "id-at-organizationName",
|
|
|
|
"Organization"),
|
2013-04-07 22:00:46 +02:00
|
|
|
"O",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_ORG_UNIT, "id-at-organizationalUnitName", "Org Unit"),
|
2013-04-07 22:00:46 +02:00
|
|
|
"OU",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_PKCS9_EMAIL,
|
|
|
|
"emailAddress",
|
|
|
|
"E-mail address"),
|
2013-04-07 22:00:46 +02:00
|
|
|
"emailAddress",
|
|
|
|
},
|
2013-10-29 14:24:37 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_SERIAL_NUMBER,
|
|
|
|
"id-at-serialNumber",
|
|
|
|
"Serial number"),
|
2013-10-29 14:24:37 +01:00
|
|
|
"serialNumber",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_POSTAL_ADDRESS,
|
|
|
|
"id-at-postalAddress",
|
|
|
|
"Postal address"),
|
2013-10-29 14:24:37 +01:00
|
|
|
"postalAddress",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_POSTAL_CODE, "id-at-postalCode", "Postal code"),
|
2013-10-29 14:24:37 +01:00
|
|
|
"postalCode",
|
|
|
|
},
|
2014-04-30 15:34:12 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_SUR_NAME, "id-at-surName", "Surname"),
|
2014-04-30 15:34:12 +02:00
|
|
|
"SN",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_GIVEN_NAME, "id-at-givenName", "Given name"),
|
2014-04-30 15:34:12 +02:00
|
|
|
"GN",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_INITIALS, "id-at-initials", "Initials"),
|
2014-04-30 15:34:12 +02:00
|
|
|
"initials",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_GENERATION_QUALIFIER,
|
|
|
|
"id-at-generationQualifier",
|
|
|
|
"Generation qualifier"),
|
2014-04-30 15:34:12 +02:00
|
|
|
"generationQualifier",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_TITLE, "id-at-title", "Title"),
|
2014-04-30 15:34:12 +02:00
|
|
|
"title",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_DN_QUALIFIER,
|
|
|
|
"id-at-dnQualifier",
|
|
|
|
"Distinguished Name qualifier"),
|
2014-04-30 15:34:12 +02:00
|
|
|
"dnQualifier",
|
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_PSEUDONYM, "id-at-pseudonym", "Pseudonym"),
|
2014-04-30 15:34:12 +02:00
|
|
|
"pseudonym",
|
|
|
|
},
|
2021-05-13 01:41:24 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_UID, "id-uid", "User Id"),
|
2021-05-13 01:41:24 +02:00
|
|
|
"uid",
|
|
|
|
},
|
2014-04-30 15:34:12 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_DOMAIN_COMPONENT,
|
|
|
|
"id-domainComponent",
|
|
|
|
"Domain component"),
|
2014-04-30 15:34:12 +02:00
|
|
|
"DC",
|
|
|
|
},
|
2015-03-27 13:03:54 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AT_UNIQUE_IDENTIFIER,
|
|
|
|
"id-at-uniqueIdentifier",
|
|
|
|
"Unique Identifier"),
|
2015-03-27 13:03:54 +01:00
|
|
|
"uniqueIdentifier",
|
|
|
|
},
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2013-04-07 22:00:46 +02:00
|
|
|
NULL,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-29 10:52:14 +02:00
|
|
|
FN_OID_TYPED_FROM_ASN1(oid_x520_attr_t, x520_attr, oid_x520_attr_type)
|
2023-01-11 14:50:10 +01:00
|
|
|
FN_OID_GET_ATTR1(mbedtls_oid_get_attr_short_name,
|
|
|
|
oid_x520_attr_t,
|
|
|
|
x520_attr,
|
|
|
|
const char *,
|
|
|
|
short_name)
|
2013-06-28 16:51:52 +02:00
|
|
|
|
2013-04-07 22:00:46 +02:00
|
|
|
/*
|
|
|
|
* For X509 extensions
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_oid_descriptor_t descriptor;
|
2013-04-07 22:00:46 +02:00
|
|
|
int ext_type;
|
|
|
|
} oid_x509_ext_t;
|
|
|
|
|
|
|
|
static const oid_x509_ext_t oid_x509_ext[] =
|
|
|
|
{
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_BASIC_CONSTRAINTS,
|
|
|
|
"id-ce-basicConstraints",
|
|
|
|
"Basic Constraints"),
|
2019-01-28 09:20:59 +01:00
|
|
|
MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_KEY_USAGE, "id-ce-keyUsage", "Key Usage"),
|
2019-01-28 09:20:59 +01:00
|
|
|
MBEDTLS_OID_X509_EXT_KEY_USAGE,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EXTENDED_KEY_USAGE,
|
|
|
|
"id-ce-extKeyUsage",
|
|
|
|
"Extended Key Usage"),
|
2019-01-28 09:20:59 +01:00
|
|
|
MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_SUBJECT_ALT_NAME,
|
|
|
|
"id-ce-subjectAltName",
|
|
|
|
"Subject Alt Name"),
|
2019-01-28 09:20:59 +01:00
|
|
|
MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_NS_CERT_TYPE,
|
|
|
|
"id-netscape-certtype",
|
|
|
|
"Netscape Certificate Type"),
|
2019-01-28 09:20:59 +01:00
|
|
|
MBEDTLS_OID_X509_EXT_NS_CERT_TYPE,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2019-04-03 08:45:07 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_CERTIFICATE_POLICIES,
|
|
|
|
"id-ce-certificatePolicies",
|
|
|
|
"Certificate Policies"),
|
2019-04-03 08:45:07 +02:00
|
|
|
MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES,
|
|
|
|
},
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-03 09:45:13 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER,
|
|
|
|
"id-ce-subjectKeyIdentifier",
|
|
|
|
"Subject Key Identifier"),
|
2021-02-12 16:11:17 +01:00
|
|
|
MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER,
|
|
|
|
},
|
|
|
|
{
|
2023-01-03 09:45:13 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER,
|
|
|
|
"id-ce-authorityKeyIdentifier",
|
|
|
|
"Authority Key Identifier"),
|
2021-02-12 16:11:17 +01:00
|
|
|
MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER,
|
|
|
|
},
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2013-04-07 22:00:46 +02:00
|
|
|
0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-05-29 10:52:14 +02:00
|
|
|
FN_OID_TYPED_FROM_ASN1(oid_x509_ext_t, x509_ext, oid_x509_ext)
|
|
|
|
FN_OID_GET_ATTR1(mbedtls_oid_get_x509_ext_type, oid_x509_ext_t, x509_ext, int, ext_type)
|
2013-06-28 16:51:52 +02:00
|
|
|
|
2020-10-09 10:19:39 +02:00
|
|
|
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_oid_descriptor_t oid_ext_key_usage[] =
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_SERVER_AUTH,
|
|
|
|
"id-kp-serverAuth",
|
|
|
|
"TLS Web Server Authentication"),
|
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_CLIENT_AUTH,
|
|
|
|
"id-kp-clientAuth",
|
|
|
|
"TLS Web Client Authentication"),
|
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_CODE_SIGNING, "id-kp-codeSigning", "Code Signing"),
|
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EMAIL_PROTECTION, "id-kp-emailProtection", "E-mail Protection"),
|
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_TIME_STAMPING, "id-kp-timeStamping", "Time Stamping"),
|
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_OCSP_SIGNING, "id-kp-OCSPSigning", "OCSP Signing"),
|
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_WISUN_FAN,
|
|
|
|
"id-kp-wisun-fan-device",
|
|
|
|
"Wi-SUN Alliance Field Area Network (FAN)"),
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2013-04-07 22:00:46 +02:00
|
|
|
};
|
2013-06-28 16:51:52 +02:00
|
|
|
|
2015-05-29 10:52:14 +02:00
|
|
|
FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, ext_key_usage, oid_ext_key_usage)
|
2023-01-11 14:50:10 +01:00
|
|
|
FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage,
|
|
|
|
mbedtls_oid_descriptor_t,
|
|
|
|
ext_key_usage,
|
|
|
|
const char *,
|
|
|
|
description)
|
2013-04-07 22:00:46 +02:00
|
|
|
|
2019-03-25 17:22:52 +01:00
|
|
|
static const mbedtls_oid_descriptor_t oid_certificate_policies[] =
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_ANY_POLICY, "anyPolicy", "Any Policy"),
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2019-03-25 17:22:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, certificate_policies, oid_certificate_policies)
|
2023-01-11 14:50:10 +01:00
|
|
|
FN_OID_GET_ATTR1(mbedtls_oid_get_certificate_policies,
|
|
|
|
mbedtls_oid_descriptor_t,
|
|
|
|
certificate_policies,
|
|
|
|
const char *,
|
|
|
|
description)
|
2020-10-09 10:19:39 +02:00
|
|
|
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
2019-03-25 17:22:52 +01:00
|
|
|
|
2013-04-07 22:00:46 +02:00
|
|
|
/*
|
|
|
|
* For SignatureAlgorithmIdentifier
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_oid_descriptor_t descriptor;
|
|
|
|
mbedtls_md_type_t md_alg;
|
|
|
|
mbedtls_pk_type_t pk_alg;
|
2013-04-07 22:00:46 +02:00
|
|
|
} oid_sig_alg_t;
|
|
|
|
|
|
|
|
static const oid_sig_alg_t oid_sig_alg[] =
|
|
|
|
{
|
2016-08-06 22:00:38 +02:00
|
|
|
#if defined(MBEDTLS_RSA_C)
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_MD5)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_MD5, "md5WithRSAEncryption", "RSA with MD5"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_MD5, MBEDTLS_PK_RSA,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_MD5 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA1)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA1, "sha-1WithRSAEncryption", "RSA with SHA1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA1, MBEDTLS_PK_RSA,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA1 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA224)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA224, "sha224WithRSAEncryption",
|
|
|
|
"RSA with SHA-224"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA224, MBEDTLS_PK_RSA,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA224 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA256)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA256, "sha256WithRSAEncryption",
|
|
|
|
"RSA with SHA-256"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA256, MBEDTLS_PK_RSA,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA256 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA384)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA384, "sha384WithRSAEncryption",
|
|
|
|
"RSA with SHA-384"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA384, MBEDTLS_PK_RSA,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA384 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA512)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA512, "sha512WithRSAEncryption",
|
|
|
|
"RSA with SHA-512"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA512, MBEDTLS_PK_RSA,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA512 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA1)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_RSA_SHA_OBS, "sha-1WithRSAEncryption", "RSA with SHA1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA1, MBEDTLS_PK_RSA,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA1 */
|
2016-08-06 22:00:38 +02:00
|
|
|
#endif /* MBEDTLS_RSA_C */
|
2023-01-31 14:29:55 +01:00
|
|
|
#if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA1)
|
2013-07-10 10:28:53 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA1, "ecdsa-with-SHA1", "ECDSA with SHA1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA1, MBEDTLS_PK_ECDSA,
|
2013-07-10 10:28:53 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA1 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA224)
|
2013-07-10 10:28:53 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA224, "ecdsa-with-SHA224", "ECDSA with SHA224"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA224, MBEDTLS_PK_ECDSA,
|
2013-07-10 10:28:53 +02:00
|
|
|
},
|
2021-04-19 16:46:28 +02:00
|
|
|
#endif
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA256)
|
2013-07-10 10:28:53 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA256, "ecdsa-with-SHA256", "ECDSA with SHA256"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA256, MBEDTLS_PK_ECDSA,
|
2013-07-10 10:28:53 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA256 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA384)
|
2013-07-10 10:28:53 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA384, "ecdsa-with-SHA384", "ECDSA with SHA384"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA384, MBEDTLS_PK_ECDSA,
|
2013-07-10 10:28:53 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA384 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA512)
|
2013-07-10 10:28:53 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA512, "ecdsa-with-SHA512", "ECDSA with SHA512"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA512, MBEDTLS_PK_ECDSA,
|
2013-07-10 10:28:53 +02:00
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA512 */
|
2023-02-02 14:18:52 +01:00
|
|
|
#endif /* MBEDTLS_PK_CAN_ECDSA_SOME */
|
2016-08-06 22:00:38 +02:00
|
|
|
#if defined(MBEDTLS_RSA_C)
|
2014-01-22 10:12:57 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_RSASSA_PSS, "RSASSA-PSS", "RSASSA-PSS"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_NONE, MBEDTLS_PK_RSASSA_PSS,
|
2014-01-22 10:12:57 +01:00
|
|
|
},
|
2016-08-06 22:00:38 +02:00
|
|
|
#endif /* MBEDTLS_RSA_C */
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_NONE, MBEDTLS_PK_NONE,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-05-29 10:52:14 +02:00
|
|
|
FN_OID_TYPED_FROM_ASN1(oid_sig_alg_t, sig_alg, oid_sig_alg)
|
2018-12-11 20:55:56 +01:00
|
|
|
|
2020-10-09 10:19:39 +02:00
|
|
|
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
2023-01-11 14:50:10 +01:00
|
|
|
FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc,
|
|
|
|
oid_sig_alg_t,
|
|
|
|
sig_alg,
|
|
|
|
const char *,
|
|
|
|
description)
|
2018-12-11 20:55:56 +01:00
|
|
|
#endif
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
FN_OID_GET_ATTR2(mbedtls_oid_get_sig_alg,
|
|
|
|
oid_sig_alg_t,
|
|
|
|
sig_alg,
|
|
|
|
mbedtls_md_type_t,
|
|
|
|
md_alg,
|
|
|
|
mbedtls_pk_type_t,
|
|
|
|
pk_alg)
|
|
|
|
FN_OID_GET_OID_BY_ATTR2(mbedtls_oid_get_oid_by_sig_alg,
|
|
|
|
oid_sig_alg_t,
|
|
|
|
oid_sig_alg,
|
|
|
|
mbedtls_pk_type_t,
|
|
|
|
pk_alg,
|
|
|
|
mbedtls_md_type_t,
|
|
|
|
md_alg)
|
2013-06-28 16:51:52 +02:00
|
|
|
|
2013-04-07 22:00:46 +02:00
|
|
|
/*
|
2013-07-01 16:57:44 +02:00
|
|
|
* For PublicKeyInfo (PKCS1, RFC 5480)
|
2013-04-07 22:00:46 +02:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_oid_descriptor_t descriptor;
|
|
|
|
mbedtls_pk_type_t pk_alg;
|
2013-04-07 22:00:46 +02:00
|
|
|
} oid_pk_alg_t;
|
|
|
|
|
|
|
|
static const oid_pk_alg_t oid_pk_alg[] =
|
|
|
|
{
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_RSA, "rsaEncryption", "RSA"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_PK_RSA,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2013-07-01 16:57:44 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_ALG_UNRESTRICTED, "id-ecPublicKey", "Generic EC key"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_PK_ECKEY,
|
2013-07-01 16:57:44 +02:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_ALG_ECDH, "id-ecDH", "EC key for ECDH"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_PK_ECKEY_DH,
|
2013-07-01 16:57:44 +02:00
|
|
|
},
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_PK_NONE,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-05-29 10:52:14 +02:00
|
|
|
FN_OID_TYPED_FROM_ASN1(oid_pk_alg_t, pk_alg, oid_pk_alg)
|
|
|
|
FN_OID_GET_ATTR1(mbedtls_oid_get_pk_alg, oid_pk_alg_t, pk_alg, mbedtls_pk_type_t, pk_alg)
|
2023-01-11 14:50:10 +01:00
|
|
|
FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_pk_alg,
|
|
|
|
oid_pk_alg_t,
|
|
|
|
oid_pk_alg,
|
|
|
|
mbedtls_pk_type_t,
|
|
|
|
pk_alg)
|
2013-06-28 16:51:52 +02:00
|
|
|
|
2023-04-05 18:19:01 +02:00
|
|
|
#if defined(MBEDTLS_ECP_LIGHT)
|
2013-07-01 17:34:57 +02:00
|
|
|
/*
|
2023-04-19 14:08:14 +02:00
|
|
|
* For elliptic curves that use namedCurve inside ECParams (RFC 5480)
|
2013-07-01 17:34:57 +02:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_oid_descriptor_t descriptor;
|
|
|
|
mbedtls_ecp_group_id grp_id;
|
2013-07-01 17:34:57 +02:00
|
|
|
} oid_ecp_grp_t;
|
|
|
|
|
|
|
|
static const oid_ecp_grp_t oid_ecp_grp[] =
|
|
|
|
{
|
2016-08-06 22:10:49 +02:00
|
|
|
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
|
2013-07-01 17:34:57 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP192R1, "secp192r1", "secp192r1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_SECP192R1,
|
2013-07-01 17:34:57 +02:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
|
2013-07-01 17:34:57 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP224R1, "secp224r1", "secp224r1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_SECP224R1,
|
2013-07-01 17:34:57 +02:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
|
2013-07-01 17:34:57 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP256R1, "secp256r1", "secp256r1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_SECP256R1,
|
2013-07-01 17:34:57 +02:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
|
2013-07-01 17:34:57 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP384R1, "secp384r1", "secp384r1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_SECP384R1,
|
2013-07-01 17:34:57 +02:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
|
2013-07-01 17:34:57 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP521R1, "secp521r1", "secp521r1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_SECP521R1,
|
2013-07-01 17:34:57 +02:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
|
2014-01-10 18:26:48 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP192K1, "secp192k1", "secp192k1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_SECP192K1,
|
2014-01-10 18:26:48 +01:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
|
2014-01-10 18:26:48 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP224K1, "secp224k1", "secp224k1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_SECP224K1,
|
2014-01-10 18:26:48 +01:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
|
2014-01-10 18:26:48 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP256K1, "secp256k1", "secp256k1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_SECP256K1,
|
2014-01-10 18:26:48 +01:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
|
2013-10-10 15:11:33 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_BP256R1, "brainpoolP256r1", "brainpool256r1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_BP256R1,
|
2013-10-10 15:11:33 +02:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
|
2013-10-10 15:11:33 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_BP384R1, "brainpoolP384r1", "brainpool384r1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_BP384R1,
|
2013-10-10 15:11:33 +02:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
|
2013-10-10 15:11:33 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_BP512R1, "brainpoolP512r1", "brainpool512r1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_BP512R1,
|
2013-10-10 15:11:33 +02:00
|
|
|
},
|
2016-08-06 22:10:49 +02:00
|
|
|
#endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
|
2013-07-01 17:34:57 +02:00
|
|
|
{
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_ECP_DP_NONE,
|
2013-07-01 17:34:57 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-05-29 10:52:14 +02:00
|
|
|
FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_t, grp_id, oid_ecp_grp)
|
|
|
|
FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp, oid_ecp_grp_t, grp_id, mbedtls_ecp_group_id, grp_id)
|
2023-01-11 14:50:10 +01:00
|
|
|
FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_ec_grp,
|
|
|
|
oid_ecp_grp_t,
|
|
|
|
oid_ecp_grp,
|
|
|
|
mbedtls_ecp_group_id,
|
|
|
|
grp_id)
|
2023-04-19 14:08:14 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For Elliptic Curve algorithms that are directly
|
|
|
|
* encoded in the AlgorithmIdentifier (RFC 8410)
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
mbedtls_oid_descriptor_t descriptor;
|
|
|
|
mbedtls_ecp_group_id grp_id;
|
|
|
|
} oid_ecp_grp_algid_t;
|
|
|
|
|
|
|
|
static const oid_ecp_grp_algid_t oid_ecp_grp_algid[] =
|
|
|
|
{
|
|
|
|
#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
|
|
|
|
{
|
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_X25519, "X25519", "X25519"),
|
|
|
|
MBEDTLS_ECP_DP_CURVE25519,
|
|
|
|
},
|
|
|
|
#endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
|
|
|
|
#if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
|
|
|
|
{
|
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_X448, "X448", "X448"),
|
|
|
|
MBEDTLS_ECP_DP_CURVE448,
|
|
|
|
},
|
|
|
|
#endif /* MBEDTLS_ECP_DP_CURVE448_ENABLED */
|
|
|
|
{
|
|
|
|
NULL_OID_DESCRIPTOR,
|
|
|
|
MBEDTLS_ECP_DP_NONE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_algid_t, grp_id_algid, oid_ecp_grp_algid)
|
|
|
|
FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp_algid,
|
|
|
|
oid_ecp_grp_algid_t,
|
|
|
|
grp_id_algid,
|
|
|
|
mbedtls_ecp_group_id,
|
|
|
|
grp_id)
|
|
|
|
FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_ec_grp_algid,
|
|
|
|
oid_ecp_grp_algid_t,
|
|
|
|
oid_ecp_grp_algid,
|
|
|
|
mbedtls_ecp_group_id,
|
|
|
|
grp_id)
|
2023-04-05 18:19:01 +02:00
|
|
|
#endif /* MBEDTLS_ECP_LIGHT */
|
2013-07-01 17:34:57 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_C)
|
2013-06-28 16:12:50 +02:00
|
|
|
/*
|
|
|
|
* For PKCS#5 PBES2 encryption algorithm
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_oid_descriptor_t descriptor;
|
|
|
|
mbedtls_cipher_type_t cipher_alg;
|
2013-06-28 16:12:50 +02:00
|
|
|
} oid_cipher_alg_t;
|
|
|
|
|
|
|
|
static const oid_cipher_alg_t oid_cipher_alg[] =
|
|
|
|
{
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_DES_CBC, "desCBC", "DES-CBC"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_DES_CBC,
|
2013-06-28 16:12:50 +02:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_DES_EDE3_CBC, "des-ede3-cbc", "DES-EDE3-CBC"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_DES_EDE3_CBC,
|
2013-06-28 16:12:50 +02:00
|
|
|
},
|
|
|
|
{
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_NONE,
|
2013-06-28 16:12:50 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-05-29 10:52:14 +02:00
|
|
|
FN_OID_TYPED_FROM_ASN1(oid_cipher_alg_t, cipher_alg, oid_cipher_alg)
|
2023-01-11 14:50:10 +01:00
|
|
|
FN_OID_GET_ATTR1(mbedtls_oid_get_cipher_alg,
|
|
|
|
oid_cipher_alg_t,
|
|
|
|
cipher_alg,
|
|
|
|
mbedtls_cipher_type_t,
|
|
|
|
cipher_alg)
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_C */
|
2013-06-28 16:51:52 +02:00
|
|
|
|
2013-04-07 22:00:46 +02:00
|
|
|
/*
|
|
|
|
* For digestAlgorithm
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_oid_descriptor_t descriptor;
|
|
|
|
mbedtls_md_type_t md_alg;
|
2013-04-07 22:00:46 +02:00
|
|
|
} oid_md_alg_t;
|
|
|
|
|
|
|
|
static const oid_md_alg_t oid_md_alg[] =
|
|
|
|
{
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_MD5)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_MD5, "id-md5", "MD5"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_MD5,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2022-07-05 11:35:52 +02:00
|
|
|
#endif
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA1)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA1, "id-sha1", "SHA-1"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA1,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2022-07-05 11:35:52 +02:00
|
|
|
#endif
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA224)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA224, "id-sha224", "SHA-224"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA224,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2021-04-19 16:46:28 +02:00
|
|
|
#endif
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA256)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA256, "id-sha256", "SHA-256"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA256,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2022-07-05 11:35:52 +02:00
|
|
|
#endif
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA384)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA384, "id-sha384", "SHA-384"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA384,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2022-07-05 11:35:52 +02:00
|
|
|
#endif
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA512)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA512, "id-sha512", "SHA-512"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA512,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
2022-07-05 11:35:52 +02:00
|
|
|
#endif
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_RIPEMD160)
|
2019-05-01 19:43:53 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_RIPEMD160, "id-ripemd160", "RIPEMD-160"),
|
2019-05-01 19:43:53 +02:00
|
|
|
MBEDTLS_MD_RIPEMD160,
|
|
|
|
},
|
2022-07-05 11:35:52 +02:00
|
|
|
#endif
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_NONE,
|
2013-04-07 22:00:46 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-05-29 10:52:14 +02:00
|
|
|
FN_OID_TYPED_FROM_ASN1(oid_md_alg_t, md_alg, oid_md_alg)
|
|
|
|
FN_OID_GET_ATTR1(mbedtls_oid_get_md_alg, oid_md_alg_t, md_alg, mbedtls_md_type_t, md_alg)
|
2023-01-11 14:50:10 +01:00
|
|
|
FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_md,
|
|
|
|
oid_md_alg_t,
|
|
|
|
oid_md_alg,
|
|
|
|
mbedtls_md_type_t,
|
|
|
|
md_alg)
|
2017-12-20 00:03:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For HMAC digestAlgorithm
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
mbedtls_oid_descriptor_t descriptor;
|
|
|
|
mbedtls_md_type_t md_hmac;
|
|
|
|
} oid_md_hmac_t;
|
|
|
|
|
|
|
|
static const oid_md_hmac_t oid_md_hmac[] =
|
|
|
|
{
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA1)
|
2017-12-20 00:03:55 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA1, "hmacSHA1", "HMAC-SHA-1"),
|
2017-12-20 00:03:55 +01:00
|
|
|
MBEDTLS_MD_SHA1,
|
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA1 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA224)
|
2017-12-20 00:03:55 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA224, "hmacSHA224", "HMAC-SHA-224"),
|
2017-12-20 00:03:55 +01:00
|
|
|
MBEDTLS_MD_SHA224,
|
|
|
|
},
|
2021-04-19 16:46:28 +02:00
|
|
|
#endif
|
2023-03-16 12:48:24 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA256)
|
2017-12-20 00:03:55 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA256, "hmacSHA256", "HMAC-SHA-256"),
|
2017-12-20 00:03:55 +01:00
|
|
|
MBEDTLS_MD_SHA256,
|
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA256 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA384)
|
2017-12-20 00:03:55 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA384, "hmacSHA384", "HMAC-SHA-384"),
|
2017-12-20 00:03:55 +01:00
|
|
|
MBEDTLS_MD_SHA384,
|
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA384 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA512)
|
2017-12-20 00:03:55 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA512, "hmacSHA512", "HMAC-SHA-512"),
|
2017-12-20 00:03:55 +01:00
|
|
|
MBEDTLS_MD_SHA512,
|
|
|
|
},
|
2023-03-16 12:48:24 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA512 */
|
2017-12-20 00:03:55 +01:00
|
|
|
{
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2017-12-20 00:03:55 +01:00
|
|
|
MBEDTLS_MD_NONE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
FN_OID_TYPED_FROM_ASN1(oid_md_hmac_t, md_hmac, oid_md_hmac)
|
|
|
|
FN_OID_GET_ATTR1(mbedtls_oid_get_md_hmac, oid_md_hmac_t, md_hmac, mbedtls_md_type_t, md_hmac)
|
2013-06-28 16:51:52 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_PKCS12_C)
|
2013-06-28 17:28:20 +02:00
|
|
|
/*
|
|
|
|
* For PKCS#12 PBEs
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_oid_descriptor_t descriptor;
|
|
|
|
mbedtls_md_type_t md_alg;
|
|
|
|
mbedtls_cipher_type_t cipher_alg;
|
2013-06-28 17:28:20 +02:00
|
|
|
} oid_pkcs12_pbe_alg_t;
|
|
|
|
|
|
|
|
static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg[] =
|
|
|
|
{
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC,
|
|
|
|
"pbeWithSHAAnd3-KeyTripleDES-CBC",
|
|
|
|
"PBE with SHA1 and 3-Key 3DES"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA1, MBEDTLS_CIPHER_DES_EDE3_CBC,
|
2013-06-28 17:28:20 +02:00
|
|
|
},
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
OID_DESCRIPTOR(MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC,
|
|
|
|
"pbeWithSHAAnd2-KeyTripleDES-CBC",
|
|
|
|
"PBE with SHA1 and 2-Key 3DES"),
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_SHA1, MBEDTLS_CIPHER_DES_EDE_CBC,
|
2013-06-28 17:28:20 +02:00
|
|
|
},
|
|
|
|
{
|
2018-12-11 20:55:56 +01:00
|
|
|
NULL_OID_DESCRIPTOR,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_MD_NONE, MBEDTLS_CIPHER_NONE,
|
2013-06-28 17:28:20 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-05-29 10:52:14 +02:00
|
|
|
FN_OID_TYPED_FROM_ASN1(oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, oid_pkcs12_pbe_alg)
|
2023-01-11 14:50:10 +01:00
|
|
|
FN_OID_GET_ATTR2(mbedtls_oid_get_pkcs12_pbe_alg,
|
|
|
|
oid_pkcs12_pbe_alg_t,
|
|
|
|
pkcs12_pbe_alg,
|
|
|
|
mbedtls_md_type_t,
|
|
|
|
md_alg,
|
|
|
|
mbedtls_cipher_type_t,
|
|
|
|
cipher_alg)
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_PKCS12_C */
|
2013-06-28 17:28:20 +02:00
|
|
|
|
2013-04-07 22:00:46 +02:00
|
|
|
/* Return the x.y.z.... style numeric string for the given OID */
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_oid_get_numeric_string(char *buf, size_t size,
|
|
|
|
const mbedtls_asn1_buf *oid)
|
2013-04-07 22:00:46 +02:00
|
|
|
{
|
2019-11-22 14:21:35 +01:00
|
|
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
2023-03-11 23:45:28 +01:00
|
|
|
char *p = buf;
|
|
|
|
size_t n = size;
|
|
|
|
unsigned int value = 0;
|
2023-02-14 15:34:15 +01:00
|
|
|
|
2023-03-11 23:45:28 +01:00
|
|
|
if (size > INT_MAX) {
|
|
|
|
/* Avoid overflow computing return value */
|
|
|
|
return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
|
2023-02-14 15:34:15 +01:00
|
|
|
}
|
2023-03-11 23:45:28 +01:00
|
|
|
|
|
|
|
if (oid->len <= 0) {
|
|
|
|
/* OID must not be empty */
|
2023-02-20 15:21:23 +01:00
|
|
|
return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
|
2023-02-14 15:34:15 +01:00
|
|
|
}
|
2013-04-07 22:00:46 +02:00
|
|
|
|
2023-03-11 23:45:28 +01:00
|
|
|
for (size_t i = 0; i < oid->len; i++) {
|
2013-07-01 17:33:31 +02:00
|
|
|
/* Prevent overflow in value. */
|
2023-02-15 14:46:53 +01:00
|
|
|
if (value > (UINT_MAX >> 7)) {
|
2023-02-20 15:21:23 +01:00
|
|
|
return MBEDTLS_ERR_ASN1_INVALID_DATA;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2023-02-15 12:48:13 +01:00
|
|
|
if ((value == 0) && ((oid->p[i]) == 0x80)) {
|
|
|
|
/* Overlong encoding is not allowed */
|
2023-02-20 15:21:23 +01:00
|
|
|
return MBEDTLS_ERR_ASN1_INVALID_DATA;
|
2023-02-15 12:48:13 +01:00
|
|
|
}
|
2013-07-01 17:33:31 +02:00
|
|
|
|
2013-04-07 22:00:46 +02:00
|
|
|
value <<= 7;
|
2023-02-15 16:44:24 +01:00
|
|
|
value |= oid->p[i] & 0x7F;
|
2013-04-07 22:00:46 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (!(oid->p[i] & 0x80)) {
|
2013-04-07 22:00:46 +02:00
|
|
|
/* Last byte */
|
2023-03-11 23:45:28 +01:00
|
|
|
if (n == size) {
|
|
|
|
int component1;
|
|
|
|
unsigned int component2;
|
|
|
|
/* First subidentifier contains first two OID components */
|
|
|
|
if (value >= 80) {
|
|
|
|
component1 = '2';
|
|
|
|
component2 = value - 80;
|
|
|
|
} else if (value >= 40) {
|
|
|
|
component1 = '1';
|
|
|
|
component2 = value - 40;
|
|
|
|
} else {
|
|
|
|
component1 = '0';
|
|
|
|
component2 = value;
|
|
|
|
}
|
|
|
|
ret = mbedtls_snprintf(p, n, "%c.%u", component1, component2);
|
|
|
|
} else {
|
|
|
|
ret = mbedtls_snprintf(p, n, ".%u", value);
|
|
|
|
}
|
|
|
|
if (ret < 2 || (size_t) ret >= n) {
|
|
|
|
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
|
|
|
|
}
|
|
|
|
n -= (size_t) ret;
|
|
|
|
p += ret;
|
2013-04-07 22:00:46 +02:00
|
|
|
value = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-11 23:45:28 +01:00
|
|
|
if (value != 0) {
|
|
|
|
/* Unterminated subidentifier */
|
|
|
|
return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return (int) (size - n);
|
2013-04-07 22:00:46 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_OID_C */
|