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

Side by Side Diff: chrome/browser/local_discovery/privetv3_session.h

Issue 877613002: Added pairing with Spake SHA224 key exchange. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@brillo1
Patch Set: Sun 01/25/2015 23:51:07.99 Created 5 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "chrome/common/extensions/api/gcd_private.h" 14 #include "chrome/common/extensions/api/gcd_private.h"
15 #include "net/url_request/url_fetcher.h"
15 16
16 namespace base { 17 namespace base {
17 class DictionaryValue; 18 class DictionaryValue;
18 } 19 }
19 20
21 namespace crypto {
22 class P224EncryptedKeyExchange;
23 }
24
20 namespace local_discovery { 25 namespace local_discovery {
21 26
22 class PrivetHTTPClient; 27 class PrivetHTTPClient;
28 class PrivetJSONOperation;
29 class PrivetURLFetcher;
23 30
24 // Manages secure communication between browser and local Privet device. 31 // Manages secure communication between browser and local Privet device.
25 class PrivetV3Session { 32 class PrivetV3Session {
26 private: 33 private:
27 class FetcherDelegate; 34 class FetcherDelegate;
28 35
29 public: 36 public:
30 typedef extensions::api::gcd_private::PairingType PairingType; 37 typedef extensions::api::gcd_private::PairingType PairingType;
31 typedef extensions::api::gcd_private::Status Result; 38 typedef extensions::api::gcd_private::Status Result;
32 39
33 typedef base::Callback< 40 typedef base::Callback<
34 void(Result result, const std::vector<PairingType>& types)> InitCallback; 41 void(Result result, const std::vector<PairingType>& types)> InitCallback;
35 42
36 typedef base::Callback<void(Result result)> ResultCallback; 43 typedef base::Callback<void(Result result)> ResultCallback;
37 typedef base::Callback<void(Result result, 44 typedef base::Callback<void(Result result,
38 const base::DictionaryValue& response)> 45 const base::DictionaryValue& response)>
39 MessageCallback; 46 MessageCallback;
40 47
41 explicit PrivetV3Session(scoped_ptr<PrivetHTTPClient> client); 48 explicit PrivetV3Session(scoped_ptr<PrivetHTTPClient> client);
42 ~PrivetV3Session(); 49 ~PrivetV3Session();
43 50
44 // Initialized session. 51 // Initializes session. Queries /privet/info and returns supported pairing
52 // types in callback.
45 void Init(const InitCallback& callback); 53 void Init(const InitCallback& callback);
46 54
55 // Starts pairing by calling /privet/v3/pairing/start.
47 void StartPairing(PairingType pairing_type, const ResultCallback& callback); 56 void StartPairing(PairingType pairing_type, const ResultCallback& callback);
48 57
58 // Confirms pairing code by calling /privet/v3/pairing/confirm.
59 // TODO(vitalybuka): Call /privet/v3/pairing/auth after pairing.
49 void ConfirmCode(const std::string& code, const ResultCallback& callback); 60 void ConfirmCode(const std::string& code, const ResultCallback& callback);
50 61
51 // Create a single /privet/v3/session/call request. 62 // TODO(vitalybuka): Make HTTPS request to device with certificate validation.
52 void SendMessage(const std::string& api, 63 void SendMessage(const std::string& api,
53 const base::DictionaryValue& input, 64 const base::DictionaryValue& input,
54 const MessageCallback& callback); 65 const MessageCallback& callback);
55 66
56 private: 67 private:
68 void OnInfoDone(const InitCallback& callback,
69 Result result,
70 const base::DictionaryValue& response);
71 void OnPairingStartDone(const ResultCallback& callback,
72 Result result,
73 const base::DictionaryValue& response);
74 void OnPairingConfirmDone(const ResultCallback& callback,
75 Result result,
76 const base::DictionaryValue& response);
57 void RunCallback(const base::Closure& callback); 77 void RunCallback(const base::Closure& callback);
78 void StartGetRequest(const std::string& api, const MessageCallback& callback);
79 void StartPostRequest(const std::string& api,
80 const base::DictionaryValue& input,
81 const MessageCallback& callback);
82 PrivetURLFetcher* CreateFetcher(const std::string& api,
83 net::URLFetcher::RequestType request_type,
84 const MessageCallback& callback);
58 void DeleteFetcher(const FetcherDelegate* fetcher); 85 void DeleteFetcher(const FetcherDelegate* fetcher);
59 86
87 // Creates instances of PrivetURLFetcher.
60 scoped_ptr<PrivetHTTPClient> client_; 88 scoped_ptr<PrivetHTTPClient> client_;
61 bool code_confirmed_; 89
90 // Current authentication token.
91 std::string privet_auth_token_;
92
93 // ID of the session received from pairing/start.
94 std::string session_id_;
95
96 // Device commitment received from pairing/start.
97 std::string commitment_;
98
99 // Key exchange algorithm for pairing.
100 scoped_ptr<crypto::P224EncryptedKeyExchange> spake_;
101
102 // HTTPS certificate fingerprint received during pairing.
103 std::string fingerprint_;
104
105 // List of fetches to cancel when session is destroyed.
62 ScopedVector<FetcherDelegate> fetchers_; 106 ScopedVector<FetcherDelegate> fetchers_;
63 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_; 107 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_;
64 std::string privet_auth_token_;
65 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session); 108 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session);
66 }; 109 };
67 110
68 } // namespace local_discovery 111 } // namespace local_discovery
69 112
70 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ 113 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/local_discovery/privetv3_session.cc » ('j') | chrome/browser/local_discovery/privetv3_session.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698