/* The first byte of the value in the asn1_named_data structure is reserved * to store the critical boolean for us */ 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 ) { asn1_named_data *cur; if( ( cur = asn1_store_named_data( head, oid, oid_len, NULL, val_len + 1 ) ) == NULL ) { return( POLARSSL_ERR_X509_MALLOC_FAILED ); } cur->val.p[0] = critical; memcpy( cur->val.p + 1, val, val_len ); return( 0 ); }
int x509_string_to_names( asn1_named_data **head, const char *name ) { int ret = 0; const char *s = name, *c = s; const char *end = s + strlen( s ); const char *oid = NULL; int in_tag = 1; /* Clear existing chain if present */ asn1_free_named_data_list( head ); while( c <= end ) { if( in_tag && *c == '=' ) { if( ( oid = x509_at_oid_from_name( s, c - s ) ) == NULL ) { ret = POLARSSL_ERR_X509_UNKNOWN_OID; goto exit; } s = c + 1; in_tag = 0; } if( !in_tag && ( *c == ',' || c == end ) ) { if( asn1_store_named_data( head, oid, strlen( oid ), (unsigned char *) s, c - s ) == NULL ) { return( POLARSSL_ERR_X509_MALLOC_FAILED ); } while( c < end && *(c + 1) == ' ' ) c++; s = c + 1; in_tag = 1; } c++; } exit: return( ret ); }
int x509_string_to_names( asn1_named_data **head, const char *name ) { int ret = 0; const char *s = name, *c = s; const char *end = s + strlen( s ); const char *oid = NULL; int in_tag = 1; asn1_named_data *cur; /* Clear existing chain if present */ asn1_free_named_data_list( head ); while( c <= end ) { if( in_tag && *c == '=' ) { if( c - s == 2 && strncasecmp( s, "CN", 2 ) == 0 ) oid = OID_AT_CN; else if( c - s == 1 && strncasecmp( s, "C", 1 ) == 0 ) oid = OID_AT_COUNTRY; else if( c - s == 1 && strncasecmp( s, "O", 1 ) == 0 ) oid = OID_AT_ORGANIZATION; else if( c - s == 1 && strncasecmp( s, "L", 1 ) == 0 ) oid = OID_AT_LOCALITY; else if( c - s == 1 && strncasecmp( s, "R", 1 ) == 0 ) oid = OID_PKCS9_EMAIL; else if( c - s == 2 && strncasecmp( s, "OU", 2 ) == 0 ) oid = OID_AT_ORG_UNIT; else if( c - s == 2 && strncasecmp( s, "ST", 2 ) == 0 ) oid = OID_AT_STATE; else if( c - s == 12 && strncasecmp( s, "serialNumber", 12 ) == 0 ) oid = OID_AT_SERIAL_NUMBER; else if( c - s == 13 && strncasecmp( s, "postalAddress", 13 ) == 0 ) oid = OID_AT_POSTAL_ADDRESS; else if( c - s == 10 && strncasecmp( s, "postalCode", 10 ) == 0 ) oid = OID_AT_POSTAL_CODE; else { ret = POLARSSL_ERR_X509_UNKNOWN_OID; goto exit; } s = c + 1; in_tag = 0; } if( !in_tag && ( *c == ',' || c == end ) ) { if( ( cur = asn1_store_named_data( head, oid, strlen( oid ), (unsigned char *) s, c - s ) ) == NULL ) { return( POLARSSL_ERR_X509_MALLOC_FAILED ); } while( c < end && *(c + 1) == ' ' ) c++; s = c + 1; in_tag = 1; } c++; } exit: return( ret ); }
int x509_string_to_names( asn1_named_data **head, char *name ) { int ret = 0; char *s = name, *c = s; char *end = s + strlen( s ); char *oid = NULL; int in_tag = 1; asn1_named_data *cur; /* Clear existing chain if present */ asn1_free_named_data_list( head ); while( c <= end ) { if( in_tag && *c == '=' ) { if( memcmp( s, "CN", 2 ) == 0 && c - s == 2 ) oid = OID_AT_CN; else if( memcmp( s, "C", 1 ) == 0 && c - s == 1 ) oid = OID_AT_COUNTRY; else if( memcmp( s, "O", 1 ) == 0 && c - s == 1 ) oid = OID_AT_ORGANIZATION; else if( memcmp( s, "L", 1 ) == 0 && c - s == 1 ) oid = OID_AT_LOCALITY; else if( memcmp( s, "R", 1 ) == 0 && c - s == 1 ) oid = OID_PKCS9_EMAIL; else if( memcmp( s, "OU", 2 ) == 0 && c - s == 2 ) oid = OID_AT_ORG_UNIT; else if( memcmp( s, "ST", 2 ) == 0 && c - s == 2 ) oid = OID_AT_STATE; else { ret = POLARSSL_ERR_X509_UNKNOWN_OID; goto exit; } s = c + 1; in_tag = 0; } if( !in_tag && ( *c == ',' || c == end ) ) { if( ( cur = asn1_store_named_data( head, oid, strlen( oid ), (unsigned char *) s, c - s ) ) == NULL ) { return( POLARSSL_ERR_X509_MALLOC_FAILED ); } while( c < end && *(c + 1) == ' ' ) c++; s = c + 1; in_tag = 1; } c++; } exit: return( ret ); }