1 /*
2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10 #include <stdio.h>
11
12 #include <openssl/mem.h>
13 #include <openssl/obj.h>
14 #include <openssl/x509.h>
15 #include <openssl/x509v3.h>
16
17 #include "ext_dat.h"
18 #include "internal.h"
19
20
21 typedef BIT_STRING_BITNAME ENUMERATED_NAMES;
22
23 static const ENUMERATED_NAMES crl_reasons[] = {
24 {CRL_REASON_UNSPECIFIED, "Unspecified", "unspecified"},
25 {CRL_REASON_KEY_COMPROMISE, "Key Compromise", "keyCompromise"},
26 {CRL_REASON_CA_COMPROMISE, "CA Compromise", "CACompromise"},
27 {CRL_REASON_AFFILIATION_CHANGED, "Affiliation Changed",
28 "affiliationChanged"},
29 {CRL_REASON_SUPERSEDED, "Superseded", "superseded"},
30 {CRL_REASON_CESSATION_OF_OPERATION, "Cessation Of Operation",
31 "cessationOfOperation"},
32 {CRL_REASON_CERTIFICATE_HOLD, "Certificate Hold", "certificateHold"},
33 {CRL_REASON_REMOVE_FROM_CRL, "Remove From CRL", "removeFromCRL"},
34 {CRL_REASON_PRIVILEGE_WITHDRAWN, "Privilege Withdrawn",
35 "privilegeWithdrawn"},
36 {CRL_REASON_AA_COMPROMISE, "AA Compromise", "AACompromise"},
37 {-1, NULL, NULL}};
38
i2s_ASN1_ENUMERATED_TABLE(const X509V3_EXT_METHOD * method,void * ext)39 static char *i2s_ASN1_ENUMERATED_TABLE(const X509V3_EXT_METHOD *method,
40 void *ext) {
41 const ASN1_ENUMERATED *e = reinterpret_cast<const ASN1_ENUMERATED *>(ext);
42 long strval = ASN1_ENUMERATED_get(e);
43 for (const ENUMERATED_NAMES *enam =
44 reinterpret_cast<const ENUMERATED_NAMES *>(method->usr_data);
45 enam->lname; enam++) {
46 if (strval == enam->bitnum) {
47 return OPENSSL_strdup(enam->lname);
48 }
49 }
50 return i2s_ASN1_ENUMERATED(method, e);
51 }
52
53 const X509V3_EXT_METHOD v3_crl_reason = {
54 NID_crl_reason,
55 0,
56 ASN1_ITEM_ref(ASN1_ENUMERATED),
57 0,
58 0,
59 0,
60 0,
61 i2s_ASN1_ENUMERATED_TABLE,
62 0,
63 0,
64 0,
65 0,
66 0,
67 (void *)crl_reasons,
68 };
69