summaryrefslogtreecommitdiffstats
path: root/lib/libssl/src/ssl/bs_ber.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libssl/src/ssl/bs_ber.c')
-rw-r--r--lib/libssl/src/ssl/bs_ber.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/lib/libssl/src/ssl/bs_ber.c b/lib/libssl/src/ssl/bs_ber.c
index 3d39def111b..1310d4a94ce 100644
--- a/lib/libssl/src/ssl/bs_ber.c
+++ b/lib/libssl/src/ssl/bs_ber.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bs_ber.c,v 1.5 2015/06/15 07:35:49 doug Exp $ */
+/* $OpenBSD: bs_ber.c,v 1.6 2015/06/16 06:37:58 doug Exp $ */
/*
* Copyright (c) 2014, Google Inc.
*
@@ -29,7 +29,7 @@ static const unsigned kMaxDepth = 2048;
/* Non-strict version that allows a relaxed DER with indefinite form. */
static int
-cbs_nonstrict_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
+cbs_nonstrict_get_any_asn1_element(CBS *cbs, CBS *out, unsigned int *out_tag,
size_t *out_header_len)
{
return cbs_get_any_asn1_element_internal(cbs, out,
@@ -37,13 +37,15 @@ cbs_nonstrict_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
}
/*
- * cbs_find_ber walks an ASN.1 structure in |orig_in| and sets |*ber_found|
- * depending on whether an indefinite length element was found. The value of
- * |in| is not changed. It returns one on success (i.e. |*ber_found| was set)
- * and zero on error.
+ * cbs_find_indefinite walks an ASN.1 structure in |orig_in| and sets
+ * |*indefinite_found| depending on whether an indefinite length element was
+ * found. The value of |orig_in| is not modified.
+ *
+ * Returns one on success (i.e. |*indefinite_found| was set) and zero on error.
*/
static int
-cbs_find_ber(CBS *orig_in, char *ber_found, unsigned depth)
+cbs_find_indefinite(const CBS *orig_in, char *indefinite_found,
+ unsigned int depth)
{
CBS in;
@@ -51,7 +53,6 @@ cbs_find_ber(CBS *orig_in, char *ber_found, unsigned depth)
return 0;
CBS_init(&in, CBS_data(orig_in), CBS_len(orig_in));
- *ber_found = 0;
while (CBS_len(&in) > 0) {
CBS contents;
@@ -65,16 +66,18 @@ cbs_find_ber(CBS *orig_in, char *ber_found, unsigned depth)
/* Indefinite form not allowed by DER. */
if (CBS_len(&contents) == header_len && header_len > 0 &&
CBS_data(&contents)[header_len - 1] == 0x80) {
- *ber_found = 1;
+ *indefinite_found = 1;
return 1;
}
if (tag & CBS_ASN1_CONSTRUCTED) {
if (!CBS_skip(&contents, header_len) ||
- !cbs_find_ber(&contents, ber_found, depth + 1))
+ !cbs_find_indefinite(&contents, indefinite_found,
+ depth + 1))
return 0;
}
}
+ *indefinite_found = 0;
return 1;
}
@@ -104,7 +107,8 @@ is_eoc(size_t header_len, CBS *contents)
}
/*
- * cbs_convert_ber reads BER data from |in| and writes DER data to |out|. If
+ * cbs_convert_indefinite reads data with DER encoding (but relaxed to allow
+ * indefinite form) from |in| and writes definite form DER data to |out|. If
* |squash_header| is set then the top-level of elements from |in| will not
* have their headers written. This is used when concatenating the fragments of
* an indefinite length, primitive value. If |looking_for_eoc| is set then any
@@ -112,8 +116,8 @@ is_eoc(size_t header_len, CBS *contents)
* It returns one on success and zero on error.
*/
static int
-cbs_convert_ber(CBS *in, CBB *out, char squash_header, char looking_for_eoc,
- unsigned depth)
+cbs_convert_indefinite(CBS *in, CBB *out, char squash_header,
+ char looking_for_eoc, unsigned depth)
{
if (depth > kMaxDepth)
return 0;
@@ -143,7 +147,7 @@ cbs_convert_ber(CBS *in, CBB *out, char squash_header, char looking_for_eoc,
* with a concrete length prefix.
*
* If it's a something else then the contents
- * will be a series of BER elements of the same
+ * will be a series of DER elements of the same
* type which need to be concatenated.
*/
const char context_specific = (tag & 0xc0)
@@ -193,7 +197,7 @@ cbs_convert_ber(CBS *in, CBB *out, char squash_header, char looking_for_eoc,
out_contents = &out_contents_storage;
}
- if (!cbs_convert_ber(in, out_contents,
+ if (!cbs_convert_indefinite(in, out_contents,
squash_child_headers,
1 /* looking for eoc */, depth + 1))
return 0;
@@ -216,7 +220,7 @@ cbs_convert_ber(CBS *in, CBB *out, char squash_header, char looking_for_eoc,
return 0;
if (tag & CBS_ASN1_CONSTRUCTED) {
- if (!cbs_convert_ber(&contents, out_contents,
+ if (!cbs_convert_indefinite(&contents, out_contents,
0 /* don't squash header */,
0 /* not looking for eoc */, depth + 1))
return 0;
@@ -234,7 +238,7 @@ cbs_convert_ber(CBS *in, CBB *out, char squash_header, char looking_for_eoc,
}
int
-CBS_asn1_ber_to_der(CBS *in, uint8_t **out, size_t *out_len)
+CBS_asn1_indefinite_to_definite(CBS *in, uint8_t **out, size_t *out_len)
{
CBB cbb;
@@ -244,7 +248,7 @@ CBS_asn1_ber_to_der(CBS *in, uint8_t **out, size_t *out_len)
* return.
*/
char conversion_needed;
- if (!cbs_find_ber(in, &conversion_needed, 0))
+ if (!cbs_find_indefinite(in, &conversion_needed, 0))
return 0;
if (!conversion_needed) {
@@ -254,7 +258,7 @@ CBS_asn1_ber_to_der(CBS *in, uint8_t **out, size_t *out_len)
}
CBB_init(&cbb, CBS_len(in));
- if (!cbs_convert_ber(in, &cbb, 0, 0, 0)) {
+ if (!cbs_convert_indefinite(in, &cbb, 0, 0, 0)) {
CBB_cleanup(&cbb);
return 0;
}