PolarSSL v1.3.1
oid.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_OID_H
28 #define POLARSSL_OID_H
29 
30 #include <string.h>
31 #include "config.h"
32 #include "asn1.h"
33 #include "pk.h"
34 #if defined(POLARSSL_CIPHER_C)
35 #include "cipher.h"
36 #endif
37 
38 #if defined(POLARSSL_MD_C)
39 #include "md.h"
40 #endif
41 
42 #if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
43 #include "x509.h"
44 #endif
45 
46 #define POLARSSL_ERR_OID_NOT_FOUND -0x002E
48 /*
49  * Top level OID tuples
50  */
51 #define OID_ISO_MEMBER_BODIES "\x2a" /* {iso(1) member-body(2)} */
52 #define OID_ISO_IDENTIFIED_ORG "\x2b" /* {iso(1) identified-organization(3)} */
53 #define OID_ISO_CCITT_DS "\x55" /* {joint-iso-ccitt(2) ds(5)} */
54 #define OID_ISO_ITU_COUNTRY "\x60" /* {joint-iso-itu-t(2) country(16)} */
55 
56 /*
57  * ISO Member bodies OID parts
58  */
59 #define OID_COUNTRY_US "\x86\x48" /* {us(840)} */
60 #define OID_ORG_RSA_DATA_SECURITY "\x86\xf7\x0d" /* {rsadsi(113549)} */
61 #define OID_RSA_COMPANY OID_ISO_MEMBER_BODIES OID_COUNTRY_US \
62  OID_ORG_RSA_DATA_SECURITY /* {iso(1) member-body(2) us(840) rsadsi(113549)} */
63 #define OID_ORG_ANSI_X9_62 "\xce\x3d" /* ansi-X9-62(10045) */
64 #define OID_ANSI_X9_62 OID_ISO_MEMBER_BODIES OID_COUNTRY_US \
65  OID_ORG_ANSI_X9_62
66 
67 /*
68  * ISO Identified organization OID parts
69  */
70 #define OID_ORG_DOD "\x06" /* {dod(6)} */
71 #define OID_ORG_OIW "\x0e"
72 #define OID_OIW_SECSIG OID_ORG_OIW "\x03"
73 #define OID_OIW_SECSIG_ALG OID_OIW_SECSIG "\x02"
74 #define OID_OIW_SECSIG_SHA1 OID_OIW_SECSIG_ALG "\x1a"
75 #define OID_ORG_CERTICOM "\x81\x04" /* certicom(132) */
76 #define OID_CERTICOM OID_ISO_IDENTIFIED_ORG OID_ORG_CERTICOM
77 #define OID_ORG_TELETRUST "\x24" /* teletrust(36) */
78 #define OID_TELETRUST OID_ISO_IDENTIFIED_ORG OID_ORG_TELETRUST
79 
80 /*
81  * ISO ITU OID parts
82  */
83 #define OID_ORGANIZATION "\x01" /* {organization(1)} */
84 #define OID_ISO_ITU_US_ORG OID_ISO_ITU_COUNTRY OID_COUNTRY_US OID_ORGANIZATION /* {joint-iso-itu-t(2) country(16) us(840) organization(1)} */
85 
86 #define OID_ORG_GOV "\x65" /* {gov(101)} */
87 #define OID_GOV OID_ISO_ITU_US_ORG OID_ORG_GOV /* {joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101)} */
88 
89 #define OID_ORG_NETSCAPE "\x86\xF8\x42" /* {netscape(113730)} */
90 #define OID_NETSCAPE OID_ISO_ITU_US_ORG OID_ORG_NETSCAPE /* Netscape OID {joint-iso-itu-t(2) country(16) us(840) organization(1) netscape(113730)} */
91 
92 /* ISO arc for standard certificate and CRL extensions */
93 #define OID_ID_CE OID_ISO_CCITT_DS "\x1D"
100 #define OID_PKIX OID_ISO_IDENTIFIED_ORG OID_ORG_DOD "\x01\x05\x05\x07"
101 
102 /*
103  * Arc for standard naming attributes
104  */
105 #define OID_AT OID_ISO_CCITT_DS "\x04"
106 #define OID_AT_CN OID_AT "\x03"
107 #define OID_AT_COUNTRY OID_AT "\x06"
108 #define OID_AT_LOCALITY OID_AT "\x07"
109 #define OID_AT_STATE OID_AT "\x08"
110 #define OID_AT_ORGANIZATION OID_AT "\x0A"
111 #define OID_AT_ORG_UNIT OID_AT "\x0B"
113 /*
114  * OIDs for standard certificate extensions
115  */
116 #define OID_AUTHORITY_KEY_IDENTIFIER OID_ID_CE "\x23"
117 #define OID_SUBJECT_KEY_IDENTIFIER OID_ID_CE "\x0E"
118 #define OID_KEY_USAGE OID_ID_CE "\x0F"
119 #define OID_CERTIFICATE_POLICIES OID_ID_CE "\x20"
120 #define OID_POLICY_MAPPINGS OID_ID_CE "\x21"
121 #define OID_SUBJECT_ALT_NAME OID_ID_CE "\x11"
122 #define OID_ISSUER_ALT_NAME OID_ID_CE "\x12"
123 #define OID_SUBJECT_DIRECTORY_ATTRS OID_ID_CE "\x09"
124 #define OID_BASIC_CONSTRAINTS OID_ID_CE "\x13"
125 #define OID_NAME_CONSTRAINTS OID_ID_CE "\x1E"
126 #define OID_POLICY_CONSTRAINTS OID_ID_CE "\x24"
127 #define OID_EXTENDED_KEY_USAGE OID_ID_CE "\x25"
128 #define OID_CRL_DISTRIBUTION_POINTS OID_ID_CE "\x1F"
129 #define OID_INIHIBIT_ANYPOLICY OID_ID_CE "\x36"
130 #define OID_FRESHEST_CRL OID_ID_CE "\x2E"
132 /*
133  * Netscape certificate extensions
134  */
135 #define OID_NS_CERT OID_NETSCAPE "\x01"
136 #define OID_NS_CERT_TYPE OID_NS_CERT "\x01"
137 #define OID_NS_BASE_URL OID_NS_CERT "\x02"
138 #define OID_NS_REVOCATION_URL OID_NS_CERT "\x03"
139 #define OID_NS_CA_REVOCATION_URL OID_NS_CERT "\x04"
140 #define OID_NS_RENEWAL_URL OID_NS_CERT "\x07"
141 #define OID_NS_CA_POLICY_URL OID_NS_CERT "\x08"
142 #define OID_NS_SSL_SERVER_NAME OID_NS_CERT "\x0C"
143 #define OID_NS_COMMENT OID_NS_CERT "\x0D"
144 #define OID_NS_DATA_TYPE OID_NETSCAPE "\x02"
145 #define OID_NS_CERT_SEQUENCE OID_NS_DATA_TYPE "\x05"
146 
147 /*
148  * OIDs for CRL extensions
149  */
150 #define OID_PRIVATE_KEY_USAGE_PERIOD OID_ID_CE "\x10"
151 #define OID_CRL_NUMBER OID_ID_CE "\x14"
153 /*
154  * X.509 v3 Extended key usage OIDs
155  */
156 #define OID_ANY_EXTENDED_KEY_USAGE OID_EXTENDED_KEY_USAGE "\x00"
158 #define OID_KP OID_PKIX "\x03"
159 #define OID_SERVER_AUTH OID_KP "\x01"
160 #define OID_CLIENT_AUTH OID_KP "\x02"
161 #define OID_CODE_SIGNING OID_KP "\x03"
162 #define OID_EMAIL_PROTECTION OID_KP "\x04"
163 #define OID_TIME_STAMPING OID_KP "\x08"
164 #define OID_OCSP_SIGNING OID_KP "\x09"
166 /*
167  * PKCS definition OIDs
168  */
169 
170 #define OID_PKCS OID_RSA_COMPANY "\x01"
171 #define OID_PKCS1 OID_PKCS "\x01"
172 #define OID_PKCS5 OID_PKCS "\x05"
173 #define OID_PKCS9 OID_PKCS "\x09"
174 #define OID_PKCS12 OID_PKCS "\x0c"
176 /*
177  * PKCS#1 OIDs
178  */
179 #define OID_PKCS1_RSA OID_PKCS1 "\x01"
180 #define OID_PKCS1_MD2 OID_PKCS1 "\x02"
181 #define OID_PKCS1_MD4 OID_PKCS1 "\x03"
182 #define OID_PKCS1_MD5 OID_PKCS1 "\x04"
183 #define OID_PKCS1_SHA1 OID_PKCS1 "\x05"
184 #define OID_PKCS1_SHA224 OID_PKCS1 "\x0e"
185 #define OID_PKCS1_SHA256 OID_PKCS1 "\x0b"
186 #define OID_PKCS1_SHA384 OID_PKCS1 "\x0c"
187 #define OID_PKCS1_SHA512 OID_PKCS1 "\x0d"
189 #define OID_RSA_SHA_OBS "\x2B\x0E\x03\x02\x1D"
190 
191 #define OID_PKCS9_EMAIL OID_PKCS9 "\x01"
193 /*
194  * Digest algorithms
195  */
196 #define OID_DIGEST_ALG_MD2 OID_RSA_COMPANY "\x02\x02"
197 #define OID_DIGEST_ALG_MD4 OID_RSA_COMPANY "\x02\x04"
198 #define OID_DIGEST_ALG_MD5 OID_RSA_COMPANY "\x02\x05"
199 #define OID_DIGEST_ALG_SHA1 OID_ISO_IDENTIFIED_ORG OID_OIW_SECSIG_SHA1
200 #define OID_DIGEST_ALG_SHA224 OID_GOV "\x03\x04\x02\x04"
201 #define OID_DIGEST_ALG_SHA256 OID_GOV "\x03\x04\x02\x01"
203 #define OID_DIGEST_ALG_SHA384 OID_GOV "\x03\x04\x02\x02"
205 #define OID_DIGEST_ALG_SHA512 OID_GOV "\x03\x04\x02\x03"
207 #define OID_HMAC_SHA1 OID_RSA_COMPANY "\x02\x07"
209 /*
210  * Encryption algorithms
211  */
212 #define OID_DES_CBC OID_ISO_IDENTIFIED_ORG OID_OIW_SECSIG_ALG "\x07"
213 #define OID_DES_EDE3_CBC OID_RSA_COMPANY "\x03\x07"
215 /*
216  * PKCS#5 OIDs
217  */
218 #define OID_PKCS5_PBKDF2 OID_PKCS5 "\x0c"
219 #define OID_PKCS5_PBES2 OID_PKCS5 "\x0d"
220 #define OID_PKCS5_PBMAC1 OID_PKCS5 "\x0e"
222 /*
223  * PKCS#5 PBES1 algorithms
224  */
225 #define OID_PKCS5_PBE_MD2_DES_CBC OID_PKCS5 "\x01"
226 #define OID_PKCS5_PBE_MD2_RC2_CBC OID_PKCS5 "\x04"
227 #define OID_PKCS5_PBE_MD5_DES_CBC OID_PKCS5 "\x03"
228 #define OID_PKCS5_PBE_MD5_RC2_CBC OID_PKCS5 "\x06"
229 #define OID_PKCS5_PBE_SHA1_DES_CBC OID_PKCS5 "\x0a"
230 #define OID_PKCS5_PBE_SHA1_RC2_CBC OID_PKCS5 "\x0b"
232 /*
233  * PKCS#8 OIDs
234  */
235 #define OID_PKCS9_CSR_EXT_REQ OID_PKCS9 "\x0e"
237 /*
238  * PKCS#12 PBE OIDs
239  */
240 #define OID_PKCS12_PBE OID_PKCS12 "\x01"
242 #define OID_PKCS12_PBE_SHA1_RC4_128 OID_PKCS12_PBE "\x01"
243 #define OID_PKCS12_PBE_SHA1_RC4_40 OID_PKCS12_PBE "\x02"
244 #define OID_PKCS12_PBE_SHA1_DES3_EDE_CBC OID_PKCS12_PBE "\x03"
245 #define OID_PKCS12_PBE_SHA1_DES2_EDE_CBC OID_PKCS12_PBE "\x04"
246 #define OID_PKCS12_PBE_SHA1_RC2_128_CBC OID_PKCS12_PBE "\x05"
247 #define OID_PKCS12_PBE_SHA1_RC2_40_CBC OID_PKCS12_PBE "\x06"
249 /*
250  * EC key algorithms from RFC 5480
251  */
252 
253 /* id-ecPublicKey OBJECT IDENTIFIER ::= {
254  * iso(1) member-body(2) us(840) ansi-X9-62(10045) keyType(2) 1 } */
255 #define OID_EC_ALG_UNRESTRICTED OID_ANSI_X9_62 "\x02\01"
256 
257 /* id-ecDH OBJECT IDENTIFIER ::= {
258  * iso(1) identified-organization(3) certicom(132)
259  * schemes(1) ecdh(12) } */
260 #define OID_EC_ALG_ECDH OID_CERTICOM "\x01\x0c"
261 
262 /*
263  * ECParameters namedCurve identifiers, from RFC 5480 and RFC 5639
264  */
265 
266 /* secp192r1 OBJECT IDENTIFIER ::= {
267  * iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3) prime(1) 1 } */
268 #define OID_EC_GRP_SECP192R1 OID_ANSI_X9_62 "\x03\x01\x01"
269 
270 /* secp224r1 OBJECT IDENTIFIER ::= {
271  * iso(1) identified-organization(3) certicom(132) curve(0) 33 } */
272 #define OID_EC_GRP_SECP224R1 OID_CERTICOM "\x00\x21"
273 
274 /* secp256r1 OBJECT IDENTIFIER ::= {
275  * iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3) prime(1) 7 } */
276 #define OID_EC_GRP_SECP256R1 OID_ANSI_X9_62 "\x03\x01\x07"
277 
278 /* secp384r1 OBJECT IDENTIFIER ::= {
279  * iso(1) identified-organization(3) certicom(132) curve(0) 34 } */
280 #define OID_EC_GRP_SECP384R1 OID_CERTICOM "\x00\x22"
281 
282 /* secp521r1 OBJECT IDENTIFIER ::= {
283  * iso(1) identified-organization(3) certicom(132) curve(0) 35 } */
284 #define OID_EC_GRP_SECP521R1 OID_CERTICOM "\x00\x23"
285 
286 /* RFC 5639 4.1
287  * ecStdCurvesAndGeneration OBJECT IDENTIFIER::= {iso(1)
288  * identified-organization(3) teletrust(36) algorithm(3) signature-
289  * algorithm(3) ecSign(2) 8}
290  * ellipticCurve OBJECT IDENTIFIER ::= {ecStdCurvesAndGeneration 1}
291  * versionOne OBJECT IDENTIFIER ::= {ellipticCurve 1} */
292 #define OID_EC_BRAINPOOL_V1 OID_TELETRUST "\x03\x03\x02\x08\x01\x01"
293 
294 /* brainpoolP256r1 OBJECT IDENTIFIER ::= {versionOne 7} */
295 #define OID_EC_GRP_BP256R1 OID_EC_BRAINPOOL_V1 "\x07"
296 
297 /* brainpoolP384r1 OBJECT IDENTIFIER ::= {versionOne 11} */
298 #define OID_EC_GRP_BP384R1 OID_EC_BRAINPOOL_V1 "\x0B"
299 
300 /* brainpoolP512r1 OBJECT IDENTIFIER ::= {versionOne 13} */
301 #define OID_EC_GRP_BP512R1 OID_EC_BRAINPOOL_V1 "\x0D"
302 
303 /*
304  * ECDSA signature identifers, from RFC 5480
305  */
306 #define OID_ANSI_X9_62_SIG OID_ANSI_X9_62 "\x04" /* signatures(4) */
307 #define OID_ANSI_X9_62_SIG_SHA2 OID_ANSI_X9_62_SIG "\x03" /* ecdsa-with-SHA2(3) */
308 
309 /* ecdsa-with-SHA1 OBJECT IDENTIFIER ::= {
310  * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4) 1 } */
311 #define OID_ECDSA_SHA1 OID_ANSI_X9_62_SIG "\x01"
312 
313 /* ecdsa-with-SHA224 OBJECT IDENTIFIER ::= {
314  * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
315  * ecdsa-with-SHA2(3) 1 } */
316 #define OID_ECDSA_SHA224 OID_ANSI_X9_62_SIG_SHA2 "\x01"
317 
318 /* ecdsa-with-SHA256 OBJECT IDENTIFIER ::= {
319  * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
320  * ecdsa-with-SHA2(3) 2 } */
321 #define OID_ECDSA_SHA256 OID_ANSI_X9_62_SIG_SHA2 "\x02"
322 
323 /* ecdsa-with-SHA384 OBJECT IDENTIFIER ::= {
324  * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
325  * ecdsa-with-SHA2(3) 3 } */
326 #define OID_ECDSA_SHA384 OID_ANSI_X9_62_SIG_SHA2 "\x03"
327 
328 /* ecdsa-with-SHA512 OBJECT IDENTIFIER ::= {
329  * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
330  * ecdsa-with-SHA2(3) 4 } */
331 #define OID_ECDSA_SHA512 OID_ANSI_X9_62_SIG_SHA2 "\x04"
332 
333 #ifdef __cplusplus
334 extern "C" {
335 #endif
336 
340 typedef struct {
341  const char *asn1;
342  size_t asn1_len;
343  const char *name;
344  const char *description;
346 
357 int oid_get_numeric_string( char *buf, size_t size, const asn1_buf *oid );
358 
359 #if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
360 
368 int oid_get_x509_ext_type( const asn1_buf *oid, int *ext_type );
369 #endif
370 
380 int oid_get_attr_short_name( const asn1_buf *oid, const char **short_name );
381 
390 int oid_get_pk_alg( const asn1_buf *oid, pk_type_t *pk_alg );
391 
401 int oid_get_oid_by_pk_alg( pk_type_t pk_alg,
402  const char **oid, size_t *olen );
403 
404 #if defined(POLARSSL_ECP_C)
405 
413 int oid_get_ec_grp( const asn1_buf *oid, ecp_group_id *grp_id );
414 
425  const char **oid, size_t *olen );
426 #endif /* POLARSSL_ECP_C */
427 
428 #if defined(POLARSSL_MD_C)
429 
438 int oid_get_sig_alg( const asn1_buf *oid,
439  md_type_t *md_alg, pk_type_t *pk_alg );
440 
449 int oid_get_sig_alg_desc( const asn1_buf *oid, const char **desc );
450 
461 int oid_get_oid_by_sig_alg( pk_type_t pk_alg, md_type_t md_alg,
462  const char **oid, size_t *olen );
463 
472 int oid_get_md_alg( const asn1_buf *oid, md_type_t *md_alg );
473 #endif /* POLARSSL_MD_C */
474 
483 int oid_get_extended_key_usage( const asn1_buf *oid, const char **desc );
484 
494 int oid_get_oid_by_md( md_type_t md_alg, const char **oid, size_t *olen );
495 
496 #if defined(POLARSSL_CIPHER_C)
497 
505 int oid_get_cipher_alg( const asn1_buf *oid, cipher_type_t *cipher_alg );
506 #endif /* POLARSSL_CIPHER_C */
507 
508 #if defined(POLARSSL_PKCS12_C)
509 
519 int oid_get_pkcs12_pbe_alg( const asn1_buf *oid, md_type_t *md_alg,
520  cipher_type_t *cipher_alg );
521 #endif /* POLARSSL_PKCS12_C */
522 
523 #ifdef __cplusplus
524 }
525 #endif
526 
527 #endif /* oid.h */
int oid_get_numeric_string(char *buf, size_t size, const asn1_buf *oid)
Translate an ASN.1 OID into its numeric representation (e.g.
int oid_get_oid_by_ec_grp(ecp_group_id grp_id, const char **oid, size_t *olen)
Translate EC group identifier into NamedCurve OID.
const char * description
Definition: oid.h:344
int oid_get_oid_by_pk_alg(pk_type_t pk_alg, const char **oid, size_t *olen)
Translate pk_type into PublicKeyAlgorithm OID.
int oid_get_pk_alg(const asn1_buf *oid, pk_type_t *pk_alg)
Translate PublicKeyAlgorithm OID into pk_type.
int oid_get_x509_ext_type(const asn1_buf *oid, int *ext_type)
Translate an X.509 extension OID into local values.
Configuration options (set of defines)
int oid_get_md_alg(const asn1_buf *oid, md_type_t *md_alg)
Translate hash algorithm OID into md_type.
Base OID descriptor structure.
Definition: oid.h:340
Public Key abstraction layer.
md_type_t
Definition: md.h:51
Generic ASN.1 parsing.
const char * name
Definition: oid.h:343
cipher_type_t
Definition: cipher.h:75
int oid_get_cipher_alg(const asn1_buf *oid, cipher_type_t *cipher_alg)
Translate encryption algorithm OID into cipher_type.
const char * asn1
Definition: oid.h:341
int oid_get_sig_alg_desc(const asn1_buf *oid, const char **desc)
Translate SignatureAlgorithm OID into description.
Generic cipher wrapper.
pk_type_t
Public key types.
Definition: pk.h:90
int oid_get_pkcs12_pbe_alg(const asn1_buf *oid, md_type_t *md_alg, cipher_type_t *cipher_alg)
Translate PKCS#12 PBE algorithm OID into md_type and cipher_type.
X.509 generic defines and structures.
Generic message digest wrapper.
Type-length-value structure that allows for ASN1 using DER.
Definition: asn1.h:116
int oid_get_ec_grp(const asn1_buf *oid, ecp_group_id *grp_id)
Translate NamedCurve OID into an EC group identifier.
ecp_group_id
Domain parameters (curve, subgroup and generator) identifiers.
Definition: ecp.h:56
int oid_get_oid_by_md(md_type_t md_alg, const char **oid, size_t *olen)
Translate md_type into hash algorithm OID.
size_t asn1_len
Definition: oid.h:342
int oid_get_sig_alg(const asn1_buf *oid, md_type_t *md_alg, pk_type_t *pk_alg)
Translate SignatureAlgorithm OID into md_type and pk_type.
int oid_get_attr_short_name(const asn1_buf *oid, const char **short_name)
Translate an X.509 attribute type OID into the short name (e.g.
int oid_get_extended_key_usage(const asn1_buf *oid, const char **desc)
Translate Extended Key Usage OID into description.
int oid_get_oid_by_sig_alg(pk_type_t pk_alg, md_type_t md_alg, const char **oid, size_t *olen)
Translate md_type and pk_type into SignatureAlgorithm OID.