]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/x509/v3_bitst.c
threads_pthread.c: change inline to ossl_inline
[thirdparty/openssl.git] / crypto / x509 / v3_bitst.c
CommitLineData
0f113f3e 1/*
3c2bdd7d 2 * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
9aeaf1b4 3 *
4286ca47 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
d2e9e320
RS
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
9aeaf1b4
DSH
8 */
9
10#include <stdio.h>
b39fc560 11#include "internal/cryptlib.h"
ec577822
BM
12#include <openssl/conf.h>
13#include <openssl/x509v3.h>
df2ee0e2 14#include "ext_dat.h"
9aeaf1b4 15
9aeaf1b4 16static BIT_STRING_BITNAME ns_cert_type_table[] = {
0f113f3e
MC
17 {0, "SSL Client", "client"},
18 {1, "SSL Server", "server"},
19 {2, "S/MIME", "email"},
20 {3, "Object Signing", "objsign"},
21 {4, "Unused", "reserved"},
22 {5, "SSL CA", "sslCA"},
23 {6, "S/MIME CA", "emailCA"},
24 {7, "Object Signing CA", "objCA"},
25 {-1, NULL, NULL}
9aeaf1b4
DSH
26};
27
28static BIT_STRING_BITNAME key_usage_type_table[] = {
0f113f3e
MC
29 {0, "Digital Signature", "digitalSignature"},
30 {1, "Non Repudiation", "nonRepudiation"},
31 {2, "Key Encipherment", "keyEncipherment"},
32 {3, "Data Encipherment", "dataEncipherment"},
33 {4, "Key Agreement", "keyAgreement"},
34 {5, "Certificate Sign", "keyCertSign"},
35 {6, "CRL Sign", "cRLSign"},
36 {7, "Encipher Only", "encipherOnly"},
37 {8, "Decipher Only", "decipherOnly"},
38 {-1, NULL, NULL}
9aeaf1b4
DSH
39};
40
47864aea 41const X509V3_EXT_METHOD ossl_v3_nscert =
0f113f3e 42EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
47864aea 43const X509V3_EXT_METHOD ossl_v3_key_usage =
0f113f3e 44EXT_BITSTRING(NID_key_usage, key_usage_type_table);
9aeaf1b4 45
5d6383c8 46STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
0f113f3e
MC
47 ASN1_BIT_STRING *bits,
48 STACK_OF(CONF_VALUE) *ret)
9aeaf1b4 49{
0f113f3e
MC
50 BIT_STRING_BITNAME *bnam;
51 for (bnam = method->usr_data; bnam->lname; bnam++) {
52 if (ASN1_BIT_STRING_get_bit(bits, bnam->bitnum))
53 X509V3_add_value(bnam->lname, NULL, &ret);
54 }
55 return ret;
9aeaf1b4 56}
0f113f3e 57
5d6383c8 58ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
0f113f3e
MC
59 X509V3_CTX *ctx,
60 STACK_OF(CONF_VALUE) *nval)
9aeaf1b4 61{
0f113f3e
MC
62 CONF_VALUE *val;
63 ASN1_BIT_STRING *bs;
64 int i;
65 BIT_STRING_BITNAME *bnam;
75ebbd9a 66 if ((bs = ASN1_BIT_STRING_new()) == NULL) {
e077455e 67 ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
0f113f3e
MC
68 return NULL;
69 }
70 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
71 val = sk_CONF_VALUE_value(nval, i);
72 for (bnam = method->usr_data; bnam->lname; bnam++) {
86885c28
RS
73 if (strcmp(bnam->sname, val->name) == 0
74 || strcmp(bnam->lname, val->name) == 0) {
0f113f3e 75 if (!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) {
e077455e 76 ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
f422a514 77 ASN1_BIT_STRING_free(bs);
0f113f3e
MC
78 return NULL;
79 }
80 break;
81 }
82 }
83 if (!bnam->lname) {
a150f8e1
RL
84 ERR_raise_data(ERR_LIB_X509V3, X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT,
85 "%s", val->name);
f422a514 86 ASN1_BIT_STRING_free(bs);
0f113f3e
MC
87 return NULL;
88 }
89 }
90 return bs;
9aeaf1b4 91}