summaryrefslogtreecommitdiffstats
path: root/remoting/test/host_info.cc
blob: 1370011a4a97871e8e603c35dd266c47758e7e15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2015 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 "remoting/protocol/authentication_method.h"
#include "remoting/test/host_info.h"

#include "base/logging.h"

namespace remoting {
namespace test {

HostInfo::HostInfo() {
}

HostInfo::~HostInfo() {
}

bool HostInfo::ParseHostInfo(const base::DictionaryValue& host_info) {
  const base::ListValue* list_value = nullptr;

  // Add TokenUrlPatterns to HostInfo.
  if (host_info.GetList("tokenUrlPatterns", &list_value)) {
    if (!list_value->empty()) {
      for (base::Value* item : *list_value) {
        std::string token_url_pattern;
        if (!item->GetAsString(&token_url_pattern)) {
          return false;
        }
        token_url_patterns.push_back(token_url_pattern);
      }
    }
  }

  std::string response_status;
  host_info.GetString("status", &response_status);
  if (response_status == "ONLINE") {
    status = kHostStatusOnline;
  } else if (response_status == "OFFLINE") {
    status = kHostStatusOffline;
  } else {
    LOG(ERROR) << "Response Status is " << response_status;
    return false;
  }

  if (!host_info.GetString("hostId", &host_id)) {
    LOG(ERROR) << "hostId was not found in host_info";
    return false;
  }

  if (!host_info.GetString("hostName", &host_name)) {
    LOG(ERROR) << "hostName was not found in host_info";
    return false;
  }

  if (!host_info.GetString("publicKey", &public_key)) {
    LOG(ERROR) << "publicKey was not found for " << host_name;
    return false;
  }

  // If the host entry was created but the host was never online, then the jid
  // is never set.
  if (!host_info.GetString("jabberId", &host_jid) &&
      status == kHostStatusOnline) {
    LOG(ERROR) << host_name << " is online but is missing a jabberId";
    return false;
  }

  host_info.GetString("hostOfflineReason", &offline_reason);

  return true;
}

bool HostInfo::IsReadyForConnection() const {
  return !host_jid.empty() && status == kHostStatusOnline;
}

ConnectionSetupInfo HostInfo::GenerateConnectionSetupInfo(
    const std::string& access_token,
    const std::string& user_name,
    const std::string& pin) const {
  ConnectionSetupInfo connection_setup_info;
  connection_setup_info.access_token = access_token;
  connection_setup_info.host_id = host_id;
  connection_setup_info.host_jid = host_jid;
  connection_setup_info.host_name = host_name;
  connection_setup_info.pin = pin;
  connection_setup_info.public_key = public_key;
  connection_setup_info.user_name = user_name;

  connection_setup_info.auth_methods.push_back(
      protocol::AuthenticationMethod::Spake2Pair());
  connection_setup_info.auth_methods.push_back(
      protocol::AuthenticationMethod::Spake2(
          protocol::AuthenticationMethod::HashFunction::NONE));
  connection_setup_info.auth_methods.push_back(
      protocol::AuthenticationMethod::Spake2(
          protocol::AuthenticationMethod::HashFunction::HMAC_SHA256));
  connection_setup_info.auth_methods.push_back(
      protocol::AuthenticationMethod::ThirdParty());

  return connection_setup_info;
}

}  // namespace test
}  // namespace remoting