Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1856)

Unified Diff: net/cert/ignore_errors_cert_verifier.cc

Issue 2753123002: Add --ignore-certificate-errors-spki-list switch and UMA histogram. (Closed)
Patch Set: Really add IgnoreErrorsCertVerifier. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/cert/ignore_errors_cert_verifier.cc
diff --git a/net/cert/ignore_errors_cert_verifier.cc b/net/cert/ignore_errors_cert_verifier.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2530e2eb66cf4d34f3963b8b157eab32da3854ab
--- /dev/null
+++ b/net/cert/ignore_errors_cert_verifier.cc
@@ -0,0 +1,93 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/cert/ignore_errors_cert_verifier.h"
+
+#include "crypto/sha2.h"
+#include "net/base/net_errors.h"
+#include "net/cert/asn1_util.h"
+
+namespace net {
+
+// static
+IgnoreErrorsCertVerifier::SPKIHashSet IgnoreErrorsCertVerifier::MakeWhitelist(
+ const std::vector<std::string>& fingerprints) {
+ IgnoreErrorsCertVerifier::SPKIHashSet whitelist;
+ for (const std::string& fingerprint : fingerprints) {
+ net::HashValue hv;
+ if (!hv.FromString("sha256/" + fingerprint)) {
+ LOG(ERROR) << "Invalid SPKI: " << fingerprint;
+ continue;
+ }
+ net::SHA256HashValue sha256;
+ DCHECK_EQ(hv.size(), sizeof(sha256));
+ memcpy(&sha256, hv.data(), sizeof(sha256));
+ whitelist.insert(sha256);
+ }
+ return whitelist;
+}
+
+IgnoreErrorsCertVerifier::IgnoreErrorsCertVerifier(
+ std::unique_ptr<CertVerifier> verifier,
+ IgnoreErrorsCertVerifier::SPKIHashSet whitelist)
+ : verifier_(std::move(verifier)), whitelist_(std::move(whitelist)){};
+
+IgnoreErrorsCertVerifier::~IgnoreErrorsCertVerifier() {}
+
+int IgnoreErrorsCertVerifier::Verify(const RequestParams& params,
+ CRLSet* crl_set,
+ CertVerifyResult* verify_result,
+ const CompletionCallback& callback,
+ std::unique_ptr<Request>* out_req,
+ const NetLogWithSource& net_log) {
+ SPKIHashSet spki_fingerprints;
+ std::string cert_der;
+ base::StringPiece cert_spki;
+ SHA256HashValue hash;
+ if (X509Certificate::GetDEREncoded(params.certificate()->os_cert_handle(),
+ &cert_der) &&
+ asn1::ExtractSPKIFromDERCert(cert_der, &cert_spki)) {
+ crypto::SHA256HashString(cert_spki, &hash, sizeof(SHA256HashValue));
+ spki_fingerprints.insert(hash);
+ }
+ for (const net::X509Certificate::OSCertHandle& intermediate :
+ params.certificate()->GetIntermediateCertificates()) {
+ if (X509Certificate::GetDEREncoded(intermediate, &cert_der) &&
+ asn1::ExtractSPKIFromDERCert(cert_der, &cert_spki)) {
+ crypto::SHA256HashString(cert_spki, &hash, sizeof(SHA256HashValue));
+ spki_fingerprints.insert(hash);
+ }
+ }
+
+ // Intersect SPKI hashes from the chain with the whitelist.
+ auto wl = whitelist_.begin();
+ auto wl_end = whitelist_.end();
+ auto sf = spki_fingerprints.begin();
+ auto sf_end = spki_fingerprints.end();
+ static const net::SHA256HashValueLessThan sha256_lt;
+ bool ignore_errors = false;
+ while (wl != wl_end && sf != sf_end) {
+ if (sha256_lt(*wl, *sf))
+ ++wl;
+ else if (sha256_lt(*sf, *wl))
+ ++sf;
+ else {
+ ignore_errors = true;
+ break;
+ }
+ }
+
+ CompletionCallback callback_ok = base::Bind(
+ [](CompletionCallback callback, int result) { callback.Run(OK); },
+ callback);
Ryan Sleevi 2017/04/07 16:08:05 I'm not sure - why do you chain to the verifier if
martinkr 2017/04/07 21:40:57 IIUC, at least CertVerifyResult.verified_cert need
+ int result = verifier_->Verify(params, crl_set, verify_result,
+ ignore_errors ? callback_ok : callback,
+ out_req, net_log);
+ if (ignore_errors && result != ERR_IO_PENDING) {
+ return OK;
+ }
+ return result;
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698