xref: /openssl/crypto/x509/v3_authattid.c (revision a6e0d6d5)
1 /*
2  * Copyright 1999-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_acert.h>
13 #include <openssl/x509_acert.h>
14 #include "crypto/asn1.h"
15 #include "ext_dat.h"
16 
17 DECLARE_ASN1_ITEM(OSSL_ISSUER_SERIAL)
18 
ASN1_ITEM_TEMPLATE(OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX)19 ASN1_ITEM_TEMPLATE(OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX) =
20     ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX, OSSL_ISSUER_SERIAL)
21 ASN1_ITEM_TEMPLATE_END(OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX)
22 
23 IMPLEMENT_ASN1_FUNCTIONS(OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX)
24 
25 static int i2r_ISSUER_SERIAL(X509V3_EXT_METHOD *method,
26                              OSSL_ISSUER_SERIAL *iss,
27                              BIO *out, int indent)
28 {
29     if (iss->issuer != NULL) {
30         BIO_printf(out, "%*sIssuer Names:\n", indent, "");
31         OSSL_GENERAL_NAMES_print(out, iss->issuer, indent);
32         BIO_puts(out, "\n");
33     } else {
34         BIO_printf(out, "%*sIssuer Names: <none>\n", indent, "");
35     }
36     BIO_printf(out, "%*sIssuer Serial: ", indent, "");
37     if (i2a_ASN1_INTEGER(out, &(iss->serial)) <= 0)
38         return 0;
39     BIO_puts(out, "\n");
40     if (iss->issuerUID != NULL) {
41         BIO_printf(out, "%*sIssuer UID: ", indent, "");
42         if (i2a_ASN1_STRING(out, iss->issuerUID, V_ASN1_BIT_STRING) <= 0)
43             return 0;
44         BIO_puts(out, "\n");
45     } else {
46         BIO_printf(out, "%*sIssuer UID: <none>\n", indent, "");
47     }
48     return 1;
49 }
50 
i2r_auth_attr_id(X509V3_EXT_METHOD * method,OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX * aids,BIO * out,int indent)51 static int i2r_auth_attr_id(X509V3_EXT_METHOD *method,
52                             OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX *aids,
53                             BIO *out, int indent)
54 {
55     int i;
56     OSSL_ISSUER_SERIAL *aid;
57 
58     for (i = 0; i < sk_OSSL_ISSUER_SERIAL_num(aids); i++) {
59         if (BIO_printf(out, "%*sIssuer-Serials:\n", indent, "") <= 0)
60             return 0;
61         aid = sk_OSSL_ISSUER_SERIAL_value(aids, i);
62         if (i2r_ISSUER_SERIAL(method, aid, out, indent + 4) <= 0)
63             return 0;
64         if (BIO_puts(out, "\n") <= 0)
65             return 0;
66     }
67     return 1;
68 }
69 
70 const X509V3_EXT_METHOD ossl_v3_authority_attribute_identifier = {
71     NID_authority_attribute_identifier, X509V3_EXT_MULTILINE,
72     ASN1_ITEM_ref(OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX),
73     0, 0, 0, 0,
74     0,
75     0,
76     0, 0,
77     (X509V3_EXT_I2R)i2r_auth_attr_id,
78     0,
79     NULL
80 };
81