| 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_ITEM_TEMPLATE(OSSL_ATTRIBUTES_SYNTAX) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Attributes, X509_ATTRIBUTE) |
| 16 |
ASN1_ITEM_TEMPLATE_END(OSSL_ATTRIBUTES_SYNTAX) |
| 17 |
|
| 18 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTES_SYNTAX) |
| 19 |
|
| 20 |
static int i2r_ATTRIBUTES_SYNTAX(X509V3_EXT_METHOD *method, |
| 21 |
OSSL_ATTRIBUTES_SYNTAX *attrlst, |
| 22 |
BIO *out, int indent) |
| 23 |
{ |
| 24 |
X509_ATTRIBUTE *attr; |
| 25 |
ASN1_TYPE *av; |
| 26 |
int i, j, attr_nid; |
| 27 |
|
| 28 |
if (!attrlst) { |
| 29 |
if (BIO_printf(out, "<No Attributes>\n") <= 0) |
| 30 |
return 0; |
| 31 |
return 1; |
| 32 |
} |
| 33 |
if (!sk_X509_ATTRIBUTE_num(attrlst)) { |
| 34 |
if (BIO_printf(out, "<Empty Attributes>\n") <= 0) |
| 35 |
return 0; |
| 36 |
return 1; |
| 37 |
} |
| 38 |
|
| 39 |
for (i = 0; i < sk_X509_ATTRIBUTE_num(attrlst); i++) { |
| 40 |
ASN1_OBJECT *attr_obj; |
| 41 |
attr = sk_X509_ATTRIBUTE_value(attrlst, i); |
| 42 |
attr_obj = X509_ATTRIBUTE_get0_object(attr); |
| 43 |
attr_nid = OBJ_obj2nid(attr_obj); |
| 44 |
if (indent && BIO_printf(out, "%*s", indent, "") <= 0) |
| 45 |
return 0; |
| 46 |
if (attr_nid == NID_undef) { |
| 47 |
if (i2a_ASN1_OBJECT(out, attr_obj) <= 0) |
| 48 |
return 0; |
| 49 |
if (BIO_puts(out, ":\n") <= 0) |
| 50 |
return 0; |
| 51 |
} else if (BIO_printf(out, "%s:\n", OBJ_nid2ln(attr_nid)) <= 0) { |
| 52 |
return 0; |
| 53 |
} |
| 54 |
|
| 55 |
if (X509_ATTRIBUTE_count(attr)) { |
| 56 |
for (j = 0; j < X509_ATTRIBUTE_count(attr); j++) { |
| 57 |
av = X509_ATTRIBUTE_get0_type(attr, j); |
| 58 |
if (ossl_print_attribute_value(out, attr_nid, av, indent + 4) <= 0) |
| 59 |
return 0; |
| 60 |
if (BIO_puts(out, "\n") <= 0) |
| 61 |
return 0; |
| 62 |
} |
| 63 |
} else if (BIO_printf(out, "%*s<No Values>\n", indent + 4, "") <= 0) { |
| 64 |
return 0; |
| 65 |
} |
| 66 |
} |
| 67 |
return 1; |
| 68 |
} |
| 69 |
|
| 70 |
const X509V3_EXT_METHOD ossl_v3_subj_dir_attrs = { |
| 71 |
NID_subject_directory_attributes, X509V3_EXT_MULTILINE, |
| 72 |
ASN1_ITEM_ref(OSSL_ATTRIBUTES_SYNTAX), |
| 73 |
0, 0, 0, 0, |
| 74 |
0, 0, 0, 0, |
| 75 |
(X509V3_EXT_I2R)i2r_ATTRIBUTES_SYNTAX, |
| 76 |
0, |
| 77 |
NULL |
| 78 |
}; |
| 79 |
|
| 80 |
const X509V3_EXT_METHOD ossl_v3_associated_info = { |
| 81 |
NID_associated_information, X509V3_EXT_MULTILINE, |
| 82 |
ASN1_ITEM_ref(OSSL_ATTRIBUTES_SYNTAX), |
| 83 |
0, 0, 0, 0, |
| 84 |
0, 0, 0, 0, |
| 85 |
(X509V3_EXT_I2R)i2r_ATTRIBUTES_SYNTAX, |
| 86 |
0, |
| 87 |
NULL |
| 88 |
}; |