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

Unified Diff: chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest.cc

Issue 214863002: Extension API enterprise.platformKeys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @kalman only Created 6 years, 7 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: chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest.cc
diff --git a/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest.cc b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..df01d559d687d2b3cff74bd5be2c2f9074234447
--- /dev/null
+++ b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest.cc
@@ -0,0 +1,112 @@
+// Copyright 2014 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 <cryptohi.h>
Ryan Sleevi 2014/05/08 20:52:04 Same comments re: _nss suffix - you're relying on
pneubeck (no reviews) 2014/05/14 15:01:49 Done.
+
+#include "base/macros.h"
+#include "chrome/browser/extensions/extension_apitest.h"
+#include "chrome/browser/net/nss_context.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/test/test_utils.h"
+#include "crypto/nss_util.h"
+#include "net/base/net_errors.h"
+#include "net/cert/nss_cert_database.h"
+
+namespace {
+
+// openssl genrsa > privkey.pem
+// openssl pkcs8 -inform pem -in privkey.pem -topk8
+// -outform der -out privkey8.der -nocrypt
+// xxd -i privkey8.der
+const unsigned char privateKeyPkcs8[] = {
+ 0x30, 0x82, 0x01, 0x55, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
+ 0x86,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0x25,
+ 0x31, 0x12, 0x99, 0x43, 0x06, 0x3c, 0xb0, 0x80, 0x35, 0x2b, 0xf4, 0xc5,
+ 0xa2, 0xd3, 0x02, 0x21, 0x00, 0xd6, 0x9b, 0x8b, 0x75, 0x91, 0x52, 0xd4,
+ 0xf0, 0x76, 0xcf, 0xa2, 0xbe, 0xa6, 0xaf, 0x72, 0x6c, 0x52, 0xf9, 0xc9,
+ 0x0e, 0xea, 0x4a, 0x4c, 0xd2, 0xdf, 0x25, 0x70, 0xc6, 0x66, 0x35, 0x9d,
+ 0xbf, 0x02, 0x21, 0x00, 0xe8, 0x9e, 0x40, 0x21, 0xcc, 0x37, 0xde, 0xc7,
+ 0xd1, 0x13, 0x55, 0xcd, 0x0a, 0x8c, 0x40, 0xcd, 0xb1, 0xed, 0xa5, 0xf1,
+ 0x7d, 0x33, 0x64, 0x64, 0x5c, 0xfe, 0x5c, 0x6a, 0x34, 0x03, 0xb8, 0xc7,
+ 0x02, 0x20, 0x17, 0xe1, 0xb5, 0x52, 0x3e, 0xfa, 0xc5, 0xc1, 0x80, 0xa7,
+ 0x38, 0x88, 0x18, 0xca, 0x7b, 0x64, 0x3c, 0x93, 0x99, 0x61, 0x34, 0x87,
+ 0x52, 0x27, 0x41, 0x37, 0xcc, 0x65, 0xf7, 0xa7, 0xcd, 0xc7, 0x02, 0x21,
+ 0x00, 0x8a, 0x17, 0x7f, 0xf9, 0x45, 0xf3, 0xfd, 0xf7, 0x96, 0x62, 0xf3,
+ 0x7a, 0x09, 0xfb, 0xe9, 0x9e, 0xc7, 0x7a, 0x1f, 0x53, 0x1a, 0xb8, 0xd5,
+ 0x88, 0x9d, 0xd4, 0x79, 0x57, 0x88, 0x68, 0x72, 0x6f};
+
+namespace nss {
+
+void DidGetCertDatabase(net::NSSCertDatabase* cert_db) {
+ // In order to use a prepared certificate, import a private key at first for
+ // which the Javscript test will import the certificate.
+ SECItem pki_der = {
+ siBuffer,
+ // NSS requires non-const data even though it is just for input.
+ const_cast<unsigned char*>((const unsigned char*)privateKeyPkcs8),
+ arraysize(privateKeyPkcs8)};
+
+ crypto::ScopedPK11Slot private_slot(cert_db->GetPrivateSlot());
+ SECKEYPrivateKey* seckey_private_key = NULL;
+ ASSERT_EQ(SECSuccess,
+ PK11_ImportDERPrivateKeyInfoAndReturnKey(private_slot.get(),
+ &pki_der,
+ NULL, // nickname
+ NULL, // publicValue
+ true, // isPerm
+ true, // isPrivate
+ KU_ALL, // usage
+ &seckey_private_key,
+ NULL));
+}
+
+void PrepareCertDatabase(Profile* profile) {
+ GetNSSCertDatabaseForProfile(profile, base::Bind(&DidGetCertDatabase));
+
+ content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
+ content::RunAllPendingInMessageLoop();
+}
+
+} // namespace nss
+
+class EnterprisePlatformKeysTest : public ExtensionApiTest {
+ public:
+ EnterprisePlatformKeysTest() : test_nssdb_(true) {}
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ ExtensionApiTest::SetUpCommandLine(command_line);
+ command_line->AppendSwitch(
+ switches::kEnableExperimentalWebPlatformFeatures);
+ }
+
+ virtual void SetUpOnMainThread() OVERRIDE {
+ ExtensionApiTest::SetUpOnMainThread();
+
+ nss::PrepareCertDatabase(browser()->profile());
+ }
+
+ private:
+ crypto::ScopedTestNSSDB test_nssdb_;
+};
+
+} // namespace
+
+IN_PROC_BROWSER_TEST_F(EnterprisePlatformKeysTest, Basic) {
+ ASSERT_TRUE(RunExtensionSubtest("enterprise_platform_keys", "basic.html"))
+ << message_;
+}

Powered by Google App Engine
This is Rietveld 408576698