]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/asn1/asn_moid.c
Copyright consolidation 08/10
[thirdparty/openssl.git] / crypto / asn1 / asn_moid.c
CommitLineData
0f113f3e 1/*
2039c421 2 * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
bc37d996 3 *
2039c421
RS
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
bc37d996
DSH
8 */
9
10#include <stdio.h>
6446e0c3 11#include <ctype.h>
bc37d996 12#include <openssl/crypto.h>
b39fc560 13#include "internal/cryptlib.h"
bc37d996 14#include <openssl/conf.h>
bc37d996 15#include <openssl/x509.h>
2e430277 16#include "internal/asn1_int.h"
7b8cc9b3 17#include "internal/objects.h"
bc37d996
DSH
18
19/* Simple ASN1 OID module: add all objects in a given section */
20
6446e0c3
DSH
21static int do_create(char *value, char *name);
22
9dd5ae65 23static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
0f113f3e
MC
24{
25 int i;
26 const char *oid_section;
27 STACK_OF(CONF_VALUE) *sktmp;
28 CONF_VALUE *oval;
75ebbd9a 29
0f113f3e 30 oid_section = CONF_imodule_get_value(md);
75ebbd9a 31 if ((sktmp = NCONF_get_section(cnf, oid_section)) == NULL) {
0f113f3e
MC
32 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
33 return 0;
34 }
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);
39 return 0;
40 }
41 }
42 return 1;
43}
5fa5eb71
DSH
44
45static void oid_module_finish(CONF_IMODULE *md)
0f113f3e 46{
0f113f3e 47}
bc37d996
DSH
48
49void ASN1_add_oid_module(void)
0f113f3e
MC
50{
51 CONF_module_add("oid_section", oid_module_init, oid_module_finish);
52}
6446e0c3 53
c80fd6b2
MC
54/*-
55 * Create an OID based on a name value pair. Accept two formats.
6446e0c3
DSH
56 * shortname = 1.2.3.4
57 * shortname = some long name, 1.2.3.4
58 */
59
6446e0c3 60static int do_create(char *value, char *name)
0f113f3e
MC
61{
62 int nid;
63 ASN1_OBJECT *oid;
64 char *ln, *ostr, *p, *lntmp;
65 p = strrchr(value, ',');
66 if (!p) {
67 ln = name;
68 ostr = value;
69 } else {
70 ln = NULL;
71 ostr = p + 1;
72 if (!*ostr)
73 return 0;
74 while (isspace((unsigned char)*ostr))
75 ostr++;
76 }
6446e0c3 77
0f113f3e 78 nid = OBJ_create(ostr, name, ln);
6446e0c3 79
0f113f3e
MC
80 if (nid == NID_undef)
81 return 0;
6446e0c3 82
0f113f3e
MC
83 if (p) {
84 ln = value;
85 while (isspace((unsigned char)*ln))
86 ln++;
87 p--;
88 while (isspace((unsigned char)*p)) {
89 if (p == ln)
90 return 0;
91 p--;
92 }
93 p++;
94 lntmp = OPENSSL_malloc((p - ln) + 1);
95 if (lntmp == NULL)
96 return 0;
97 memcpy(lntmp, ln, p - ln);
98 lntmp[p - ln] = 0;
99 oid = OBJ_nid2obj(nid);
100 oid->ln = lntmp;
101 }
6446e0c3 102
0f113f3e
MC
103 return 1;
104}