aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2015-12-16 13:45:35 -0800
committerVitaly Buka <vitalybuka@google.com>2015-12-17 00:28:21 +0000
commit483d5970e88b56442f19baea841f6af75b5a0006 (patch)
tree6826076156c2d6b6d6b7c0c38a36e3975ccbc52f
parent3264eca548566ffc0bddf43204537351bde6ede7 (diff)
downloadlibweave-483d5970e88b56442f19baea841f6af75b5a0006.tar.gz
Add 'sessionId' into privet/info
Current implementation is a Unix timestamp plus counter. BUG=26140026 Change-Id: Idfe0aa81c49e6dab5d638cbedfbeb460b70b5864 Reviewed-on: https://weave-review.googlesource.com/2010 Reviewed-by: Alex Vakulenko <avakulenko@google.com>
-rw-r--r--src/privet/auth_manager.cc13
-rw-r--r--src/privet/auth_manager.h3
-rw-r--r--src/privet/mock_delegates.h2
-rw-r--r--src/privet/privet_handler.cc3
-rw-r--r--src/privet/privet_handler_unittest.cc6
-rw-r--r--src/privet/security_delegate.h2
-rw-r--r--src/privet/security_manager.cc4
-rw-r--r--src/privet/security_manager.h2
8 files changed, 31 insertions, 4 deletions
diff --git a/src/privet/auth_manager.cc b/src/privet/auth_manager.cc
index 62a640f..51d7592 100644
--- a/src/privet/auth_manager.cc
+++ b/src/privet/auth_manager.cc
@@ -27,6 +27,12 @@ const size_t kCaveatBuffetSize = 32;
const size_t kMaxMacaroonSize = 1024;
const size_t kMaxPendingClaims = 10;
+template <class T>
+void AppendToArray(T value, std::vector<uint8_t>* array) {
+ auto begin = reinterpret_cast<const uint8_t*>(&value);
+ array->insert(array->end(), begin, begin + sizeof(value));
+}
+
// Returns "scope:id:time".
std::string CreateTokenData(const UserInfo& user_info, const base::Time& time) {
return base::IntToString(static_cast<int>(user_info.scope())) +
@@ -230,5 +236,12 @@ bool AuthManager::IsValidAuthToken(const std::vector<uint8_t>& token) const {
return uw_macaroon_verify_(&macaroon, secret_.data(), secret_.size());
}
+std::vector<uint8_t> AuthManager::CreateSessionId() {
+ std::vector<uint8_t> result;
+ AppendToArray(Now().ToTimeT(), &result);
+ AppendToArray(++session_counter_, &result);
+ return result;
+}
+
} // namespace privet
} // namespace weave
diff --git a/src/privet/auth_manager.h b/src/privet/auth_manager.h
index 44b8bca..a74e43b 100644
--- a/src/privet/auth_manager.h
+++ b/src/privet/auth_manager.h
@@ -55,10 +55,13 @@ class AuthManager {
void SetSecret(const std::vector<uint8_t>& secret,
RootClientTokenOwner owner);
+ std::vector<uint8_t> CreateSessionId();
+
private:
Config* config_{nullptr};
base::DefaultClock default_clock_;
base::Clock* clock_{&default_clock_};
+ uint32_t session_counter_{0};
std::vector<uint8_t> secret_;
std::vector<uint8_t> certificate_fingerprint_;
diff --git a/src/privet/mock_delegates.h b/src/privet/mock_delegates.h
index de94fe9..8cede23 100644
--- a/src/privet/mock_delegates.h
+++ b/src/privet/mock_delegates.h
@@ -80,6 +80,7 @@ class MockSecurityDelegate : public SecurityDelegate {
std::string*,
ErrorPtr*));
MOCK_METHOD2(CancelPairing, bool(const std::string&, ErrorPtr*));
+ MOCK_METHOD0(CreateSessionId, std::string());
MockSecurityDelegate() {
EXPECT_CALL(*this, CreateAccessToken(_))
@@ -114,6 +115,7 @@ class MockSecurityDelegate : public SecurityDelegate {
.WillRepeatedly(DoAll(SetArgPointee<2>("testFingerprint"),
SetArgPointee<3>("testSignature"), Return(true)));
EXPECT_CALL(*this, CancelPairing(_, _)).WillRepeatedly(Return(true));
+ EXPECT_CALL(*this, CreateSessionId()).WillRepeatedly(Return("SessionId"));
}
};
diff --git a/src/privet/privet_handler.cc b/src/privet/privet_handler.cc
index 57c8633..d7e68bb 100644
--- a/src/privet/privet_handler.cc
+++ b/src/privet/privet_handler.cc
@@ -69,8 +69,8 @@ const char kInfoAuthAnonymousMaxScopeKey[] = "anonymousMaxScope";
const char kInfoWifiCapabilitiesKey[] = "capabilities";
const char kInfoWifiSsidKey[] = "ssid";
const char kInfoWifiHostedSsidKey[] = "hostedSsid";
-
const char kInfoTimeKey[] = "time";
+const char kInfoSessionIdKey[] = "sessionId";
const char kPairingKey[] = "pairing";
const char kPairingSessionIdKey[] = "sessionId";
@@ -607,6 +607,7 @@ void PrivetHandler::HandleInfo(const base::DictionaryValue&,
output.Set(kGcdKey, CreateGcdSection(*cloud_).release());
output.SetDouble(kInfoTimeKey, clock_->Now().ToJsTime());
+ output.SetString(kInfoSessionIdKey, security_->CreateSessionId());
callback.Run(http::kOk, output);
}
diff --git a/src/privet/privet_handler_unittest.cc b/src/privet/privet_handler_unittest.cc
index fcbd0d0..c4180b9 100644
--- a/src/privet/privet_handler_unittest.cc
+++ b/src/privet/privet_handler_unittest.cc
@@ -247,7 +247,8 @@ TEST_F(PrivetHandlerTest, InfoMinimal) {
'id': '',
'status': 'disabled'
},
- 'time': 1410000001000.0
+ 'time': 1410000001000.0,
+ 'sessionId': 'SessionId'
})";
EXPECT_JSON_EQ(kExpected, HandleRequest("/privet/info", "{}"));
}
@@ -308,7 +309,8 @@ TEST_F(PrivetHandlerTest, Info) {
'id': 'TestCloudId',
'status': 'online'
},
- 'time': 1410000001000.0
+ 'time': 1410000001000.0,
+ 'sessionId': 'SessionId'
})";
EXPECT_JSON_EQ(kExpected, HandleRequest("/privet/info", "{}"));
}
diff --git a/src/privet/security_delegate.h b/src/privet/security_delegate.h
index 54f957d..d8090bd 100644
--- a/src/privet/security_delegate.h
+++ b/src/privet/security_delegate.h
@@ -60,6 +60,8 @@ class SecurityDelegate {
virtual bool CancelPairing(const std::string& session_id,
ErrorPtr* error) = 0;
+
+ virtual std::string CreateSessionId() = 0;
};
} // namespace privet
diff --git a/src/privet/security_manager.cc b/src/privet/security_manager.cc
index d2025b1..46212f4 100644
--- a/src/privet/security_manager.cc
+++ b/src/privet/security_manager.cc
@@ -317,6 +317,10 @@ bool SecurityManager::CancelPairing(const std::string& session_id,
return false;
}
+std::string SecurityManager::CreateSessionId() {
+ return Base64Encode(auth_manager_->CreateSessionId());
+}
+
void SecurityManager::RegisterPairingListeners(
const PairingStartListener& on_start,
const PairingEndListener& on_end) {
diff --git a/src/privet/security_manager.h b/src/privet/security_manager.h
index 93618d2..2505099 100644
--- a/src/privet/security_manager.h
+++ b/src/privet/security_manager.h
@@ -69,7 +69,6 @@ class SecurityManager : public SecurityDelegate {
bool ConfirmClientAuthToken(const std::string& token,
ErrorPtr* error) override;
bool IsValidPairingCode(const std::string& auth_code) const override;
-
bool StartPairing(PairingType mode,
CryptoType crypto,
std::string* session_id,
@@ -82,6 +81,7 @@ class SecurityManager : public SecurityDelegate {
std::string* signature,
ErrorPtr* error) override;
bool CancelPairing(const std::string& session_id, ErrorPtr* error) override;
+ std::string CreateSessionId() override;
void RegisterPairingListeners(const PairingStartListener& on_start,
const PairingEndListener& on_end);