aboutsummaryrefslogtreecommitdiff
path: root/src/privet/auth_manager.cc
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2015-12-09 20:04:34 -0800
committerVitaly Buka <vitalybuka@google.com>2015-12-10 18:54:12 +0000
commit41aa8090265b73876da7b99b5d246b4a64fe0474 (patch)
tree0210143a2204b2a339a8c3f2289e8e27f022c8c0 /src/privet/auth_manager.cc
parentece713e1f51b6d9e7afda725ae258dc7e12f8c90 (diff)
downloadlibweave-41aa8090265b73876da7b99b5d246b4a64fe0474.tar.gz
Use base::Clock in AuthManager for better testing
Change-Id: Ifbb23e4da565a1c86ff728803d2e07e3f8c3b1f4 Reviewed-on: https://weave-review.googlesource.com/1873 Reviewed-by: Alex Vakulenko <avakulenko@google.com>
Diffstat (limited to 'src/privet/auth_manager.cc')
-rw-r--r--src/privet/auth_manager.cc21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/privet/auth_manager.cc b/src/privet/auth_manager.cc
index be7e971..49ef787 100644
--- a/src/privet/auth_manager.cc
+++ b/src/privet/auth_manager.cc
@@ -74,8 +74,11 @@ class Caveat {
} // namespace
AuthManager::AuthManager(const std::vector<uint8_t>& secret,
- const std::vector<uint8_t>& certificate_fingerprint)
- : secret_{secret}, certificate_fingerprint_{certificate_fingerprint} {
+ const std::vector<uint8_t>& certificate_fingerprint,
+ base::Clock* clock)
+ : clock_{clock ? clock : &default_clock_},
+ secret_{secret},
+ certificate_fingerprint_{certificate_fingerprint} {
if (secret_.size() != kSha256OutputSize) {
secret_.resize(kSha256OutputSize);
base::RandBytes(secret_.data(), secret_.size());
@@ -85,9 +88,8 @@ AuthManager::AuthManager(const std::vector<uint8_t>& secret,
AuthManager::~AuthManager() {}
// Returns "[hmac]scope:id:time".
-std::vector<uint8_t> AuthManager::CreateAccessToken(const UserInfo& user_info,
- const base::Time& time) {
- std::string data_str{CreateTokenData(user_info, time)};
+std::vector<uint8_t> AuthManager::CreateAccessToken(const UserInfo& user_info) {
+ std::string data_str{CreateTokenData(user_info, Now())};
std::vector<uint8_t> data{data_str.begin(), data_str.end()};
std::vector<uint8_t> hash{HmacSha256(secret_, data)};
hash.insert(hash.end(), data.begin(), data.end());
@@ -106,11 +108,10 @@ UserInfo AuthManager::ParseAccessToken(const std::vector<uint8_t>& token,
return SplitTokenData(std::string(data.begin(), data.end()), time);
}
-std::vector<uint8_t> AuthManager::GetRootDeviceToken(
- const base::Time& time) const {
+std::vector<uint8_t> AuthManager::GetRootDeviceToken() const {
Caveat scope{kUwMacaroonCaveatTypeScope, kUwMacaroonCaveatScopeTypeOwner};
Caveat issued{kUwMacaroonCaveatTypeIssued,
- static_cast<uint32_t>(time.ToTimeT())};
+ static_cast<uint32_t>(Now().ToTimeT())};
UwMacaroonCaveat caveats[] = {
scope.GetCaveat(), issued.GetCaveat(),
@@ -127,5 +128,9 @@ std::vector<uint8_t> AuthManager::GetRootDeviceToken(
return token;
}
+base::Time AuthManager::Now() const {
+ return clock_->Now();
+}
+
} // namespace privet
} // namespace weave