18edacedfSDaniel Fojt /* $OpenBSD: x509_enum.c,v 1.1 2020/06/04 15:19:31 jsing Exp $ */
28edacedfSDaniel Fojt /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
38edacedfSDaniel Fojt  * project 1999.
48edacedfSDaniel Fojt  */
58edacedfSDaniel Fojt /* ====================================================================
68edacedfSDaniel Fojt  * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
78edacedfSDaniel Fojt  *
88edacedfSDaniel Fojt  * Redistribution and use in source and binary forms, with or without
98edacedfSDaniel Fojt  * modification, are permitted provided that the following conditions
108edacedfSDaniel Fojt  * are met:
118edacedfSDaniel Fojt  *
128edacedfSDaniel Fojt  * 1. Redistributions of source code must retain the above copyright
138edacedfSDaniel Fojt  *    notice, this list of conditions and the following disclaimer.
148edacedfSDaniel Fojt  *
158edacedfSDaniel Fojt  * 2. Redistributions in binary form must reproduce the above copyright
168edacedfSDaniel Fojt  *    notice, this list of conditions and the following disclaimer in
178edacedfSDaniel Fojt  *    the documentation and/or other materials provided with the
188edacedfSDaniel Fojt  *    distribution.
198edacedfSDaniel Fojt  *
208edacedfSDaniel Fojt  * 3. All advertising materials mentioning features or use of this
218edacedfSDaniel Fojt  *    software must display the following acknowledgment:
228edacedfSDaniel Fojt  *    "This product includes software developed by the OpenSSL Project
238edacedfSDaniel Fojt  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
248edacedfSDaniel Fojt  *
258edacedfSDaniel Fojt  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
268edacedfSDaniel Fojt  *    endorse or promote products derived from this software without
278edacedfSDaniel Fojt  *    prior written permission. For written permission, please contact
288edacedfSDaniel Fojt  *    licensing@OpenSSL.org.
298edacedfSDaniel Fojt  *
308edacedfSDaniel Fojt  * 5. Products derived from this software may not be called "OpenSSL"
318edacedfSDaniel Fojt  *    nor may "OpenSSL" appear in their names without prior written
328edacedfSDaniel Fojt  *    permission of the OpenSSL Project.
338edacedfSDaniel Fojt  *
348edacedfSDaniel Fojt  * 6. Redistributions of any form whatsoever must retain the following
358edacedfSDaniel Fojt  *    acknowledgment:
368edacedfSDaniel Fojt  *    "This product includes software developed by the OpenSSL Project
378edacedfSDaniel Fojt  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
388edacedfSDaniel Fojt  *
398edacedfSDaniel Fojt  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
408edacedfSDaniel Fojt  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
418edacedfSDaniel Fojt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
428edacedfSDaniel Fojt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
438edacedfSDaniel Fojt  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
448edacedfSDaniel Fojt  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
458edacedfSDaniel Fojt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
468edacedfSDaniel Fojt  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
478edacedfSDaniel Fojt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
488edacedfSDaniel Fojt  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
498edacedfSDaniel Fojt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
508edacedfSDaniel Fojt  * OF THE POSSIBILITY OF SUCH DAMAGE.
518edacedfSDaniel Fojt  * ====================================================================
528edacedfSDaniel Fojt  *
538edacedfSDaniel Fojt  * This product includes cryptographic software written by Eric Young
548edacedfSDaniel Fojt  * (eay@cryptsoft.com).  This product includes software written by Tim
558edacedfSDaniel Fojt  * Hudson (tjh@cryptsoft.com).
568edacedfSDaniel Fojt  *
578edacedfSDaniel Fojt  */
588edacedfSDaniel Fojt 
598edacedfSDaniel Fojt #include <stdio.h>
608edacedfSDaniel Fojt #include <string.h>
618edacedfSDaniel Fojt #include <openssl/x509v3.h>
628edacedfSDaniel Fojt 
638edacedfSDaniel Fojt static ENUMERATED_NAMES crl_reasons[] = {
648edacedfSDaniel Fojt 	{CRL_REASON_UNSPECIFIED, 	 "Unspecified", "unspecified"},
658edacedfSDaniel Fojt 	{CRL_REASON_KEY_COMPROMISE,	 "Key Compromise", "keyCompromise"},
668edacedfSDaniel Fojt 	{CRL_REASON_CA_COMPROMISE,	 "CA Compromise", "CACompromise"},
678edacedfSDaniel Fojt 	{CRL_REASON_AFFILIATION_CHANGED, "Affiliation Changed", "affiliationChanged"},
688edacedfSDaniel Fojt 	{CRL_REASON_SUPERSEDED, 	 "Superseded", "superseded"},
698edacedfSDaniel Fojt 		{CRL_REASON_CESSATION_OF_OPERATION,
708edacedfSDaniel Fojt 	"Cessation Of Operation", "cessationOfOperation"},
718edacedfSDaniel Fojt 	{CRL_REASON_CERTIFICATE_HOLD,	 "Certificate Hold", "certificateHold"},
728edacedfSDaniel Fojt 	{CRL_REASON_REMOVE_FROM_CRL,	 "Remove From CRL", "removeFromCRL"},
738edacedfSDaniel Fojt 	{CRL_REASON_PRIVILEGE_WITHDRAWN, "Privilege Withdrawn", "privilegeWithdrawn"},
748edacedfSDaniel Fojt 	{CRL_REASON_AA_COMPROMISE,	 "AA Compromise", "AACompromise"},
758edacedfSDaniel Fojt 	{-1, NULL, NULL}
768edacedfSDaniel Fojt };
778edacedfSDaniel Fojt 
788edacedfSDaniel Fojt const X509V3_EXT_METHOD v3_crl_reason = {
798edacedfSDaniel Fojt 	.ext_nid = NID_crl_reason,
808edacedfSDaniel Fojt 	.ext_flags = 0,
818edacedfSDaniel Fojt 	.it = &ASN1_ENUMERATED_it,
828edacedfSDaniel Fojt 	.ext_new = NULL,
838edacedfSDaniel Fojt 	.ext_free = NULL,
848edacedfSDaniel Fojt 	.d2i = NULL,
858edacedfSDaniel Fojt 	.i2d = NULL,
868edacedfSDaniel Fojt 	.i2s = (X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
878edacedfSDaniel Fojt 	.s2i = NULL,
888edacedfSDaniel Fojt 	.i2v = NULL,
898edacedfSDaniel Fojt 	.v2i = NULL,
908edacedfSDaniel Fojt 	.i2r = NULL,
918edacedfSDaniel Fojt 	.r2i = NULL,
928edacedfSDaniel Fojt 	.usr_data = crl_reasons,
938edacedfSDaniel Fojt };
948edacedfSDaniel Fojt 
958edacedfSDaniel Fojt char *
i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD * method,const ASN1_ENUMERATED * e)968edacedfSDaniel Fojt i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method, const ASN1_ENUMERATED *e)
978edacedfSDaniel Fojt {
988edacedfSDaniel Fojt 	ENUMERATED_NAMES *enam;
998edacedfSDaniel Fojt 	long strval;
1008edacedfSDaniel Fojt 
1018edacedfSDaniel Fojt 	strval = ASN1_ENUMERATED_get(e);
1028edacedfSDaniel Fojt 	for (enam = method->usr_data; enam->lname; enam++) {
1038edacedfSDaniel Fojt 		if (strval == enam->bitnum)
1048edacedfSDaniel Fojt 			return strdup(enam->lname);
1058edacedfSDaniel Fojt 	}
1068edacedfSDaniel Fojt 	return i2s_ASN1_ENUMERATED(method, e);
1078edacedfSDaniel Fojt }
108