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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_LOGIN_AUTH_EXTENDED_AUTHENTICATOR_IMPL_H_
6 #define CHROMEOS_LOGIN_AUTH_EXTENDED_AUTHENTICATOR_IMPL_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/login/auth/extended_authenticator.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
20 class AuthStatusConsumer;
23 // Implements ExtendedAuthenticator.
24 class CHROMEOS_EXPORT ExtendedAuthenticatorImpl : public ExtendedAuthenticator {
26 explicit ExtendedAuthenticatorImpl(NewAuthStatusConsumer* consumer);
27 explicit ExtendedAuthenticatorImpl(AuthStatusConsumer* consumer);
29 // ExtendedAuthenticator:
30 virtual void SetConsumer(AuthStatusConsumer* consumer) override;
31 virtual void AuthenticateToMount(
32 const UserContext& context,
33 const ResultCallback& success_callback) override;
34 virtual void AuthenticateToCheck(
35 const UserContext& context,
36 const base::Closure& success_callback) override;
37 virtual void CreateMount(const std::string& user_id,
38 const std::vector<cryptohome::KeyDefinition>& keys,
39 const ResultCallback& success_callback) override;
40 virtual void AddKey(const UserContext& context,
41 const cryptohome::KeyDefinition& key,
42 bool replace_existing,
43 const base::Closure& success_callback) override;
44 virtual void UpdateKeyAuthorized(
45 const UserContext& context,
46 const cryptohome::KeyDefinition& key,
47 const std::string& signature,
48 const base::Closure& success_callback) override;
49 virtual void RemoveKey(const UserContext& context,
50 const std::string& key_to_remove,
51 const base::Closure& success_callback) override;
52 virtual void TransformKeyIfNeeded(const UserContext& user_context,
53 const ContextCallback& callback) override;
56 virtual ~ExtendedAuthenticatorImpl();
58 // Callback for system salt getter.
59 void OnSaltObtained(const std::string& system_salt);
61 // Performs actual operation with fully configured |context|.
62 void DoAuthenticateToMount(const ResultCallback& success_callback,
63 const UserContext& context);
64 void DoAuthenticateToCheck(const base::Closure& success_callback,
65 const UserContext& context);
66 void DoAddKey(const cryptohome::KeyDefinition& key,
67 bool replace_existing,
68 const base::Closure& success_callback,
69 const UserContext& context);
70 void DoUpdateKeyAuthorized(const cryptohome::KeyDefinition& key,
71 const std::string& signature,
72 const base::Closure& success_callback,
73 const UserContext& context);
74 void DoRemoveKey(const std::string& key_to_remove,
75 const base::Closure& success_callback,
76 const UserContext& context);
78 // Inner operation callbacks.
79 void OnMountComplete(const std::string& time_marker,
80 const UserContext& context,
81 const ResultCallback& success_callback,
83 cryptohome::MountError return_code,
84 const std::string& mount_hash);
85 void OnOperationComplete(const std::string& time_marker,
86 const UserContext& context,
87 const base::Closure& success_callback,
89 cryptohome::MountError return_code);
92 std::string system_salt_;
93 std::vector<base::Closure> system_salt_callbacks_;
95 NewAuthStatusConsumer* consumer_;
96 AuthStatusConsumer* old_consumer_;
98 DISALLOW_COPY_AND_ASSIGN(ExtendedAuthenticatorImpl);
101 } // namespace chromeos
103 #endif // CHROMEOS_LOGIN_AUTH_EXTENDED_AUTHENTICATOR_IMPL_H_