2 * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
12 #include <openssl/crypto.h>
13 #include "internal/cryptlib.h"
14 #include <openssl/conf.h>
15 #include <openssl/x509.h>
16 #include "internal/asn1_int.h"
17 #include "internal/objects.h"
19 /* Simple ASN1 OID module: add all objects in a given section */
21 static int do_create(char *value
, char *name
);
23 static int oid_module_init(CONF_IMODULE
*md
, const CONF
*cnf
)
26 const char *oid_section
;
27 STACK_OF(CONF_VALUE
) *sktmp
;
30 oid_section
= CONF_imodule_get_value(md
);
31 if ((sktmp
= NCONF_get_section(cnf
, oid_section
)) == NULL
) {
32 ASN1err(ASN1_F_OID_MODULE_INIT
, ASN1_R_ERROR_LOADING_SECTION
);
35 for (i
= 0; i
< sk_CONF_VALUE_num(sktmp
); i
++) {
36 oval
= sk_CONF_VALUE_value(sktmp
, i
);
37 if (!do_create(oval
->value
, oval
->name
)) {
38 ASN1err(ASN1_F_OID_MODULE_INIT
, ASN1_R_ADDING_OBJECT
);
45 static void oid_module_finish(CONF_IMODULE
*md
)
49 void ASN1_add_oid_module(void)
51 CONF_module_add("oid_section", oid_module_init
, oid_module_finish
);
55 * Create an OID based on a name value pair. Accept two formats.
57 * shortname = some long name, 1.2.3.4
60 static int do_create(char *value
, char *name
)
64 char *ln
, *ostr
, *p
, *lntmp
;
65 p
= strrchr(value
, ',');
74 while (isspace((unsigned char)*ostr
))
78 nid
= OBJ_create(ostr
, name
, ln
);
85 while (isspace((unsigned char)*ln
))
88 while (isspace((unsigned char)*p
)) {
94 lntmp
= OPENSSL_malloc((p
- ln
) + 1);
97 memcpy(lntmp
, ln
, p
- ln
);
99 oid
= OBJ_nid2obj(nid
);