diff options
author | Tao Bao <tbao@google.com> | 2017-03-22 18:07:14 +0100 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-03-22 18:07:14 +0100 |
commit | d7846b73030821c0e4a89f6c9bc151594ac76949 (patch) | |
tree | 7b0b21017701259738e60cbf260e00687b23f1b4 /verifier.cpp | |
parent | Merge "Fix updater include generation w/installclean" (diff) | |
parent | Merge "Refactor asn1_decoder functions into a class." (diff) | |
download | android_bootable_recovery-d7846b73030821c0e4a89f6c9bc151594ac76949.tar android_bootable_recovery-d7846b73030821c0e4a89f6c9bc151594ac76949.tar.gz android_bootable_recovery-d7846b73030821c0e4a89f6c9bc151594ac76949.tar.bz2 android_bootable_recovery-d7846b73030821c0e4a89f6c9bc151594ac76949.tar.lz android_bootable_recovery-d7846b73030821c0e4a89f6c9bc151594ac76949.tar.xz android_bootable_recovery-d7846b73030821c0e4a89f6c9bc151594ac76949.tar.zst android_bootable_recovery-d7846b73030821c0e4a89f6c9bc151594ac76949.zip |
Diffstat (limited to 'verifier.cpp')
-rw-r--r-- | verifier.cpp | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/verifier.cpp b/verifier.cpp index 7f165860e..8be6da09f 100644 --- a/verifier.cpp +++ b/verifier.cpp @@ -66,48 +66,50 @@ static bool read_pkcs7(const uint8_t* pkcs7_der, size_t pkcs7_der_len, CHECK(sig_der != nullptr); sig_der->clear(); - asn1_context_t* ctx = asn1_context_new(pkcs7_der, pkcs7_der_len); - if (ctx == NULL) { + asn1_context ctx(pkcs7_der, pkcs7_der_len); + + std::unique_ptr<asn1_context> pkcs7_seq(ctx.asn1_sequence_get()); + if (pkcs7_seq == nullptr || !pkcs7_seq->asn1_sequence_next()) { return false; } - asn1_context_t* pkcs7_seq = asn1_sequence_get(ctx); - if (pkcs7_seq != NULL && asn1_sequence_next(pkcs7_seq)) { - asn1_context_t *signed_data_app = asn1_constructed_get(pkcs7_seq); - if (signed_data_app != NULL) { - asn1_context_t* signed_data_seq = asn1_sequence_get(signed_data_app); - if (signed_data_seq != NULL - && asn1_sequence_next(signed_data_seq) - && asn1_sequence_next(signed_data_seq) - && asn1_sequence_next(signed_data_seq) - && asn1_constructed_skip_all(signed_data_seq)) { - asn1_context_t *sig_set = asn1_set_get(signed_data_seq); - if (sig_set != NULL) { - asn1_context_t* sig_seq = asn1_sequence_get(sig_set); - if (sig_seq != NULL - && asn1_sequence_next(sig_seq) - && asn1_sequence_next(sig_seq) - && asn1_sequence_next(sig_seq) - && asn1_sequence_next(sig_seq)) { - const uint8_t* sig_der_ptr; - size_t sig_der_length; - if (asn1_octet_string_get(sig_seq, &sig_der_ptr, &sig_der_length)) { - sig_der->resize(sig_der_length); - std::copy(sig_der_ptr, sig_der_ptr + sig_der_length, sig_der->begin()); - } - asn1_context_free(sig_seq); - } - asn1_context_free(sig_set); - } - asn1_context_free(signed_data_seq); - } - asn1_context_free(signed_data_app); - } - asn1_context_free(pkcs7_seq); + std::unique_ptr<asn1_context> signed_data_app(pkcs7_seq->asn1_constructed_get()); + if (signed_data_app == nullptr) { + return false; + } + + std::unique_ptr<asn1_context> signed_data_seq(signed_data_app->asn1_sequence_get()); + if (signed_data_seq == nullptr || + !signed_data_seq->asn1_sequence_next() || + !signed_data_seq->asn1_sequence_next() || + !signed_data_seq->asn1_sequence_next() || + !signed_data_seq->asn1_constructed_skip_all()) { + return false; + } + + std::unique_ptr<asn1_context> sig_set(signed_data_seq->asn1_set_get()); + if (sig_set == nullptr) { + return false; + } + + std::unique_ptr<asn1_context> sig_seq(sig_set->asn1_sequence_get()); + if (sig_seq == nullptr || + !sig_seq->asn1_sequence_next() || + !sig_seq->asn1_sequence_next() || + !sig_seq->asn1_sequence_next() || + !sig_seq->asn1_sequence_next()) { + return false; + } + + const uint8_t* sig_der_ptr; + size_t sig_der_length; + if (!sig_seq->asn1_octet_string_get(&sig_der_ptr, &sig_der_length)) { + return false; } - asn1_context_free(ctx); - return !sig_der->empty(); + sig_der->resize(sig_der_length); + std::copy(sig_der_ptr, sig_der_ptr + sig_der_length, sig_der->begin()); + return true; } /* |