OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "remoting/host/plugin/host_script_object.h" | 5 #include "remoting/host/plugin/host_script_object.h" |
6 | 6 |
7 #include "base/base64.h" | |
8 #include "base/bind.h" | 7 #include "base/bind.h" |
9 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
11 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
12 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
13 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
14 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
15 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
16 #include "base/values.h" | 15 #include "base/values.h" |
17 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
18 #include "remoting/base/auth_token_util.h" | 17 #include "remoting/base/auth_token_util.h" |
19 #include "remoting/host/chromoting_host.h" | 18 #include "remoting/host/chromoting_host.h" |
20 #include "remoting/host/chromoting_host_context.h" | 19 #include "remoting/host/chromoting_host_context.h" |
21 #include "remoting/host/desktop_environment.h" | 20 #include "remoting/host/desktop_environment.h" |
22 #include "remoting/host/host_config.h" | 21 #include "remoting/host/host_config.h" |
23 #include "remoting/host/host_key_pair.h" | 22 #include "remoting/host/host_key_pair.h" |
24 #include "remoting/host/host_secret.h" | 23 #include "remoting/host/host_secret.h" |
25 #include "remoting/host/it2me_host_user_interface.h" | 24 #include "remoting/host/it2me_host_user_interface.h" |
| 25 #include "remoting/host/pin_hash.h" |
26 #include "remoting/host/plugin/daemon_controller.h" | 26 #include "remoting/host/plugin/daemon_controller.h" |
27 #include "remoting/host/plugin/host_log_handler.h" | 27 #include "remoting/host/plugin/host_log_handler.h" |
28 #include "remoting/host/policy_hack/nat_policy.h" | 28 #include "remoting/host/policy_hack/nat_policy.h" |
29 #include "remoting/host/register_support_host_request.h" | 29 #include "remoting/host/register_support_host_request.h" |
30 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 30 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
31 #include "remoting/protocol/authentication_method.h" | |
32 #include "remoting/protocol/it2me_host_authenticator_factory.h" | 31 #include "remoting/protocol/it2me_host_authenticator_factory.h" |
33 | 32 |
34 namespace remoting { | 33 namespace remoting { |
35 | 34 |
36 namespace { | 35 namespace { |
37 | 36 |
38 const char* kAttrNameAccessCode = "accessCode"; | 37 const char* kAttrNameAccessCode = "accessCode"; |
39 const char* kAttrNameAccessCodeLifetime = "accessCodeLifetime"; | 38 const char* kAttrNameAccessCodeLifetime = "accessCodeLifetime"; |
40 const char* kAttrNameClient = "client"; | 39 const char* kAttrNameClient = "client"; |
41 const char* kAttrNameDaemonState = "daemonState"; | 40 const char* kAttrNameDaemonState = "daemonState"; |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 SetException("getPinHash: bad hostId parameter"); | 630 SetException("getPinHash: bad hostId parameter"); |
632 return false; | 631 return false; |
633 } | 632 } |
634 | 633 |
635 if (!NPVARIANT_IS_STRING(args[1])) { | 634 if (!NPVARIANT_IS_STRING(args[1])) { |
636 SetException("getPinHash: bad pin parameter"); | 635 SetException("getPinHash: bad pin parameter"); |
637 return false; | 636 return false; |
638 } | 637 } |
639 std::string pin = StringFromNPVariant(args[1]); | 638 std::string pin = StringFromNPVariant(args[1]); |
640 | 639 |
641 std::string hash = protocol::AuthenticationMethod::ApplyHashFunction( | 640 *result = NPVariantFromString(remoting::MakeHostPinHash(host_id, pin)); |
642 protocol::AuthenticationMethod::HMAC_SHA256, host_id, pin); | |
643 std::string hash_base64; | |
644 bool base64_result = base::Base64Encode(hash, &hash_base64); | |
645 if (!base64_result) { | |
646 LOG(FATAL) << "Base64Encode failed"; | |
647 } | |
648 | |
649 *result = NPVariantFromString(hash_base64); | |
650 | 641 |
651 return true; | 642 return true; |
652 } | 643 } |
653 | 644 |
654 bool HostNPScriptObject::GenerateKeyPair(const NPVariant* args, | 645 bool HostNPScriptObject::GenerateKeyPair(const NPVariant* args, |
655 uint32_t arg_count, | 646 uint32_t arg_count, |
656 NPVariant* result) { | 647 NPVariant* result) { |
657 if (arg_count != 1) { | 648 if (arg_count != 1) { |
658 SetException("generateKeyPair: bad number of arguments"); | 649 SetException("generateKeyPair: bad number of arguments"); |
659 return false; | 650 return false; |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 return is_good; | 1116 return is_good; |
1126 } | 1117 } |
1127 | 1118 |
1128 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1119 void HostNPScriptObject::SetException(const std::string& exception_string) { |
1129 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 1120 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); |
1130 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1121 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
1131 LOG(INFO) << exception_string; | 1122 LOG(INFO) << exception_string; |
1132 } | 1123 } |
1133 | 1124 |
1134 } // namespace remoting | 1125 } // namespace remoting |
OLD | NEW |