[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/quic/crypto/proof_verifier_chromium.h" |
| 6 | |
| 7 | #include "base/bind.h" |
| 8 | #include "base/bind_helpers.h" |
| 9 | #include "base/callback_helpers.h" |
| 10 | #include "base/compiler_specific.h" |
| 11 | #include "base/logging.h" |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame^] | 12 | #include "base/metrics/histogram.h" |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 13 | #include "base/stl_util.h" |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 14 | #include "base/strings/stringprintf.h" |
| 15 | #include "crypto/signature_verifier.h" |
| 16 | #include "net/base/net_errors.h" |
| 17 | #include "net/base/net_log.h" |
| 18 | #include "net/cert/asn1_util.h" |
| 19 | #include "net/cert/cert_status_flags.h" |
| 20 | #include "net/cert/cert_verifier.h" |
| 21 | #include "net/cert/cert_verify_result.h" |
| 22 | #include "net/cert/single_request_cert_verifier.h" |
| 23 | #include "net/cert/x509_certificate.h" |
| 24 | #include "net/cert/x509_util.h" |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame^] | 25 | #include "net/http/transport_security_state.h" |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 26 | #include "net/quic/crypto/crypto_protocol.h" |
| 27 | #include "net/ssl/ssl_config_service.h" |
| 28 | |
| 29 | using base::StringPiece; |
| 30 | using base::StringPrintf; |
| 31 | using std::string; |
| 32 | using std::vector; |
| 33 | |
| 34 | namespace net { |
| 35 | |
[email protected] | 92bc621d | 2014-07-29 21:42:13 | [diff] [blame] | 36 | ProofVerifyDetails* ProofVerifyDetailsChromium::Clone() const { |
| 37 | ProofVerifyDetailsChromium* other = new ProofVerifyDetailsChromium; |
| 38 | other->cert_verify_result = cert_verify_result; |
| 39 | return other; |
| 40 | } |
| 41 | |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 42 | // A Job handles the verification of a single proof. It is owned by the |
| 43 | // ProofVerifier. If the verification can not complete synchronously, it |
| 44 | // will notify the ProofVerifier upon completion. |
| 45 | class ProofVerifierChromium::Job { |
| 46 | public: |
| 47 | Job(ProofVerifierChromium* proof_verifier, |
| 48 | CertVerifier* cert_verifier, |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame^] | 49 | TransportSecurityState* transport_security_state, |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 50 | const BoundNetLog& net_log); |
| 51 | |
[email protected] | 05bfc260f | 2014-06-07 06:31:25 | [diff] [blame] | 52 | // Starts the proof verification. If |QUIC_PENDING| is returned, then |
| 53 | // |callback| will be invoked asynchronously when the verification completes. |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 54 | QuicAsyncStatus VerifyProof(const std::string& hostname, |
| 55 | const std::string& server_config, |
| 56 | const std::vector<std::string>& certs, |
| 57 | const std::string& signature, |
| 58 | std::string* error_details, |
| 59 | scoped_ptr<ProofVerifyDetails>* verify_details, |
| 60 | ProofVerifierCallback* callback); |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | enum State { |
| 64 | STATE_NONE, |
| 65 | STATE_VERIFY_CERT, |
| 66 | STATE_VERIFY_CERT_COMPLETE, |
| 67 | }; |
| 68 | |
| 69 | int DoLoop(int last_io_result); |
| 70 | void OnIOComplete(int result); |
| 71 | int DoVerifyCert(int result); |
| 72 | int DoVerifyCertComplete(int result); |
| 73 | |
| 74 | bool VerifySignature(const std::string& signed_data, |
| 75 | const std::string& signature, |
| 76 | const std::string& cert); |
| 77 | |
| 78 | // Proof verifier to notify when this jobs completes. |
| 79 | ProofVerifierChromium* proof_verifier_; |
| 80 | |
| 81 | // The underlying verifier used for verifying certificates. |
| 82 | scoped_ptr<SingleRequestCertVerifier> verifier_; |
| 83 | |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame^] | 84 | TransportSecurityState* transport_security_state_; |
| 85 | |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 86 | // |hostname| specifies the hostname for which |certs| is a valid chain. |
| 87 | std::string hostname_; |
| 88 | |
| 89 | scoped_ptr<ProofVerifierCallback> callback_; |
| 90 | scoped_ptr<ProofVerifyDetailsChromium> verify_details_; |
| 91 | std::string error_details_; |
| 92 | |
| 93 | // X509Certificate from a chain of DER encoded certificates. |
| 94 | scoped_refptr<X509Certificate> cert_; |
| 95 | |
| 96 | State next_state_; |
| 97 | |
| 98 | BoundNetLog net_log_; |
| 99 | |
| 100 | DISALLOW_COPY_AND_ASSIGN(Job); |
| 101 | }; |
| 102 | |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame^] | 103 | ProofVerifierChromium::Job::Job( |
| 104 | ProofVerifierChromium* proof_verifier, |
| 105 | CertVerifier* cert_verifier, |
| 106 | TransportSecurityState* transport_security_state, |
| 107 | const BoundNetLog& net_log) |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 108 | : proof_verifier_(proof_verifier), |
| 109 | verifier_(new SingleRequestCertVerifier(cert_verifier)), |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame^] | 110 | transport_security_state_(transport_security_state), |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 111 | next_state_(STATE_NONE), |
| 112 | net_log_(net_log) { |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 113 | } |
| 114 | |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 115 | QuicAsyncStatus ProofVerifierChromium::Job::VerifyProof( |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 116 | const string& hostname, |
| 117 | const string& server_config, |
| 118 | const vector<string>& certs, |
| 119 | const string& signature, |
| 120 | std::string* error_details, |
[email protected] | c817c67 | 2014-03-21 22:25:34 | [diff] [blame] | 121 | scoped_ptr<ProofVerifyDetails>* verify_details, |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 122 | ProofVerifierCallback* callback) { |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 123 | DCHECK(error_details); |
[email protected] | c817c67 | 2014-03-21 22:25:34 | [diff] [blame] | 124 | DCHECK(verify_details); |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 125 | DCHECK(callback); |
| 126 | |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 127 | error_details->clear(); |
| 128 | |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 129 | if (STATE_NONE != next_state_) { |
| 130 | *error_details = "Certificate is already set and VerifyProof has begun"; |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 131 | DLOG(DFATAL) << *error_details; |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 132 | return QUIC_FAILURE; |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 133 | } |
| 134 | |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 135 | verify_details_.reset(new ProofVerifyDetailsChromium); |
| 136 | |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 137 | if (certs.empty()) { |
| 138 | *error_details = "Failed to create certificate chain. Certs are empty."; |
| 139 | DLOG(WARNING) << *error_details; |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 140 | verify_details_->cert_verify_result.cert_status = CERT_STATUS_INVALID; |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 141 | *verify_details = verify_details_.Pass(); |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 142 | return QUIC_FAILURE; |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | // Convert certs to X509Certificate. |
| 146 | vector<StringPiece> cert_pieces(certs.size()); |
| 147 | for (unsigned i = 0; i < certs.size(); i++) { |
| 148 | cert_pieces[i] = base::StringPiece(certs[i]); |
| 149 | } |
| 150 | cert_ = X509Certificate::CreateFromDERCertChain(cert_pieces); |
| 151 | if (!cert_.get()) { |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 152 | *error_details = "Failed to create certificate chain"; |
| 153 | DLOG(WARNING) << *error_details; |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 154 | verify_details_->cert_verify_result.cert_status = CERT_STATUS_INVALID; |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 155 | *verify_details = verify_details_.Pass(); |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 156 | return QUIC_FAILURE; |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | // We call VerifySignature first to avoid copying of server_config and |
| 160 | // signature. |
[email protected] | d5c9e4ba | 2013-09-14 05:25:58 | [diff] [blame] | 161 | if (!VerifySignature(server_config, signature, certs[0])) { |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 162 | *error_details = "Failed to verify signature of server config"; |
| 163 | DLOG(WARNING) << *error_details; |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 164 | verify_details_->cert_verify_result.cert_status = CERT_STATUS_INVALID; |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 165 | *verify_details = verify_details_.Pass(); |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 166 | return QUIC_FAILURE; |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | hostname_ = hostname; |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 170 | |
| 171 | next_state_ = STATE_VERIFY_CERT; |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 172 | switch (DoLoop(OK)) { |
| 173 | case OK: |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 174 | *verify_details = verify_details_.Pass(); |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 175 | return QUIC_SUCCESS; |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 176 | case ERR_IO_PENDING: |
[email protected] | 3ce3bf2 | 2014-04-03 08:02:01 | [diff] [blame] | 177 | callback_.reset(callback); |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 178 | return QUIC_PENDING; |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 179 | default: |
| 180 | *error_details = error_details_; |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 181 | *verify_details = verify_details_.Pass(); |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 182 | return QUIC_FAILURE; |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 183 | } |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 184 | } |
| 185 | |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 186 | int ProofVerifierChromium::Job::DoLoop(int last_result) { |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 187 | int rv = last_result; |
| 188 | do { |
| 189 | State state = next_state_; |
| 190 | next_state_ = STATE_NONE; |
| 191 | switch (state) { |
| 192 | case STATE_VERIFY_CERT: |
| 193 | DCHECK(rv == OK); |
| 194 | rv = DoVerifyCert(rv); |
| 195 | break; |
| 196 | case STATE_VERIFY_CERT_COMPLETE: |
| 197 | rv = DoVerifyCertComplete(rv); |
| 198 | break; |
| 199 | case STATE_NONE: |
| 200 | default: |
| 201 | rv = ERR_UNEXPECTED; |
| 202 | LOG(DFATAL) << "unexpected state " << state; |
| 203 | break; |
| 204 | } |
| 205 | } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 206 | return rv; |
| 207 | } |
| 208 | |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 209 | void ProofVerifierChromium::Job::OnIOComplete(int result) { |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 210 | int rv = DoLoop(result); |
| 211 | if (rv != ERR_IO_PENDING) { |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 212 | scoped_ptr<ProofVerifierCallback> callback(callback_.Pass()); |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 213 | // Callback expects ProofVerifyDetails not ProofVerifyDetailsChromium. |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 214 | scoped_ptr<ProofVerifyDetails> verify_details(verify_details_.Pass()); |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 215 | callback->Run(rv == OK, error_details_, &verify_details); |
| 216 | // Will delete |this|. |
| 217 | proof_verifier_->OnJobComplete(this); |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 221 | int ProofVerifierChromium::Job::DoVerifyCert(int result) { |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 222 | next_state_ = STATE_VERIFY_CERT_COMPLETE; |
| 223 | |
| 224 | int flags = 0; |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 225 | return verifier_->Verify( |
| 226 | cert_.get(), |
| 227 | hostname_, |
| 228 | flags, |
| 229 | SSLConfigService::GetCRLSet().get(), |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 230 | &verify_details_->cert_verify_result, |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 231 | base::Bind(&ProofVerifierChromium::Job::OnIOComplete, |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 232 | base::Unretained(this)), |
| 233 | net_log_); |
| 234 | } |
| 235 | |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 236 | int ProofVerifierChromium::Job::DoVerifyCertComplete(int result) { |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 237 | verifier_.reset(); |
| 238 | |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame^] | 239 | #if defined(OFFICIAL_BUILD) && !defined(OS_ANDROID) && !defined(OS_IOS) |
| 240 | // TODO(wtc): The following code was copied from ssl_client_socket_nss.cc. |
| 241 | // Convert it to a new function that can be called by both files. These |
| 242 | // variables simulate the arguments to the new function. |
| 243 | const CertVerifyResult& cert_verify_result = |
| 244 | verify_details_->cert_verify_result; |
| 245 | bool sni_available = true; |
| 246 | const std::string& host = hostname_; |
| 247 | TransportSecurityState* transport_security_state = transport_security_state_; |
| 248 | std::string* pinning_failure_log = &verify_details_->pinning_failure_log; |
| 249 | |
| 250 | // Take care of any mandates for public key pinning. |
| 251 | // |
| 252 | // Pinning is only enabled for official builds to make sure that others don't |
| 253 | // end up with pins that cannot be easily updated. |
| 254 | // |
| 255 | // TODO(agl): We might have an issue here where a request for foo.example.com |
| 256 | // merges into a SPDY connection to www.example.com, and gets a different |
| 257 | // certificate. |
| 258 | |
| 259 | // Perform pin validation if, and only if, all these conditions obtain: |
| 260 | // |
| 261 | // * a TransportSecurityState object is available; |
| 262 | // * the server's certificate chain is valid (or suffers from only a minor |
| 263 | // error); |
| 264 | // * the server's certificate chain chains up to a known root (i.e. not a |
| 265 | // user-installed trust anchor); and |
| 266 | // * the build is recent (very old builds should fail open so that users |
| 267 | // have some chance to recover). |
| 268 | // |
| 269 | const CertStatus cert_status = cert_verify_result.cert_status; |
| 270 | if (transport_security_state && |
| 271 | (result == OK || |
| 272 | (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) && |
| 273 | cert_verify_result.is_issued_by_known_root && |
| 274 | TransportSecurityState::IsBuildTimely()) { |
| 275 | if (transport_security_state->HasPublicKeyPins(host, sni_available)) { |
| 276 | if (!transport_security_state->CheckPublicKeyPins( |
| 277 | host, |
| 278 | sni_available, |
| 279 | cert_verify_result.public_key_hashes, |
| 280 | pinning_failure_log)) { |
| 281 | LOG(ERROR) << *pinning_failure_log; |
| 282 | result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN; |
| 283 | UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", false); |
| 284 | TransportSecurityState::ReportUMAOnPinFailure(host); |
| 285 | } else { |
| 286 | UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", true); |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | #endif |
| 291 | |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 292 | if (result != OK) { |
[email protected] | 72e6599 | 2013-07-30 17:16:14 | [diff] [blame] | 293 | error_details_ = StringPrintf("Failed to verify certificate chain: %s", |
| 294 | ErrorToString(result)); |
| 295 | DLOG(WARNING) << error_details_; |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | // Exit DoLoop and return the result to the caller to VerifyProof. |
| 299 | DCHECK_EQ(STATE_NONE, next_state_); |
| 300 | return result; |
| 301 | } |
| 302 | |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 303 | bool ProofVerifierChromium::Job::VerifySignature(const string& signed_data, |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 304 | const string& signature, |
| 305 | const string& cert) { |
| 306 | StringPiece spki; |
| 307 | if (!asn1::ExtractSPKIFromDERCert(cert, &spki)) { |
| 308 | DLOG(WARNING) << "ExtractSPKIFromDERCert failed"; |
| 309 | return false; |
| 310 | } |
| 311 | |
| 312 | crypto::SignatureVerifier verifier; |
| 313 | |
| 314 | size_t size_bits; |
| 315 | X509Certificate::PublicKeyType type; |
| 316 | X509Certificate::GetPublicKeyInfo(cert_->os_cert_handle(), &size_bits, |
| 317 | &type); |
| 318 | if (type == X509Certificate::kPublicKeyTypeRSA) { |
| 319 | crypto::SignatureVerifier::HashAlgorithm hash_alg = |
| 320 | crypto::SignatureVerifier::SHA256; |
| 321 | crypto::SignatureVerifier::HashAlgorithm mask_hash_alg = hash_alg; |
| 322 | unsigned int hash_len = 32; // 32 is the length of a SHA-256 hash. |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 323 | |
| 324 | bool ok = verifier.VerifyInitRSAPSS( |
[email protected] | d5c9e4ba | 2013-09-14 05:25:58 | [diff] [blame] | 325 | hash_alg, mask_hash_alg, hash_len, |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 326 | reinterpret_cast<const uint8*>(signature.data()), signature.size(), |
| 327 | reinterpret_cast<const uint8*>(spki.data()), spki.size()); |
| 328 | if (!ok) { |
| 329 | DLOG(WARNING) << "VerifyInitRSAPSS failed"; |
| 330 | return false; |
| 331 | } |
| 332 | } else if (type == X509Certificate::kPublicKeyTypeECDSA) { |
| 333 | // This is the algorithm ID for ECDSA with SHA-256. Parameters are ABSENT. |
| 334 | // RFC 5758: |
| 335 | // ecdsa-with-SHA256 OBJECT IDENTIFIER ::= { iso(1) member-body(2) |
| 336 | // us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 2 } |
| 337 | // ... |
| 338 | // When the ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with-SHA384, or |
| 339 | // ecdsa-with-SHA512 algorithm identifier appears in the algorithm field |
| 340 | // as an AlgorithmIdentifier, the encoding MUST omit the parameters |
| 341 | // field. That is, the AlgorithmIdentifier SHALL be a SEQUENCE of one |
| 342 | // component, the OID ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with- |
| 343 | // SHA384, or ecdsa-with-SHA512. |
| 344 | // See also RFC 5480, Appendix A. |
| 345 | static const uint8 kECDSAWithSHA256AlgorithmID[] = { |
| 346 | 0x30, 0x0a, |
| 347 | 0x06, 0x08, |
| 348 | 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, |
| 349 | }; |
| 350 | |
| 351 | if (!verifier.VerifyInit( |
| 352 | kECDSAWithSHA256AlgorithmID, sizeof(kECDSAWithSHA256AlgorithmID), |
| 353 | reinterpret_cast<const uint8*>(signature.data()), |
| 354 | signature.size(), |
| 355 | reinterpret_cast<const uint8*>(spki.data()), |
| 356 | spki.size())) { |
| 357 | DLOG(WARNING) << "VerifyInit failed"; |
| 358 | return false; |
| 359 | } |
| 360 | } else { |
| 361 | LOG(ERROR) << "Unsupported public key type " << type; |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | verifier.VerifyUpdate(reinterpret_cast<const uint8*>(kProofSignatureLabel), |
| 366 | sizeof(kProofSignatureLabel)); |
| 367 | verifier.VerifyUpdate(reinterpret_cast<const uint8*>(signed_data.data()), |
| 368 | signed_data.size()); |
| 369 | |
| 370 | if (!verifier.VerifyFinal()) { |
| 371 | DLOG(WARNING) << "VerifyFinal failed"; |
| 372 | return false; |
| 373 | } |
| 374 | |
[email protected] | 3e5fed1 | 2013-11-22 22:21:41 | [diff] [blame] | 375 | DVLOG(1) << "VerifyFinal success"; |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 376 | return true; |
| 377 | } |
| 378 | |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame^] | 379 | ProofVerifierChromium::ProofVerifierChromium( |
| 380 | CertVerifier* cert_verifier, |
| 381 | TransportSecurityState* transport_security_state) |
| 382 | : cert_verifier_(cert_verifier), |
| 383 | transport_security_state_(transport_security_state) { |
| 384 | } |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 385 | |
| 386 | ProofVerifierChromium::~ProofVerifierChromium() { |
| 387 | STLDeleteElements(&active_jobs_); |
| 388 | } |
| 389 | |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 390 | QuicAsyncStatus ProofVerifierChromium::VerifyProof( |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 391 | const std::string& hostname, |
| 392 | const std::string& server_config, |
| 393 | const std::vector<std::string>& certs, |
| 394 | const std::string& signature, |
[email protected] | c817c67 | 2014-03-21 22:25:34 | [diff] [blame] | 395 | const ProofVerifyContext* verify_context, |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 396 | std::string* error_details, |
[email protected] | c817c67 | 2014-03-21 22:25:34 | [diff] [blame] | 397 | scoped_ptr<ProofVerifyDetails>* verify_details, |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 398 | ProofVerifierCallback* callback) { |
[email protected] | c817c67 | 2014-03-21 22:25:34 | [diff] [blame] | 399 | if (!verify_context) { |
| 400 | *error_details = "Missing context"; |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 401 | return QUIC_FAILURE; |
[email protected] | c817c67 | 2014-03-21 22:25:34 | [diff] [blame] | 402 | } |
| 403 | const ProofVerifyContextChromium* chromium_context = |
| 404 | reinterpret_cast<const ProofVerifyContextChromium*>(verify_context); |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame^] | 405 | scoped_ptr<Job> job(new Job(this, |
| 406 | cert_verifier_, |
| 407 | transport_security_state_, |
| 408 | chromium_context->net_log)); |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 409 | QuicAsyncStatus status = job->VerifyProof(hostname, server_config, certs, |
| 410 | signature, error_details, |
| 411 | verify_details, callback); |
| 412 | if (status == QUIC_PENDING) { |
[email protected] | 5c78ce6 | 2014-03-13 19:48:01 | [diff] [blame] | 413 | active_jobs_.insert(job.release()); |
| 414 | } |
| 415 | return status; |
| 416 | } |
| 417 | |
| 418 | void ProofVerifierChromium::OnJobComplete(Job* job) { |
| 419 | active_jobs_.erase(job); |
| 420 | delete job; |
| 421 | } |
| 422 | |
[email protected] | 2662ed56 | 2013-07-03 10:27:46 | [diff] [blame] | 423 | } // namespace net |