Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chromeos/login/auth/cryptohome_authenticator.cc

Issue 2886913005: Rename TaskRunner::RunsTasksOnCurrentThread() in //dbus, //chromeos, //ppapi (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chromeos/login/auth/login_performer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chromeos/login/auth/cryptohome_authenticator.h" 5 #include "chromeos/login/auth/cryptohome_authenticator.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 false)); // user_is_new 543 false)); // user_is_new
544 remove_user_data_on_failure_ = false; 544 remove_user_data_on_failure_ = false;
545 check_key_attempted_ = true; 545 check_key_attempted_ = true;
546 SystemSaltGetter::Get()->GetSystemSalt( 546 SystemSaltGetter::Get()->GetSystemSalt(
547 base::Bind(&CheckKey, current_state_->AsWeakPtr(), 547 base::Bind(&CheckKey, current_state_->AsWeakPtr(),
548 scoped_refptr<CryptohomeAuthenticator>(this))); 548 scoped_refptr<CryptohomeAuthenticator>(this)));
549 } 549 }
550 550
551 void CryptohomeAuthenticator::LoginAsSupervisedUser( 551 void CryptohomeAuthenticator::LoginAsSupervisedUser(
552 const UserContext& user_context) { 552 const UserContext& user_context) {
553 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 553 DCHECK(task_runner_->RunsTasksInCurrentSequence());
554 DCHECK_EQ(user_manager::USER_TYPE_SUPERVISED, user_context.GetUserType()); 554 DCHECK_EQ(user_manager::USER_TYPE_SUPERVISED, user_context.GetUserType());
555 555
556 // TODO(nkostylev): Pass proper value for |user_is_new| or remove (not used). 556 // TODO(nkostylev): Pass proper value for |user_is_new| or remove (not used).
557 current_state_.reset(new AuthAttemptState(user_context, 557 current_state_.reset(new AuthAttemptState(user_context,
558 false, // unlock 558 false, // unlock
559 false, // online_complete 559 false, // online_complete
560 false)); // user_is_new 560 false)); // user_is_new
561 remove_user_data_on_failure_ = false; 561 remove_user_data_on_failure_ = false;
562 StartMount(current_state_->AsWeakPtr(), 562 StartMount(current_state_->AsWeakPtr(),
563 scoped_refptr<CryptohomeAuthenticator>(this), 563 scoped_refptr<CryptohomeAuthenticator>(this),
564 false /* ephemeral */, false /* create_if_nonexistent */); 564 false /* ephemeral */, false /* create_if_nonexistent */);
565 } 565 }
566 566
567 void CryptohomeAuthenticator::LoginOffTheRecord() { 567 void CryptohomeAuthenticator::LoginOffTheRecord() {
568 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 568 DCHECK(task_runner_->RunsTasksInCurrentSequence());
569 current_state_.reset( 569 current_state_.reset(
570 new AuthAttemptState(UserContext(user_manager::USER_TYPE_GUEST, 570 new AuthAttemptState(UserContext(user_manager::USER_TYPE_GUEST,
571 user_manager::GuestAccountId()), 571 user_manager::GuestAccountId()),
572 false, // unlock 572 false, // unlock
573 false, // online_complete 573 false, // online_complete
574 false)); // user_is_new 574 false)); // user_is_new
575 remove_user_data_on_failure_ = false; 575 remove_user_data_on_failure_ = false;
576 ephemeral_mount_attempted_ = true; 576 ephemeral_mount_attempted_ = true;
577 MountGuestAndGetHash(current_state_->AsWeakPtr(), 577 MountGuestAndGetHash(current_state_->AsWeakPtr(),
578 scoped_refptr<CryptohomeAuthenticator>(this)); 578 scoped_refptr<CryptohomeAuthenticator>(this));
579 } 579 }
580 580
581 void CryptohomeAuthenticator::LoginAsPublicSession( 581 void CryptohomeAuthenticator::LoginAsPublicSession(
582 const UserContext& user_context) { 582 const UserContext& user_context) {
583 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 583 DCHECK(task_runner_->RunsTasksInCurrentSequence());
584 DCHECK_EQ(user_manager::USER_TYPE_PUBLIC_ACCOUNT, user_context.GetUserType()); 584 DCHECK_EQ(user_manager::USER_TYPE_PUBLIC_ACCOUNT, user_context.GetUserType());
585 585
586 current_state_.reset( 586 current_state_.reset(
587 new AuthAttemptState(user_context, 587 new AuthAttemptState(user_context,
588 false, // unlock 588 false, // unlock
589 false, // online_complete 589 false, // online_complete
590 false)); // user_is_new 590 false)); // user_is_new
591 remove_user_data_on_failure_ = false; 591 remove_user_data_on_failure_ = false;
592 ephemeral_mount_attempted_ = true; 592 ephemeral_mount_attempted_ = true;
593 StartMount(current_state_->AsWeakPtr(), 593 StartMount(current_state_->AsWeakPtr(),
594 scoped_refptr<CryptohomeAuthenticator>(this), true /* ephemeral */, 594 scoped_refptr<CryptohomeAuthenticator>(this), true /* ephemeral */,
595 true /* create_if_nonexistent */); 595 true /* create_if_nonexistent */);
596 } 596 }
597 597
598 void CryptohomeAuthenticator::LoginAsKioskAccount( 598 void CryptohomeAuthenticator::LoginAsKioskAccount(
599 const AccountId& app_account_id, 599 const AccountId& app_account_id,
600 bool use_guest_mount) { 600 bool use_guest_mount) {
601 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 601 DCHECK(task_runner_->RunsTasksInCurrentSequence());
602 602
603 const AccountId& account_id = 603 const AccountId& account_id =
604 use_guest_mount ? user_manager::GuestAccountId() : app_account_id; 604 use_guest_mount ? user_manager::GuestAccountId() : app_account_id;
605 current_state_.reset(new AuthAttemptState( 605 current_state_.reset(new AuthAttemptState(
606 UserContext(user_manager::USER_TYPE_KIOSK_APP, account_id), 606 UserContext(user_manager::USER_TYPE_KIOSK_APP, account_id),
607 false, // unlock 607 false, // unlock
608 false, // online_complete 608 false, // online_complete
609 false)); // user_is_new 609 false)); // user_is_new
610 610
611 remove_user_data_on_failure_ = true; 611 remove_user_data_on_failure_ = true;
612 if (!use_guest_mount) { 612 if (!use_guest_mount) {
613 MountPublic(current_state_->AsWeakPtr(), 613 MountPublic(current_state_->AsWeakPtr(),
614 scoped_refptr<CryptohomeAuthenticator>(this), 614 scoped_refptr<CryptohomeAuthenticator>(this),
615 cryptohome::CREATE_IF_MISSING); 615 cryptohome::CREATE_IF_MISSING);
616 } else { 616 } else {
617 ephemeral_mount_attempted_ = true; 617 ephemeral_mount_attempted_ = true;
618 MountGuestAndGetHash(current_state_->AsWeakPtr(), 618 MountGuestAndGetHash(current_state_->AsWeakPtr(),
619 scoped_refptr<CryptohomeAuthenticator>(this)); 619 scoped_refptr<CryptohomeAuthenticator>(this));
620 } 620 }
621 } 621 }
622 622
623 void CryptohomeAuthenticator::LoginAsArcKioskAccount( 623 void CryptohomeAuthenticator::LoginAsArcKioskAccount(
624 const AccountId& app_account_id) { 624 const AccountId& app_account_id) {
625 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 625 DCHECK(task_runner_->RunsTasksInCurrentSequence());
626 626
627 current_state_.reset(new AuthAttemptState( 627 current_state_.reset(new AuthAttemptState(
628 UserContext(user_manager::USER_TYPE_ARC_KIOSK_APP, app_account_id), 628 UserContext(user_manager::USER_TYPE_ARC_KIOSK_APP, app_account_id),
629 false, // unlock 629 false, // unlock
630 false, // online_complete 630 false, // online_complete
631 false)); // user_is_new 631 false)); // user_is_new
632 632
633 remove_user_data_on_failure_ = true; 633 remove_user_data_on_failure_ = true;
634 MountPublic(current_state_->AsWeakPtr(), 634 MountPublic(current_state_->AsWeakPtr(),
635 scoped_refptr<CryptohomeAuthenticator>(this), 635 scoped_refptr<CryptohomeAuthenticator>(this),
636 cryptohome::CREATE_IF_MISSING); 636 cryptohome::CREATE_IF_MISSING);
637 } 637 }
638 638
639 void CryptohomeAuthenticator::OnAuthSuccess() { 639 void CryptohomeAuthenticator::OnAuthSuccess() {
640 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 640 DCHECK(task_runner_->RunsTasksInCurrentSequence());
641 VLOG(1) << "Login success"; 641 VLOG(1) << "Login success";
642 // Send notification of success 642 // Send notification of success
643 chromeos::LoginEventRecorder::Get()->RecordAuthenticationSuccess(); 643 chromeos::LoginEventRecorder::Get()->RecordAuthenticationSuccess();
644 { 644 {
645 base::AutoLock for_this_block(success_lock_); 645 base::AutoLock for_this_block(success_lock_);
646 already_reported_success_ = true; 646 already_reported_success_ = true;
647 } 647 }
648 if (consumer_) 648 if (consumer_)
649 consumer_->OnAuthSuccess(current_state_->user_context); 649 consumer_->OnAuthSuccess(current_state_->user_context);
650 } 650 }
651 651
652 void CryptohomeAuthenticator::OnOffTheRecordAuthSuccess() { 652 void CryptohomeAuthenticator::OnOffTheRecordAuthSuccess() {
653 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 653 DCHECK(task_runner_->RunsTasksInCurrentSequence());
654 chromeos::LoginEventRecorder::Get()->RecordAuthenticationSuccess(); 654 chromeos::LoginEventRecorder::Get()->RecordAuthenticationSuccess();
655 if (consumer_) 655 if (consumer_)
656 consumer_->OnOffTheRecordAuthSuccess(); 656 consumer_->OnOffTheRecordAuthSuccess();
657 } 657 }
658 658
659 void CryptohomeAuthenticator::OnPasswordChangeDetected() { 659 void CryptohomeAuthenticator::OnPasswordChangeDetected() {
660 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 660 DCHECK(task_runner_->RunsTasksInCurrentSequence());
661 if (consumer_) 661 if (consumer_)
662 consumer_->OnPasswordChangeDetected(); 662 consumer_->OnPasswordChangeDetected();
663 } 663 }
664 664
665 void CryptohomeAuthenticator::OnOldEncryptionDetected( 665 void CryptohomeAuthenticator::OnOldEncryptionDetected(
666 bool has_incomplete_migration) { 666 bool has_incomplete_migration) {
667 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 667 DCHECK(task_runner_->RunsTasksInCurrentSequence());
668 if (consumer_) { 668 if (consumer_) {
669 consumer_->OnOldEncryptionDetected(current_state_->user_context, 669 consumer_->OnOldEncryptionDetected(current_state_->user_context,
670 has_incomplete_migration); 670 has_incomplete_migration);
671 } 671 }
672 } 672 }
673 673
674 void CryptohomeAuthenticator::OnAuthFailure(const AuthFailure& error) { 674 void CryptohomeAuthenticator::OnAuthFailure(const AuthFailure& error) {
675 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 675 DCHECK(task_runner_->RunsTasksInCurrentSequence());
676 676
677 // OnAuthFailure will be called again with the same |error| 677 // OnAuthFailure will be called again with the same |error|
678 // after the cryptohome has been removed. 678 // after the cryptohome has been removed.
679 if (remove_user_data_on_failure_) { 679 if (remove_user_data_on_failure_) {
680 delayed_login_failure_ = &error; 680 delayed_login_failure_ = &error;
681 RemoveEncryptedData(); 681 RemoveEncryptedData();
682 return; 682 return;
683 } 683 }
684 chromeos::LoginEventRecorder::Get()->RecordAuthenticationFailure(); 684 chromeos::LoginEventRecorder::Get()->RecordAuthenticationFailure();
685 LOGIN_LOG(ERROR) << "Login failed: " << error.GetErrorString(); 685 LOGIN_LOG(ERROR) << "Login failed: " << error.GetErrorString();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 void CryptohomeAuthenticator::OnUnmount(DBusMethodCallStatus call_status, 739 void CryptohomeAuthenticator::OnUnmount(DBusMethodCallStatus call_status,
740 bool success) { 740 bool success) {
741 if (call_status != DBUS_METHOD_CALL_SUCCESS || !success) { 741 if (call_status != DBUS_METHOD_CALL_SUCCESS || !success) {
742 // Maybe we should reboot immediately here? 742 // Maybe we should reboot immediately here?
743 LOGIN_LOG(ERROR) << "Couldn't unmount users home!"; 743 LOGIN_LOG(ERROR) << "Couldn't unmount users home!";
744 } 744 }
745 OnAuthFailure(AuthFailure(AuthFailure::OWNER_REQUIRED)); 745 OnAuthFailure(AuthFailure(AuthFailure::OWNER_REQUIRED));
746 } 746 }
747 747
748 void CryptohomeAuthenticator::Resolve() { 748 void CryptohomeAuthenticator::Resolve() {
749 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 749 DCHECK(task_runner_->RunsTasksInCurrentSequence());
750 bool create_if_nonexistent = false; 750 bool create_if_nonexistent = false;
751 CryptohomeAuthenticator::AuthState state = ResolveState(); 751 CryptohomeAuthenticator::AuthState state = ResolveState();
752 VLOG(1) << "Resolved state to: " << state; 752 VLOG(1) << "Resolved state to: " << state;
753 switch (state) { 753 switch (state) {
754 case CONTINUE: 754 case CONTINUE:
755 case POSSIBLE_PW_CHANGE: 755 case POSSIBLE_PW_CHANGE:
756 case NO_MOUNT: 756 case NO_MOUNT:
757 // These are intermediate states; we need more info from a request that 757 // These are intermediate states; we need more info from a request that
758 // is still pending. 758 // is still pending.
759 break; 759 break;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 default: 882 default:
883 NOTREACHED(); 883 NOTREACHED();
884 break; 884 break;
885 } 885 }
886 } 886 }
887 887
888 CryptohomeAuthenticator::~CryptohomeAuthenticator() { 888 CryptohomeAuthenticator::~CryptohomeAuthenticator() {
889 } 889 }
890 890
891 CryptohomeAuthenticator::AuthState CryptohomeAuthenticator::ResolveState() { 891 CryptohomeAuthenticator::AuthState CryptohomeAuthenticator::ResolveState() {
892 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 892 DCHECK(task_runner_->RunsTasksInCurrentSequence());
893 // If we haven't mounted the user's home dir yet or 893 // If we haven't mounted the user's home dir yet or
894 // haven't got sanitized username value, we can't be done. 894 // haven't got sanitized username value, we can't be done.
895 // We never get past here if any of these two cryptohome ops is still pending. 895 // We never get past here if any of these two cryptohome ops is still pending.
896 // This is an important invariant. 896 // This is an important invariant.
897 if (!current_state_->cryptohome_complete() || 897 if (!current_state_->cryptohome_complete() ||
898 !current_state_->username_hash_obtained()) { 898 !current_state_->username_hash_obtained()) {
899 return CONTINUE; 899 return CONTINUE;
900 } 900 }
901 901
902 AuthState state = CONTINUE; 902 AuthState state = CONTINUE;
(...skipping 25 matching lines...) Expand all
928 return ResolveOnlineSuccessState(state); 928 return ResolveOnlineSuccessState(state);
929 } 929 }
930 NOTREACHED() << "Using obsolete ClientLogin code path."; 930 NOTREACHED() << "Using obsolete ClientLogin code path.";
931 } 931 }
932 // if online isn't complete yet, just return the offline result. 932 // if online isn't complete yet, just return the offline result.
933 return state; 933 return state;
934 } 934 }
935 935
936 CryptohomeAuthenticator::AuthState 936 CryptohomeAuthenticator::AuthState
937 CryptohomeAuthenticator::ResolveCryptohomeFailureState() { 937 CryptohomeAuthenticator::ResolveCryptohomeFailureState() {
938 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 938 DCHECK(task_runner_->RunsTasksInCurrentSequence());
939 if (remove_attempted_ || resync_attempted_) 939 if (remove_attempted_ || resync_attempted_)
940 return FAILED_REMOVE; 940 return FAILED_REMOVE;
941 if (ephemeral_mount_attempted_) 941 if (ephemeral_mount_attempted_)
942 return FAILED_TMPFS; 942 return FAILED_TMPFS;
943 if (migrate_attempted_) 943 if (migrate_attempted_)
944 return NEED_OLD_PW; 944 return NEED_OLD_PW;
945 if (check_key_attempted_) 945 if (check_key_attempted_)
946 return LOGIN_FAILED; 946 return LOGIN_FAILED;
947 947
948 if (current_state_->cryptohome_code() == 948 if (current_state_->cryptohome_code() ==
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 } 980 }
981 981
982 if (!current_state_->username_hash_valid()) 982 if (!current_state_->username_hash_valid())
983 return FAILED_USERNAME_HASH; 983 return FAILED_USERNAME_HASH;
984 984
985 return FAILED_MOUNT; 985 return FAILED_MOUNT;
986 } 986 }
987 987
988 CryptohomeAuthenticator::AuthState 988 CryptohomeAuthenticator::AuthState
989 CryptohomeAuthenticator::ResolveCryptohomeSuccessState() { 989 CryptohomeAuthenticator::ResolveCryptohomeSuccessState() {
990 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 990 DCHECK(task_runner_->RunsTasksInCurrentSequence());
991 if (resync_attempted_) 991 if (resync_attempted_)
992 return CREATE_NEW; 992 return CREATE_NEW;
993 if (remove_attempted_) 993 if (remove_attempted_)
994 return REMOVED_DATA_AFTER_FAILURE; 994 return REMOVED_DATA_AFTER_FAILURE;
995 if (migrate_attempted_) 995 if (migrate_attempted_)
996 return RECOVER_MOUNT; 996 return RECOVER_MOUNT;
997 if (check_key_attempted_) 997 if (check_key_attempted_)
998 return UNLOCK; 998 return UNLOCK;
999 999
1000 const user_manager::UserType user_type = 1000 const user_manager::UserType user_type =
1001 current_state_->user_context.GetUserType(); 1001 current_state_->user_context.GetUserType();
1002 if (user_type == user_manager::USER_TYPE_GUEST) 1002 if (user_type == user_manager::USER_TYPE_GUEST)
1003 return GUEST_LOGIN; 1003 return GUEST_LOGIN;
1004 if (user_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT) 1004 if (user_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT)
1005 return PUBLIC_ACCOUNT_LOGIN; 1005 return PUBLIC_ACCOUNT_LOGIN;
1006 if (user_type == user_manager::USER_TYPE_KIOSK_APP) 1006 if (user_type == user_manager::USER_TYPE_KIOSK_APP)
1007 return KIOSK_ACCOUNT_LOGIN; 1007 return KIOSK_ACCOUNT_LOGIN;
1008 if (user_type == user_manager::USER_TYPE_SUPERVISED) 1008 if (user_type == user_manager::USER_TYPE_SUPERVISED)
1009 return SUPERVISED_USER_LOGIN; 1009 return SUPERVISED_USER_LOGIN;
1010 1010
1011 if (!VerifyOwner()) 1011 if (!VerifyOwner())
1012 return CONTINUE; 1012 return CONTINUE;
1013 return user_can_login_ ? OFFLINE_LOGIN : OWNER_REQUIRED; 1013 return user_can_login_ ? OFFLINE_LOGIN : OWNER_REQUIRED;
1014 } 1014 }
1015 1015
1016 CryptohomeAuthenticator::AuthState 1016 CryptohomeAuthenticator::AuthState
1017 CryptohomeAuthenticator::ResolveOnlineSuccessState( 1017 CryptohomeAuthenticator::ResolveOnlineSuccessState(
1018 CryptohomeAuthenticator::AuthState offline_state) { 1018 CryptohomeAuthenticator::AuthState offline_state) {
1019 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 1019 DCHECK(task_runner_->RunsTasksInCurrentSequence());
1020 switch (offline_state) { 1020 switch (offline_state) {
1021 case POSSIBLE_PW_CHANGE: 1021 case POSSIBLE_PW_CHANGE:
1022 return NEED_OLD_PW; 1022 return NEED_OLD_PW;
1023 case NO_MOUNT: 1023 case NO_MOUNT:
1024 return CREATE_NEW; 1024 return CREATE_NEW;
1025 case OFFLINE_LOGIN: 1025 case OFFLINE_LOGIN:
1026 return ONLINE_LOGIN; 1026 return ONLINE_LOGIN;
1027 default: 1027 default:
1028 NOTREACHED(); 1028 NOTREACHED();
1029 return offline_state; 1029 return offline_state;
1030 } 1030 }
1031 } 1031 }
1032 1032
1033 void CryptohomeAuthenticator::ResolveLoginCompletionStatus() { 1033 void CryptohomeAuthenticator::ResolveLoginCompletionStatus() {
1034 // Shortcut online state resolution process. 1034 // Shortcut online state resolution process.
1035 current_state_->RecordOnlineLoginStatus(AuthFailure::AuthFailureNone()); 1035 current_state_->RecordOnlineLoginStatus(AuthFailure::AuthFailureNone());
1036 Resolve(); 1036 Resolve();
1037 } 1037 }
1038 1038
1039 void CryptohomeAuthenticator::SetOwnerState(bool owner_check_finished, 1039 void CryptohomeAuthenticator::SetOwnerState(bool owner_check_finished,
1040 bool check_result) { 1040 bool check_result) {
1041 owner_is_verified_ = owner_check_finished; 1041 owner_is_verified_ = owner_check_finished;
1042 user_can_login_ = check_result; 1042 user_can_login_ = check_result;
1043 } 1043 }
1044 1044
1045 } // namespace chromeos 1045 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/login/auth/login_performer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698