PolarSSL v1.3.3
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_SERIAL_NUMBER OID_AT "\x05"
108 #define OID_AT_COUNTRY OID_AT "\x06"
109 #define OID_AT_LOCALITY OID_AT "\x07"
110 #define OID_AT_STATE OID_AT "\x08"
111 #define OID_AT_ORGANIZATION OID_AT "\x0A"
112 #define OID_AT_ORG_UNIT OID_AT "\x0B"
113 #define OID_AT_POSTAL_ADDRESS OID_AT "\x10"
114 #define OID_AT_POSTAL_CODE OID_AT "\x11"
116 /*
117  * OIDs for standard certificate extensions
118  */
119 #define OID_AUTHORITY_KEY_IDENTIFIER OID_ID_CE "\x23"
120 #define OID_SUBJECT_KEY_IDENTIFIER OID_ID_CE "\x0E"
121 #define OID_KEY_USAGE OID_ID_CE "\x0F"
122 #define OID_CERTIFICATE_POLICIES OID_ID_CE "\x20"
123 #define OID_POLICY_MAPPINGS OID_ID_CE "\x21"
124 #define OID_SUBJECT_ALT_NAME OID_ID_CE "\x11"
125 #define OID_ISSUER_ALT_NAME OID_ID_CE "\x12"
126 #define OID_SUBJECT_DIRECTORY_ATTRS OID_ID_CE "\x09"
127 #define OID_BASIC_CONSTRAINTS OID_ID_CE "\x13"
128 #define OID_NAME_CONSTRAINTS OID_ID_CE "\x1E"
129 #define OID_POLICY_CONSTRAINTS OID_ID_CE "\x24"
130 #define OID_EXTENDED_KEY_USAGE OID_ID_CE "\x25"
131 #define OID_CRL_DISTRIBUTION_POINTS OID_ID_CE "\x1F"
132 #define OID_INIHIBIT_ANYPOLICY OID_ID_CE "\x36"
133 #define OID_FRESHEST_CRL OID_ID_CE "\x2E"
135 /*
136  * Netscape certificate extensions
137  */
138 #define OID_NS_CERT OID_NETSCAPE "\x01"
139 #define OID_NS_CERT_TYPE OID_NS_CERT "\x01"
140 #define OID_NS_BASE_URL OID_NS_CERT "\x02"
141 #define OID_NS_REVOCATION_URL OID_NS_CERT "\x03"
142 #define OID_NS_CA_REVOCATION_URL OID_NS_CERT "\x04"
143 #define OID_NS_RENEWAL_URL OID_NS_CERT "\x07"
144 #define OID_NS_CA_POLICY_URL OID_NS_CERT "\x08"
145 #define OID_NS_SSL_SERVER_NAME OID_NS_CERT "\x0C"
146 #define OID_NS_COMMENT OID_NS_CERT "\x0D"
147 #define OID_NS_DATA_TYPE OID_NETSCAPE "\x02"
148 #define OID_NS_CERT_SEQUENCE OID_NS_DATA_TYPE "\x05"
149 
150 /*
151  * OIDs for CRL extensions
152  */
153 #define OID_PRIVATE_KEY_USAGE_PERIOD OID_ID_CE "\x10"
154 #define OID_CRL_NUMBER OID_ID_CE "\x14"
156 /*
157  * X.509 v3 Extended key usage OIDs
158  */
159 #define OID_ANY_EXTENDED_KEY_USAGE OID_EXTENDED_KEY_USAGE "\x00"
161 #define OID_KP OID_PKIX "\x03"
162 #define OID_SERVER_AUTH OID_KP "\x01"
163 #define OID_CLIENT_AUTH OID_KP "\x02"
164 #define OID_CODE_SIGNING OID_KP "\x03"
165 #define OID_EMAIL_PROTECTION OID_KP "\x04"
166 #define OID_TIME_STAMPING OID_KP "\x08"
167 #define OID_OCSP_SIGNING OID_KP "\x09"
169 /*
170  * PKCS definition OIDs
171  */
172 
173 #define OID_PKCS OID_RSA_COMPANY "\x01"
174 #define OID_PKCS1 OID_PKCS "\x01"
175 #define OID_PKCS5 OID_PKCS "\x05"
176 #define OID_PKCS9 OID_PKCS "\x09"
177 #define OID_PKCS12 OID_PKCS "\x0c"
179 /*
180  * PKCS#1 OIDs
181  */
182 #define OID_PKCS1_RSA OID_PKCS1 "\x01"
183 #define OID_PKCS1_MD2 OID_PKCS1 "\x02"
184 #define OID_PKCS1_MD4 OID_PKCS1 "\x03"
185 #define OID_PKCS1_MD5 OID_PKCS1 "\x04"
186 #define OID_PKCS1_SHA1 OID_PKCS1 "\x05"
187 #define OID_PKCS1_SHA224 OID_PKCS1 "\x0e"
188 #define OID_PKCS1_SHA256 OID_PKCS1 "\x0b"
189 #define OID_PKCS1_SHA384 OID_PKCS1 "\x0c"
190 #define OID_PKCS1_SHA512 OID_PKCS1 "\x0d"
192 #define OID_RSA_SHA_OBS "\x2B\x0E\x03\x02\x1D"
193 
194 #define OID_PKCS9_EMAIL OID_PKCS9 "\x01"
196 /*
197  * Digest algorithms
198  */
199 #define OID_DIGEST_ALG_MD2 OID_RSA_COMPANY "\x02\x02"
200 #define OID_DIGEST_ALG_MD4 OID_RSA_COMPANY "\x02\x04"
201 #define OID_DIGEST_ALG_MD5 OID_RSA_COMPANY "\x02\x05"
202 #define OID_DIGEST_ALG_SHA1 OID_ISO_IDENTIFIED_ORG OID_OIW_SECSIG_SHA1
203 #define OID_DIGEST_ALG_SHA224 OID_GOV "\x03\x04\x02\x04"
204 #define OID_DIGEST_ALG_SHA256 OID_GOV "\x03\x04\x02\x01"
206 #define OID_DIGEST_ALG_SHA384 OID_GOV "\x03\x04\x02\x02"
208 #define OID_DIGEST_ALG_SHA512 OID_GOV "\x03\x04\x02\x03"
210 #define OID_HMAC_SHA1 OID_RSA_COMPANY "\x02\x07"
212 /*
213  * Encryption algorithms
214  */
215 #define OID_DES_CBC OID_ISO_IDENTIFIED_ORG OID_OIW_SECSIG_ALG "\x07"
216 #define OID_DES_EDE3_CBC OID_RSA_COMPANY "\x03\x07"
218 /*
219  * PKCS#5 OIDs
220  */
221 #define OID_PKCS5_PBKDF2 OID_PKCS5 "\x0c"
222 #define OID_PKCS5_PBES2 OID_PKCS5 "\x0d"
223 #define OID_PKCS5_PBMAC1 OID_PKCS5 "\x0e"
225 /*
226  * PKCS#5 PBES1 algorithms
227  */
228 #define OID_PKCS5_PBE_MD2_DES_CBC OID_PKCS5 "\x01"
229 #define OID_PKCS5_PBE_MD2_RC2_CBC OID_PKCS5 "\x04"
230 #define OID_PKCS5_PBE_MD5_DES_CBC OID_PKCS5 "\x03"
231 #define OID_PKCS5_PBE_MD5_RC2_CBC OID_PKCS5 "\x06"
232 #define OID_PKCS5_PBE_SHA1_DES_CBC OID_PKCS5 "\x0a"
233 #define OID_PKCS5_PBE_SHA1_RC2_CBC OID_PKCS5 "\x0b"
235 /*
236  * PKCS#8 OIDs
237  */
238 #define OID_PKCS9_CSR_EXT_REQ OID_PKCS9 "\x0e"
240 /*
241  * PKCS#12 PBE OIDs
242  */
243 #define OID_PKCS12_PBE OID_PKCS12 "\x01"
245 #define OID_PKCS12_PBE_SHA1_RC4_128 OID_PKCS12_PBE "\x01"
246 #define OID_PKCS12_PBE_SHA1_RC4_40 OID_PKCS12_PBE "\x02"
247 #define OID_PKCS12_PBE_SHA1_DES3_EDE_CBC OID_PKCS12_PBE "\x03"
248 #define OID_PKCS12_PBE_SHA1_DES2_EDE_CBC OID_PKCS12_PBE "\x04"
249 #define OID_PKCS12_PBE_SHA1_RC2_128_CBC OID_PKCS12_PBE "\x05"
250 #define OID_PKCS12_PBE_SHA1_RC2_40_CBC OID_PKCS12_PBE "\x06"
252 /*
253  * EC key algorithms from RFC 5480
254  */
255 
256 /* id-ecPublicKey OBJECT IDENTIFIER ::= {
257  * iso(1) member-body(2) us(840) ansi-X9-62(10045) keyType(2) 1 } */
258 #define OID_EC_ALG_UNRESTRICTED OID_ANSI_X9_62 "\x02\01"
259 
260 /* id-ecDH OBJECT IDENTIFIER ::= {
261  * iso(1) identified-organization(3) certicom(132)
262  * schemes(1) ecdh(12) } */
263 #define OID_EC_ALG_ECDH OID_CERTICOM "\x01\x0c"
264 
265 /*
266  * ECParameters namedCurve identifiers, from RFC 5480 and RFC 5639
267  */
268 
269 /* secp192r1 OBJECT IDENTIFIER ::= {
270  * iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3) prime(1) 1 } */
271 #define OID_EC_GRP_SECP192R1 OID_ANSI_X9_62 "\x03\x01\x01"
272 
273 /* secp224r1 OBJECT IDENTIFIER ::= {
274  * iso(1) identified-organization(3) certicom(132) curve(0) 33 } */
275 #define OID_EC_GRP_SECP224R1 OID_CERTICOM "\x00\x21"
276 
277 /* secp256r1 OBJECT IDENTIFIER ::= {
278  * iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3) prime(1) 7 } */
279 #define OID_EC_GRP_SECP256R1 OID_ANSI_X9_62 "\x03\x01\x07"
280 
281 /* secp384r1 OBJECT IDENTIFIER ::= {
282  * iso(1) identified-organization(3) certicom(132) curve(0) 34 } */
283 #define OID_EC_GRP_SECP384R1 OID_CERTICOM "\x00\x22"
284 
285 /* secp521r1 OBJECT IDENTIFIER ::= {
286  * iso(1) identified-organization(3) certicom(132) curve(0) 35 } */
287 #define OID_EC_GRP_SECP521R1 OID_CERTICOM "\x00\x23"
288 
289 /* RFC 5639 4.1
290  * ecStdCurvesAndGeneration OBJECT IDENTIFIER::= {iso(1)
291  * identified-organization(3) teletrust(36) algorithm(3) signature-
292  * algorithm(3) ecSign(2) 8}
293  * ellipticCurve OBJECT IDENTIFIER ::= {ecStdCurvesAndGeneration 1}
294  * versionOne OBJECT IDENTIFIER ::= {ellipticCurve 1} */
295 #define OID_EC_BRAINPOOL_V1 OID_TELETRUST "\x03\x03\x02\x08\x01\x01"
296 
297 /* brainpoolP256r1 OBJECT IDENTIFIER ::= {versionOne 7} */
298 #define OID_EC_GRP_BP256R1 OID_EC_BRAINPOOL_V1 "\x07"
299 
300 /* brainpoolP384r1 OBJECT IDENTIFIER ::= {versionOne 11} */
301 #define OID_EC_GRP_BP384R1 OID_EC_BRAINPOOL_V1 "\x0B"
302 
303 /* brainpoolP512r1 OBJECT IDENTIFIER ::= {versionOne 13} */
304 #define OID_EC_GRP_BP512R1 OID_EC_BRAINPOOL_V1 "\x0D"
305 
306 /*
307  * ECDSA signature identifers, from RFC 5480
308  */
309 #define OID_ANSI_X9_62_SIG OID_ANSI_X9_62 "\x04" /* signatures(4) */
310 #define OID_ANSI_X9_62_SIG_SHA2 OID_ANSI_X9_62_SIG "\x03" /* ecdsa-with-SHA2(3) */
311 
312 /* ecdsa-with-SHA1 OBJECT IDENTIFIER ::= {
313  * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4) 1 } */
314 #define OID_ECDSA_SHA1 OID_ANSI_X9_62_SIG "\x01"
315 
316 /* ecdsa-with-SHA224 OBJECT IDENTIFIER ::= {
317  * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
318  * ecdsa-with-SHA2(3) 1 } */
319 #define OID_ECDSA_SHA224 OID_ANSI_X9_62_SIG_SHA2 "\x01"
320 
321 /* ecdsa-with-SHA256 OBJECT IDENTIFIER ::= {
322  * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
323  * ecdsa-with-SHA2(3) 2 } */
324 #define OID_ECDSA_SHA256 OID_ANSI_X9_62_SIG_SHA2 "\x02"
325 
326 /* ecdsa-with-SHA384 OBJECT IDENTIFIER ::= {
327  * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
328  * ecdsa-with-SHA2(3) 3 } */
329 #define OID_ECDSA_SHA384 OID_ANSI_X9_62_SIG_SHA2 "\x03"
330 
331 /* ecdsa-with-SHA512 OBJECT IDENTIFIER ::= {
332  * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
333  * ecdsa-with-SHA2(3) 4 } */
334 #define OID_ECDSA_SHA512 OID_ANSI_X9_62_SIG_SHA2 "\x04"
335 
336 #ifdef __cplusplus
337 extern "C" {
338 #endif
339 
343 typedef struct {
344  const char *asn1;
345  size_t asn1_len;
346  const char *name;
347  const char *description;
349 
360 int oid_get_numeric_string( char *buf, size_t size, const asn1_buf *oid );
361 
362 #if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
363 
371 int oid_get_x509_ext_type( const asn1_buf *oid, int *ext_type );
372 #endif
373 
383 int oid_get_attr_short_name( const asn1_buf *oid, const char **short_name );
384 
393 int oid_get_pk_alg( const asn1_buf *oid, pk_type_t *pk_alg );
394 
404 int oid_get_oid_by_pk_alg( pk_type_t pk_alg,
405  const char **oid, size_t *olen );
406 
407 #if defined(POLARSSL_ECP_C)
408 
416 int oid_get_ec_grp( const asn1_buf *oid, ecp_group_id *grp_id );
417 
428  const char **oid, size_t *olen );
429 #endif /* POLARSSL_ECP_C */
430 
431 #if defined(POLARSSL_MD_C)
432 
441 int oid_get_sig_alg( const asn1_buf *oid,
442  md_type_t *md_alg, pk_type_t *pk_alg );
443 
452 int oid_get_sig_alg_desc( const asn1_buf *oid, const char **desc );
453 
464 int oid_get_oid_by_sig_alg( pk_type_t pk_alg, md_type_t md_alg,
465  const char **oid, size_t *olen );
466 
475 int oid_get_md_alg( const asn1_buf *oid, md_type_t *md_alg );
476 #endif /* POLARSSL_MD_C */
477 
486 int oid_get_extended_key_usage( const asn1_buf *oid, const char **desc );
487 
497 int oid_get_oid_by_md( md_type_t md_alg, const char **oid, size_t *olen );
498 
499 #if defined(POLARSSL_CIPHER_C)
500 
508 int oid_get_cipher_alg( const asn1_buf *oid, cipher_type_t *cipher_alg );
509 #endif /* POLARSSL_CIPHER_C */
510 
511 #if defined(POLARSSL_PKCS12_C)
512 
522 int oid_get_pkcs12_pbe_alg( const asn1_buf *oid, md_type_t *md_alg,
523  cipher_type_t *cipher_alg );
524 #endif /* POLARSSL_PKCS12_C */
525 
526 #ifdef __cplusplus
527 }
528 #endif
529 
530 #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:347
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:343
Public Key abstraction layer.
md_type_t
Definition: md.h:51
Generic ASN.1 parsing.
const char * name
Definition: oid.h:346
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:344
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:345
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.