Commit 21d28490 authored by davidben's avatar davidben Committed by Commit bot

Follow-up changes to https://codereview.chromium.org/795773002/

Per post-commit comments.

BUG=439134

Review URL: https://codereview.chromium.org/873723003

Cr-Commit-Position: refs/heads/master@{#314063}
parent a7b8dcb6
...@@ -40,35 +40,38 @@ namespace { ...@@ -40,35 +40,38 @@ namespace {
// inspection. // inspection.
class ClientCertStoreStub : public net::ClientCertStore { class ClientCertStoreStub : public net::ClientCertStore {
public: public:
ClientCertStoreStub(const net::CertificateList& certs) // Creates a new ClientCertStoreStub that returns |response| on query. It
: response_(certs), async_(false), request_count_(0) {} // saves the number of requests and most recently certificate authorities list
// in |requested_authorities| and |request_count|, respectively. The caller is
~ClientCertStoreStub() override {} // responsible for ensuring those pointers outlive the ClientCertStoreStub.
//
// Configures whether the certificates are returned asynchronously or not.
void set_async(bool async) { async_ = async; }
// Returns |cert_authorities| field of the certificate request passed in the
// most recent call to GetClientCerts().
// TODO(ppi): Make the stub independent from the internal representation of // TODO(ppi): Make the stub independent from the internal representation of
// SSLCertRequestInfo. For now it seems that we cannot neither save the // SSLCertRequestInfo. For now it seems that we can neither save the
// scoped_refptr<> (since it is never passed to us) nor copy the entire // scoped_refptr<> (since it is never passed to us) nor copy the entire
// CertificateRequestInfo (since there is no copy constructor). // CertificateRequestInfo (since there is no copy constructor).
std::vector<std::string> requested_authorities() { ClientCertStoreStub(const net::CertificateList& response,
return requested_authorities_; int* request_count,
std::vector<std::string>* requested_authorities)
: response_(response),
async_(false),
requested_authorities_(requested_authorities),
request_count_(request_count) {
requested_authorities_->clear();
*request_count_ = 0;
} }
// Returns the number of calls to GetClientCerts(). ~ClientCertStoreStub() override {}
int request_count() {
return request_count_; // Configures whether the certificates are returned asynchronously or not.
} void set_async(bool async) { async_ = async; }
// net::ClientCertStore: // net::ClientCertStore:
void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info, void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info,
net::CertificateList* selected_certs, net::CertificateList* selected_certs,
const base::Closure& callback) override { const base::Closure& callback) override {
++request_count_; *requested_authorities_ = cert_request_info.cert_authorities;
requested_authorities_ = cert_request_info.cert_authorities; ++(*request_count_);
*selected_certs = response_; *selected_certs = response_;
if (async_) { if (async_) {
base::MessageLoop::current()->PostTask(FROM_HERE, callback); base::MessageLoop::current()->PostTask(FROM_HERE, callback);
...@@ -80,8 +83,8 @@ class ClientCertStoreStub : public net::ClientCertStore { ...@@ -80,8 +83,8 @@ class ClientCertStoreStub : public net::ClientCertStore {
private: private:
const net::CertificateList response_; const net::CertificateList response_;
bool async_; bool async_;
int request_count_; std::vector<std::string>* requested_authorities_;
std::vector<std::string> requested_authorities_; int* request_count_;
}; };
// Arbitrary read buffer size. // Arbitrary read buffer size.
...@@ -377,15 +380,12 @@ class ResourceLoaderTest : public testing::Test, ...@@ -377,15 +380,12 @@ class ResourceLoaderTest : public testing::Test,
// selection. // selection.
TEST_F(ResourceLoaderTest, ClientCertStoreLookup) { TEST_F(ResourceLoaderTest, ClientCertStoreLookup) {
// Set up the test client cert store. // Set up the test client cert store.
int store_request_count;
std::vector<std::string> store_requested_authorities;
net::CertificateList dummy_certs(1, scoped_refptr<net::X509Certificate>( net::CertificateList dummy_certs(1, scoped_refptr<net::X509Certificate>(
new net::X509Certificate("test", "test", base::Time(), base::Time()))); new net::X509Certificate("test", "test", base::Time(), base::Time())));
scoped_ptr<ClientCertStoreStub> test_store( scoped_ptr<ClientCertStoreStub> test_store(new ClientCertStoreStub(
new ClientCertStoreStub(dummy_certs)); dummy_certs, &store_request_count, &store_requested_authorities));
EXPECT_EQ(0, test_store->request_count());
// Ownership of the |test_store| is about to be turned over to ResourceLoader.
// We need to keep raw pointer copies to access these objects later.
ClientCertStoreStub* raw_ptr_to_store = test_store.get();
resource_context_.SetClientCertStore(test_store.Pass()); resource_context_.SetClientCertStore(test_store.Pass());
// Prepare a dummy certificate request. // Prepare a dummy certificate request.
...@@ -407,8 +407,8 @@ TEST_F(ResourceLoaderTest, ClientCertStoreLookup) { ...@@ -407,8 +407,8 @@ TEST_F(ResourceLoaderTest, ClientCertStoreLookup) {
SetBrowserClientForTesting(old_client); SetBrowserClientForTesting(old_client);
// Check if the test store was queried against correct |cert_authorities|. // Check if the test store was queried against correct |cert_authorities|.
EXPECT_EQ(1, raw_ptr_to_store->request_count()); EXPECT_EQ(1, store_request_count);
EXPECT_EQ(dummy_authority, raw_ptr_to_store->requested_authorities()); EXPECT_EQ(dummy_authority, store_requested_authorities);
// Check if the retrieved certificates were passed to the content browser // Check if the retrieved certificates were passed to the content browser
// client. // client.
...@@ -446,14 +446,13 @@ TEST_F(ResourceLoaderTest, ClientCertStoreNull) { ...@@ -446,14 +446,13 @@ TEST_F(ResourceLoaderTest, ClientCertStoreNull) {
TEST_F(ResourceLoaderTest, ClientCertStoreAsyncCancel) { TEST_F(ResourceLoaderTest, ClientCertStoreAsyncCancel) {
// Set up the test client cert store. // Set up the test client cert store.
int store_request_count;
std::vector<std::string> store_requested_authorities;
scoped_ptr<ClientCertStoreStub> test_store( scoped_ptr<ClientCertStoreStub> test_store(
new ClientCertStoreStub(net::CertificateList())); new ClientCertStoreStub(net::CertificateList(), &store_request_count,
&store_requested_authorities));
test_store->set_async(true); test_store->set_async(true);
EXPECT_EQ(0, test_store->request_count()); EXPECT_EQ(0, store_request_count);
// Ownership of the |test_store| is about to be turned over to ResourceLoader.
// We need to keep raw pointer copies to access these objects later.
ClientCertStoreStub* raw_ptr_to_store = test_store.get();
resource_context_.SetClientCertStore(test_store.Pass()); resource_context_.SetClientCertStore(test_store.Pass());
// Prepare a dummy certificate request. // Prepare a dummy certificate request.
...@@ -467,8 +466,8 @@ TEST_F(ResourceLoaderTest, ClientCertStoreAsyncCancel) { ...@@ -467,8 +466,8 @@ TEST_F(ResourceLoaderTest, ClientCertStoreAsyncCancel) {
loader_->OnCertificateRequested(raw_ptr_to_request_, cert_request_info.get()); loader_->OnCertificateRequested(raw_ptr_to_request_, cert_request_info.get());
// Check if the test store was queried against correct |cert_authorities|. // Check if the test store was queried against correct |cert_authorities|.
EXPECT_EQ(1, raw_ptr_to_store->request_count()); EXPECT_EQ(1, store_request_count);
EXPECT_EQ(dummy_authority, raw_ptr_to_store->requested_authorities()); EXPECT_EQ(dummy_authority, store_requested_authorities);
// Cancel the request before the store calls the callback. // Cancel the request before the store calls the callback.
loader_.reset(); loader_.reset();
......
...@@ -56,6 +56,10 @@ class SSLClientAuthHandler::Core : public base::RefCountedThreadSafe<Core> { ...@@ -56,6 +56,10 @@ class SSLClientAuthHandler::Core : public base::RefCountedThreadSafe<Core> {
void GetClientCerts() { void GetClientCerts() {
if (client_cert_store_) { if (client_cert_store_) {
// TODO(davidben): This is still a cyclical ownership where
// GetClientCerts' requirement that |client_cert_store_| remains alive
// until the call completes is maintained by the reference held in the
// callback.
client_cert_store_->GetClientCerts( client_cert_store_->GetClientCerts(
*cert_request_info_, &cert_request_info_->client_certs, *cert_request_info_, &cert_request_info_->client_certs,
base::Bind(&SSLClientAuthHandler::Core::DidGetClientCerts, this)); base::Bind(&SSLClientAuthHandler::Core::DidGetClientCerts, this));
...@@ -85,8 +89,7 @@ SSLClientAuthHandler::SSLClientAuthHandler( ...@@ -85,8 +89,7 @@ SSLClientAuthHandler::SSLClientAuthHandler(
net::URLRequest* request, net::URLRequest* request,
net::SSLCertRequestInfo* cert_request_info, net::SSLCertRequestInfo* cert_request_info,
const SSLClientAuthHandler::CertificateCallback& callback) const SSLClientAuthHandler::CertificateCallback& callback)
: core_(nullptr), : request_(request),
request_(request),
cert_request_info_(cert_request_info), cert_request_info_(cert_request_info),
callback_(callback), callback_(callback),
weak_factory_(this) { weak_factory_(this) {
......
...@@ -43,7 +43,8 @@ class SSLClientAuthHandler { ...@@ -43,7 +43,8 @@ class SSLClientAuthHandler {
// Called when |core_| is done retrieving the cert list. // Called when |core_| is done retrieving the cert list.
void DidGetClientCerts(); void DidGetClientCerts();
// Called when the user has selected a cert. // Called when the user has selected a cert. If the user chose to continue
// with no certificate, |cert| is NULL.
void CertificateSelected(net::X509Certificate* cert); void CertificateSelected(net::X509Certificate* cert);
// A reference-counted core so the ClientCertStore may outlive // A reference-counted core so the ClientCertStore may outlive
......
...@@ -399,7 +399,8 @@ class CONTENT_EXPORT ContentBrowserClient { ...@@ -399,7 +399,8 @@ class CONTENT_EXPORT ContentBrowserClient {
CertificateRequestResultType* result) {} CertificateRequestResultType* result) {}
// Selects a SSL client certificate and returns it to the |callback|. If no // Selects a SSL client certificate and returns it to the |callback|. If no
// certificate was selected nullptr is returned to the |callback|. // certificate was selected nullptr is returned to the |callback|. Note:
// |callback| may be called synchronously or asynchronously.
virtual void SelectClientCertificate( virtual void SelectClientCertificate(
int render_process_id, int render_process_id,
int render_frame_id, int render_frame_id,
......
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