summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordoug <>2015-02-07 06:10:32 +0000
committerdoug <>2015-02-07 06:10:32 +0000
commit4d71037d26a6de59efacc048b6d8eaef040cf31f (patch)
treef0807b7a55d8647c713e337b2666be1d98420047 /src
parent76989ea410ba792cf5aa153d83128fbbac2609cf (diff)
downloadopenbsd-4d71037d26a6de59efacc048b6d8eaef040cf31f.tar.gz
openbsd-4d71037d26a6de59efacc048b6d8eaef040cf31f.tar.bz2
openbsd-4d71037d26a6de59efacc048b6d8eaef040cf31f.zip
Don't allow tag number 31 in CBB_add_asn1().
Tag 31 is invalid for a short form identifier octet (single byte). KNF a little more. Based on BoringSSL commit 5ba305643f55d37a3e45e8388a36d50c1b2d4ff5 ok miod@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/bs_cbb.c33
-rw-r--r--src/lib/libssl/bytestring.h6
-rw-r--r--src/lib/libssl/src/ssl/bs_cbb.c33
-rw-r--r--src/lib/libssl/src/ssl/bytestring.h6
4 files changed, 54 insertions, 24 deletions
diff --git a/src/lib/libssl/bs_cbb.c b/src/lib/libssl/bs_cbb.c
index eed8091698..5546fac97f 100644
--- a/src/lib/libssl/bs_cbb.c
+++ b/src/lib/libssl/bs_cbb.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bs_cbb.c,v 1.4 2015/02/07 04:37:35 doug Exp $ */ 1/* $OpenBSD: bs_cbb.c,v 1.5 2015/02/07 06:10:32 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -28,9 +28,8 @@ cbb_init(CBB *cbb, uint8_t *buf, size_t cap)
28 struct cbb_buffer_st *base; 28 struct cbb_buffer_st *base;
29 29
30 base = malloc(sizeof(struct cbb_buffer_st)); 30 base = malloc(sizeof(struct cbb_buffer_st));
31 if (base == NULL) { 31 if (base == NULL)
32 return 0; 32 return 0;
33 }
34 33
35 base->buf = buf; 34 base->buf = buf;
36 base->len = 0; 35 base->len = 0;
@@ -148,7 +147,10 @@ CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len)
148 return 0; 147 return 0;
149 148
150 if (cbb->base->can_resize && (out_data == NULL || out_len == NULL)) 149 if (cbb->base->can_resize && (out_data == NULL || out_len == NULL))
151 /* |out_data| and |out_len| can only be NULL if the CBB is fixed. */ 150 /*
151 * |out_data| and |out_len| can only be NULL if the CBB is
152 * fixed.
153 */
152 return 0; 154 return 0;
153 155
154 if (out_data != NULL) 156 if (out_data != NULL)
@@ -187,9 +189,11 @@ CBB_flush(CBB *cbb)
187 len = cbb->base->len - child_start; 189 len = cbb->base->len - child_start;
188 190
189 if (cbb->pending_is_asn1) { 191 if (cbb->pending_is_asn1) {
190 /* For ASN.1 we assume that we'll only need a single byte for the length. 192 /*
191 * If that turned out to be incorrect, we have to move the contents along 193 * For ASN.1 we assume that we'll only need a single byte for
192 * in order to make space. */ 194 * the length. If that turned out to be incorrect, we have to
195 * move the contents along in order to make space.
196 */
193 size_t len_len; 197 size_t len_len;
194 uint8_t initial_length_byte; 198 uint8_t initial_length_byte;
195 199
@@ -217,7 +221,10 @@ CBB_flush(CBB *cbb)
217 } 221 }
218 222
219 if (len_len != 1) { 223 if (len_len != 1) {
220 /* We need to move the contents along in order to make space. */ 224 /*
225 * We need to move the contents along in order to make
226 * space.
227 */
221 size_t extra_bytes = len_len - 1; 228 size_t extra_bytes = len_len - 1;
222 if (!cbb_buffer_add(cbb->base, NULL, extra_bytes)) 229 if (!cbb_buffer_add(cbb->base, NULL, extra_bytes))
223 return 0; 230 return 0;
@@ -289,6 +296,10 @@ CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents)
289int 296int
290CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag) 297CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag)
291{ 298{
299 /* Long form identifier octets are not supported. */
300 if ((tag & 0x1f) == 0x1f)
301 return 0;
302
292 if (!CBB_flush(cbb) || !CBB_add_u8(cbb, tag)) 303 if (!CBB_flush(cbb) || !CBB_add_u8(cbb, tag))
293 return 0; 304 return 0;
294 305
@@ -370,8 +381,10 @@ CBB_add_asn1_uint64(CBB *cbb, uint64_t value)
370 /* Don't encode leading zeros. */ 381 /* Don't encode leading zeros. */
371 continue; 382 continue;
372 383
373 /* If the high bit is set, add a padding byte to make it 384 /*
374 * unsigned. */ 385 * If the high bit is set, add a padding byte to make it
386 * unsigned.
387 */
375 if ((byte & 0x80) && !CBB_add_u8(&child, 0)) 388 if ((byte & 0x80) && !CBB_add_u8(&child, 0))
376 return 0; 389 return 0;
377 390
diff --git a/src/lib/libssl/bytestring.h b/src/lib/libssl/bytestring.h
index 209bb38e24..93c3df6f10 100644
--- a/src/lib/libssl/bytestring.h
+++ b/src/lib/libssl/bytestring.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bytestring.h,v 1.3 2015/02/07 02:02:28 doug Exp $ */ 1/* $OpenBSD: bytestring.h,v 1.4 2015/02/07 06:10:32 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -374,7 +374,9 @@ int CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents);
374/* 374/*
375 * CBB_add_asn sets |*out_contents| to a |CBB| into which the contents of an 375 * CBB_add_asn sets |*out_contents| to a |CBB| into which the contents of an
376 * ASN.1 object can be written. The |tag| argument will be used as the tag for 376 * ASN.1 object can be written. The |tag| argument will be used as the tag for
377 * the object. It returns one on success or zero on error. 377 * the object. Passing in |tag| number 31 will return in an error since only
378 * single octet identifiers are supported. It returns one on success or zero
379 * on error.
378 */ 380 */
379int CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag); 381int CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag);
380 382
diff --git a/src/lib/libssl/src/ssl/bs_cbb.c b/src/lib/libssl/src/ssl/bs_cbb.c
index eed8091698..5546fac97f 100644
--- a/src/lib/libssl/src/ssl/bs_cbb.c
+++ b/src/lib/libssl/src/ssl/bs_cbb.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bs_cbb.c,v 1.4 2015/02/07 04:37:35 doug Exp $ */ 1/* $OpenBSD: bs_cbb.c,v 1.5 2015/02/07 06:10:32 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -28,9 +28,8 @@ cbb_init(CBB *cbb, uint8_t *buf, size_t cap)
28 struct cbb_buffer_st *base; 28 struct cbb_buffer_st *base;
29 29
30 base = malloc(sizeof(struct cbb_buffer_st)); 30 base = malloc(sizeof(struct cbb_buffer_st));
31 if (base == NULL) { 31 if (base == NULL)
32 return 0; 32 return 0;
33 }
34 33
35 base->buf = buf; 34 base->buf = buf;
36 base->len = 0; 35 base->len = 0;
@@ -148,7 +147,10 @@ CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len)
148 return 0; 147 return 0;
149 148
150 if (cbb->base->can_resize && (out_data == NULL || out_len == NULL)) 149 if (cbb->base->can_resize && (out_data == NULL || out_len == NULL))
151 /* |out_data| and |out_len| can only be NULL if the CBB is fixed. */ 150 /*
151 * |out_data| and |out_len| can only be NULL if the CBB is
152 * fixed.
153 */
152 return 0; 154 return 0;
153 155
154 if (out_data != NULL) 156 if (out_data != NULL)
@@ -187,9 +189,11 @@ CBB_flush(CBB *cbb)
187 len = cbb->base->len - child_start; 189 len = cbb->base->len - child_start;
188 190
189 if (cbb->pending_is_asn1) { 191 if (cbb->pending_is_asn1) {
190 /* For ASN.1 we assume that we'll only need a single byte for the length. 192 /*
191 * If that turned out to be incorrect, we have to move the contents along 193 * For ASN.1 we assume that we'll only need a single byte for
192 * in order to make space. */ 194 * the length. If that turned out to be incorrect, we have to
195 * move the contents along in order to make space.
196 */
193 size_t len_len; 197 size_t len_len;
194 uint8_t initial_length_byte; 198 uint8_t initial_length_byte;
195 199
@@ -217,7 +221,10 @@ CBB_flush(CBB *cbb)
217 } 221 }
218 222
219 if (len_len != 1) { 223 if (len_len != 1) {
220 /* We need to move the contents along in order to make space. */ 224 /*
225 * We need to move the contents along in order to make
226 * space.
227 */
221 size_t extra_bytes = len_len - 1; 228 size_t extra_bytes = len_len - 1;
222 if (!cbb_buffer_add(cbb->base, NULL, extra_bytes)) 229 if (!cbb_buffer_add(cbb->base, NULL, extra_bytes))
223 return 0; 230 return 0;
@@ -289,6 +296,10 @@ CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents)
289int 296int
290CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag) 297CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag)
291{ 298{
299 /* Long form identifier octets are not supported. */
300 if ((tag & 0x1f) == 0x1f)
301 return 0;
302
292 if (!CBB_flush(cbb) || !CBB_add_u8(cbb, tag)) 303 if (!CBB_flush(cbb) || !CBB_add_u8(cbb, tag))
293 return 0; 304 return 0;
294 305
@@ -370,8 +381,10 @@ CBB_add_asn1_uint64(CBB *cbb, uint64_t value)
370 /* Don't encode leading zeros. */ 381 /* Don't encode leading zeros. */
371 continue; 382 continue;
372 383
373 /* If the high bit is set, add a padding byte to make it 384 /*
374 * unsigned. */ 385 * If the high bit is set, add a padding byte to make it
386 * unsigned.
387 */
375 if ((byte & 0x80) && !CBB_add_u8(&child, 0)) 388 if ((byte & 0x80) && !CBB_add_u8(&child, 0))
376 return 0; 389 return 0;
377 390
diff --git a/src/lib/libssl/src/ssl/bytestring.h b/src/lib/libssl/src/ssl/bytestring.h
index 209bb38e24..93c3df6f10 100644
--- a/src/lib/libssl/src/ssl/bytestring.h
+++ b/src/lib/libssl/src/ssl/bytestring.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bytestring.h,v 1.3 2015/02/07 02:02:28 doug Exp $ */ 1/* $OpenBSD: bytestring.h,v 1.4 2015/02/07 06:10:32 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -374,7 +374,9 @@ int CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents);
374/* 374/*
375 * CBB_add_asn sets |*out_contents| to a |CBB| into which the contents of an 375 * CBB_add_asn sets |*out_contents| to a |CBB| into which the contents of an
376 * ASN.1 object can be written. The |tag| argument will be used as the tag for 376 * ASN.1 object can be written. The |tag| argument will be used as the tag for
377 * the object. It returns one on success or zero on error. 377 * the object. Passing in |tag| number 31 will return in an error since only
378 * single octet identifiers are supported. It returns one on success or zero
379 * on error.
378 */ 380 */
379int CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag); 381int CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag);
380 382