]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/x509/v3_bcons.c
Update copyright year
[thirdparty/openssl.git] / crypto / x509 / v3_bcons.c
CommitLineData
0f113f3e 1/*
3c2bdd7d 2 * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
9aeaf1b4 3 *
4286ca47 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
d2e9e320
RS
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
9aeaf1b4
DSH
8 */
9
10#include <stdio.h>
b39fc560 11#include "internal/cryptlib.h"
ec577822 12#include <openssl/asn1.h>
9d6b1ce6 13#include <openssl/asn1t.h>
ec577822
BM
14#include <openssl/conf.h>
15#include <openssl/x509v3.h>
df2ee0e2 16#include "ext_dat.h"
c90c4693 17#include "x509_local.h"
9aeaf1b4 18
0f113f3e
MC
19static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
20 BASIC_CONSTRAINTS *bcons,
21 STACK_OF(CONF_VALUE)
22 *extlist);
23static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
24 X509V3_CTX *ctx,
25 STACK_OF(CONF_VALUE) *values);
9aeaf1b4 26
47864aea 27const X509V3_EXT_METHOD ossl_v3_bcons = {
0f113f3e
MC
28 NID_basic_constraints, 0,
29 ASN1_ITEM_ref(BASIC_CONSTRAINTS),
30 0, 0, 0, 0,
31 0, 0,
32 (X509V3_EXT_I2V) i2v_BASIC_CONSTRAINTS,
33 (X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS,
34 NULL, NULL,
35 NULL
9aeaf1b4
DSH
36};
37
9d6b1ce6 38ASN1_SEQUENCE(BASIC_CONSTRAINTS) = {
0f113f3e
MC
39 ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN),
40 ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER)
d339187b 41} ASN1_SEQUENCE_END(BASIC_CONSTRAINTS)
9aeaf1b4 42
9d6b1ce6 43IMPLEMENT_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)
9aeaf1b4 44
ba404b5e 45static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
0f113f3e
MC
46 BASIC_CONSTRAINTS *bcons,
47 STACK_OF(CONF_VALUE)
48 *extlist)
9aeaf1b4 49{
0f113f3e
MC
50 X509V3_add_value_bool("CA", bcons->ca, &extlist);
51 X509V3_add_value_int("pathlen", bcons->pathlen, &extlist);
52 return extlist;
9aeaf1b4
DSH
53}
54
6b691a5c 55static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
0f113f3e
MC
56 X509V3_CTX *ctx,
57 STACK_OF(CONF_VALUE) *values)
9aeaf1b4 58{
0f113f3e
MC
59 BASIC_CONSTRAINTS *bcons = NULL;
60 CONF_VALUE *val;
61 int i;
75ebbd9a
RS
62
63 if ((bcons = BASIC_CONSTRAINTS_new()) == NULL) {
9311d0c4 64 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
0f113f3e
MC
65 return NULL;
66 }
67 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
68 val = sk_CONF_VALUE_value(values, i);
86885c28 69 if (strcmp(val->name, "CA") == 0) {
0f113f3e
MC
70 if (!X509V3_get_value_bool(val, &bcons->ca))
71 goto err;
86885c28 72 } else if (strcmp(val->name, "pathlen") == 0) {
0f113f3e
MC
73 if (!X509V3_get_value_int(val, &bcons->pathlen))
74 goto err;
c90c4693 75 /* TODO add sanity check on int value - at least, must be >= 0 */
0f113f3e 76 } else {
9311d0c4 77 ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NAME);
c90c4693 78 X509V3_conf_add_error_name_value(val);
0f113f3e
MC
79 goto err;
80 }
81 }
82 return bcons;
83 err:
84 BASIC_CONSTRAINTS_free(bcons);
85 return NULL;
9aeaf1b4 86}