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
47 } x509_attr_descriptor_t;
49 #define ADD_STRLEN( s ) s, sizeof( s ) - 1
51 static const x509_attr_descriptor_t x509_attrs[] =
54 { ADD_STRLEN(
"commonName" ),
OID_AT_CN },
84 static const char *x509_at_oid_from_name(
const char *name,
size_t name_len )
86 const x509_attr_descriptor_t *cur;
88 for( cur = x509_attrs; cur->name != NULL; cur++ )
89 if( cur->name_len == name_len &&
90 strncasecmp( cur->name, name, name_len ) == 0 )
99 const char *s = name, *c = s;
100 const char *end = s + strlen( s );
101 const char *oid = NULL;
111 if( in_tag && *c ==
'=' )
113 if( ( oid = x509_at_oid_from_name( s, c - s ) ) == NULL )
124 if( !in_tag && *c ==
'\\' && c != end )
129 if( c == end || *c !=
',' )
135 else if( !in_tag && ( *c ==
',' || c == end ) )
138 (
unsigned char *) data,
144 while( c < end && *(c + 1) ==
' ' )
151 if( !in_tag && s != c + 1 )
174 int critical,
const unsigned char *val,
size_t val_len )
179 NULL, val_len + 1 ) ) == NULL )
184 cur->
val.
p[0] = critical;
185 memcpy( cur->
val.
p + 1, val, val_len );
202 static int x509_write_name(
unsigned char **p,
unsigned char *start,
203 const char *oid,
size_t oid_len,
204 const unsigned char *name,
size_t name_len )
263 const char *oid,
size_t oid_len,
264 unsigned char *sig,
size_t size )
269 if( *p - start < (
int) size + 1 )
274 memcpy( *p, sig, len );
290 static int x509_write_extension(
unsigned char **p,
unsigned char *start,
301 if( ext->
val.
p[0] != 0 )
335 while( cur_ext != NULL )
337 ASN1_CHK_ADD( len, x509_write_extension( p, start, cur_ext ) );
338 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...
#define X509_MAX_DN_NAME_SIZE
Maximum value size of a DN entry.
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 POLARSSL_ERR_X509_INVALID_NAME
The name tag or value is invalid.
#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}