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

Unified Diff: net/base/temporary_root_certs_win.cc

Issue 4646001: Implement LoadTemporaryRoot for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/net/base
Patch Set: Feedback from phajdan.jr and bulach Created 10 years, 1 month 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/base/temporary_root_certs_win.cc
diff --git a/net/base/temporary_root_certs_win.cc b/net/base/temporary_root_certs_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..06d91ffb5eb467e1d8630472a386eae95e26f898
--- /dev/null
+++ b/net/base/temporary_root_certs_win.cc
@@ -0,0 +1,49 @@
+// Copyright (c) 2010 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/base/temporary_root_certs.h"
+
+#include "base/logging.h"
+#include "net/base/x509_certificate.h"
+
+namespace net {
+
+bool TemporaryRootCerts::Add(X509Certificate* certificate) {
+ BOOL ok = CertAddCertificateContextToStore(
+ temporary_roots_, certificate->os_cert_handle(),
+ CERT_STORE_ADD_NEW, NULL);
+ if (!ok) {
+ if (GetLastError() == CRYPT_E_EXISTS)
wtc 2010/11/16 23:24:01 Nit: you can just say if (!ok) { // If certi
+ return true; // Certificate is already added.
+ return false;
+ }
+
+ ++cert_count_;
+ return true;
+}
+
+void TemporaryRootCerts::Remove(X509Certificate* certificate) {
+ PCCERT_CONTEXT cert = CertFindCertificateInStore(
+ temporary_roots_, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
+ 0, CERT_FIND_EXISTING, certificate->os_cert_handle(), NULL);
+ if (cert) {
+ CertDeleteCertificateFromStore(cert);
+ DCHECK_GT(cert_count_, 0U);
+ --cert_count_;
+ }
+}
+
+TemporaryRootCerts::TemporaryRootCerts()
+ : temporary_roots_(NULL), cert_count_(0) {
bulach 2010/11/09 16:21:09 nit: I think it's either all in one line (includin
+ temporary_roots_ = CertOpenStore(
+ CERT_STORE_PROV_MEMORY, 0, NULL,
+ CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL);
+ DCHECK(temporary_roots_);
+}
+
+TemporaryRootCerts::~TemporaryRootCerts() {
+ CertCloseStore(temporary_roots_, 0);
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698