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) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF,
25 0, OSSL_ROLE_SPEC_CERT_ID_SYNTAX, OSSL_ROLE_SPEC_CERT_ID)
26 ASN1_ITEM_TEMPLATE_END(OSSL_ROLE_SPEC_CERT_ID_SYNTAX)
27
28 IMPLEMENT_ASN1_FUNCTIONS(OSSL_ROLE_SPEC_CERT_ID_SYNTAX)
29
30 static int i2r_OSSL_ROLE_SPEC_CERT_ID(X509V3_EXT_METHOD *method,
31 OSSL_ROLE_SPEC_CERT_ID *rscid,
32 BIO *out, int indent)
33 {
34 if (BIO_printf(out, "%*sRole Name: ", indent, "") <= 0)
35 return 0;
36 if (GENERAL_NAME_print(out, rscid->roleName) <= 0)
37 return 0;
38 if (BIO_puts(out, "\n") <= 0)
39 return 0;
40 if (BIO_printf(out, "%*sRole Certificate Issuer: ", indent, "") <= 0)
41 return 0;
42 if (GENERAL_NAME_print(out, rscid->roleCertIssuer) <= 0)
43 return 0;
44 if (rscid->roleCertSerialNumber != NULL) {
45 if (BIO_puts(out, "\n") <= 0)
46 return 0;
47 if (BIO_printf(out, "%*sRole Certificate Serial Number:", indent, "") <= 0)
48 return 0;
49 if (ossl_serial_number_print(out, rscid->roleCertSerialNumber, indent) != 0)
50 return 0;
51 }
52 if (rscid->roleCertLocator != NULL) {
53 if (BIO_puts(out, "\n") <= 0)
54 return 0;
55 if (BIO_printf(out, "%*sRole Certificate Locator:\n", indent, "") <= 0)
56 return 0;
57 if (OSSL_GENERAL_NAMES_print(out, rscid->roleCertLocator, indent) <= 0)
58 return 0;
59 }
60 return BIO_puts(out, "\n");
61 }
62
i2r_OSSL_ROLE_SPEC_CERT_ID_SYNTAX(X509V3_EXT_METHOD * method,OSSL_ROLE_SPEC_CERT_ID_SYNTAX * rscids,BIO * out,int indent)63 static int i2r_OSSL_ROLE_SPEC_CERT_ID_SYNTAX(X509V3_EXT_METHOD *method,
64 OSSL_ROLE_SPEC_CERT_ID_SYNTAX *rscids,
65 BIO *out, int indent)
66 {
67 OSSL_ROLE_SPEC_CERT_ID *rscid;
68 int i;
69
70 for (i = 0; i < sk_OSSL_ROLE_SPEC_CERT_ID_num(rscids); i++) {
71 if (i > 0 && BIO_puts(out, "\n") <= 0)
72 return 0;
73 if (BIO_printf(out,
74 "%*sRole Specification Certificate Identifier #%d:\n",
75 indent, "", i + 1)
76 <= 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