#include "mbedtls/asn1write.h" #include "mbedtls/oid.h" #include <string.h> typedef struct { const char *name; size_t name_len; const char*oid; } x509_attr_descriptor_t; #define ADD_STRLEN( s ) s, sizeof( s ) - 1 static const x509_attr_descriptor_t x509_attrs[] = { { ADD_STRLEN( "CN" ), MBEDTLS_OID_AT_CN }, { ADD_STRLEN( "commonName" ), MBEDTLS_OID_AT_CN }, { ADD_STRLEN( "C" ), MBEDTLS_OID_AT_COUNTRY }, { ADD_STRLEN( "countryName" ), MBEDTLS_OID_AT_COUNTRY }, { ADD_STRLEN( "O" ), MBEDTLS_OID_AT_ORGANIZATION }, { ADD_STRLEN( "organizationName" ), MBEDTLS_OID_AT_ORGANIZATION }, { ADD_STRLEN( "L" ), MBEDTLS_OID_AT_LOCALITY }, { ADD_STRLEN( "locality" ), MBEDTLS_OID_AT_LOCALITY }, { ADD_STRLEN( "R" ), MBEDTLS_OID_PKCS9_EMAIL }, { ADD_STRLEN( "OU" ), MBEDTLS_OID_AT_ORG_UNIT }, { ADD_STRLEN( "organizationalUnitName" ), MBEDTLS_OID_AT_ORG_UNIT }, { ADD_STRLEN( "ST" ), MBEDTLS_OID_AT_STATE }, { ADD_STRLEN( "stateOrProvinceName" ), MBEDTLS_OID_AT_STATE }, { ADD_STRLEN( "emailAddress" ), MBEDTLS_OID_PKCS9_EMAIL }, { ADD_STRLEN( "serialNumber" ), MBEDTLS_OID_AT_SERIAL_NUMBER }, { ADD_STRLEN( "postalAddress" ), MBEDTLS_OID_AT_POSTAL_ADDRESS },
const char *name; /* String representation of AttributeType, e.g. * "CN" or "emailAddress". */ size_t name_len; /* Length of 'name', without trailing 0 byte. */ const char *oid; /* String representation of OID of AttributeType, * as per RFC 5280, Appendix A.1. */ int default_tag; /* The default character encoding used for the * given attribute type, e.g. * MBEDTLS_ASN1_UTF8_STRING for UTF-8. */ } x509_attr_descriptor_t; #define ADD_STRLEN( s ) s, sizeof( s ) - 1 /* X.509 DN attributes from RFC 5280, Appendix A.1. */ static const x509_attr_descriptor_t x509_attrs[] = { { ADD_STRLEN( "CN" ), MBEDTLS_OID_AT_CN, MBEDTLS_ASN1_UTF8_STRING }, { ADD_STRLEN( "commonName" ), MBEDTLS_OID_AT_CN, MBEDTLS_ASN1_UTF8_STRING }, { ADD_STRLEN( "C" ), MBEDTLS_OID_AT_COUNTRY, MBEDTLS_ASN1_PRINTABLE_STRING }, { ADD_STRLEN( "countryName" ), MBEDTLS_OID_AT_COUNTRY, MBEDTLS_ASN1_PRINTABLE_STRING }, { ADD_STRLEN( "O" ), MBEDTLS_OID_AT_ORGANIZATION, MBEDTLS_ASN1_UTF8_STRING }, { ADD_STRLEN( "organizationName" ), MBEDTLS_OID_AT_ORGANIZATION, MBEDTLS_ASN1_UTF8_STRING }, { ADD_STRLEN( "L" ), MBEDTLS_OID_AT_LOCALITY, MBEDTLS_ASN1_UTF8_STRING }, { ADD_STRLEN( "locality" ), MBEDTLS_OID_AT_LOCALITY, MBEDTLS_ASN1_UTF8_STRING },