Coverage Report

Created: 2025-09-05 06:13

/src/boringssl/crypto/x509/v3_bcons.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include <stdio.h>
16
#include <string.h>
17
18
#include <openssl/asn1.h>
19
#include <openssl/asn1t.h>
20
#include <openssl/conf.h>
21
#include <openssl/err.h>
22
#include <openssl/obj.h>
23
#include <openssl/x509.h>
24
25
#include "internal.h"
26
27
28
static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(
29
    const X509V3_EXT_METHOD *method, void *ext, STACK_OF(CONF_VALUE) *extlist);
30
static void *v2i_BASIC_CONSTRAINTS(const X509V3_EXT_METHOD *method,
31
                                   const X509V3_CTX *ctx,
32
                                   const STACK_OF(CONF_VALUE) *values);
33
34
const X509V3_EXT_METHOD v3_bcons = {
35
    NID_basic_constraints,
36
    0,
37
    ASN1_ITEM_ref(BASIC_CONSTRAINTS),
38
    0,
39
    0,
40
    0,
41
    0,
42
    0,
43
    0,
44
    i2v_BASIC_CONSTRAINTS,
45
    v2i_BASIC_CONSTRAINTS,
46
    NULL,
47
    NULL,
48
    NULL,
49
};
50
51
ASN1_SEQUENCE(BASIC_CONSTRAINTS) = {
52
    ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN),
53
    ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER),
54
} ASN1_SEQUENCE_END(BASIC_CONSTRAINTS)
55
56
IMPLEMENT_ASN1_FUNCTIONS_const(BASIC_CONSTRAINTS)
57
58
static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(
59
182
    const X509V3_EXT_METHOD *method, void *ext, STACK_OF(CONF_VALUE) *extlist) {
60
182
  const BASIC_CONSTRAINTS *bcons =
61
182
      reinterpret_cast<const BASIC_CONSTRAINTS *>(ext);
62
182
  X509V3_add_value_bool("CA", bcons->ca, &extlist);
63
182
  X509V3_add_value_int("pathlen", bcons->pathlen, &extlist);
64
182
  return extlist;
65
182
}
66
67
static void *v2i_BASIC_CONSTRAINTS(const X509V3_EXT_METHOD *method,
68
                                   const X509V3_CTX *ctx,
69
252
                                   const STACK_OF(CONF_VALUE) *values) {
70
252
  BASIC_CONSTRAINTS *bcons = NULL;
71
252
  if (!(bcons = BASIC_CONSTRAINTS_new())) {
72
0
    return NULL;
73
0
  }
74
771
  for (size_t i = 0; i < sk_CONF_VALUE_num(values); i++) {
75
716
    const CONF_VALUE *val = sk_CONF_VALUE_value(values, i);
76
716
    if (!strcmp(val->name, "CA")) {
77
170
      if (!X509V3_get_value_bool(val, &bcons->ca)) {
78
19
        goto err;
79
19
      }
80
546
    } else if (!strcmp(val->name, "pathlen")) {
81
374
      if (!X509V3_get_value_int(val, &bcons->pathlen)) {
82
6
        goto err;
83
6
      }
84
374
    } else {
85
172
      OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NAME);
86
172
      X509V3_conf_err(val);
87
172
      goto err;
88
172
    }
89
716
  }
90
55
  return bcons;
91
197
err:
92
197
  BASIC_CONSTRAINTS_free(bcons);
93
197
  return NULL;
94
252
}