1 // Copyright 2015 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.
5 #include "remoting/protocol/authentication_method.h"
6 #include "remoting/test/host_info.h"
8 #include "base/logging.h"
13 HostInfo::HostInfo() {
16 HostInfo::~HostInfo() {
19 bool HostInfo::ParseHostInfo(const base::DictionaryValue
& host_info
) {
20 const base::ListValue
* list_value
= nullptr;
22 // Add TokenUrlPatterns to HostInfo.
23 if (host_info
.GetList("tokenUrlPatterns", &list_value
)) {
24 if (!list_value
->empty()) {
25 for (base::Value
* item
: *list_value
) {
26 std::string token_url_pattern
;
27 if (!item
->GetAsString(&token_url_pattern
)) {
30 token_url_patterns
.push_back(token_url_pattern
);
35 std::string response_status
;
36 host_info
.GetString("status", &response_status
);
37 if (response_status
== "ONLINE") {
38 status
= kHostStatusOnline
;
39 } else if (response_status
== "OFFLINE") {
40 status
= kHostStatusOffline
;
42 LOG(ERROR
) << "Response Status is " << response_status
;
46 if (!host_info
.GetString("hostId", &host_id
)) {
47 LOG(ERROR
) << "hostId was not found in host_info";
51 if (!host_info
.GetString("hostName", &host_name
)) {
52 LOG(ERROR
) << "hostName was not found in host_info";
56 if (!host_info
.GetString("publicKey", &public_key
)) {
57 LOG(ERROR
) << "publicKey was not found for " << host_name
;
61 // If the host entry was created but the host was never online, then the jid
63 if (!host_info
.GetString("jabberId", &host_jid
) &&
64 status
== kHostStatusOnline
) {
65 LOG(ERROR
) << host_name
<< " is online but is missing a jabberId";
69 host_info
.GetString("hostOfflineReason", &offline_reason
);
74 bool HostInfo::IsReadyForConnection() const {
75 return !host_jid
.empty() && status
== kHostStatusOnline
;
78 ConnectionSetupInfo
HostInfo::GenerateConnectionSetupInfo(
79 const std::string
& access_token
,
80 const std::string
& user_name
,
81 const std::string
& pin
) const {
82 ConnectionSetupInfo connection_setup_info
;
83 connection_setup_info
.access_token
= access_token
;
84 connection_setup_info
.host_id
= host_id
;
85 connection_setup_info
.host_jid
= host_jid
;
86 connection_setup_info
.host_name
= host_name
;
87 connection_setup_info
.pin
= pin
;
88 connection_setup_info
.public_key
= public_key
;
89 connection_setup_info
.user_name
= user_name
;
91 connection_setup_info
.auth_methods
.push_back(
92 protocol::AuthenticationMethod::Spake2Pair());
93 connection_setup_info
.auth_methods
.push_back(
94 protocol::AuthenticationMethod::Spake2(
95 protocol::AuthenticationMethod::HashFunction::NONE
));
96 connection_setup_info
.auth_methods
.push_back(
97 protocol::AuthenticationMethod::Spake2(
98 protocol::AuthenticationMethod::HashFunction::HMAC_SHA256
));
99 connection_setup_info
.auth_methods
.push_back(
100 protocol::AuthenticationMethod::ThirdParty());
102 return connection_setup_info
;
106 } // namespace remoting