Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/extensions/api/networking_private/crypto_verify_impl.cc

Issue 442073003: Separate CryptoVerifyImpl into its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/networking_private/crypto_verify_impl.h"
6
7 #include "base/base64.h"
8 #include "chrome/browser/extensions/api/networking_private/networking_private_cr edentials_getter.h"
9 #include "chrome/browser/extensions/api/networking_private/networking_private_se rvice_client.h"
10 #include "chrome/common/extensions/api/networking_private/networking_private_cry pto.h"
11
12 namespace {
13
14 bool VerifyCredentials(const CryptoVerifyImpl::Credentials& credentials) {
15 return networking_private_crypto::VerifyCredentials(credentials.certificate,
16 credentials.signed_data,
17 credentials.unsigned_data,
18 credentials.device_bssid);
19 }
20
21 } // namespace
22
23 using extensions::NetworkingPrivateServiceClient;
24 using extensions::NetworkingPrivateCredentialsGetter;
25
26 NetworkingPrivateServiceClient::CryptoVerify*
27 NetworkingPrivateServiceClient::CryptoVerify::Create() {
28 return new CryptoVerifyImpl();
29 }
30
31 CryptoVerifyImpl::CryptoVerifyImpl() {
32 }
33
34 CryptoVerifyImpl::~CryptoVerifyImpl() {
35 }
36
37 void CryptoVerifyImpl::VerifyDestination(const Credentials& credentials,
38 bool* verified,
39 std::string* error) {
40 *verified = VerifyCredentials(credentials);
41 }
42
43 void CryptoVerifyImpl::VerifyAndEncryptCredentials(
44 const std::string& network_guid,
45 const Credentials& credentials,
46 const VerifyAndEncryptCredentialsCallback& callback) {
47 if (!VerifyCredentials(credentials)) {
48 callback.Run("", "VerifyError");
49 return;
50 }
51
52 scoped_ptr<NetworkingPrivateCredentialsGetter> credentials_getter(
53 NetworkingPrivateCredentialsGetter::Create());
54
55 // Start getting credentials. On Windows |callback| will be called
56 // asynchronously on a different thread after |credentials_getter|
57 // is deleted.
58 credentials_getter->Start(network_guid, credentials.public_key, callback);
59 }
60
61 void CryptoVerifyImpl::VerifyAndEncryptData(
62 const Credentials& credentials,
63 const std::string& data,
64 std::string* base64_encoded_ciphertext,
65 std::string* error) {
66 if (!VerifyCredentials(credentials)) {
67 *error = "VerifyError";
68 return;
69 }
70
71 std::vector<uint8> public_key_data(credentials.public_key.begin(),
72 credentials.public_key.end());
73 std::vector<uint8> ciphertext;
74 if (!networking_private_crypto::EncryptByteString(
75 public_key_data, data, &ciphertext)) {
76 *error = "EncryptError";
77 return;
78 }
79
80 base::Base64Encode(std::string(ciphertext.begin(), ciphertext.end()),
81 base64_encoded_ciphertext);
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698