18edacedfSDaniel Fojt /* $OpenBSD: x509_pku.c,v 1.1 2020/06/04 15:19:32 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
618edacedfSDaniel Fojt #include <openssl/asn1.h>
628edacedfSDaniel Fojt #include <openssl/asn1t.h>
638edacedfSDaniel Fojt #include <openssl/x509v3.h>
648edacedfSDaniel Fojt
658edacedfSDaniel Fojt static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
668edacedfSDaniel Fojt PKEY_USAGE_PERIOD *usage, BIO *out, int indent);
678edacedfSDaniel Fojt
688edacedfSDaniel Fojt const X509V3_EXT_METHOD v3_pkey_usage_period = {
698edacedfSDaniel Fojt .ext_nid = NID_private_key_usage_period,
708edacedfSDaniel Fojt .ext_flags = 0,
718edacedfSDaniel Fojt .it = &PKEY_USAGE_PERIOD_it,
728edacedfSDaniel Fojt .ext_new = NULL,
738edacedfSDaniel Fojt .ext_free = NULL,
748edacedfSDaniel Fojt .d2i = NULL,
758edacedfSDaniel Fojt .i2d = NULL,
768edacedfSDaniel Fojt .i2s = NULL,
778edacedfSDaniel Fojt .s2i = NULL,
788edacedfSDaniel Fojt .i2v = NULL,
798edacedfSDaniel Fojt .v2i = NULL,
808edacedfSDaniel Fojt .i2r = (X509V3_EXT_I2R)i2r_PKEY_USAGE_PERIOD,
818edacedfSDaniel Fojt .r2i = NULL,
828edacedfSDaniel Fojt .usr_data = NULL,
838edacedfSDaniel Fojt };
848edacedfSDaniel Fojt
858edacedfSDaniel Fojt static const ASN1_TEMPLATE PKEY_USAGE_PERIOD_seq_tt[] = {
868edacedfSDaniel Fojt {
878edacedfSDaniel Fojt .flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL,
888edacedfSDaniel Fojt .tag = 0,
898edacedfSDaniel Fojt .offset = offsetof(PKEY_USAGE_PERIOD, notBefore),
908edacedfSDaniel Fojt .field_name = "notBefore",
918edacedfSDaniel Fojt .item = &ASN1_GENERALIZEDTIME_it,
928edacedfSDaniel Fojt },
938edacedfSDaniel Fojt {
948edacedfSDaniel Fojt .flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL,
958edacedfSDaniel Fojt .tag = 1,
968edacedfSDaniel Fojt .offset = offsetof(PKEY_USAGE_PERIOD, notAfter),
978edacedfSDaniel Fojt .field_name = "notAfter",
988edacedfSDaniel Fojt .item = &ASN1_GENERALIZEDTIME_it,
998edacedfSDaniel Fojt },
1008edacedfSDaniel Fojt };
1018edacedfSDaniel Fojt
1028edacedfSDaniel Fojt const ASN1_ITEM PKEY_USAGE_PERIOD_it = {
1038edacedfSDaniel Fojt .itype = ASN1_ITYPE_SEQUENCE,
1048edacedfSDaniel Fojt .utype = V_ASN1_SEQUENCE,
1058edacedfSDaniel Fojt .templates = PKEY_USAGE_PERIOD_seq_tt,
1068edacedfSDaniel Fojt .tcount = sizeof(PKEY_USAGE_PERIOD_seq_tt) / sizeof(ASN1_TEMPLATE),
1078edacedfSDaniel Fojt .funcs = NULL,
1088edacedfSDaniel Fojt .size = sizeof(PKEY_USAGE_PERIOD),
1098edacedfSDaniel Fojt .sname = "PKEY_USAGE_PERIOD",
1108edacedfSDaniel Fojt };
1118edacedfSDaniel Fojt
1128edacedfSDaniel Fojt
1138edacedfSDaniel Fojt PKEY_USAGE_PERIOD *
d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD ** a,const unsigned char ** in,long len)1148edacedfSDaniel Fojt d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD **a, const unsigned char **in, long len)
1158edacedfSDaniel Fojt {
1168edacedfSDaniel Fojt return (PKEY_USAGE_PERIOD *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
1178edacedfSDaniel Fojt &PKEY_USAGE_PERIOD_it);
1188edacedfSDaniel Fojt }
1198edacedfSDaniel Fojt
1208edacedfSDaniel Fojt int
i2d_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD * a,unsigned char ** out)1218edacedfSDaniel Fojt i2d_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD *a, unsigned char **out)
1228edacedfSDaniel Fojt {
1238edacedfSDaniel Fojt return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKEY_USAGE_PERIOD_it);
1248edacedfSDaniel Fojt }
1258edacedfSDaniel Fojt
1268edacedfSDaniel Fojt PKEY_USAGE_PERIOD *
PKEY_USAGE_PERIOD_new(void)1278edacedfSDaniel Fojt PKEY_USAGE_PERIOD_new(void)
1288edacedfSDaniel Fojt {
1298edacedfSDaniel Fojt return (PKEY_USAGE_PERIOD *)ASN1_item_new(&PKEY_USAGE_PERIOD_it);
1308edacedfSDaniel Fojt }
1318edacedfSDaniel Fojt
1328edacedfSDaniel Fojt void
PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD * a)1338edacedfSDaniel Fojt PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a)
1348edacedfSDaniel Fojt {
1358edacedfSDaniel Fojt ASN1_item_free((ASN1_VALUE *)a, &PKEY_USAGE_PERIOD_it);
1368edacedfSDaniel Fojt }
1378edacedfSDaniel Fojt
1388edacedfSDaniel Fojt static int
i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD * method,PKEY_USAGE_PERIOD * usage,BIO * out,int indent)1398edacedfSDaniel Fojt i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, PKEY_USAGE_PERIOD *usage,
1408edacedfSDaniel Fojt BIO *out, int indent)
1418edacedfSDaniel Fojt {
1428edacedfSDaniel Fojt BIO_printf(out, "%*s", indent, "");
1438edacedfSDaniel Fojt if (usage->notBefore) {
1448edacedfSDaniel Fojt BIO_write(out, "Not Before: ", 12);
1458edacedfSDaniel Fojt ASN1_GENERALIZEDTIME_print(out, usage->notBefore);
1468edacedfSDaniel Fojt if (usage->notAfter)
1478edacedfSDaniel Fojt BIO_write(out, ", ", 2);
1488edacedfSDaniel Fojt }
1498edacedfSDaniel Fojt if (usage->notAfter) {
1508edacedfSDaniel Fojt BIO_write(out, "Not After: ", 11);
1518edacedfSDaniel Fojt ASN1_GENERALIZEDTIME_print(out, usage->notAfter);
1528edacedfSDaniel Fojt }
1538edacedfSDaniel Fojt return 1;
1548edacedfSDaniel Fojt }
155