OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/it2me/it2me_host.h" | 5 #include "remoting/host/it2me/it2me_host.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 // This is used for tagging system event logs. | 48 // This is used for tagging system event logs. |
49 const char kApplicationName[] = "chromoting"; | 49 const char kApplicationName[] = "chromoting"; |
50 const int kMaxLoginAttempts = 5; | 50 const int kMaxLoginAttempts = 5; |
51 | 51 |
52 using protocol::ValidatingAuthenticator; | 52 using protocol::ValidatingAuthenticator; |
53 typedef ValidatingAuthenticator::Result ValidationResult; | 53 typedef ValidatingAuthenticator::Result ValidationResult; |
54 typedef ValidatingAuthenticator::ValidationCallback ValidationCallback; | 54 typedef ValidatingAuthenticator::ValidationCallback ValidationCallback; |
| 55 typedef ValidatingAuthenticator::ResultCallback ValidationResultCallback; |
55 | 56 |
56 } // namespace | 57 } // namespace |
57 | 58 |
58 It2MeHost::It2MeHost( | 59 It2MeHost::It2MeHost( |
59 std::unique_ptr<ChromotingHostContext> host_context, | 60 std::unique_ptr<ChromotingHostContext> host_context, |
60 std::unique_ptr<PolicyWatcher> policy_watcher, | 61 std::unique_ptr<PolicyWatcher> policy_watcher, |
61 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog, | 62 std::unique_ptr<It2MeConfirmationDialog> confirmation_dialog, |
62 base::WeakPtr<It2MeHost::Observer> observer, | 63 base::WeakPtr<It2MeHost::Observer> observer, |
63 std::unique_ptr<SignalStrategy> signal_strategy, | 64 std::unique_ptr<SignalStrategy> signal_strategy, |
64 const std::string& username, | 65 const std::string& username, |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 // Pass the Access Code to the script object before changing state. | 476 // Pass the Access Code to the script object before changing state. |
476 host_context_->ui_task_runner()->PostTask( | 477 host_context_->ui_task_runner()->PostTask( |
477 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, observer_, | 478 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, observer_, |
478 access_code, lifetime)); | 479 access_code, lifetime)); |
479 | 480 |
480 SetState(kReceivedAccessCode, ""); | 481 SetState(kReceivedAccessCode, ""); |
481 } | 482 } |
482 | 483 |
483 void It2MeHost::ValidateConnectionDetails( | 484 void It2MeHost::ValidateConnectionDetails( |
484 const std::string& remote_jid, | 485 const std::string& remote_jid, |
485 const protocol::ValidatingAuthenticator::ResultCallback& result_callback) { | 486 const ValidationResultCallback& result_callback) { |
486 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 487 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
487 | 488 |
488 // First ensure the JID we received is valid. | 489 // First ensure the JID we received is valid. |
489 std::string client_username; | 490 std::string client_username; |
490 if (!SplitJidResource(remote_jid, &client_username, /*resource=*/nullptr)) { | 491 if (!SplitJidResource(remote_jid, &client_username, /*resource=*/nullptr)) { |
491 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid | 492 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid |
492 << ": Invalid JID."; | 493 << ": Invalid JID."; |
493 result_callback.Run( | 494 result_callback.Run( |
494 protocol::ValidatingAuthenticator::Result::ERROR_INVALID_ACCOUNT); | 495 protocol::ValidatingAuthenticator::Result::ERROR_INVALID_ACCOUNT); |
495 DisconnectOnNetworkThread(); | 496 DisconnectOnNetworkThread(); |
(...skipping 14 matching lines...) Expand all Loading... |
510 std::string("@") + required_client_domain_, | 511 std::string("@") + required_client_domain_, |
511 base::CompareCase::INSENSITIVE_ASCII)) { | 512 base::CompareCase::INSENSITIVE_ASCII)) { |
512 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid | 513 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid |
513 << ": Domain mismatch."; | 514 << ": Domain mismatch."; |
514 result_callback.Run(ValidationResult::ERROR_INVALID_ACCOUNT); | 515 result_callback.Run(ValidationResult::ERROR_INVALID_ACCOUNT); |
515 DisconnectOnNetworkThread(); | 516 DisconnectOnNetworkThread(); |
516 return; | 517 return; |
517 } | 518 } |
518 } | 519 } |
519 | 520 |
| 521 // If we receive valid connection details multiple times, then we don't know |
| 522 // which remote user (if either) is valid so disconnect everyone. |
| 523 if (state_ != kReceivedAccessCode) { |
| 524 DCHECK_EQ(kConnecting, state_); |
| 525 LOG(ERROR) << "Received too many connection requests."; |
| 526 result_callback.Run(ValidationResult::ERROR_TOO_MANY_CONNECTIONS); |
| 527 DisconnectOnNetworkThread(); |
| 528 return; |
| 529 } |
| 530 |
520 HOST_LOG << "Client " << client_username << " connecting."; | 531 HOST_LOG << "Client " << client_username << " connecting."; |
521 SetState(kConnecting, std::string()); | 532 SetState(kConnecting, std::string()); |
522 | 533 |
523 // Show a confirmation dialog to the user to allow them to confirm/reject it. | 534 // Show a confirmation dialog to the user to allow them to confirm/reject it. |
524 confirmation_dialog_proxy_.reset(new It2MeConfirmationDialogProxy( | 535 confirmation_dialog_proxy_.reset(new It2MeConfirmationDialogProxy( |
525 host_context_->ui_task_runner(), std::move(confirmation_dialog_))); | 536 host_context_->ui_task_runner(), std::move(confirmation_dialog_))); |
526 | 537 |
527 confirmation_dialog_proxy_->Show( | 538 confirmation_dialog_proxy_->Show( |
528 client_username, base::Bind(&It2MeHost::OnConfirmationResult, | 539 client_username, base::Bind(&It2MeHost::OnConfirmationResult, |
529 base::Unretained(this), result_callback)); | 540 base::Unretained(this), result_callback)); |
530 } | 541 } |
531 | 542 |
532 void It2MeHost::OnConfirmationResult( | 543 void It2MeHost::OnConfirmationResult( |
533 const protocol::ValidatingAuthenticator::ResultCallback& result_callback, | 544 const ValidationResultCallback& result_callback, |
534 It2MeConfirmationDialog::Result result) { | 545 It2MeConfirmationDialog::Result result) { |
535 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 546 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
536 | 547 |
537 switch (result) { | 548 switch (result) { |
538 case It2MeConfirmationDialog::Result::OK: | 549 case It2MeConfirmationDialog::Result::OK: |
539 result_callback.Run(ValidationResult::SUCCESS); | 550 result_callback.Run(ValidationResult::SUCCESS); |
540 break; | 551 break; |
541 | 552 |
542 case It2MeConfirmationDialog::Result::CANCEL: | 553 case It2MeConfirmationDialog::Result::CANCEL: |
543 result_callback.Run(ValidationResult::ERROR_REJECTED_BY_USER); | 554 result_callback.Run(ValidationResult::ERROR_REJECTED_BY_USER); |
(...skipping 16 matching lines...) Expand all Loading... |
560 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); | 571 DCHECK(context->ui_task_runner()->BelongsToCurrentThread()); |
561 | 572 |
562 std::unique_ptr<PolicyWatcher> policy_watcher = | 573 std::unique_ptr<PolicyWatcher> policy_watcher = |
563 PolicyWatcher::Create(policy_service, context->file_task_runner()); | 574 PolicyWatcher::Create(policy_service, context->file_task_runner()); |
564 return new It2MeHost(std::move(context), std::move(policy_watcher), | 575 return new It2MeHost(std::move(context), std::move(policy_watcher), |
565 It2MeConfirmationDialog::Create(), observer, | 576 It2MeConfirmationDialog::Create(), observer, |
566 std::move(signal_strategy), username, directory_bot_jid); | 577 std::move(signal_strategy), username, directory_bot_jid); |
567 } | 578 } |
568 | 579 |
569 } // namespace remoting | 580 } // namespace remoting |
OLD | NEW |