1d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* v3_enum.c */
2d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * project 1999.
4d9e397b599b13d642138480a28c14db7a136bf0Adam Langley */
5d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* ====================================================================
6d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
7d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
8d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * Redistribution and use in source and binary forms, with or without
9d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * modification, are permitted provided that the following conditions
10d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * are met:
11d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
12d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 1. Redistributions of source code must retain the above copyright
13d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    notice, this list of conditions and the following disclaimer.
14d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
15d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 2. Redistributions in binary form must reproduce the above copyright
16d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    notice, this list of conditions and the following disclaimer in
17d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    the documentation and/or other materials provided with the
18d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    distribution.
19d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
20d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 3. All advertising materials mentioning features or use of this
21d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    software must display the following acknowledgment:
22d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    "This product includes software developed by the OpenSSL Project
23d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
25d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    endorse or promote products derived from this software without
27d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    prior written permission. For written permission, please contact
28d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    licensing@OpenSSL.org.
29d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
30d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 5. Products derived from this software may not be called "OpenSSL"
31d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    nor may "OpenSSL" appear in their names without prior written
32d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    permission of the OpenSSL Project.
33d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
34d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 6. Redistributions of any form whatsoever must retain the following
35d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    acknowledgment:
36d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    "This product includes software developed by the OpenSSL Project
37d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
39d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * OF THE POSSIBILITY OF SUCH DAMAGE.
51d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * ====================================================================
52d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
53d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * This product includes cryptographic software written by Eric Young
54d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * (eay@cryptsoft.com).  This product includes software written by Tim
55d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * Hudson (tjh@cryptsoft.com). */
56d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
57d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#include <stdio.h>
58d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
59d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#include <openssl/buf.h>
60d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#include <openssl/obj.h>
61d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#include <openssl/x509v3.h>
62d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
63d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
64d9e397b599b13d642138480a28c14db7a136bf0Adam Langleystatic const ENUMERATED_NAMES crl_reasons[] = {
65d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{CRL_REASON_UNSPECIFIED, 	 "Unspecified", "unspecified"},
66d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{CRL_REASON_KEY_COMPROMISE,	 "Key Compromise", "keyCompromise"},
67d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{CRL_REASON_CA_COMPROMISE,	 "CA Compromise", "CACompromise"},
68d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{CRL_REASON_AFFILIATION_CHANGED, "Affiliation Changed", "affiliationChanged"},
69d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{CRL_REASON_SUPERSEDED, 	 "Superseded", "superseded"},
70d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{CRL_REASON_CESSATION_OF_OPERATION,
71d9e397b599b13d642138480a28c14db7a136bf0Adam Langley			"Cessation Of Operation", "cessationOfOperation"},
72d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{CRL_REASON_CERTIFICATE_HOLD,	 "Certificate Hold", "certificateHold"},
73d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{CRL_REASON_REMOVE_FROM_CRL,	 "Remove From CRL", "removeFromCRL"},
74d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{CRL_REASON_PRIVILEGE_WITHDRAWN, "Privilege Withdrawn", "privilegeWithdrawn"},
75d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{CRL_REASON_AA_COMPROMISE,	 "AA Compromise", "AACompromise"},
76d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{-1, NULL, NULL}
77d9e397b599b13d642138480a28c14db7a136bf0Adam Langley};
78d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
79d9e397b599b13d642138480a28c14db7a136bf0Adam Langleyconst X509V3_EXT_METHOD v3_crl_reason = {
80d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyNID_crl_reason, 0, ASN1_ITEM_ref(ASN1_ENUMERATED),
81d9e397b599b13d642138480a28c14db7a136bf0Adam Langley0,0,0,0,
82d9e397b599b13d642138480a28c14db7a136bf0Adam Langley(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
83d9e397b599b13d642138480a28c14db7a136bf0Adam Langley0,
84d9e397b599b13d642138480a28c14db7a136bf0Adam Langley0,0,0,0,
85d9e397b599b13d642138480a28c14db7a136bf0Adam Langley(void *)crl_reasons};
86d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
87d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
88d9e397b599b13d642138480a28c14db7a136bf0Adam Langleychar *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method,
89d9e397b599b13d642138480a28c14db7a136bf0Adam Langley	     ASN1_ENUMERATED *e)
90d9e397b599b13d642138480a28c14db7a136bf0Adam Langley{
91d9e397b599b13d642138480a28c14db7a136bf0Adam Langley	const ENUMERATED_NAMES *enam;
92d9e397b599b13d642138480a28c14db7a136bf0Adam Langley	long strval;
93d9e397b599b13d642138480a28c14db7a136bf0Adam Langley	strval = ASN1_ENUMERATED_get(e);
94d9e397b599b13d642138480a28c14db7a136bf0Adam Langley	for(enam = method->usr_data; enam->lname; enam++) {
95d9e397b599b13d642138480a28c14db7a136bf0Adam Langley		if(strval == enam->bitnum) return BUF_strdup(enam->lname);
96d9e397b599b13d642138480a28c14db7a136bf0Adam Langley	}
97d9e397b599b13d642138480a28c14db7a136bf0Adam Langley	return i2s_ASN1_ENUMERATED(method, e);
98d9e397b599b13d642138480a28c14db7a136bf0Adam Langley}
99