/src/openssl/crypto/x509/v3_battcons.c
Line | Count | Source (jump to first uncovered line) |
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 "internal/cryptlib.h" |
11 | | #include <openssl/asn1t.h> |
12 | | #include <openssl/conf.h> |
13 | | #include <openssl/x509v3.h> |
14 | | #include "x509_local.h" |
15 | | #include "ext_dat.h" |
16 | | |
17 | | static STACK_OF(CONF_VALUE) *i2v_OSSL_BASIC_ATTR_CONSTRAINTS( |
18 | | X509V3_EXT_METHOD *method, |
19 | | OSSL_BASIC_ATTR_CONSTRAINTS *battcons, |
20 | | STACK_OF(CONF_VALUE) |
21 | | *extlist); |
22 | | static OSSL_BASIC_ATTR_CONSTRAINTS *v2i_OSSL_BASIC_ATTR_CONSTRAINTS( |
23 | | X509V3_EXT_METHOD *method, |
24 | | X509V3_CTX *ctx, |
25 | | STACK_OF(CONF_VALUE) *values); |
26 | | |
27 | | const X509V3_EXT_METHOD ossl_v3_battcons = { |
28 | | NID_basic_att_constraints, 0, |
29 | | ASN1_ITEM_ref(OSSL_BASIC_ATTR_CONSTRAINTS), |
30 | | 0, 0, 0, 0, |
31 | | 0, 0, |
32 | | (X509V3_EXT_I2V) i2v_OSSL_BASIC_ATTR_CONSTRAINTS, |
33 | | (X509V3_EXT_V2I)v2i_OSSL_BASIC_ATTR_CONSTRAINTS, |
34 | | NULL, NULL, |
35 | | NULL |
36 | | }; |
37 | | |
38 | | ASN1_SEQUENCE(OSSL_BASIC_ATTR_CONSTRAINTS) = { |
39 | | ASN1_OPT(OSSL_BASIC_ATTR_CONSTRAINTS, authority, ASN1_FBOOLEAN), |
40 | | ASN1_OPT(OSSL_BASIC_ATTR_CONSTRAINTS, pathlen, ASN1_INTEGER) |
41 | | } ASN1_SEQUENCE_END(OSSL_BASIC_ATTR_CONSTRAINTS) |
42 | | |
43 | | IMPLEMENT_ASN1_FUNCTIONS(OSSL_BASIC_ATTR_CONSTRAINTS) |
44 | | |
45 | | static STACK_OF(CONF_VALUE) *i2v_OSSL_BASIC_ATTR_CONSTRAINTS( |
46 | | X509V3_EXT_METHOD *method, |
47 | | OSSL_BASIC_ATTR_CONSTRAINTS *battcons, |
48 | | STACK_OF(CONF_VALUE) *extlist) |
49 | 0 | { |
50 | 0 | X509V3_add_value_bool("authority", battcons->authority, &extlist); |
51 | 0 | X509V3_add_value_int("pathlen", battcons->pathlen, &extlist); |
52 | 0 | return extlist; |
53 | 0 | } |
54 | | |
55 | | static OSSL_BASIC_ATTR_CONSTRAINTS *v2i_OSSL_BASIC_ATTR_CONSTRAINTS( |
56 | | X509V3_EXT_METHOD *method, |
57 | | X509V3_CTX *ctx, |
58 | | STACK_OF(CONF_VALUE) *values) |
59 | 0 | { |
60 | 0 | OSSL_BASIC_ATTR_CONSTRAINTS *battcons = NULL; |
61 | 0 | CONF_VALUE *val; |
62 | 0 | int i; |
63 | |
|
64 | 0 | if ((battcons = OSSL_BASIC_ATTR_CONSTRAINTS_new()) == NULL) { |
65 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
66 | 0 | return NULL; |
67 | 0 | } |
68 | 0 | for (i = 0; i < sk_CONF_VALUE_num(values); i++) { |
69 | 0 | val = sk_CONF_VALUE_value(values, i); |
70 | 0 | if (strcmp(val->name, "authority") == 0) { |
71 | 0 | if (!X509V3_get_value_bool(val, &battcons->authority)) |
72 | 0 | goto err; |
73 | 0 | } else if (strcmp(val->name, "pathlen") == 0) { |
74 | 0 | if (!X509V3_get_value_int(val, &battcons->pathlen)) |
75 | 0 | goto err; |
76 | 0 | } else { |
77 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NAME); |
78 | 0 | X509V3_conf_add_error_name_value(val); |
79 | 0 | goto err; |
80 | 0 | } |
81 | 0 | } |
82 | 0 | return battcons; |
83 | 0 | err: |
84 | 0 | OSSL_BASIC_ATTR_CONSTRAINTS_free(battcons); |
85 | 0 | return NULL; |
86 | 0 | } |