| 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/bytestring.h> |
| 7 #include <openssl/evp.h> | 8 #include <openssl/evp.h> |
| 8 #include <openssl/x509.h> | 9 #include <openssl/x509.h> |
| 9 #include <stdint.h> | 10 #include <stdint.h> |
| 10 | 11 |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "crypto/openssl_util.h" | 16 #include "crypto/openssl_util.h" |
| 16 #include "crypto/scoped_openssl_types.h" | 17 #include "crypto/scoped_openssl_types.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 const uint8_t* public_key_info, | 133 const uint8_t* public_key_info, |
| 133 int public_key_info_len, | 134 int public_key_info_len, |
| 134 EVP_PKEY_CTX** pkey_ctx) { | 135 EVP_PKEY_CTX** pkey_ctx) { |
| 135 if (verify_context_) | 136 if (verify_context_) |
| 136 return false; | 137 return false; |
| 137 | 138 |
| 138 verify_context_ = new VerifyContext; | 139 verify_context_ = new VerifyContext; |
| 139 | 140 |
| 140 signature_.assign(signature, signature + signature_len); | 141 signature_.assign(signature, signature + signature_len); |
| 141 | 142 |
| 142 const uint8_t* ptr = public_key_info; | 143 CBS cbs; |
| 143 ScopedEVP_PKEY public_key(d2i_PUBKEY(nullptr, &ptr, public_key_info_len)); | 144 CBS_init(&cbs, public_key_info, public_key_info_len); |
| 144 if (!public_key.get() || ptr != public_key_info + public_key_info_len) | 145 ScopedEVP_PKEY public_key(EVP_parse_public_key(&cbs)); |
| 146 if (!public_key || CBS_len(&cbs) != 0) |
| 145 return false; | 147 return false; |
| 146 | 148 |
| 147 verify_context_->ctx.reset(EVP_MD_CTX_create()); | 149 verify_context_->ctx.reset(EVP_MD_CTX_create()); |
| 148 int rv = EVP_DigestVerifyInit(verify_context_->ctx.get(), pkey_ctx, | 150 int rv = EVP_DigestVerifyInit(verify_context_->ctx.get(), pkey_ctx, |
| 149 digest, nullptr, public_key.get()); | 151 digest, nullptr, public_key.get()); |
| 150 return rv == 1; | 152 return rv == 1; |
| 151 } | 153 } |
| 152 | 154 |
| 153 void SignatureVerifier::Reset() { | 155 void SignatureVerifier::Reset() { |
| 154 delete verify_context_; | 156 delete verify_context_; |
| 155 verify_context_ = NULL; | 157 verify_context_ = NULL; |
| 156 signature_.clear(); | 158 signature_.clear(); |
| 157 } | 159 } |
| 158 | 160 |
| 159 } // namespace crypto | 161 } // namespace crypto |
| OLD | NEW |