| 1 |
/* |
| 2 |
* Copyright 2024-2025 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_HASH) = { |
| 16 |
ASN1_SIMPLE(OSSL_HASH, algorithmIdentifier, X509_ALGOR), |
| 17 |
ASN1_OPT(OSSL_HASH, hashValue, ASN1_BIT_STRING), |
| 18 |
} ASN1_SEQUENCE_END(OSSL_HASH) |
| 19 |
|
| 20 |
ASN1_SEQUENCE(OSSL_INFO_SYNTAX_POINTER) = { |
| 21 |
ASN1_SIMPLE(OSSL_INFO_SYNTAX_POINTER, name, GENERAL_NAMES), |
| 22 |
ASN1_OPT(OSSL_INFO_SYNTAX_POINTER, hash, OSSL_HASH), |
| 23 |
} ASN1_SEQUENCE_END(OSSL_INFO_SYNTAX_POINTER) |
| 24 |
|
| 25 |
ASN1_CHOICE(OSSL_INFO_SYNTAX) = { |
| 26 |
ASN1_SIMPLE(OSSL_INFO_SYNTAX, choice.content, DIRECTORYSTRING), |
| 27 |
ASN1_SIMPLE(OSSL_INFO_SYNTAX, choice.pointer, OSSL_INFO_SYNTAX_POINTER) |
| 28 |
} ASN1_CHOICE_END(OSSL_INFO_SYNTAX) |
| 29 |
|
| 30 |
ASN1_SEQUENCE(OSSL_PRIVILEGE_POLICY_ID) = { |
| 31 |
ASN1_SIMPLE(OSSL_PRIVILEGE_POLICY_ID, privilegePolicy, ASN1_OBJECT), |
| 32 |
ASN1_SIMPLE(OSSL_PRIVILEGE_POLICY_ID, privPolSyntax, OSSL_INFO_SYNTAX), |
| 33 |
} ASN1_SEQUENCE_END(OSSL_PRIVILEGE_POLICY_ID) |
| 34 |
|
| 35 |
ASN1_SEQUENCE(OSSL_ATTRIBUTE_DESCRIPTOR) = { |
| 36 |
ASN1_SIMPLE(OSSL_ATTRIBUTE_DESCRIPTOR, identifier, ASN1_OBJECT), |
| 37 |
ASN1_SIMPLE(OSSL_ATTRIBUTE_DESCRIPTOR, attributeSyntax, ASN1_OCTET_STRING), |
| 38 |
ASN1_IMP_OPT(OSSL_ATTRIBUTE_DESCRIPTOR, name, ASN1_UTF8STRING, 0), |
| 39 |
ASN1_IMP_OPT(OSSL_ATTRIBUTE_DESCRIPTOR, description, ASN1_UTF8STRING, 1), |
| 40 |
ASN1_SIMPLE(OSSL_ATTRIBUTE_DESCRIPTOR, dominationRule, OSSL_PRIVILEGE_POLICY_ID), |
| 41 |
} ASN1_SEQUENCE_END(OSSL_ATTRIBUTE_DESCRIPTOR) |
| 42 |
|
| 43 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_HASH) |
| 44 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_INFO_SYNTAX) |
| 45 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_INFO_SYNTAX_POINTER) |
| 46 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_PRIVILEGE_POLICY_ID) |
| 47 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_DESCRIPTOR) |
| 48 |
|
| 49 |
static int i2r_HASH(X509V3_EXT_METHOD *method, |
| 50 |
OSSL_HASH *hash, |
| 51 |
BIO *out, int indent) |
| 52 |
{ |
| 53 |
if (BIO_printf(out, "%*sAlgorithm: ", indent, "") <= 0) |
| 54 |
return 0; |
| 55 |
if (i2a_ASN1_OBJECT(out, hash->algorithmIdentifier->algorithm) <= 0) |
| 56 |
return 0; |
| 57 |
if (BIO_puts(out, "\n") <= 0) |
| 58 |
return 0; |
| 59 |
if (hash->algorithmIdentifier->parameter) { |
| 60 |
if (BIO_printf(out, "%*sParameter: ", indent, "") <= 0) |
| 61 |
return 0; |
| 62 |
if (ossl_print_attribute_value(out, 0, hash->algorithmIdentifier->parameter, |
| 63 |
indent + 4) |
| 64 |
<= 0) |
| 65 |
return 0; |
| 66 |
if (BIO_puts(out, "\n") <= 0) |
| 67 |
return 0; |
| 68 |
} |
| 69 |
if (BIO_printf(out, "%*sHash Value: ", indent, "") <= 0) |
| 70 |
return 0; |
| 71 |
if (hash->hashValue == NULL) |
| 72 |
return 0; |
| 73 |
return ossl_bio_print_hex(out, hash->hashValue->data, hash->hashValue->length); |
| 74 |
} |
| 75 |
|
| 76 |
static int i2r_INFO_SYNTAX_POINTER(X509V3_EXT_METHOD *method, |
| 77 |
OSSL_INFO_SYNTAX_POINTER *pointer, |
| 78 |
BIO *out, int indent) |
| 79 |
{ |
| 80 |
if (BIO_printf(out, "%*sNames:\n", indent, "") <= 0) |
| 81 |
return 0; |
| 82 |
if (OSSL_GENERAL_NAMES_print(out, pointer->name, indent) <= 0) |
| 83 |
return 0; |
| 84 |
if (BIO_puts(out, "\n") <= 0) |
| 85 |
return 0; |
| 86 |
if (pointer->hash != NULL) { |
| 87 |
if (BIO_printf(out, "%*sHash:\n", indent, "") <= 0) |
| 88 |
return 0; |
| 89 |
if (i2r_HASH(method, pointer->hash, out, indent + 4) <= 0) |
| 90 |
return 0; |
| 91 |
} |
| 92 |
return 1; |
| 93 |
} |
| 94 |
|
| 95 |
static int i2r_OSSL_INFO_SYNTAX(X509V3_EXT_METHOD *method, |
| 96 |
OSSL_INFO_SYNTAX *info, |
| 97 |
BIO *out, int indent) |
| 98 |
{ |
| 99 |
switch (info->type) { |
| 100 |
case OSSL_INFO_SYNTAX_TYPE_CONTENT: |
| 101 |
if (BIO_printf(out, "%*sContent: ", indent, "") <= 0) |
| 102 |
return 0; |
| 103 |
if (BIO_printf(out, "%.*s", info->choice.content->length, info->choice.content->data) <= 0) |
| 104 |
return 0; |
| 105 |
if (BIO_puts(out, "\n") <= 0) |
| 106 |
return 0; |
| 107 |
return 1; |
| 108 |
case OSSL_INFO_SYNTAX_TYPE_POINTER: |
| 109 |
if (BIO_printf(out, "%*sPointer:\n", indent, "") <= 0) |
| 110 |
return 0; |
| 111 |
return i2r_INFO_SYNTAX_POINTER(method, info->choice.pointer, out, indent + 4); |
| 112 |
default: |
| 113 |
return 0; |
| 114 |
} |
| 115 |
return 0; |
| 116 |
} |
| 117 |
|
| 118 |
static int i2r_OSSL_PRIVILEGE_POLICY_ID(X509V3_EXT_METHOD *method, |
| 119 |
OSSL_PRIVILEGE_POLICY_ID *ppid, |
| 120 |
BIO *out, int indent) |
| 121 |
{ |
| 122 |
char buf[80]; |
| 123 |
|
| 124 |
/* Intentionally display the numeric OID, rather than the textual name. */ |
| 125 |
if (OBJ_obj2txt(buf, sizeof(buf), ppid->privilegePolicy, 1) <= 0) |
| 126 |
return 0; |
| 127 |
if (BIO_printf(out, "%*sPrivilege Policy Identifier: %s\n", indent, "", buf) <= 0) |
| 128 |
return 0; |
| 129 |
if (BIO_printf(out, "%*sPrivilege Policy Syntax:\n", indent, "") <= 0) |
| 130 |
return 0; |
| 131 |
return i2r_OSSL_INFO_SYNTAX(method, ppid->privPolSyntax, out, indent + 4); |
| 132 |
} |
| 133 |
|
| 134 |
static int i2r_OSSL_ATTRIBUTE_DESCRIPTOR(X509V3_EXT_METHOD *method, |
| 135 |
OSSL_ATTRIBUTE_DESCRIPTOR *ad, |
| 136 |
BIO *out, int indent) |
| 137 |
{ |
| 138 |
char buf[80]; |
| 139 |
|
| 140 |
/* Intentionally display the numeric OID, rather than the textual name. */ |
| 141 |
if (OBJ_obj2txt(buf, sizeof(buf), ad->identifier, 1) <= 0) |
| 142 |
return 0; |
| 143 |
if (BIO_printf(out, "%*sIdentifier: %s\n", indent, "", buf) <= 0) |
| 144 |
return 0; |
| 145 |
if (BIO_printf(out, "%*sSyntax:\n", indent, "") <= 0) |
| 146 |
return 0; |
| 147 |
if (BIO_printf(out, "%*s%.*s", indent + 4, "", |
| 148 |
ad->attributeSyntax->length, ad->attributeSyntax->data) |
| 149 |
<= 0) |
| 150 |
return 0; |
| 151 |
if (BIO_puts(out, "\n\n") <= 0) |
| 152 |
return 0; |
| 153 |
if (ad->name != NULL) { |
| 154 |
if (BIO_printf(out, "%*sName: %.*s\n", indent, "", ad->name->length, ad->name->data) <= 0) |
| 155 |
return 0; |
| 156 |
} |
| 157 |
if (ad->description != NULL) { |
| 158 |
if (BIO_printf(out, "%*sDescription: %.*s\n", indent, "", |
| 159 |
ad->description->length, ad->description->data) |
| 160 |
<= 0) |
| 161 |
return 0; |
| 162 |
} |
| 163 |
if (BIO_printf(out, "%*sDomination Rule:\n", indent, "") <= 0) |
| 164 |
return 0; |
| 165 |
return i2r_OSSL_PRIVILEGE_POLICY_ID(method, ad->dominationRule, out, indent + 4); |
| 166 |
} |
| 167 |
|
| 168 |
const X509V3_EXT_METHOD ossl_v3_attribute_descriptor = { |
| 169 |
NID_attribute_descriptor, X509V3_EXT_MULTILINE, |
| 170 |
ASN1_ITEM_ref(OSSL_ATTRIBUTE_DESCRIPTOR), |
| 171 |
0, 0, 0, 0, |
| 172 |
0, 0, |
| 173 |
0, |
| 174 |
0, |
| 175 |
(X509V3_EXT_I2R)i2r_OSSL_ATTRIBUTE_DESCRIPTOR, |
| 176 |
NULL, |
| 177 |
NULL |
| 178 |
}; |