Chromium Code Reviews| Index: chrome/browser/extensions/api/networking_private/crypto_verify_impl.cc |
| diff --git a/chrome/browser/extensions/api/networking_private/crypto_verify_impl.cc b/chrome/browser/extensions/api/networking_private/crypto_verify_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..db09c3d782f6b22f7516e6fd4443929ab6a2ac5b |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/networking_private/crypto_verify_impl.cc |
| @@ -0,0 +1,82 @@ |
| +// 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 "chrome/browser/extensions/api/networking_private/crypto_verify_impl.h" |
| + |
| +#include "base/base64.h" |
| +#include "chrome/browser/extensions/api/networking_private/networking_private_credentials_getter.h" |
| +#include "chrome/browser/extensions/api/networking_private/networking_private_service_client.h" |
| +#include "chrome/common/extensions/api/networking_private/networking_private_crypto.h" |
| + |
| +namespace { |
| + |
| + bool VerifyCredentials(const CryptoVerifyImpl::Credentials& credentials) { |
|
pneubeck (no reviews)
2014/08/06 16:01:38
nit: indentation is off
stevenjb
2014/08/06 16:52:14
Done.
|
| + return networking_private_crypto::VerifyCredentials(credentials.certificate, |
| + credentials.signed_data, |
| + credentials.unsigned_data, |
| + credentials.device_bssid); |
| +} |
| + |
| +} // namespace |
| + |
| +using extensions::NetworkingPrivateServiceClient; |
| +using extensions::NetworkingPrivateCredentialsGetter; |
| + |
| +NetworkingPrivateServiceClient::CryptoVerify* |
| +NetworkingPrivateServiceClient::CryptoVerify::Create() { |
|
pneubeck (no reviews)
2014/08/06 16:01:38
Couldn't the caller as well just call 'new CryptoV
stevenjb
2014/08/06 16:52:14
NetworkingPrivateServiceClient will be getting mov
|
| + return new CryptoVerifyImpl(); |
| +} |
| + |
| +CryptoVerifyImpl::CryptoVerifyImpl() { |
| +} |
| + |
| +CryptoVerifyImpl::~CryptoVerifyImpl() { |
| +} |
| + |
| +void CryptoVerifyImpl::VerifyDestination(const Credentials& credentials, |
| + bool* verified, |
| + std::string* error) { |
| + *verified = VerifyCredentials(credentials); |
| +} |
| + |
| +void CryptoVerifyImpl::VerifyAndEncryptCredentials( |
| + const std::string& network_guid, |
| + const Credentials& credentials, |
| + const VerifyAndEncryptCredentialsCallback& callback) { |
| + if (!VerifyCredentials(credentials)) { |
| + callback.Run("", "VerifyError"); |
| + return; |
| + } |
| + |
| + scoped_ptr<NetworkingPrivateCredentialsGetter> credentials_getter( |
| + NetworkingPrivateCredentialsGetter::Create()); |
| + |
| + // Start getting credentials. On Windows |callback| will be called |
| + // asynchronously on a different thread after |credentials_getter| |
| + // is deleted. |
| + credentials_getter->Start(network_guid, credentials.public_key, callback); |
| +} |
| + |
| +void CryptoVerifyImpl::VerifyAndEncryptData( |
| + const Credentials& credentials, |
| + const std::string& data, |
| + std::string* base64_encoded_ciphertext, |
| + std::string* error) { |
| + if (!VerifyCredentials(credentials)) { |
| + *error = "VerifyError"; |
| + return; |
| + } |
| + |
| + std::vector<uint8> public_key_data(credentials.public_key.begin(), |
| + credentials.public_key.end()); |
| + std::vector<uint8> ciphertext; |
| + if (!networking_private_crypto::EncryptByteString( |
| + public_key_data, data, &ciphertext)) { |
| + *error = "EncryptError"; |
| + return; |
| + } |
| + |
| + base::Base64Encode(std::string(ciphertext.begin(), ciphertext.end()), |
| + base64_encoded_ciphertext); |
| +} |