OLD | NEW |
---|---|
(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) { | |
pneubeck (no reviews)
2014/08/06 16:01:38
nit: indentation is off
stevenjb
2014/08/06 16:52:14
Done.
| |
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() { | |
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
| |
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 } | |
OLD | NEW |