28 #if defined(POLARSSL_X509_CREATE_C)
34 #if defined(_MSC_VER) && !defined strncasecmp && !defined(EFIX64) && \
36 #define strncasecmp _strnicmp
42 const char *s = name, *c = s;
43 const char *end = s + strlen( s );
44 const char *oid = NULL;
53 if( in_tag && *c ==
'=' )
55 if( c - s == 2 && strncasecmp( s,
"CN", 2 ) == 0 )
57 else if( c - s == 1 && strncasecmp( s,
"C", 1 ) == 0 )
59 else if( c - s == 1 && strncasecmp( s,
"O", 1 ) == 0 )
61 else if( c - s == 1 && strncasecmp( s,
"L", 1 ) == 0 )
63 else if( c - s == 1 && strncasecmp( s,
"R", 1 ) == 0 )
65 else if( c - s == 2 && strncasecmp( s,
"OU", 2 ) == 0 )
67 else if( c - s == 2 && strncasecmp( s,
"ST", 2 ) == 0 )
69 else if( c - s == 12 && strncasecmp( s,
"serialNumber", 12 ) == 0 )
71 else if( c - s == 13 && strncasecmp( s,
"postalAddress", 13 ) == 0 )
73 else if( c - s == 10 && strncasecmp( s,
"postalCode", 10 ) == 0 )
85 if( !in_tag && ( *c ==
',' || c == end ) )
94 while( c < end && *(c + 1) ==
' ' )
112 int critical,
const unsigned char *val,
size_t val_len )
117 NULL, val_len + 1 ) ) == NULL )
122 cur->
val.
p[0] = critical;
123 memcpy( cur->
val.
p + 1, val, val_len );
140 static int x509_write_name(
unsigned char **p,
unsigned char *start,
141 const char *oid,
size_t oid_len,
142 const unsigned char *name,
size_t name_len )
198 const char *oid,
size_t oid_len,
199 unsigned char *sig,
size_t size )
204 if( *p - start < (
int) size + 1 )
209 memcpy( *p, sig, len );
225 static int x509_write_extension(
unsigned char **p,
unsigned char *start,
236 if( ext->
val.
p[0] != 0 )
269 while( cur_ext != NULL )
271 ASN1_CHK_ADD( len, x509_write_extension( p, start, cur_ext ) );
272 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_CN
id-at-commonName AttributeType:= {id-at 3}
#define OID_SIZE(x)
Returns the size of the binary string, without the trailing \0.
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.
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_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 }
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_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_COUNTRY
id-at-countryName AttributeType:= {id-at 6}