]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/x509/v3_bitst.c
Update copyright year
[thirdparty/openssl.git] / crypto / x509 / v3_bitst.c
CommitLineData
0f113f3e 1/*
454afd98 2 * Copyright 1999-2020 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
852c2ed2
RS
16DEFINE_STACK_OF(CONF_VALUE)
17
9aeaf1b4 18static BIT_STRING_BITNAME ns_cert_type_table[] = {
0f113f3e
MC
19 {0, "SSL Client", "client"},
20 {1, "SSL Server", "server"},
21 {2, "S/MIME", "email"},
22 {3, "Object Signing", "objsign"},
23 {4, "Unused", "reserved"},
24 {5, "SSL CA", "sslCA"},
25 {6, "S/MIME CA", "emailCA"},
26 {7, "Object Signing CA", "objCA"},
27 {-1, NULL, NULL}
9aeaf1b4
DSH
28};
29
30static BIT_STRING_BITNAME key_usage_type_table[] = {
0f113f3e
MC
31 {0, "Digital Signature", "digitalSignature"},
32 {1, "Non Repudiation", "nonRepudiation"},
33 {2, "Key Encipherment", "keyEncipherment"},
34 {3, "Data Encipherment", "dataEncipherment"},
35 {4, "Key Agreement", "keyAgreement"},
36 {5, "Certificate Sign", "keyCertSign"},
37 {6, "CRL Sign", "cRLSign"},
38 {7, "Encipher Only", "encipherOnly"},
39 {8, "Decipher Only", "decipherOnly"},
40 {-1, NULL, NULL}
9aeaf1b4
DSH
41};
42
0f113f3e
MC
43const X509V3_EXT_METHOD v3_nscert =
44EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
45const X509V3_EXT_METHOD v3_key_usage =
46EXT_BITSTRING(NID_key_usage, key_usage_type_table);
9aeaf1b4 47
5d6383c8 48STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
0f113f3e
MC
49 ASN1_BIT_STRING *bits,
50 STACK_OF(CONF_VALUE) *ret)
9aeaf1b4 51{
0f113f3e
MC
52 BIT_STRING_BITNAME *bnam;
53 for (bnam = method->usr_data; bnam->lname; bnam++) {
54 if (ASN1_BIT_STRING_get_bit(bits, bnam->bitnum))
55 X509V3_add_value(bnam->lname, NULL, &ret);
56 }
57 return ret;
9aeaf1b4 58}
0f113f3e 59
5d6383c8 60ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
0f113f3e
MC
61 X509V3_CTX *ctx,
62 STACK_OF(CONF_VALUE) *nval)
9aeaf1b4 63{
0f113f3e
MC
64 CONF_VALUE *val;
65 ASN1_BIT_STRING *bs;
66 int i;
67 BIT_STRING_BITNAME *bnam;
75ebbd9a 68 if ((bs = ASN1_BIT_STRING_new()) == NULL) {
0f113f3e
MC
69 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, ERR_R_MALLOC_FAILURE);
70 return NULL;
71 }
72 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
73 val = sk_CONF_VALUE_value(nval, i);
74 for (bnam = method->usr_data; bnam->lname; bnam++) {
86885c28
RS
75 if (strcmp(bnam->sname, val->name) == 0
76 || strcmp(bnam->lname, val->name) == 0) {
0f113f3e
MC
77 if (!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) {
78 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
79 ERR_R_MALLOC_FAILURE);
f422a514 80 ASN1_BIT_STRING_free(bs);
0f113f3e
MC
81 return NULL;
82 }
83 break;
84 }
85 }
86 if (!bnam->lname) {
87 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
88 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
89 X509V3_conf_err(val);
f422a514 90 ASN1_BIT_STRING_free(bs);
0f113f3e
MC
91 return NULL;
92 }
93 }
94 return bs;
9aeaf1b4 95}