// Copyright 2015 The Weave Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef LIBWEAVE_SRC_PRIVET_AUTH_MANAGER_H_ #define LIBWEAVE_SRC_PRIVET_AUTH_MANAGER_H_ #include #include #include #include #include #include #include "src/privet/privet_types.h" namespace weave { class Config; enum class RootClientTokenOwner; namespace privet { class AuthManager { public: AuthManager(Config* config, const std::vector& certificate_fingerprint); // Constructor for tests. AuthManager(const std::vector& auth_secret, const std::vector& certificate_fingerprint, const std::vector& access_secret, base::Clock* clock = nullptr); ~AuthManager(); std::vector CreateAccessToken(const UserInfo& user_info, base::TimeDelta ttl) const; bool ParseAccessToken(const std::vector& token, UserInfo* user_info, ErrorPtr* error) const; const std::vector& GetAuthSecret() const { return auth_secret_; } const std::vector& GetAccessSecret() const { return access_secret_; } const std::vector& GetCertificateFingerprint() const { return certificate_fingerprint_; } base::Time Now() const; std::vector ClaimRootClientAuthToken(RootClientTokenOwner owner, ErrorPtr* error); bool ConfirmClientAuthToken(const std::vector& token, ErrorPtr* error); std::vector GetRootClientAuthToken() const; bool IsValidAuthToken(const std::vector& token, ErrorPtr* error) const; bool CreateAccessTokenFromAuth(const std::vector& auth_token, base::TimeDelta ttl, std::vector* access_token, AuthScope* access_token_scope, base::TimeDelta* access_token_ttl, ErrorPtr* error) const; void SetAuthSecret(const std::vector& secret, RootClientTokenOwner owner); std::vector CreateSessionId(); private: Config* config_{nullptr}; // Can be nullptr for tests. base::DefaultClock default_clock_; base::Clock* clock_{&default_clock_}; uint32_t session_counter_{0}; std::vector auth_secret_; // Persistent. std::vector certificate_fingerprint_; std::vector access_secret_; // New on every reboot. std::deque, RootClientTokenOwner>> pending_claims_; DISALLOW_COPY_AND_ASSIGN(AuthManager); }; } // namespace privet } // namespace weave #endif // LIBWEAVE_SRC_PRIVET_AUTH_MANAGER_H_