diff options
author | noamsml <noamsml@chromium.org> | 2014-08-26 14:55:55 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-26 21:57:27 +0000 |
commit | 18d64ecb4fc72171c55498ee507682085c684e01 (patch) | |
tree | 7914bcd17013b980efa36cb349699071d2f22b92 /chrome/browser/local_discovery | |
parent | 6b6cd502e50d93232afee8f993dc47a563f74c84 (diff) | |
download | chromium_src-18d64ecb4fc72171c55498ee507682085c684e01.zip chromium_src-18d64ecb4fc72171c55498ee507682085c684e01.tar.gz chromium_src-18d64ecb4fc72171c55498ee507682085c684e01.tar.bz2 |
API change to allow sticker authentication for devices
Change API to match protocol that may allow sticker authentication
for devices. The PIN will not necessarily be available at provision
time, and the client will need to send a user-typed PIN at
code verification time.
BUG=
Review URL: https://codereview.chromium.org/468613003
Cr-Commit-Position: refs/heads/master@{#291988}
Diffstat (limited to 'chrome/browser/local_discovery')
5 files changed, 57 insertions, 38 deletions
diff --git a/chrome/browser/local_discovery/privetv3_session.cc b/chrome/browser/local_discovery/privetv3_session.cc index 69583c2..6428457 100644 --- a/chrome/browser/local_discovery/privetv3_session.cc +++ b/chrome/browser/local_discovery/privetv3_session.cc @@ -16,6 +16,8 @@ namespace { const char kUrlPlaceHolder[] = "http://host/"; +const char kStubPrivetCode[] = "01234"; + GURL CreatePrivetURL(const std::string& path) { GURL url(kUrlPlaceHolder); GURL::Replacements replacements; @@ -105,9 +107,14 @@ void PrivetV3Session::Start() { base::TimeDelta::FromSeconds(1)); } -void PrivetV3Session::ConfirmCode() { - code_confirmed_ = true; - delegate_->OnSessionEstablished(); +void PrivetV3Session::ConfirmCode(const std::string& code) { + if (code == kStubPrivetCode) { + code_confirmed_ = true; + delegate_->OnSessionStatus(extensions::api::gcd_private::STATUS_SUCCESS); + } else { + delegate_->OnSessionStatus( + extensions::api::gcd_private::STATUS_BADCONFIRMATIONCODEERROR); + } } void PrivetV3Session::StartRequest(Request* request) { @@ -130,7 +137,9 @@ void PrivetV3Session::StartRequest(Request* request) { } void PrivetV3Session::ConfirmFakeCode() { - delegate_->OnSetupConfirmationNeeded("01234"); + delegate_->OnSetupConfirmationNeeded( + kStubPrivetCode, + extensions::api::gcd_private::CONFIRMATION_TYPE_DISPLAYCODE); } } // namespace local_discovery diff --git a/chrome/browser/local_discovery/privetv3_session.h b/chrome/browser/local_discovery/privetv3_session.h index b6631a2..91771b1 100644 --- a/chrome/browser/local_discovery/privetv3_session.h +++ b/chrome/browser/local_discovery/privetv3_session.h @@ -10,6 +10,7 @@ #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/local_discovery/privet_url_fetcher.h" +#include "chrome/common/extensions/api/gcd_private.h" namespace base { class DictionaryValue; @@ -32,14 +33,11 @@ class PrivetV3Session { // Called when client code should prompt user to check |confirmation_code|. virtual void OnSetupConfirmationNeeded( - const std::string& confirmation_code) = 0; + const std::string& confirmation_code, + extensions::api::gcd_private::ConfirmationType confirmation_type) = 0; - // Called when session successfully establish and client code my call - // |CreateRequest| method. - virtual void OnSessionEstablished() = 0; - - // Called when session setup fails. - virtual void OnCannotEstablishSession() = 0; + virtual void OnSessionStatus( + extensions::api::gcd_private::Status status) = 0; }; // Represents request in progress using secure session. @@ -66,7 +64,7 @@ class PrivetV3Session { // |OnSessionEstablished|. void Start(); - void ConfirmCode(); + void ConfirmCode(const std::string& code); // Create a single /privet/v3/session/call request. void StartRequest(Request* request); diff --git a/chrome/browser/local_discovery/privetv3_session_unittest.cc b/chrome/browser/local_discovery/privetv3_session_unittest.cc index 6a21760..fd117a4 100644 --- a/chrome/browser/local_discovery/privetv3_session_unittest.cc +++ b/chrome/browser/local_discovery/privetv3_session_unittest.cc @@ -21,9 +21,10 @@ using testing::_; class MockDelegate : public PrivetV3Session::Delegate { public: - MOCK_METHOD1(OnSetupConfirmationNeeded, void(const std::string&)); - MOCK_METHOD0(OnSessionEstablished, void()); - MOCK_METHOD0(OnCannotEstablishSession, void()); + MOCK_METHOD2(OnSetupConfirmationNeeded, + void(const std::string&, + extensions::api::gcd_private::ConfirmationType)); + MOCK_METHOD1(OnSessionStatus, void(extensions::api::gcd_private::Status)); }; class PrivetV3SessionTest : public testing::Test { @@ -37,12 +38,16 @@ class PrivetV3SessionTest : public testing::Test { base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); } + void ConfirmCode(const std::string& code, + extensions::api::gcd_private::ConfirmationType type) { + session_.ConfirmCode(code); + } + protected: virtual void SetUp() OVERRIDE { quit_closure_ = run_loop_.QuitClosure(); - EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_)).Times(0); - EXPECT_CALL(delegate_, OnSessionEstablished()).Times(0); - EXPECT_CALL(delegate_, OnCannotEstablishSession()).Times(0); + EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(0); + EXPECT_CALL(delegate_, OnSessionStatus(_)).Times(0); } StrictMock<MockDelegate> delegate_; @@ -53,17 +58,19 @@ class PrivetV3SessionTest : public testing::Test { }; TEST_F(PrivetV3SessionTest, NotConfirmed) { - EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_)).Times(1).WillOnce( + EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(1).WillOnce( InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop)); session_.Start(); run_loop_.Run(); } TEST_F(PrivetV3SessionTest, Confirmed) { - EXPECT_CALL(delegate_, OnSessionEstablished()).Times(1).WillOnce( - InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop)); - EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_)).Times(1).WillOnce( - InvokeWithoutArgs(&session_, &PrivetV3Session::ConfirmCode)); + EXPECT_CALL(delegate_, + OnSessionStatus(extensions::api::gcd_private::STATUS_SUCCESS)) + .Times(1) + .WillOnce(InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop)); + EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(1).WillOnce( + Invoke(this, &PrivetV3SessionTest::ConfirmCode)); session_.Start(); run_loop_.Run(); } diff --git a/chrome/browser/local_discovery/privetv3_setup_flow.cc b/chrome/browser/local_discovery/privetv3_setup_flow.cc index 97705c7..64142d7 100644 --- a/chrome/browser/local_discovery/privetv3_setup_flow.cc +++ b/chrome/browser/local_discovery/privetv3_setup_flow.cc @@ -109,19 +109,22 @@ void PrivetV3SetupFlow::SetupWifiAndRegister(const std::string& device_ssid) { #endif // ENABLE_WIFI_BOOTSTRAPPING void PrivetV3SetupFlow::OnSetupConfirmationNeeded( - const std::string& confirmation_code) { + const std::string& confirmation_code, + extensions::api::gcd_private::ConfirmationType confirmation_type) { delegate_->ConfirmSecurityCode(confirmation_code, base::Bind(&PrivetV3SetupFlow::OnCodeConfirmed, - weak_ptr_factory_.GetWeakPtr())); + weak_ptr_factory_.GetWeakPtr(), + confirmation_code)); } -void PrivetV3SetupFlow::OnSessionEstablished() { - DCHECK(setup_request_); - session_->StartRequest(setup_request_.get()); -} - -void PrivetV3SetupFlow::OnCannotEstablishSession() { - OnSetupError(); +void PrivetV3SetupFlow::OnSessionStatus( + extensions::api::gcd_private::Status status) { + if (status == extensions::api::gcd_private::STATUS_SUCCESS) { + DCHECK(setup_request_); + session_->StartRequest(setup_request_.get()); + } else { + OnSetupError(); + } } void PrivetV3SetupFlow::OnSetupError() { @@ -159,10 +162,10 @@ void PrivetV3SetupFlow::OnPrivetClientCreated( session_->Start(); } -void PrivetV3SetupFlow::OnCodeConfirmed(bool success) { +void PrivetV3SetupFlow::OnCodeConfirmed(const std::string& code, bool success) { if (!success) return OnSetupError(); - session_->ConfirmCode(); + session_->ConfirmCode(code); } } // namespace local_discovery diff --git a/chrome/browser/local_discovery/privetv3_setup_flow.h b/chrome/browser/local_discovery/privetv3_setup_flow.h index e99e3e2..f53e506 100644 --- a/chrome/browser/local_discovery/privetv3_setup_flow.h +++ b/chrome/browser/local_discovery/privetv3_setup_flow.h @@ -73,9 +73,11 @@ class PrivetV3SetupFlow : public PrivetV3Session::Delegate { // PrivetV3Session::Delegate implementation. virtual void OnSetupConfirmationNeeded( - const std::string& confirmation_code) OVERRIDE; - virtual void OnSessionEstablished() OVERRIDE; - virtual void OnCannotEstablishSession() OVERRIDE; + const std::string& confirmation_code, + extensions::api::gcd_private::ConfirmationType confirmation_type) + OVERRIDE; + virtual void OnSessionStatus( + extensions::api::gcd_private::Status status) OVERRIDE; void OnSetupError(); void OnDeviceRegistered(); @@ -86,7 +88,7 @@ class PrivetV3SetupFlow : public PrivetV3Session::Delegate { void OnTicketCreated(const std::string& ticket_id, const std::string& device_id); void OnPrivetClientCreated(scoped_ptr<PrivetHTTPClient> privet_http_client); - void OnCodeConfirmed(bool success); + void OnCodeConfirmed(const std::string& code, bool success); Delegate* delegate_; std::string service_name_; |