2 * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
11 #include "internal/cryptlib.h"
12 #include <openssl/conf.h>
13 #include <openssl/x509v3.h>
16 DEFINE_STACK_OF(CONF_VALUE)
18 static BIT_STRING_BITNAME ns_cert_type_table[] = {
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"},
30 static BIT_STRING_BITNAME key_usage_type_table[] = {
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"},
43 const X509V3_EXT_METHOD v3_nscert =
44 EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
45 const X509V3_EXT_METHOD v3_key_usage =
46 EXT_BITSTRING(NID_key_usage, key_usage_type_table);
48 STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
49 ASN1_BIT_STRING *bits,
50 STACK_OF(CONF_VALUE) *ret)
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);
60 ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
62 STACK_OF(CONF_VALUE) *nval)
67 BIT_STRING_BITNAME *bnam;
68 if ((bs = ASN1_BIT_STRING_new()) == NULL) {
69 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, ERR_R_MALLOC_FAILURE);
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++) {
75 if (strcmp(bnam->sname, val->name) == 0
76 || strcmp(bnam->lname, val->name) == 0) {
77 if (!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) {
78 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
79 ERR_R_MALLOC_FAILURE);
80 ASN1_BIT_STRING_free(bs);
87 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
88 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
90 ASN1_BIT_STRING_free(bs);