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

Unified Diff: net/test/cert_test_util_nss.cc

Issue 429633004: Test NSSCertDatabaseChromeOS in the presence of the system slot. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed a comment. Created 6 years, 5 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
« no previous file with comments | « net/test/cert_test_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/test/cert_test_util_nss.cc
diff --git a/net/test/cert_test_util_nss.cc b/net/test/cert_test_util_nss.cc
index 5ff783070fe97c6974157000351b86903f457f89..a3e06c70654baf5ed1d2a06297cdc8ccc1400711 100644
--- a/net/test/cert_test_util_nss.cc
+++ b/net/test/cert_test_util_nss.cc
@@ -4,10 +4,15 @@
#include "net/test/cert_test_util.h"
+#include <pk11pub.h>
+#include <secmodt.h>
+
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
+#include "crypto/nss_util.h"
#include "crypto/rsa_private_key.h"
+#include "net/cert/cert_type.h"
namespace net {
@@ -36,4 +41,48 @@ scoped_ptr<crypto::RSAPrivateKey> ImportSensitiveKeyFromFile(
return private_key.Pass();
}
+bool ImportClientCertToSlot(const scoped_refptr<X509Certificate>& cert,
+ PK11SlotInfo* slot) {
+ std::string nickname = cert->GetDefaultNickname(USER_CERT);
+ {
+ crypto::AutoNSSWriteLock lock;
+ SECStatus rv = PK11_ImportCert(slot,
+ cert->os_cert_handle(),
+ CK_INVALID_HANDLE,
+ nickname.c_str(),
+ PR_FALSE);
+ if (rv != SECSuccess) {
+ LOG(ERROR) << "Could not import cert";
+ return false;
+ }
+ }
+ return true;
+}
+
+scoped_refptr<X509Certificate> ImportClientCertAndKeyFromFile(
+ const base::FilePath& dir,
+ const std::string& cert_filename,
+ const std::string& key_filename,
+ PK11SlotInfo* slot) {
+ if (!ImportSensitiveKeyFromFile(dir, key_filename, slot)) {
+ LOG(ERROR) << "Could not import private key from file " << key_filename;
+ return NULL;
+ }
+
+ scoped_refptr<X509Certificate> cert(ImportCertFromFile(dir, cert_filename));
+
+ if (!cert) {
+ LOG(ERROR) << "Failed to parse cert from file " << cert_filename;
+ return NULL;
+ }
+
+ if (!ImportClientCertToSlot(cert, slot))
+ return NULL;
+
+ // |cert| continues to point to the original X509Certificate before the
+ // import to |slot|. However this should not make a difference as NSS handles
+ // state globally.
+ return cert;
+}
+
} // namespace net
« no previous file with comments | « net/test/cert_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698