/src/openssl/crypto/x509/v3_rolespec.c
Line  | Count  | Source  | 
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  | 0  | } ASN1_SEQUENCE_END(OSSL_ROLE_SPEC_CERT_ID)  | 
21  | 0  | 
  | 
22  | 0  | IMPLEMENT_ASN1_FUNCTIONS(OSSL_ROLE_SPEC_CERT_ID)  | 
23  | 0  | 
  | 
24  | 0  | ASN1_ITEM_TEMPLATE(OSSL_ROLE_SPEC_CERT_ID_SYNTAX) =  | 
25  | 0  |     ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF,  | 
26  | 0  |                           0, OSSL_ROLE_SPEC_CERT_ID_SYNTAX, OSSL_ROLE_SPEC_CERT_ID)  | 
27  | 0  | 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  | 0  | { | 
35  | 0  |     if (BIO_printf(out, "%*sRole Name: ", indent, "") <= 0)  | 
36  | 0  |         return 0;  | 
37  | 0  |     if (GENERAL_NAME_print(out, rscid->roleName) <= 0)  | 
38  | 0  |         return 0;  | 
39  | 0  |     if (BIO_puts(out, "\n") <= 0)  | 
40  | 0  |         return 0;  | 
41  | 0  |     if (BIO_printf(out, "%*sRole Certificate Issuer: ", indent, "") <= 0)  | 
42  | 0  |         return 0;  | 
43  | 0  |     if (GENERAL_NAME_print(out, rscid->roleCertIssuer) <= 0)  | 
44  | 0  |         return 0;  | 
45  | 0  |     if (rscid->roleCertSerialNumber != NULL) { | 
46  | 0  |         if (BIO_puts(out, "\n") <= 0)  | 
47  | 0  |             return 0;  | 
48  | 0  |         if (BIO_printf(out, "%*sRole Certificate Serial Number:", indent, "") <= 0)  | 
49  | 0  |             return 0;  | 
50  | 0  |         if (ossl_serial_number_print(out, rscid->roleCertSerialNumber, indent) != 0)  | 
51  | 0  |             return 0;  | 
52  | 0  |     }  | 
53  | 0  |     if (rscid->roleCertLocator != NULL) { | 
54  | 0  |         if (BIO_puts(out, "\n") <= 0)  | 
55  | 0  |             return 0;  | 
56  | 0  |         if (BIO_printf(out, "%*sRole Certificate Locator:\n", indent, "") <= 0)  | 
57  | 0  |             return 0;  | 
58  | 0  |         if (OSSL_GENERAL_NAMES_print(out, rscid->roleCertLocator, indent) <= 0)  | 
59  | 0  |             return 0;  | 
60  | 0  |     }  | 
61  | 0  |     return BIO_puts(out, "\n");  | 
62  | 0  | }  | 
63  |  |  | 
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  | 0  | { | 
68  | 0  |     OSSL_ROLE_SPEC_CERT_ID *rscid;  | 
69  | 0  |     int i;  | 
70  |  | 
  | 
71  | 0  |     for (i = 0; i < sk_OSSL_ROLE_SPEC_CERT_ID_num(rscids); i++) { | 
72  | 0  |         if (i > 0 && BIO_puts(out, "\n") <= 0)  | 
73  | 0  |             return 0;  | 
74  | 0  |         if (BIO_printf(out,  | 
75  | 0  |                        "%*sRole Specification Certificate Identifier #%d:\n",  | 
76  | 0  |                        indent, "", i + 1) <= 0)  | 
77  | 0  |             return 0;  | 
78  | 0  |         rscid = sk_OSSL_ROLE_SPEC_CERT_ID_value(rscids, i);  | 
79  | 0  |         if (i2r_OSSL_ROLE_SPEC_CERT_ID(method, rscid, out, indent + 4) != 1)  | 
80  | 0  |             return 0;  | 
81  | 0  |     }  | 
82  | 0  |     return 1;  | 
83  | 0  | }  | 
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  |  | };  |