#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_EXTENDED_AUTHENTICATOR_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_EXTENDED_AUTHENTICATOR_H_
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/login/user.h"
#include "chromeos/cryptohome/cryptohome_parameters.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace chromeos {
class LoginStatusConsumer;
class ExtendedAuthenticator
: public base::RefCountedThreadSafe<ExtendedAuthenticator> {
public:
enum AuthState {
SUCCESS,
NO_MOUNT,
FAILED_MOUNT,
FAILED_TPM,
};
typedef base::Callback<void(const std::string& hash)> HashSuccessCallback;
typedef base::Callback<void(const UserContext& context)> ContextCallback;
class AuthStatusConsumer {
public:
virtual ~AuthStatusConsumer() {}
virtual void OnAuthenticationFailure(AuthState state) = 0;
};
explicit ExtendedAuthenticator(AuthStatusConsumer* consumer);
explicit ExtendedAuthenticator(LoginStatusConsumer* consumer);
void SetConsumer(LoginStatusConsumer* consumer);
void AuthenticateToMount(const UserContext& context,
const HashSuccessCallback& success_callback);
void AuthenticateToCheck(const UserContext& context,
const base::Closure& success_callback);
void CreateMount(const std::string& user_id,
const std::vector<cryptohome::KeyDefinition>& keys,
const HashSuccessCallback& success_callback);
void HashPasswordWithSalt(const std::string& password,
const HashSuccessCallback& success_callback);
void AddKey(const UserContext& context,
const cryptohome::KeyDefinition& key,
bool replace_existing,
const base::Closure& success_callback);
void UpdateKeyAuthorized(const UserContext& context,
const cryptohome::KeyDefinition& key,
const std::string& signature,
const base::Closure& success_callback);
void RemoveKey(const UserContext& context,
const std::string& key_to_remove,
const base::Closure& success_callback);
void TransformContext(const UserContext& user_context,
const ContextCallback& callback);
private:
friend class base::RefCountedThreadSafe<ExtendedAuthenticator>;
~ExtendedAuthenticator();
typedef base::Callback<void(const std::string& system_salt)>
PendingHashCallback;
void OnSaltObtained(const std::string& system_salt);
void UpdateContextToMount(const UserContext& context,
const std::string& hashed_password);
void UpdateContextAndCheckKey(const UserContext& context,
const std::string& hashed_password);
void DoAuthenticateToMount(const HashSuccessCallback& success_callback,
const UserContext& context);
void DoAuthenticateToCheck(const base::Closure& success_callback,
const UserContext& context);
void DoAddKey(const cryptohome::KeyDefinition& key,
bool replace_existing,
const base::Closure& success_callback,
const UserContext& context);
void DoUpdateKeyAuthorized(const cryptohome::KeyDefinition& key,
const std::string& signature,
const base::Closure& success_callback,
const UserContext& context);
void DoRemoveKey(const std::string& key_to_remove,
const base::Closure& success_callback,
const UserContext& context);
void OnMountComplete(const std::string& time_marker,
const UserContext& context,
const HashSuccessCallback& success_callback,
bool success,
cryptohome::MountError return_code,
const std::string& mount_hash);
void OnOperationComplete(const std::string& time_marker,
const UserContext& context,
const base::Closure& success_callback,
bool success,
cryptohome::MountError return_code);
void DoHashWithSalt(const std::string& password,
const HashSuccessCallback& callback,
const std::string& system_salt);
void DidTransformContext(const UserContext& user_context,
const ContextCallback& callback,
const std::string& hashed_password);
bool salt_obtained_;
std::string system_salt_;
std::vector<PendingHashCallback> hashing_queue_;
AuthStatusConsumer* consumer_;
LoginStatusConsumer* old_consumer_;
DISALLOW_COPY_AND_ASSIGN(ExtendedAuthenticator);
};
}
#endif