2 * Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "internal/cryptlib.h"
13 #include <openssl/asn1t.h>
14 #include <openssl/conf.h>
15 #include <openssl/x509v3.h>
17 #include "x509_local.h"
19 static STACK_OF(CONF_VALUE
) *i2v_TLS_FEATURE(const X509V3_EXT_METHOD
*method
,
20 TLS_FEATURE
*tls_feature
,
21 STACK_OF(CONF_VALUE
) *ext_list
);
22 static TLS_FEATURE
*v2i_TLS_FEATURE(const X509V3_EXT_METHOD
*method
,
24 STACK_OF(CONF_VALUE
) *nval
);
26 ASN1_ITEM_TEMPLATE(TLS_FEATURE
) =
27 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF
, 0, TLS_FEATURE
, ASN1_INTEGER
)
28 static_ASN1_ITEM_TEMPLATE_END(TLS_FEATURE
)
30 IMPLEMENT_ASN1_ALLOC_FUNCTIONS(TLS_FEATURE
)
32 const X509V3_EXT_METHOD v3_tls_feature
= {
34 ASN1_ITEM_ref(TLS_FEATURE
),
37 (X509V3_EXT_I2V
)i2v_TLS_FEATURE
,
38 (X509V3_EXT_V2I
)v2i_TLS_FEATURE
,
49 static TLS_FEATURE_NAME tls_feature_tbl
[] = {
50 { 5, "status_request" },
51 { 17, "status_request_v2" }
55 * i2v_TLS_FEATURE converts the TLS_FEATURE structure tls_feature into the
56 * STACK_OF(CONF_VALUE) structure ext_list. STACK_OF(CONF_VALUE) is the format
57 * used by the CONF library to represent a multi-valued extension. ext_list is
60 static STACK_OF(CONF_VALUE
) *i2v_TLS_FEATURE(const X509V3_EXT_METHOD
*method
,
61 TLS_FEATURE
*tls_feature
,
62 STACK_OF(CONF_VALUE
) *ext_list
)
68 for (i
= 0; i
< sk_ASN1_INTEGER_num(tls_feature
); i
++) {
69 ai
= sk_ASN1_INTEGER_value(tls_feature
, i
);
70 tlsextid
= ASN1_INTEGER_get(ai
);
71 for (j
= 0; j
< OSSL_NELEM(tls_feature_tbl
); j
++)
72 if (tlsextid
== tls_feature_tbl
[j
].num
)
74 if (j
< OSSL_NELEM(tls_feature_tbl
))
75 X509V3_add_value(NULL
, tls_feature_tbl
[j
].name
, &ext_list
);
77 X509V3_add_value_int(NULL
, ai
, &ext_list
);
83 * v2i_TLS_FEATURE converts the multi-valued extension nval into a TLS_FEATURE
84 * structure, which is returned if the conversion is successful. In case of
85 * error, NULL is returned.
87 static TLS_FEATURE
*v2i_TLS_FEATURE(const X509V3_EXT_METHOD
*method
,
88 X509V3_CTX
*ctx
, STACK_OF(CONF_VALUE
) *nval
)
91 char *extval
, *endptr
;
92 ASN1_INTEGER
*ai
= NULL
;
98 if ((tlsf
= sk_ASN1_INTEGER_new_null()) == NULL
) {
99 X509V3err(X509V3_F_V2I_TLS_FEATURE
, ERR_R_MALLOC_FAILURE
);
103 for (i
= 0; i
< sk_CONF_VALUE_num(nval
); i
++) {
104 val
= sk_CONF_VALUE_value(nval
, i
);
110 for (j
= 0; j
< OSSL_NELEM(tls_feature_tbl
); j
++)
111 if (strcasecmp(extval
, tls_feature_tbl
[j
].name
) == 0)
113 if (j
< OSSL_NELEM(tls_feature_tbl
))
114 tlsextid
= tls_feature_tbl
[j
].num
;
116 tlsextid
= strtol(extval
, &endptr
, 10);
117 if (((*endptr
) != '\0') || (extval
== endptr
) || (tlsextid
< 0) ||
118 (tlsextid
> 65535)) {
119 X509V3err(X509V3_F_V2I_TLS_FEATURE
, X509V3_R_INVALID_SYNTAX
);
120 X509V3_conf_add_error_name_value(val
);
125 if ((ai
= ASN1_INTEGER_new()) == NULL
126 || !ASN1_INTEGER_set(ai
, tlsextid
)
127 || sk_ASN1_INTEGER_push(tlsf
, ai
) <= 0) {
128 X509V3err(X509V3_F_V2I_TLS_FEATURE
, ERR_R_MALLOC_FAILURE
);
131 /* So it doesn't get purged if an error occurs next time around */
137 sk_ASN1_INTEGER_pop_free(tlsf
, ASN1_INTEGER_free
);
138 ASN1_INTEGER_free(ai
);