aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-03-22 12:07:14 -0500
committerandroid-build-merger2017-03-22 12:07:14 -0500
commitd7846b73030821c0e4a89f6c9bc151594ac76949 (patch)
tree7b0b21017701259738e60cbf260e00687b23f1b4 /verifier.cpp
parentc1cb30f8428a2f82e23bd7f6fefedd471ad08656 (diff)
parentea3d0b923d5ce4c81d88f14b7295027eebb9f09d (diff)
downloadplatform-bootable-recovery-d7846b73030821c0e4a89f6c9bc151594ac76949.tar.gz
platform-bootable-recovery-d7846b73030821c0e4a89f6c9bc151594ac76949.tar.xz
platform-bootable-recovery-d7846b73030821c0e4a89f6c9bc151594ac76949.zip
Merge "Refactor asn1_decoder functions into a class."
am: ea3d0b923d Change-Id: I581e85f453fe1dc8b3a7cb6a7b660539f99ec55e
Diffstat (limited to 'verifier.cpp')
-rw-r--r--verifier.cpp76
1 files changed, 39 insertions, 37 deletions
diff --git a/verifier.cpp b/verifier.cpp
index 7f165860..8be6da09 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,
66 CHECK(sig_der != nullptr); 66 CHECK(sig_der != nullptr);
67 sig_der->clear(); 67 sig_der->clear();
68 68
69 asn1_context_t* ctx = asn1_context_new(pkcs7_der, pkcs7_der_len); 69 asn1_context ctx(pkcs7_der, pkcs7_der_len);
70 if (ctx == NULL) { 70
71 std::unique_ptr<asn1_context> pkcs7_seq(ctx.asn1_sequence_get());
72 if (pkcs7_seq == nullptr || !pkcs7_seq->asn1_sequence_next()) {
71 return false; 73 return false;
72 } 74 }
73 75
74 asn1_context_t* pkcs7_seq = asn1_sequence_get(ctx); 76 std::unique_ptr<asn1_context> signed_data_app(pkcs7_seq->asn1_constructed_get());
75 if (pkcs7_seq != NULL && asn1_sequence_next(pkcs7_seq)) { 77 if (signed_data_app == nullptr) {
76 asn1_context_t *signed_data_app = asn1_constructed_get(pkcs7_seq); 78 return false;
77 if (signed_data_app != NULL) { 79 }
78 asn1_context_t* signed_data_seq = asn1_sequence_get(signed_data_app); 80
79 if (signed_data_seq != NULL 81 std::unique_ptr<asn1_context> signed_data_seq(signed_data_app->asn1_sequence_get());
80 && asn1_sequence_next(signed_data_seq) 82 if (signed_data_seq == nullptr ||
81 && asn1_sequence_next(signed_data_seq) 83 !signed_data_seq->asn1_sequence_next() ||
82 && asn1_sequence_next(signed_data_seq) 84 !signed_data_seq->asn1_sequence_next() ||
83 && asn1_constructed_skip_all(signed_data_seq)) { 85 !signed_data_seq->asn1_sequence_next() ||
84 asn1_context_t *sig_set = asn1_set_get(signed_data_seq); 86 !signed_data_seq->asn1_constructed_skip_all()) {
85 if (sig_set != NULL) { 87 return false;
86 asn1_context_t* sig_seq = asn1_sequence_get(sig_set); 88 }
87 if (sig_seq != NULL 89
88 && asn1_sequence_next(sig_seq) 90 std::unique_ptr<asn1_context> sig_set(signed_data_seq->asn1_set_get());
89 && asn1_sequence_next(sig_seq) 91 if (sig_set == nullptr) {
90 && asn1_sequence_next(sig_seq) 92 return false;
91 && asn1_sequence_next(sig_seq)) { 93 }
92 const uint8_t* sig_der_ptr; 94
93 size_t sig_der_length; 95 std::unique_ptr<asn1_context> sig_seq(sig_set->asn1_sequence_get());
94 if (asn1_octet_string_get(sig_seq, &sig_der_ptr, &sig_der_length)) { 96 if (sig_seq == nullptr ||
95 sig_der->resize(sig_der_length); 97 !sig_seq->asn1_sequence_next() ||
96 std::copy(sig_der_ptr, sig_der_ptr + sig_der_length, sig_der->begin()); 98 !sig_seq->asn1_sequence_next() ||
97 } 99 !sig_seq->asn1_sequence_next() ||
98 asn1_context_free(sig_seq); 100 !sig_seq->asn1_sequence_next()) {
99 } 101 return false;
100 asn1_context_free(sig_set); 102 }
101 } 103
102 asn1_context_free(signed_data_seq); 104 const uint8_t* sig_der_ptr;
103 } 105 size_t sig_der_length;
104 asn1_context_free(signed_data_app); 106 if (!sig_seq->asn1_octet_string_get(&sig_der_ptr, &sig_der_length)) {
105 } 107 return false;
106 asn1_context_free(pkcs7_seq);
107 } 108 }
108 asn1_context_free(ctx);
109 109
110 return !sig_der->empty(); 110 sig_der->resize(sig_der_length);
111 std::copy(sig_der_ptr, sig_der_ptr + sig_der_length, sig_der->begin());
112 return true;
111} 113}
112 114
113/* 115/*