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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 NPVariant* result) { | 608 NPVariant* result) { |
610 if (arg_count != 0) { | 609 if (arg_count != 0) { |
611 SetException("getHostName: bad number of arguments"); | 610 SetException("getHostName: bad number of arguments"); |
612 return false; | 611 return false; |
613 } | 612 } |
614 DCHECK(result); | 613 DCHECK(result); |
615 *result = NPVariantFromString(net::GetHostName()); | 614 *result = NPVariantFromString(net::GetHostName()); |
616 return true; | 615 return true; |
617 } | 616 } |
618 | 617 |
619 bool HostNPScriptObject::GetPinHash(const NPVariant* args, | 618 bool HostNPScriptObject::GetPinHash(const NPVariant* args, |
Wez
2012/04/30 23:13:57
As for the underlying method, we should have a bet
simonmorris
2012/05/01 00:25:55
I think that's out of scope for this CL.
Wez
2012/05/01 01:02:36
My thinking was that since the API return value is
| |
620 uint32_t arg_count, | 619 uint32_t arg_count, |
621 NPVariant* result) { | 620 NPVariant* result) { |
622 if (arg_count != 2) { | 621 if (arg_count != 2) { |
623 SetException("getPinHash: bad number of arguments"); | 622 SetException("getPinHash: bad number of arguments"); |
624 return false; | 623 return false; |
625 } | 624 } |
626 | 625 |
627 std::string host_id = StringFromNPVariant(args[0]); | 626 std::string host_id = StringFromNPVariant(args[0]); |
628 if (host_id.empty()) { | 627 if (host_id.empty()) { |
629 SetException("getPinHash: bad hostId parameter"); | 628 SetException("getPinHash: bad hostId parameter"); |
630 return false; | 629 return false; |
631 } | 630 } |
632 | 631 |
633 if (!NPVARIANT_IS_STRING(args[1])) { | 632 if (!NPVARIANT_IS_STRING(args[1])) { |
634 SetException("getPinHash: bad pin parameter"); | 633 SetException("getPinHash: bad pin parameter"); |
635 return false; | 634 return false; |
636 } | 635 } |
637 std::string pin = StringFromNPVariant(args[1]); | 636 std::string pin = StringFromNPVariant(args[1]); |
638 | 637 |
639 std::string hash = protocol::AuthenticationMethod::ApplyHashFunction( | 638 *result = NPVariantFromString(remoting::GetPinHash(host_id, pin)); |
640 protocol::AuthenticationMethod::HMAC_SHA256, host_id, pin); | |
641 std::string hash_base64; | |
642 bool base64_result = base::Base64Encode(hash, &hash_base64); | |
643 if (!base64_result) { | |
644 LOG(FATAL) << "Base64Encode failed"; | |
645 } | |
646 | |
647 *result = NPVariantFromString(hash_base64); | |
648 | 639 |
649 return true; | 640 return true; |
650 } | 641 } |
651 | 642 |
652 bool HostNPScriptObject::GenerateKeyPair(const NPVariant* args, | 643 bool HostNPScriptObject::GenerateKeyPair(const NPVariant* args, |
653 uint32_t arg_count, | 644 uint32_t arg_count, |
654 NPVariant* result) { | 645 NPVariant* result) { |
655 if (arg_count != 1) { | 646 if (arg_count != 1) { |
656 SetException("generateKeyPair: bad number of arguments"); | 647 SetException("generateKeyPair: bad number of arguments"); |
657 return false; | 648 return false; |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1123 return is_good; | 1114 return is_good; |
1124 } | 1115 } |
1125 | 1116 |
1126 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1117 void HostNPScriptObject::SetException(const std::string& exception_string) { |
1127 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 1118 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); |
1128 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1119 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
1129 LOG(INFO) << exception_string; | 1120 LOG(INFO) << exception_string; |
1130 } | 1121 } |
1131 | 1122 |
1132 } // namespace remoting | 1123 } // namespace remoting |
OLD | NEW |