diff options
author | Richard Levitte <levitte@openssl.org> | 2020-10-02 13:56:54 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-10-04 12:58:41 +0200 |
commit | ecadfdadde491572b0bdf3c5a95e7a6a004585c6 (patch) | |
tree | 5598e1c5a8297d2499517b7ae84f1ebed3a40d75 /crypto/encode_decode | |
parent | 4232a9e57f48276974a8891e58db9b06b5db696f (diff) |
DECODER: Handle abstract object data type
The PEM->DER decoder passes the data type of its contents, something
that decoder_process() ignored.
On the other hand, the PEM->DER decoder passed nonsense.
Both issues are fixed here.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13060)
Diffstat (limited to 'crypto/encode_decode')
-rw-r--r-- | crypto/encode_decode/decoder_lib.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/crypto/encode_decode/decoder_lib.c b/crypto/encode_decode/decoder_lib.c index 0411da41f4..ab7c537038 100644 --- a/crypto/encode_decode/decoder_lib.c +++ b/crypto/encode_decode/decoder_lib.c @@ -430,6 +430,7 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) int err, ok = 0; /* For recursions */ struct decoder_process_data_st new_data; + const char *object_type = NULL; memset(&new_data, 0, sizeof(new_data)); new_data.ctx = data->ctx; @@ -471,6 +472,11 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) if (new_data.bio == NULL) goto end; bio = new_data.bio; + + /* Get the object type if there is one */ + p = OSSL_PARAM_locate_const(params, OSSL_OBJECT_PARAM_DATA_TYPE); + if (p != NULL && !OSSL_PARAM_get_utf8_string_ptr(p, &object_type)) + goto end; } /* @@ -514,6 +520,13 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) continue; /* + * If the previous decoder gave us an object type, we check to see + * if that matches the decoder we're currently considering. + */ + if (object_type != NULL && !OSSL_DECODER_is_a(new_decoder, object_type)) + continue; + + /* * Checking the return value of BIO_reset() or BIO_seek() is unsafe. * Furthermore, BIO_reset() is unsafe to use if the source BIO happens * to be a BIO_s_mem(), because the earlier BIO_tell() gives us zero |