| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crypto/signature_verifier.h" | 5 #include "crypto/signature_verifier.h" |
| 6 | 6 |
| 7 #include <openssl/evp.h> | 7 #include <openssl/evp.h> |
| 8 #include <openssl/x509.h> | 8 #include <openssl/x509.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 const uint8* public_key_info, | 134 const uint8* public_key_info, |
| 135 int public_key_info_len, | 135 int public_key_info_len, |
| 136 EVP_PKEY_CTX** pkey_ctx) { | 136 EVP_PKEY_CTX** pkey_ctx) { |
| 137 if (verify_context_) | 137 if (verify_context_) |
| 138 return false; | 138 return false; |
| 139 | 139 |
| 140 verify_context_ = new VerifyContext; | 140 verify_context_ = new VerifyContext; |
| 141 | 141 |
| 142 signature_.assign(signature, signature + signature_len); | 142 signature_.assign(signature, signature + signature_len); |
| 143 | 143 |
| 144 // BIO_new_mem_buf is not const aware, but it does not modify the buffer. | 144 const uint8_t* ptr = public_key_info; |
| 145 char* data = reinterpret_cast<char*>(const_cast<uint8*>(public_key_info)); | 145 ScopedEVP_PKEY public_key(d2i_PUBKEY(nullptr, &ptr, public_key_info_len)); |
| 146 ScopedBIO bio(BIO_new_mem_buf(data, public_key_info_len)); | 146 if (!public_key.get() || ptr != public_key_info + public_key_info_len) |
| 147 if (!bio.get()) | |
| 148 return false; | |
| 149 | |
| 150 ScopedEVP_PKEY public_key(d2i_PUBKEY_bio(bio.get(), NULL)); | |
| 151 if (!public_key.get()) | |
| 152 return false; | 147 return false; |
| 153 | 148 |
| 154 verify_context_->ctx.reset(EVP_MD_CTX_create()); | 149 verify_context_->ctx.reset(EVP_MD_CTX_create()); |
| 155 int rv = EVP_DigestVerifyInit(verify_context_->ctx.get(), pkey_ctx, | 150 int rv = EVP_DigestVerifyInit(verify_context_->ctx.get(), pkey_ctx, |
| 156 digest, NULL, public_key.get()); | 151 digest, nullptr, public_key.get()); |
| 157 return rv == 1; | 152 return rv == 1; |
| 158 } | 153 } |
| 159 | 154 |
| 160 void SignatureVerifier::Reset() { | 155 void SignatureVerifier::Reset() { |
| 161 delete verify_context_; | 156 delete verify_context_; |
| 162 verify_context_ = NULL; | 157 verify_context_ = NULL; |
| 163 signature_.clear(); | 158 signature_.clear(); |
| 164 } | 159 } |
| 165 | 160 |
| 166 } // namespace crypto | 161 } // namespace crypto |
| OLD | NEW |