Commit c9410ebe authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

More tests for the new certificateProvider API

Provide test coverage for the following scenarios in the
chrome.certificateProvider extensions API:
* empty certificate chain;
* empty algorithm list;
* an extension subscribing to both legacy and non-legacy
  events simultaneously.

Bug: 1067683
Change-Id: I074967716aba5c91b6b6e946345f84a4767bd722
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252187
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarFabian Sommer <fabiansommer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790996}
parent f6dbd309
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/containers/span.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/hash/sha1.h" #include "base/hash/sha1.h"
...@@ -249,8 +250,8 @@ class CertificateProviderApiMockedExtensionTest ...@@ -249,8 +250,8 @@ class CertificateProviderApiMockedExtensionTest
std::string GetKeyPk8() const { std::string GetKeyPk8() const {
std::string key_pk8; std::string key_pk8;
base::ScopedAllowBlockingForTesting allow_io; base::ScopedAllowBlockingForTesting allow_io;
base::ReadFileToString(extension_path_.AppendASCII("l1_leaf.pk8"), EXPECT_TRUE(base::ReadFileToString(
&key_pk8); extension_path_.AppendASCII("l1_leaf.pk8"), &key_pk8));
return key_pk8; return key_pk8;
} }
...@@ -302,11 +303,9 @@ class CertificateProviderApiMockedExtensionTest ...@@ -302,11 +303,9 @@ class CertificateProviderApiMockedExtensionTest
// Load the private key. // Load the private key.
std::string key_pk8 = GetKeyPk8(); std::string key_pk8 = GetKeyPk8();
const uint8_t* const key_pk8_begin =
reinterpret_cast<const uint8_t*>(key_pk8.data());
std::unique_ptr<crypto::RSAPrivateKey> key( std::unique_ptr<crypto::RSAPrivateKey> key(
crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(std::vector<uint8_t>( crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(
key_pk8_begin, key_pk8_begin + key_pk8.size()))); base::as_bytes(base::make_span(key_pk8))));
ASSERT_TRUE(key); ASSERT_TRUE(key);
// Sign using the private key. // Sign using the private key.
...@@ -529,6 +528,30 @@ IN_PROC_BROWSER_TEST_F(CertificateProviderApiMockedExtensionTest, ...@@ -529,6 +528,30 @@ IN_PROC_BROWSER_TEST_F(CertificateProviderApiMockedExtensionTest,
CheckCertificateAbsent(*certificate); CheckCertificateAbsent(*certificate);
} }
// Tests an extension that provides certificates both proactively with
// setCertificates() and in response to both events:
// onCertificatesUpdateRequested and legacy onCertificatesRequested. Verify that
// the non-legacy signature event is used.
IN_PROC_BROWSER_TEST_F(CertificateProviderApiMockedExtensionTest,
ProactiveAndRedundantLegacyResponsiveExtension) {
ExecuteJavascript("registerAsCertificateProvider();");
ExecuteJavascript("registerAsLegacyCertificateProvider();");
ExecuteJavascript("registerForSignatureRequests();");
ExecuteJavascript("registerForLegacySignatureRequests();");
ExecuteJavascriptAndWaitForCallback("setCertificates();");
scoped_refptr<net::X509Certificate> certificate = GetCertificate();
CheckCertificateProvidedByExtension(*certificate, *extension());
// Note that this verifies that the non-legacy signature event is used, since
// we're processing the raw data signature operation here.
TestNavigationToCertificateRequestingWebPage(/*is_raw_data=*/true);
// Remove the certificate.
ExecuteJavascriptAndWaitForCallback("unsetCertificates();");
CheckCertificateAbsent(*certificate);
}
// Tests an extension that only provides certificates proactively via // Tests an extension that only provides certificates proactively via
// setCertificates(). // setCertificates().
IN_PROC_BROWSER_TEST_F(CertificateProviderApiMockedExtensionTest, IN_PROC_BROWSER_TEST_F(CertificateProviderApiMockedExtensionTest,
......
...@@ -20,18 +20,29 @@ const INVALID_CERT = new Uint8Array([1, 2, 3, 4, 5]); ...@@ -20,18 +20,29 @@ const INVALID_CERT = new Uint8Array([1, 2, 3, 4, 5]);
function registerAsCertificateProvider() { function registerAsCertificateProvider() {
function reportCertificates(request) { function reportCertificates(request) {
assertTrue(Number.isInteger(request.certificatesRequestId)); assertTrue(Number.isInteger(request.certificatesRequestId));
const validCertInfo = { const validCert = {
certificateChain: [l1LeafCert.buffer], certificateChain: [l1LeafCert.buffer],
supportedAlgorithms: ['RSASSA_PKCS1_v1_5_SHA1'] supportedAlgorithms: ['RSASSA_PKCS1_v1_5_SHA1']
}; };
const invalidCertInfo = { const invalidCertBadDer = {
certificateChain: [INVALID_CERT.buffer], certificateChain: [INVALID_CERT.buffer],
supportedAlgorithms: ['RSASSA_PKCS1_v1_5_SHA256'] supportedAlgorithms: ['RSASSA_PKCS1_v1_5_SHA256']
}; };
const invalidCertEmpty = {
certificateChain: [],
supportedAlgorithms: ['RSASSA_PKCS1_v1_5_SHA256']
};
const invalidCertNoAlgorithms = {
certificateChain: [l1LeafCert.buffer],
supportedAlgorithms: []
};
chrome.certificateProvider.setCertificates( chrome.certificateProvider.setCertificates(
{ {
certificatesRequestId: request.certificatesRequestId, certificatesRequestId: request.certificatesRequestId,
clientCertificates: [validCertInfo, invalidCertInfo] clientCertificates: [
validCert, invalidCertBadDer, invalidCertEmpty,
invalidCertNoAlgorithms
]
}, },
() => { () => {
chrome.test.succeed(); chrome.test.succeed();
...@@ -68,16 +79,30 @@ function registerAsLegacyCertificateProvider() { ...@@ -68,16 +79,30 @@ function registerAsLegacyCertificateProvider() {
// This can be combined with registerAsCertificateProvider(), but can also be // This can be combined with registerAsCertificateProvider(), but can also be
// used on its own. // used on its own.
function setCertificates() { function setCertificates() {
const validCertInfo = { const validCert = {
certificateChain: [l1LeafCert.buffer], certificateChain: [l1LeafCert.buffer],
supportedAlgorithms: ['RSASSA_PKCS1_v1_5_SHA1'] supportedAlgorithms: ['RSASSA_PKCS1_v1_5_SHA1']
}; };
const invalidCertInfo = { const invalidCertBadDer = {
certificateChain: [INVALID_CERT.buffer], certificateChain: [INVALID_CERT.buffer],
supportedAlgorithms: ['RSASSA_PKCS1_v1_5_SHA256'] supportedAlgorithms: ['RSASSA_PKCS1_v1_5_SHA256']
}; };
const invalidCertEmpty = {
certificateChain: [],
supportedAlgorithms: ['RSASSA_PKCS1_v1_5_SHA256']
};
const invalidCertNoAlgorithms = {
certificateChain: [l1LeafCert.buffer],
supportedAlgorithms: []
};
chrome.certificateProvider.setCertificates( chrome.certificateProvider.setCertificates(
{clientCertificates: [validCertInfo, invalidCertInfo]}, () => { {
clientCertificates: [
validCert, invalidCertBadDer, invalidCertEmpty,
invalidCertNoAlgorithms
]
},
() => {
const success = !chrome.runtime.lastError; const success = !chrome.runtime.lastError;
domAutomationController.send(success); domAutomationController.send(success);
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment