| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/cert/ct_log_verifier.h" | 5 #include "net/cert/ct_log_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 "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 CTLogVerifier::CTLogVerifier() | 50 CTLogVerifier::CTLogVerifier() |
| 51 : hash_algorithm_(ct::DigitallySigned::HASH_ALGO_NONE), | 51 : hash_algorithm_(ct::DigitallySigned::HASH_ALGO_NONE), |
| 52 signature_algorithm_(ct::DigitallySigned::SIG_ALGO_ANONYMOUS), | 52 signature_algorithm_(ct::DigitallySigned::SIG_ALGO_ANONYMOUS), |
| 53 public_key_(NULL) {} | 53 public_key_(NULL) {} |
| 54 | 54 |
| 55 bool CTLogVerifier::Init(const base::StringPiece& public_key, | 55 bool CTLogVerifier::Init(const base::StringPiece& public_key, |
| 56 const base::StringPiece& description) { | 56 const base::StringPiece& description) { |
| 57 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 57 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 58 | 58 |
| 59 crypto::ScopedBIO bio( | 59 const uint8_t* ptr = reinterpret_cast<const uint8_t*>(public_key.data()); |
| 60 BIO_new_mem_buf(const_cast<char*>(public_key.data()), public_key.size())); | 60 const uint8_t* end = ptr + public_key.size(); |
| 61 if (!bio.get()) | 61 public_key_ = d2i_PUBKEY(nullptr, &ptr, public_key.size()); |
| 62 return false; | 62 if (!public_key_ || ptr != end) |
| 63 | |
| 64 public_key_ = d2i_PUBKEY_bio(bio.get(), NULL); | |
| 65 if (!public_key_) | |
| 66 return false; | 63 return false; |
| 67 | 64 |
| 68 key_id_ = crypto::SHA256HashString(public_key); | 65 key_id_ = crypto::SHA256HashString(public_key); |
| 69 description_ = description.as_string(); | 66 description_ = description.as_string(); |
| 70 | 67 |
| 71 // Right now, only RSASSA-PKCS1v15 with SHA-256 and ECDSA with SHA-256 are | 68 // Right now, only RSASSA-PKCS1v15 with SHA-256 and ECDSA with SHA-256 are |
| 72 // supported. | 69 // supported. |
| 73 switch (EVP_PKEY_type(public_key_->type)) { | 70 switch (EVP_PKEY_type(public_key_->type)) { |
| 74 case EVP_PKEY_RSA: | 71 case EVP_PKEY_RSA: |
| 75 hash_algorithm_ = ct::DigitallySigned::HASH_ALGO_SHA256; | 72 hash_algorithm_ = ct::DigitallySigned::HASH_ALGO_SHA256; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 1 == EVP_DigestVerifyFinal( | 110 1 == EVP_DigestVerifyFinal( |
| 114 &ctx, | 111 &ctx, |
| 115 reinterpret_cast<const uint8_t*>(signature.data()), | 112 reinterpret_cast<const uint8_t*>(signature.data()), |
| 116 signature.size())); | 113 signature.size())); |
| 117 | 114 |
| 118 EVP_MD_CTX_cleanup(&ctx); | 115 EVP_MD_CTX_cleanup(&ctx); |
| 119 return ok; | 116 return ok; |
| 120 } | 117 } |
| 121 | 118 |
| 122 } // namespace net | 119 } // namespace net |
| OLD | NEW |