Coverage Report

Created: 2026-04-30 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boringssl/crypto/x509/x509cset.cc
Line
Count
Source
1
// Copyright 2001-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 <openssl/asn1.h>
16
#include <openssl/evp.h>
17
#include <openssl/obj.h>
18
#include <openssl/x509.h>
19
20
#include "../asn1/internal.h"
21
#include "../internal.h"
22
#include "internal.h"
23
24
25
using namespace bssl;
26
27
0
int X509_CRL_set_version(X509_CRL *x, long version) {
28
0
  if (x == nullptr) {
29
0
    return 0;
30
0
  }
31
32
0
  if (version < X509_CRL_VERSION_1 || version > X509_CRL_VERSION_2) {
33
0
    OPENSSL_PUT_ERROR(X509, X509_R_INVALID_VERSION);
34
0
    return 0;
35
0
  }
36
37
  // v1(0) is default and is represented by omitting the version.
38
0
  if (version == X509_CRL_VERSION_1) {
39
0
    ASN1_INTEGER_free(x->crl->version);
40
0
    x->crl->version = nullptr;
41
0
    return 1;
42
0
  }
43
44
0
  if (x->crl->version == nullptr) {
45
0
    x->crl->version = ASN1_INTEGER_new();
46
0
    if (x->crl->version == nullptr) {
47
0
      return 0;
48
0
    }
49
0
  }
50
0
  return ASN1_INTEGER_set_int64(x->crl->version, version);
51
0
}
52
53
0
int X509_CRL_set_issuer_name(X509_CRL *x, const X509_NAME *name) {
54
0
  if ((x == nullptr) || (x->crl == nullptr)) {
55
0
    return 0;
56
0
  }
57
0
  return (X509_NAME_set(&x->crl->issuer, name));
58
0
}
59
60
0
int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm) {
61
0
  ASN1_TIME *in;
62
63
0
  if (x == nullptr) {
64
0
    return 0;
65
0
  }
66
0
  in = x->crl->lastUpdate;
67
0
  if (in != tm) {
68
0
    in = ASN1_STRING_dup(tm);
69
0
    if (in != nullptr) {
70
0
      ASN1_TIME_free(x->crl->lastUpdate);
71
0
      x->crl->lastUpdate = in;
72
0
    }
73
0
  }
74
0
  return in != nullptr;
75
0
}
76
77
0
int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm) {
78
0
  ASN1_TIME *in;
79
80
0
  if (x == nullptr) {
81
0
    return 0;
82
0
  }
83
0
  in = x->crl->nextUpdate;
84
0
  if (in != tm) {
85
0
    in = ASN1_STRING_dup(tm);
86
0
    if (in != nullptr) {
87
0
      ASN1_TIME_free(x->crl->nextUpdate);
88
0
      x->crl->nextUpdate = in;
89
0
    }
90
0
  }
91
0
  return in != nullptr;
92
0
}
93
94
0
int X509_CRL_sort(X509_CRL *c) {
95
  // Sort the data so it will be written in serial number order.
96
0
  sk_X509_REVOKED_sort(c->crl->revoked);
97
0
  asn1_encoding_clear(&c->crl->enc);
98
0
  return 1;
99
0
}
100
101
0
int X509_CRL_up_ref(X509_CRL *crl) {
102
0
  CRYPTO_refcount_inc(&crl->references);
103
0
  return 1;
104
0
}
105
106
0
long X509_CRL_get_version(const X509_CRL *crl) {
107
0
  return ASN1_INTEGER_get(crl->crl->version);
108
0
}
109
110
0
const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl) {
111
0
  return crl->crl->lastUpdate;
112
0
}
113
114
0
const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl) {
115
0
  return crl->crl->nextUpdate;
116
0
}
117
118
0
ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl) {
119
0
  return crl->crl->lastUpdate;
120
0
}
121
122
0
ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl) {
123
0
  return crl->crl->nextUpdate;
124
0
}
125
126
0
X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl) { return crl->crl->issuer; }
127
128
0
STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl) {
129
0
  return crl->crl->revoked;
130
0
}
131
132
0
const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl) {
133
0
  return crl->crl->extensions;
134
0
}
135
136
void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
137
0
                             const X509_ALGOR **palg) {
138
0
  if (psig != nullptr) {
139
0
    *psig = crl->signature;
140
0
  }
141
0
  if (palg != nullptr) {
142
0
    *palg = crl->sig_alg;
143
0
  }
144
0
}
145
146
0
int X509_CRL_get_signature_nid(const X509_CRL *crl) {
147
0
  return OBJ_obj2nid(crl->sig_alg->algorithm);
148
0
}
149
150
0
const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *revoked) {
151
0
  return revoked->revocationDate;
152
0
}
153
154
int X509_REVOKED_set_revocationDate(X509_REVOKED *revoked,
155
0
                                    const ASN1_TIME *tm) {
156
0
  ASN1_TIME *in;
157
158
0
  if (revoked == nullptr) {
159
0
    return 0;
160
0
  }
161
0
  in = revoked->revocationDate;
162
0
  if (in != tm) {
163
0
    in = ASN1_STRING_dup(tm);
164
0
    if (in != nullptr) {
165
0
      ASN1_TIME_free(revoked->revocationDate);
166
0
      revoked->revocationDate = in;
167
0
    }
168
0
  }
169
0
  return in != nullptr;
170
0
}
171
172
const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(
173
0
    const X509_REVOKED *revoked) {
174
0
  return revoked->serialNumber;
175
0
}
176
177
int X509_REVOKED_set_serialNumber(X509_REVOKED *revoked,
178
0
                                  const ASN1_INTEGER *serial) {
179
0
  ASN1_INTEGER *in;
180
181
0
  if (serial->type != V_ASN1_INTEGER && serial->type != V_ASN1_NEG_INTEGER) {
182
0
    OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
183
0
    return 0;
184
0
  }
185
186
0
  if (revoked == nullptr) {
187
0
    return 0;
188
0
  }
189
0
  in = revoked->serialNumber;
190
0
  if (in != serial) {
191
0
    in = ASN1_INTEGER_dup(serial);
192
0
    if (in != nullptr) {
193
0
      ASN1_INTEGER_free(revoked->serialNumber);
194
0
      revoked->serialNumber = in;
195
0
    }
196
0
  }
197
0
  return in != nullptr;
198
0
}
199
200
const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(
201
0
    const X509_REVOKED *r) {
202
0
  return r->extensions;
203
0
}
204
205
0
int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp) {
206
0
  asn1_encoding_clear(&crl->crl->enc);
207
0
  return i2d_X509_CRL_INFO(crl->crl, outp);
208
0
}
209
210
0
int i2d_X509_CRL_tbs(const X509_CRL *crl, unsigned char **outp) {
211
0
  return i2d_X509_CRL_INFO(crl->crl, outp);
212
0
}
213
214
0
int X509_CRL_set1_signature_algo(X509_CRL *crl, const X509_ALGOR *algo) {
215
0
  return X509_ALGOR_copy(crl->sig_alg, algo) &&
216
0
         X509_ALGOR_copy(crl->crl->sig_alg, algo);
217
0
}
218
219
int X509_CRL_set1_signature_value(X509_CRL *crl, const uint8_t *sig,
220
0
                                  size_t sig_len) {
221
0
  return ASN1_STRING_set(crl->signature, sig, sig_len);
222
0
}