Skip to content

Commit 1fd75fc

Browse files
committed
Update BoringSSL to 0226f30467f540a3f62ef48d453f93927da199b6
This patch updates BoringSSL to 0226f30467f540a3f62ef48d453f93927da199b6. As with all of our patch updates to BoringSSL, this comes in multiple commits. The first contains the changes to the vendoring script and the tweaks to product code.
1 parent 2a02d30 commit 1fd75fc

File tree

177 files changed

+8044
-4402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+8044
-4402
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Sources/CCryptoBoringSSL directory. The source repository is at
2121
// https://boringssl.googlesource.com/boringssl.
2222
//
23-
// BoringSSL Commit: 035e720641f385e82c72b7b0a9e1d89e58cb5ed5
23+
// BoringSSL Commit: 0226f30467f540a3f62ef48d453f93927da199b6
2424

2525
import PackageDescription
2626

Sources/CCryptoBoringSSL/crypto/asn1/a_bitstr.cc

Lines changed: 72 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <CCryptoBoringSSL_bytestring.h>
2121
#include <CCryptoBoringSSL_err.h>
2222
#include <CCryptoBoringSSL_mem.h>
23+
#include <CCryptoBoringSSL_span.h>
2324

2425
#include "../internal.h"
2526
#include "internal.h"
@@ -110,76 +111,96 @@ int asn1_marshal_bit_string(CBB *out, const ASN1_BIT_STRING *in,
110111
CBB_flush(out);
111112
}
112113

113-
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
114-
const unsigned char **pp, long len) {
115-
ASN1_BIT_STRING *ret = NULL;
116-
const unsigned char *p;
117-
unsigned char *s;
118-
int padding;
119-
uint8_t padding_mask;
120-
121-
if (len < 1) {
114+
static int asn1_parse_bit_string_contents(bssl::Span<const uint8_t> in,
115+
ASN1_BIT_STRING *out) {
116+
CBS cbs = in;
117+
uint8_t padding;
118+
if (!CBS_get_u8(&cbs, &padding)) {
122119
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
123-
goto err;
120+
return 0;
124121
}
125122

126-
if (len > INT_MAX) {
127-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_LONG);
128-
goto err;
123+
if (padding > 7) {
124+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
125+
return 0;
129126
}
130127

131-
if ((a == NULL) || ((*a) == NULL)) {
132-
if ((ret = ASN1_BIT_STRING_new()) == NULL) {
133-
return NULL;
128+
// Unused bits in a BIT STRING must be zero.
129+
uint8_t padding_mask = (1 << padding) - 1;
130+
if (padding != 0) {
131+
CBS copy = cbs;
132+
uint8_t last;
133+
if (!CBS_get_last_u8(&copy, &last) || (last & padding_mask) != 0) {
134+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_PADDING);
135+
return 0;
134136
}
135-
} else {
136-
ret = (*a);
137137
}
138138

139-
p = *pp;
140-
padding = *(p++);
141-
len--;
142-
if (padding > 7) {
143-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
144-
goto err;
139+
if (!ASN1_STRING_set(out, CBS_data(&cbs), CBS_len(&cbs))) {
140+
return 0;
145141
}
146142

147-
// Unused bits in a BIT STRING must be zero.
148-
padding_mask = (1 << padding) - 1;
149-
if (padding != 0 && (len < 1 || (p[len - 1] & padding_mask) != 0)) {
150-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_PADDING);
151-
goto err;
152-
}
143+
out->type = V_ASN1_BIT_STRING;
144+
// |ASN1_STRING_FLAG_BITS_LEFT| and the bottom 3 bits encode |padding|.
145+
out->flags &= ~0x07;
146+
out->flags |= ASN1_STRING_FLAG_BITS_LEFT | padding;
147+
return 1;
148+
}
153149

154-
// We do this to preserve the settings. If we modify the settings, via
155-
// the _set_bit function, we will recalculate on output
156-
ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); // clear
157-
ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | padding); // set
150+
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
151+
const unsigned char **pp, long len) {
152+
if (len < 0) {
153+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
154+
return nullptr;
155+
}
158156

159-
if (len > 0) {
160-
s = reinterpret_cast<uint8_t *>(OPENSSL_memdup(p, len));
161-
if (s == NULL) {
162-
goto err;
157+
ASN1_BIT_STRING *ret = nullptr;
158+
if (a == nullptr || *a == nullptr) {
159+
if ((ret = ASN1_BIT_STRING_new()) == nullptr) {
160+
return nullptr;
163161
}
164-
p += len;
165162
} else {
166-
s = NULL;
163+
ret = *a;
167164
}
168165

169-
ret->length = (int)len;
170-
OPENSSL_free(ret->data);
171-
ret->data = s;
172-
ret->type = V_ASN1_BIT_STRING;
173-
if (a != NULL) {
174-
(*a) = ret;
166+
if (!asn1_parse_bit_string_contents(bssl::Span(*pp, len), ret)) {
167+
if (ret != nullptr && (a == nullptr || *a != ret)) {
168+
ASN1_BIT_STRING_free(ret);
169+
}
170+
return nullptr;
175171
}
176-
*pp = p;
172+
173+
if (a != nullptr) {
174+
*a = ret;
175+
}
176+
*pp += len;
177177
return ret;
178-
err:
179-
if ((ret != NULL) && ((a == NULL) || (*a != ret))) {
180-
ASN1_BIT_STRING_free(ret);
178+
}
179+
180+
int asn1_parse_bit_string(CBS *cbs, ASN1_BIT_STRING *out, CBS_ASN1_TAG tag) {
181+
tag = tag == 0 ? CBS_ASN1_BITSTRING : tag;
182+
CBS child;
183+
if (!CBS_get_asn1(cbs, &child, tag)) {
184+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
185+
return 0;
186+
}
187+
return asn1_parse_bit_string_contents(child, out);
188+
}
189+
190+
int asn1_parse_bit_string_with_bad_length(CBS *cbs, ASN1_BIT_STRING *out) {
191+
CBS child;
192+
CBS_ASN1_TAG tag;
193+
size_t header_len;
194+
int indefinite;
195+
if (!CBS_get_any_ber_asn1_element(cbs, &child, &tag, &header_len,
196+
/*out_ber_found=*/nullptr,
197+
&indefinite) ||
198+
tag != CBS_ASN1_BITSTRING || indefinite || //
199+
!CBS_skip(&child, header_len)) {
200+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
201+
return 0;
181202
}
182-
return NULL;
203+
return asn1_parse_bit_string_contents(child, out);
183204
}
184205

185206
// These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>

Sources/CCryptoBoringSSL/crypto/asn1/a_bool.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121

2222

2323
int i2d_ASN1_BOOLEAN(ASN1_BOOLEAN a, unsigned char **outp) {
24-
CBB cbb;
25-
if (!CBB_init(&cbb, 3) || //
26-
!CBB_add_asn1_bool(&cbb, a != ASN1_BOOLEAN_FALSE)) {
27-
CBB_cleanup(&cbb);
28-
return -1;
29-
}
30-
return CBB_finish_i2d(&cbb, outp);
24+
return bssl::I2DFromCBB(
25+
/*initial_capacity=*/3, outp, [&](CBB *cbb) -> bool {
26+
return CBB_add_asn1_bool(cbb, a != ASN1_BOOLEAN_FALSE);
27+
});
3128
}
3229

3330
ASN1_BOOLEAN d2i_ASN1_BOOLEAN(ASN1_BOOLEAN *out, const unsigned char **inp,

Sources/CCryptoBoringSSL/crypto/asn1/a_gentm.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d) {
3636
return 1;
3737
}
3838

39+
int asn1_parse_generalized_time(CBS *cbs, ASN1_GENERALIZEDTIME *out,
40+
CBS_ASN1_TAG tag) {
41+
tag = tag == 0 ? CBS_ASN1_GENERALIZEDTIME : tag;
42+
CBS child;
43+
if (!CBS_get_asn1(cbs, &child, tag) ||
44+
!CBS_parse_generalized_time(&child, nullptr,
45+
/*allow_timezone_offset=*/0)) {
46+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
47+
return 0;
48+
}
49+
if (!ASN1_STRING_set(out, CBS_data(&child), CBS_len(&child))) {
50+
return 0;
51+
}
52+
out->type = V_ASN1_GENERALIZEDTIME;
53+
return 1;
54+
}
55+
3956
int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *d) {
4057
return asn1_generalizedtime_to_tm(NULL, d);
4158
}

Sources/CCryptoBoringSSL/crypto/asn1/a_int.cc

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <CCryptoBoringSSL_bytestring.h>
2222
#include <CCryptoBoringSSL_err.h>
2323
#include <CCryptoBoringSSL_mem.h>
24+
#include <CCryptoBoringSSL_span.h>
2425

2526
#include "../internal.h"
2627
#include "internal.h"
@@ -146,32 +147,13 @@ int i2c_ASN1_INTEGER(const ASN1_INTEGER *in, unsigned char **outp) {
146147
return len;
147148
}
148149

149-
ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **out, const unsigned char **inp,
150-
long len) {
151-
// This function can handle lengths up to INT_MAX - 1, but the rest of the
152-
// legacy ASN.1 code mixes integer types, so avoid exposing it to
153-
// ASN1_INTEGERS with larger lengths.
154-
if (len < 0 || len > INT_MAX / 2) {
155-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
156-
return NULL;
157-
}
158-
159-
CBS cbs;
160-
CBS_init(&cbs, *inp, (size_t)len);
150+
static int asn1_parse_integer_contents(bssl::Span<const uint8_t> in,
151+
ASN1_INTEGER *out) {
152+
CBS cbs = in;
161153
int is_negative;
162154
if (!CBS_is_valid_asn1_integer(&cbs, &is_negative)) {
163155
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
164-
return NULL;
165-
}
166-
167-
ASN1_INTEGER *ret = NULL;
168-
if (out == NULL || *out == NULL) {
169-
ret = ASN1_INTEGER_new();
170-
if (ret == NULL) {
171-
return NULL;
172-
}
173-
} else {
174-
ret = *out;
156+
return 0;
175157
}
176158

177159
// Convert to |ASN1_INTEGER|'s sign-and-magnitude representation. First,
@@ -192,33 +174,75 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **out, const unsigned char **inp,
192174
}
193175
}
194176

195-
if (!ASN1_STRING_set(ret, CBS_data(&cbs), CBS_len(&cbs))) {
196-
goto err;
177+
if (!ASN1_STRING_set(out, CBS_data(&cbs), CBS_len(&cbs))) {
178+
return 0;
197179
}
198180

199181
if (is_negative) {
200-
ret->type = V_ASN1_NEG_INTEGER;
201-
negate_twos_complement(ret->data, ret->length);
182+
out->type = V_ASN1_NEG_INTEGER;
183+
negate_twos_complement(out->data, out->length);
202184
} else {
203-
ret->type = V_ASN1_INTEGER;
185+
out->type = V_ASN1_INTEGER;
204186
}
205187

206188
// The value should be minimally-encoded.
207-
assert(ret->length == 0 || ret->data[0] != 0);
189+
assert(out->length == 0 || out->data[0] != 0);
208190
// Zero is not negative.
209-
assert(!is_negative || ret->length > 0);
191+
assert(!is_negative || out->length > 0);
192+
return 1;
193+
}
194+
195+
int asn1_parse_integer(CBS *cbs, ASN1_INTEGER *out, CBS_ASN1_TAG tag) {
196+
tag = tag == 0 ? CBS_ASN1_INTEGER : tag;
197+
CBS child;
198+
if (!CBS_get_asn1(cbs, &child, tag)) {
199+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
200+
return 0;
201+
}
202+
return asn1_parse_integer_contents(child, out);
203+
}
204+
205+
int asn1_parse_enumerated(CBS *cbs, ASN1_ENUMERATED *out, CBS_ASN1_TAG tag) {
206+
tag = tag == 0 ? CBS_ASN1_ENUMERATED : tag;
207+
if (!asn1_parse_integer(cbs, out, tag)) {
208+
return 0;
209+
}
210+
// Fix the type value.
211+
out->type =
212+
(out->type & V_ASN1_NEG) ? V_ASN1_NEG_ENUMERATED : V_ASN1_ENUMERATED;
213+
return 1;
214+
}
215+
216+
ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **out, const unsigned char **inp,
217+
long len) {
218+
if (len < 0) {
219+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
220+
return nullptr;
221+
}
222+
223+
ASN1_INTEGER *ret = nullptr;
224+
if (out == nullptr || *out == nullptr) {
225+
ret = ASN1_INTEGER_new();
226+
if (ret == nullptr) {
227+
return nullptr;
228+
}
229+
} else {
230+
ret = *out;
231+
}
232+
233+
if (!asn1_parse_integer_contents(bssl::Span(*inp, len), ret)) {
234+
if (ret != nullptr && (out == nullptr || *out != ret)) {
235+
ASN1_INTEGER_free(ret);
236+
}
237+
return nullptr;
238+
}
210239

211240
*inp += len;
212-
if (out != NULL) {
241+
if (out != nullptr) {
213242
*out = ret;
214243
}
215244
return ret;
216245

217-
err:
218-
if (ret != NULL && (out == NULL || *out != ret)) {
219-
ASN1_INTEGER_free(ret);
220-
}
221-
return NULL;
222246
}
223247

224248
int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t v) {

0 commit comments

Comments
 (0)