Coverage Report

Created: 2026-03-19 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boringssl/crypto/x509/v3_extku.cc
Line
Count
Source
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
17
#include <openssl/asn1t.h>
18
#include <openssl/conf.h>
19
#include <openssl/err.h>
20
#include <openssl/obj.h>
21
#include <openssl/x509.h>
22
23
#include "internal.h"
24
25
26
using namespace bssl;
27
28
static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
29
                                    const X509V3_CTX *ctx,
30
                                    const STACK_OF(CONF_VALUE) *nval);
31
static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(
32
    const X509V3_EXT_METHOD *method, void *eku, STACK_OF(CONF_VALUE) *extlist);
33
34
const X509V3_EXT_METHOD bssl::v3_ext_ku = {
35
    NID_ext_key_usage,
36
    0,
37
    ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
38
    nullptr,
39
    nullptr,
40
    nullptr,
41
    nullptr,
42
    nullptr,
43
    nullptr,
44
    i2v_EXTENDED_KEY_USAGE,
45
    v2i_EXTENDED_KEY_USAGE,
46
    nullptr,
47
    nullptr,
48
    nullptr,
49
};
50
51
ASN1_ITEM_TEMPLATE(EXTENDED_KEY_USAGE) = ASN1_EX_TEMPLATE_TYPE(
52
    ASN1_TFLG_SEQUENCE_OF, 0, EXTENDED_KEY_USAGE, ASN1_OBJECT)
53
ASN1_ITEM_TEMPLATE_END(EXTENDED_KEY_USAGE)
54
55
IMPLEMENT_ASN1_FUNCTIONS_const(EXTENDED_KEY_USAGE)
56
57
static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(
58
178
    const X509V3_EXT_METHOD *method, void *a, STACK_OF(CONF_VALUE) *ext_list) {
59
178
  const EXTENDED_KEY_USAGE *eku =
60
178
      reinterpret_cast<const EXTENDED_KEY_USAGE *>(a);
61
1.07k
  for (size_t i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
62
899
    const ASN1_OBJECT *obj = sk_ASN1_OBJECT_value(eku, i);
63
899
    char obj_tmp[80];
64
899
    i2t_ASN1_OBJECT(obj_tmp, 80, obj);
65
899
    X509V3_add_value(nullptr, obj_tmp, &ext_list);
66
899
  }
67
178
  return ext_list;
68
178
}
69
70
static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
71
                                    const X509V3_CTX *ctx,
72
79
                                    const STACK_OF(CONF_VALUE) *nval) {
73
79
  EXTENDED_KEY_USAGE *extku = sk_ASN1_OBJECT_new_null();
74
79
  if (extku == nullptr) {
75
0
    return nullptr;
76
0
  }
77
78
1.11k
  for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) {
79
1.07k
    const CONF_VALUE *val = sk_CONF_VALUE_value(nval, i);
80
1.07k
    const char *extval;
81
1.07k
    if (val->value) {
82
194
      extval = val->value;
83
877
    } else {
84
877
      extval = val->name;
85
877
    }
86
1.07k
    ASN1_OBJECT *obj = OBJ_txt2obj(extval, 0);
87
1.07k
    if (obj == nullptr || !sk_ASN1_OBJECT_push(extku, obj)) {
88
34
      ASN1_OBJECT_free(obj);
89
34
      sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
90
34
      OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OBJECT_IDENTIFIER);
91
34
      X509V3_conf_err(val);
92
34
      return nullptr;
93
34
    }
94
1.07k
  }
95
96
45
  return extku;
97
79
}