28 #if defined(POLARSSL_X509_CREATE_C)
37 char *s = name, *c = s;
38 char *end = s + strlen( s );
39 const char *oid = NULL;
48 if( in_tag && *c ==
'=' )
50 if( memcmp( s,
"CN", 2 ) == 0 && c - s == 2 )
52 else if( memcmp( s,
"C", 1 ) == 0 && c - s == 1 )
54 else if( memcmp( s,
"O", 1 ) == 0 && c - s == 1 )
56 else if( memcmp( s,
"L", 1 ) == 0 && c - s == 1 )
58 else if( memcmp( s,
"R", 1 ) == 0 && c - s == 1 )
60 else if( memcmp( s,
"OU", 2 ) == 0 && c - s == 2 )
62 else if( memcmp( s,
"ST", 2 ) == 0 && c - s == 2 )
74 if( !in_tag && ( *c ==
',' || c == end ) )
83 while( c < end && *(c + 1) ==
' ' )
101 int critical,
const unsigned char *val,
size_t val_len )
106 NULL, val_len + 1 ) ) == NULL )
111 cur->
val.
p[0] = critical;
112 memcpy( cur->
val.
p + 1, val, val_len );
129 static int x509_write_name(
unsigned char **p,
unsigned char *start,
130 const char *oid,
size_t oid_len,
131 const unsigned char *name,
size_t name_len )
187 const char *oid,
size_t oid_len,
188 unsigned char *sig,
size_t size )
193 if( *p - start < (
int) size + 1 )
198 memcpy( *p, sig, len );
214 static int x509_write_extension(
unsigned char **p,
unsigned char *start,
225 if( ext->
val.
p[0] != 0 )
258 while( cur_ext != NULL )
260 ASN1_CHK_ADD( len, x509_write_extension( p, start, cur_ext ) );
261 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 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_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_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)
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}
int x509_string_to_names(asn1_named_data **head, char *name)