26 #if !defined(POLARSSL_CONFIG_FILE)
29 #include POLARSSL_CONFIG_FILE
32 #if defined(POLARSSL_X509_CREATE_C)
38 #if defined(_MSC_VER) && !defined strncasecmp && !defined(EFIX64) && \
40 #define strncasecmp _strnicmp
46 const char *s = name, *c = s;
47 const char *end = s + strlen( s );
48 const char *oid = NULL;
56 if( in_tag && *c ==
'=' )
58 if( c - s == 2 && strncasecmp( s,
"CN", 2 ) == 0 )
60 else if( c - s == 10 && strncasecmp( s,
"commonName", 10 ) == 0 )
62 else if( c - s == 1 && strncasecmp( s,
"C", 1 ) == 0 )
64 else if( c - s == 11 && strncasecmp( s,
"countryName", 11 ) == 0 )
66 else if( c - s == 1 && strncasecmp( s,
"O", 1 ) == 0 )
68 else if( c - s == 16 &&
69 strncasecmp( s,
"organizationName", 16 ) == 0 )
71 else if( c - s == 1 && strncasecmp( s,
"L", 1 ) == 0 )
73 else if( c - s == 8 && strncasecmp( s,
"locality", 8 ) == 0 )
75 else if( c - s == 1 && strncasecmp( s,
"R", 1 ) == 0 )
77 else if( c - s == 2 && strncasecmp( s,
"OU", 2 ) == 0 )
79 else if( c - s == 22 &&
80 strncasecmp( s,
"organizationalUnitName", 22 ) == 0 )
82 else if( c - s == 2 && strncasecmp( s,
"ST", 2 ) == 0 )
84 else if( c - s == 19 &&
85 strncasecmp( s,
"stateOrProvinceName", 19 ) == 0 )
87 else if( c - s == 12 && strncasecmp( s,
"emailAddress", 12 ) == 0 )
89 else if( c - s == 12 && strncasecmp( s,
"serialNumber", 12 ) == 0 )
91 else if( c - s == 13 && strncasecmp( s,
"postalAddress", 13 ) == 0 )
93 else if( c - s == 10 && strncasecmp( s,
"postalCode", 10 ) == 0 )
95 else if( c - s == 11 && strncasecmp( s,
"dnQualifier", 11 ) == 0 )
97 else if( c - s == 5 && strncasecmp( s,
"title", 5 ) == 0 )
99 else if( c - s == 7 && strncasecmp( s,
"surName", 7 ) == 0 )
101 else if( c - s == 2 && strncasecmp( s,
"SN", 2 ) == 0 )
103 else if( c - s == 9 && strncasecmp( s,
"givenName", 9 ) == 0 )
105 else if( c - s == 2 && strncasecmp( s,
"GN", 2 ) == 0 )
107 else if( c - s == 8 && strncasecmp( s,
"initials", 8 ) == 0 )
109 else if( c - s == 9 && strncasecmp( s,
"pseudonym", 9 ) == 0 )
111 else if( c - s == 19 &&
112 strncasecmp( s,
"generationQualifier", 19 ) == 0 )
114 else if( c - s == 15 &&
115 strncasecmp( s,
"domainComponent", 15 ) == 0 )
117 else if( c - s == 2 && strncasecmp( s,
"DC", 2 ) == 0 )
129 if( !in_tag && ( *c ==
',' || c == end ) )
138 while( c < end && *(c + 1) ==
' ' )
156 int critical,
const unsigned char *val,
size_t val_len )
161 NULL, val_len + 1 ) ) == NULL )
166 cur->
val.
p[0] = critical;
167 memcpy( cur->
val.
p + 1, val, val_len );
184 static int x509_write_name(
unsigned char **p,
unsigned char *start,
185 const char *oid,
size_t oid_len,
186 const unsigned char *name,
size_t name_len )
245 const char *oid,
size_t oid_len,
246 unsigned char *sig,
size_t size )
251 if( *p - start < (
int) size + 1 )
256 memcpy( *p, sig, len );
272 static int x509_write_extension(
unsigned char **p,
unsigned char *start,
283 if( ext->
val.
p[0] != 0 )
317 while( cur_ext != NULL )
319 ASN1_CHK_ADD( len, x509_write_extension( p, start, cur_ext ) );
320 cur_ext = cur_ext->
next;
int x509_set_extension(asn1_named_data **head, const char *oid, size_t oid_len, int critical, const unsigned char *val, size_t val_len)
int x509_string_to_names(asn1_named_data **head, const char *name)
int asn1_write_ia5_string(unsigned char **p, unsigned char *start, const char *text, size_t text_len)
Write an IA5 string tag (ASN1_IA5_STRING) and value in ASN.1 format Note: function works backwards in...
asn1_named_data * asn1_store_named_data(asn1_named_data **list, const char *oid, size_t oid_len, const unsigned char *val, size_t val_len)
Create or find a specific named_data entry for writing in a sequence or list based on the OID...
#define POLARSSL_ERR_ASN1_BUF_TOO_SMALL
Buffer too small when writing ASN.1 data structure.
Configuration options (set of defines)
Object Identifier (OID) database.
#define OID_AT_INITIALS
id-at-initials AttributeType:= {id-at 43}
#define OID_AT_CN
id-at-commonName AttributeType:= {id-at 3}
#define OID_SIZE(x)
Returns the size of the binary string, without the trailing \0.
#define OID_AT_TITLE
id-at-title AttributeType:= {id-at 12}
int asn1_write_len(unsigned char **p, unsigned char *start, size_t len)
Write a length field in ASN.1 format Note: function works backwards in data buffer.
int asn1_write_printable_string(unsigned char **p, unsigned char *start, const char *text, size_t text_len)
Write a printable string tag (ASN1_PRINTABLE_STRING) and value in ASN.1 format Note: function works b...
asn1_buf val
The named value.
#define OID_AT_GENERATION_QUALIFIER
id-at-generationQualifier AttributeType:= {id-at 44}
int x509_write_names(unsigned char **p, unsigned char *start, asn1_named_data *first)
asn1_buf oid
The object identifier.
int asn1_write_raw_buffer(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t size)
Write raw buffer data Note: function works backwards in data buffer.
#define POLARSSL_ERR_X509_UNKNOWN_OID
Requested OID is unknown.
#define OID_AT_POSTAL_ADDRESS
id-at-postalAddress AttributeType:= {id-at 16}
#define OID_AT_ORGANIZATION
id-at-organizationName AttributeType:= {id-at 10}
unsigned char * p
ASN1 data, e.g.
int x509_write_extensions(unsigned char **p, unsigned char *start, asn1_named_data *first)
#define OID_AT_GIVEN_NAME
id-at-givenName AttributeType:= {id-at 42}
#define OID_AT_ORG_UNIT
id-at-organizationalUnitName AttributeType:= {id-at 11}
#define OID_AT_POSTAL_CODE
id-at-postalCode AttributeType:= {id-at 17}
#define OID_PKCS9_EMAIL
emailAddress AttributeType ::= { pkcs-9 1 }
#define OID_AT_PSEUDONYM
id-at-pseudonym AttributeType:= {id-at 65}
X.509 generic defines and structures.
#define OID_AT_LOCALITY
id-at-locality AttributeType:= {id-at 7}
Container for a sequence or list of 'named' ASN.1 data items.
size_t len
ASN1 length, e.g.
void asn1_free_named_data_list(asn1_named_data **head)
Free all entries in a asn1_named_data list Head will be set to NULL.
#define ASN1_CHK_ADD(g, f)
#define OID_AT_SUR_NAME
id-at-surName AttributeType:= {id-at 4}
#define OID_AT_SERIAL_NUMBER
id-at-serialNumber AttributeType:= {id-at 5}
int asn1_write_algorithm_identifier(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len, size_t par_len)
Write an AlgorithmIdentifier sequence in ASN.1 format Note: function works backwards in data buffer...
int asn1_write_bool(unsigned char **p, unsigned char *start, int boolean)
Write a boolean tag (ASN1_BOOLEAN) and value in ASN.1 format Note: function works backwards in data b...
struct _asn1_named_data * next
The next entry in the sequence.
int x509_write_sig(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len, unsigned char *sig, size_t size)
ASN.1 buffer writing functionality.
int asn1_write_oid(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len)
Write an OID tag (ASN1_OID) and data in ASN.1 format Note: function works backwards in data buffer...
#define ASN1_OCTET_STRING
int asn1_write_tag(unsigned char **p, unsigned char *start, unsigned char tag)
Write a ASN.1 tag in ASN.1 format Note: function works backwards in data buffer.
#define POLARSSL_ERR_X509_MALLOC_FAILED
Allocation of memory failed.
#define OID_AT_STATE
id-at-state AttributeType:= {id-at 8}
#define OID_AT_DN_QUALIFIER
id-at-dnQualifier AttributeType:= {id-at 46}
#define OID_DOMAIN_COMPONENT
#define OID_AT_COUNTRY
id-at-countryName AttributeType:= {id-at 6}