diff options
Diffstat (limited to 'chrome')
4 files changed, 65 insertions, 7 deletions
diff --git a/chrome/browser/chromeos/login/owner_key_utils.cc b/chrome/browser/chromeos/login/owner_key_utils.cc index 9701842..a57f7c5 100644 --- a/chrome/browser/chromeos/login/owner_key_utils.cc +++ b/chrome/browser/chromeos/login/owner_key_utils.cc @@ -194,8 +194,13 @@ bool OwnerKeyUtilsImpl::Verify(const std::string& data, bool OwnerKeyUtilsImpl::Sign(const std::string& data, std::vector<uint8>* OUT_signature, base::RSAPrivateKey* key) { - // TODO(cmasone): Add signing capabilities. - return true; + scoped_ptr<base::SignatureCreator> signer( + base::SignatureCreator::Create(key)); + if (!signer->Update(reinterpret_cast<const uint8*>(data.c_str()), + data.length())) { + return false; + } + return signer->Final(OUT_signature); } RSAPrivateKey* OwnerKeyUtilsImpl::FindPrivateKey( diff --git a/chrome/browser/chromeos/login/owner_manager_unittest.cc b/chrome/browser/chromeos/login/owner_manager_unittest.cc index d686e99..a700cc7 100644 --- a/chrome/browser/chromeos/login/owner_manager_unittest.cc +++ b/chrome/browser/chromeos/login/owner_manager_unittest.cc @@ -287,4 +287,30 @@ TEST_F(OwnerManagerTest, GetKeyAndVerify) { message_loop_.Run(); } +TEST_F(OwnerManagerTest, AlreadyHaveKeysSign) { + scoped_refptr<OwnerManager> manager(new OwnerManager); + + std::string data; + std::vector<uint8> sig(0, 2); + + EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) + .WillRepeatedly(Return(tmpfile_)); + EXPECT_CALL(*mock_, Sign(Eq(data), _, Eq(fake_private_key_.get()))) + .WillOnce(DoAll(SetArgumentPointee<1>(sig), + Return(true))) + .RetiresOnSaturation(); + + InjectKeys(manager.get()); + MockSigner delegate(OwnerManager::SUCCESS, sig); + + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod(manager.get(), + &OwnerManager::Sign, + ChromeThread::UI, + data, + &delegate)); + message_loop_.Run(); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/owner_manager_unittest.h b/chrome/browser/chromeos/login/owner_manager_unittest.h index 0e52178..9825b3d 100644 --- a/chrome/browser/chromeos/login/owner_manager_unittest.h +++ b/chrome/browser/chromeos/login/owner_manager_unittest.h @@ -80,11 +80,13 @@ class MockKeyUser : public OwnerManager::Delegate { : expected_(expected), quit_on_callback_(true) { } + MockKeyUser(const OwnerManager::KeyOpCode expected, bool quit_on_callback) + : expected_(expected), + quit_on_callback_(quit_on_callback) { + } virtual ~MockKeyUser() {} - void dont_quit_on_callback() { quit_on_callback_ = false; } - void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, const std::vector<uint8>& payload) { EXPECT_EQ(expected_, return_code); @@ -93,11 +95,36 @@ class MockKeyUser : public OwnerManager::Delegate { } const OwnerManager::KeyOpCode expected_; - bool quit_on_callback_; + const bool quit_on_callback_; private: DISALLOW_COPY_AND_ASSIGN(MockKeyUser); }; +class MockSigner : public OwnerManager::Delegate { + public: + MockSigner(const OwnerManager::KeyOpCode expected, + const std::vector<uint8>& sig) + : expected_code_(expected), + expected_sig_(sig) { + } + + virtual ~MockSigner() {} + + void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, + const std::vector<uint8>& payload) { + EXPECT_EQ(expected_code_, return_code); + for (uint32 i = 0; i < payload.size(); ++i) + EXPECT_EQ(expected_sig_[i], payload[i]); + MessageLoop::current()->Quit(); + } + + const OwnerManager::KeyOpCode expected_code_; + const std::vector<uint8> expected_sig_; + + private: + DISALLOW_COPY_AND_ASSIGN(MockSigner); +}; + } // namespace chromeos #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_MANAGER_UNITTEST_H_ diff --git a/chrome/browser/chromeos/login/ownership_service_unittest.cc b/chrome/browser/chromeos/login/ownership_service_unittest.cc index 90c4784..a73c70c 100644 --- a/chrome/browser/chromeos/login/ownership_service_unittest.cc +++ b/chrome/browser/chromeos/login/ownership_service_unittest.cc @@ -160,8 +160,8 @@ TEST_F(OwnershipServiceTest, NotYetOwnedVerify) { EXPECT_CALL(*mock_, GetOwnerKeyFilePath()) .WillRepeatedly(Return(tmpfile_)); - MockKeyUser delegate(OwnerManager::KEY_UNAVAILABLE); - delegate.dont_quit_on_callback(); + // Create delegate that does not quit the message loop on callback. + MockKeyUser delegate(OwnerManager::KEY_UNAVAILABLE, false); service_->StartVerifyAttempt("", std::vector<uint8>(), &delegate); } |