| 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_ATAV) = { |
| 16 |
ASN1_SIMPLE(OSSL_ATAV, type, ASN1_OBJECT), |
| 17 |
ASN1_SIMPLE(OSSL_ATAV, value, ASN1_ANY) |
| 18 |
} ASN1_SEQUENCE_END(OSSL_ATAV) |
| 19 |
|
| 20 |
ASN1_SEQUENCE(OSSL_ATTRIBUTE_TYPE_MAPPING) = { |
| 21 |
ASN1_IMP(OSSL_ATTRIBUTE_TYPE_MAPPING, local, ASN1_OBJECT, 0), |
| 22 |
ASN1_IMP(OSSL_ATTRIBUTE_TYPE_MAPPING, remote, ASN1_OBJECT, 1), |
| 23 |
} ASN1_SEQUENCE_END(OSSL_ATTRIBUTE_TYPE_MAPPING) |
| 24 |
|
| 25 |
ASN1_SEQUENCE(OSSL_ATTRIBUTE_VALUE_MAPPING) = { |
| 26 |
ASN1_IMP(OSSL_ATTRIBUTE_VALUE_MAPPING, local, OSSL_ATAV, 0), |
| 27 |
ASN1_IMP(OSSL_ATTRIBUTE_VALUE_MAPPING, remote, OSSL_ATAV, 1), |
| 28 |
} ASN1_SEQUENCE_END(OSSL_ATTRIBUTE_VALUE_MAPPING) |
| 29 |
|
| 30 |
ASN1_CHOICE(OSSL_ATTRIBUTE_MAPPING) = { |
| 31 |
ASN1_IMP(OSSL_ATTRIBUTE_MAPPING, choice.typeMappings, |
| 32 |
OSSL_ATTRIBUTE_TYPE_MAPPING, OSSL_ATTR_MAP_TYPE), |
| 33 |
ASN1_IMP(OSSL_ATTRIBUTE_MAPPING, choice.typeValueMappings, |
| 34 |
OSSL_ATTRIBUTE_VALUE_MAPPING, OSSL_ATTR_MAP_VALUE), |
| 35 |
} ASN1_CHOICE_END(OSSL_ATTRIBUTE_MAPPING) |
| 36 |
|
| 37 |
ASN1_ITEM_TEMPLATE(OSSL_ATTRIBUTE_MAPPINGS) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, OSSL_ATTRIBUTE_MAPPINGS, OSSL_ATTRIBUTE_MAPPING) |
| 38 |
ASN1_ITEM_TEMPLATE_END(OSSL_ATTRIBUTE_MAPPINGS) |
| 39 |
|
| 40 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATAV) |
| 41 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_TYPE_MAPPING) |
| 42 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_VALUE_MAPPING) |
| 43 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_MAPPING) |
| 44 |
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_MAPPINGS) |
| 45 |
|
| 46 |
static int i2r_ATTRIBUTE_MAPPING(X509V3_EXT_METHOD *method, |
| 47 |
OSSL_ATTRIBUTE_MAPPING *am, |
| 48 |
BIO *out, int indent) |
| 49 |
{ |
| 50 |
ASN1_OBJECT *local_type, *remote_type; |
| 51 |
int local_attr_nid, remote_attr_nid; |
| 52 |
ASN1_TYPE *local_val, *remote_val; |
| 53 |
|
| 54 |
switch (am->type) { |
| 55 |
case (OSSL_ATTR_MAP_TYPE): |
| 56 |
if (i2a_ASN1_OBJECT(out, am->choice.typeMappings->local) <= 0) |
| 57 |
return 0; |
| 58 |
if (BIO_puts(out, " == ") <= 0) |
| 59 |
return 0; |
| 60 |
return i2a_ASN1_OBJECT(out, am->choice.typeMappings->remote); |
| 61 |
case (OSSL_ATTR_MAP_VALUE): |
| 62 |
local_type = am->choice.typeValueMappings->local->type; |
| 63 |
remote_type = am->choice.typeValueMappings->remote->type; |
| 64 |
local_val = am->choice.typeValueMappings->local->value; |
| 65 |
remote_val = am->choice.typeValueMappings->remote->value; |
| 66 |
local_attr_nid = OBJ_obj2nid(local_type); |
| 67 |
remote_attr_nid = OBJ_obj2nid(remote_type); |
| 68 |
if (i2a_ASN1_OBJECT(out, local_type) <= 0) |
| 69 |
return 0; |
| 70 |
if (BIO_puts(out, ":") <= 0) |
| 71 |
return 0; |
| 72 |
if (ossl_print_attribute_value(out, local_attr_nid, local_val, 0) <= 0) |
| 73 |
return 0; |
| 74 |
if (BIO_puts(out, " == ") <= 0) |
| 75 |
return 0; |
| 76 |
if (i2a_ASN1_OBJECT(out, remote_type) <= 0) |
| 77 |
return 0; |
| 78 |
if (BIO_puts(out, ":") <= 0) |
| 79 |
return 0; |
| 80 |
return ossl_print_attribute_value(out, remote_attr_nid, remote_val, 0); |
| 81 |
default: |
| 82 |
return 0; |
| 83 |
} |
| 84 |
return 1; |
| 85 |
} |
| 86 |
|
| 87 |
static int i2r_ATTRIBUTE_MAPPINGS(X509V3_EXT_METHOD *method, |
| 88 |
OSSL_ATTRIBUTE_MAPPINGS *ams, |
| 89 |
BIO *out, int indent) |
| 90 |
{ |
| 91 |
int i; |
| 92 |
OSSL_ATTRIBUTE_MAPPING *am; |
| 93 |
|
| 94 |
for (i = 0; i < sk_OSSL_ATTRIBUTE_MAPPING_num(ams); i++) { |
| 95 |
am = sk_OSSL_ATTRIBUTE_MAPPING_value(ams, i); |
| 96 |
if (BIO_printf(out, "%*s", indent, "") <= 0) |
| 97 |
return 0; |
| 98 |
if (i2r_ATTRIBUTE_MAPPING(method, am, out, indent + 4) <= 0) |
| 99 |
return 0; |
| 100 |
if (BIO_puts(out, "\n") <= 0) |
| 101 |
return 0; |
| 102 |
} |
| 103 |
return 1; |
| 104 |
} |
| 105 |
|
| 106 |
const X509V3_EXT_METHOD ossl_v3_attribute_mappings = { |
| 107 |
NID_attribute_mappings, X509V3_EXT_MULTILINE, |
| 108 |
ASN1_ITEM_ref(OSSL_ATTRIBUTE_MAPPINGS), |
| 109 |
0, 0, 0, 0, |
| 110 |
0, 0, |
| 111 |
0, |
| 112 |
0, |
| 113 |
(X509V3_EXT_I2R)i2r_ATTRIBUTE_MAPPINGS, |
| 114 |
0, |
| 115 |
NULL |
| 116 |
}; |