1 /*
2 * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10 #include <openssl/asn1t.h>
11 #include <openssl/x509v3.h>
12 #include <crypto/x509.h>
13 #include "ext_dat.h"
14
15 ASN1_SEQUENCE(OSSL_ROLE_SPEC_CERT_ID) = {
16 ASN1_EXP(OSSL_ROLE_SPEC_CERT_ID, roleName, GENERAL_NAME, 0),
17 ASN1_EXP(OSSL_ROLE_SPEC_CERT_ID, roleCertIssuer, GENERAL_NAME, 1),
18 ASN1_IMP_OPT(OSSL_ROLE_SPEC_CERT_ID, roleCertSerialNumber, ASN1_INTEGER, 2),
19 ASN1_IMP_SEQUENCE_OF_OPT(OSSL_ROLE_SPEC_CERT_ID, roleCertLocator, GENERAL_NAME, 3),
20 } ASN1_SEQUENCE_END(OSSL_ROLE_SPEC_CERT_ID)
21
22 IMPLEMENT_ASN1_FUNCTIONS(OSSL_ROLE_SPEC_CERT_ID)
23
24 ASN1_ITEM_TEMPLATE(OSSL_ROLE_SPEC_CERT_ID_SYNTAX) =
25 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF,
26 0, OSSL_ROLE_SPEC_CERT_ID_SYNTAX, OSSL_ROLE_SPEC_CERT_ID)
27 ASN1_ITEM_TEMPLATE_END(OSSL_ROLE_SPEC_CERT_ID_SYNTAX)
28
29 IMPLEMENT_ASN1_FUNCTIONS(OSSL_ROLE_SPEC_CERT_ID_SYNTAX)
30
31 static int i2r_OSSL_ROLE_SPEC_CERT_ID(X509V3_EXT_METHOD *method,
32 OSSL_ROLE_SPEC_CERT_ID *rscid,
33 BIO *out, int indent)
34 {
35 if (BIO_printf(out, "%*sRole Name: ", indent, "") <= 0)
36 return 0;
37 if (GENERAL_NAME_print(out, rscid->roleName) <= 0)
38 return 0;
39 if (BIO_puts(out, "\n") <= 0)
40 return 0;
41 if (BIO_printf(out, "%*sRole Certificate Issuer: ", indent, "") <= 0)
42 return 0;
43 if (GENERAL_NAME_print(out, rscid->roleCertIssuer) <= 0)
44 return 0;
45 if (rscid->roleCertSerialNumber != NULL) {
46 if (BIO_puts(out, "\n") <= 0)
47 return 0;
48 if (BIO_printf(out, "%*sRole Certificate Serial Number:", indent, "") <= 0)
49 return 0;
50 if (ossl_serial_number_print(out, rscid->roleCertSerialNumber, indent) != 0)
51 return 0;
52 }
53 if (rscid->roleCertLocator != NULL) {
54 if (BIO_puts(out, "\n") <= 0)
55 return 0;
56 if (BIO_printf(out, "%*sRole Certificate Locator:\n", indent, "") <= 0)
57 return 0;
58 if (OSSL_GENERAL_NAMES_print(out, rscid->roleCertLocator, indent) <= 0)
59 return 0;
60 }
61 return BIO_puts(out, "\n");
62 }
63
i2r_OSSL_ROLE_SPEC_CERT_ID_SYNTAX(X509V3_EXT_METHOD * method,OSSL_ROLE_SPEC_CERT_ID_SYNTAX * rscids,BIO * out,int indent)64 static int i2r_OSSL_ROLE_SPEC_CERT_ID_SYNTAX(X509V3_EXT_METHOD *method,
65 OSSL_ROLE_SPEC_CERT_ID_SYNTAX *rscids,
66 BIO *out, int indent)
67 {
68 OSSL_ROLE_SPEC_CERT_ID *rscid;
69 int i;
70
71 for (i = 0; i < sk_OSSL_ROLE_SPEC_CERT_ID_num(rscids); i++) {
72 if (i > 0 && BIO_puts(out, "\n") <= 0)
73 return 0;
74 if (BIO_printf(out,
75 "%*sRole Specification Certificate Identifier #%d:\n",
76 indent, "", i + 1) <= 0)
77 return 0;
78 rscid = sk_OSSL_ROLE_SPEC_CERT_ID_value(rscids, i);
79 if (i2r_OSSL_ROLE_SPEC_CERT_ID(method, rscid, out, indent + 4) != 1)
80 return 0;
81 }
82 return 1;
83 }
84
85 const X509V3_EXT_METHOD ossl_v3_role_spec_cert_identifier = {
86 NID_role_spec_cert_identifier, X509V3_EXT_MULTILINE,
87 ASN1_ITEM_ref(OSSL_ROLE_SPEC_CERT_ID_SYNTAX),
88 0, 0, 0, 0,
89 0, 0,
90 0,
91 0,
92 (X509V3_EXT_I2R)i2r_OSSL_ROLE_SPEC_CERT_ID_SYNTAX,
93 NULL,
94 NULL
95 };
96