Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Unified Diff: extensions/browser/api/cast_channel/cast_socket.cc

Issue 2709523008: [Cast Channel] Add support for nonce challenge to Cast channel authentication. (Closed)
Patch Set: Addresses comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/cast_channel/cast_socket.cc
diff --git a/extensions/browser/api/cast_channel/cast_socket.cc b/extensions/browser/api/cast_channel/cast_socket.cc
index 3bb675cf3fd9f74b4424d13044a8cf14ba0d7d99..6ba7e934bd8a75b772053c76f0ecca59dda49bf7 100644
--- a/extensions/browser/api/cast_channel/cast_socket.cc
+++ b/extensions/browser/api/cast_channel/cast_socket.cc
@@ -12,6 +12,7 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/format_macros.h"
+#include "base/guid.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
@@ -73,6 +74,8 @@ namespace api {
namespace cast_channel {
namespace {
+long kNonceExpirationTimeInHours = 24;
+
bool IsTerminalState(proto::ConnectionState state) {
return state == proto::CONN_STATE_FINISHED ||
state == proto::CONN_STATE_ERROR || state == proto::CONN_STATE_TIMEOUT;
@@ -98,6 +101,22 @@ class FakeCertVerifier : public net::CertVerifier {
} // namespace
+// static
+std::string CastSocketImpl::nonce_ = "";
mark a. foltz 2017/03/03 23:25:51 Static variables must be POD (with a few exception
ryanchung 2017/03/06 22:57:46 Done. Thanks.
+// static
+base::Time CastSocketImpl::nonce_generation_time_ = base::Time();
+
+// static
+void CastSocketImpl::EnsureNonceTimely() {
+ if (nonce_.empty() ||
+ base::Time::Now() >
+ (nonce_generation_time_ +
+ base::TimeDelta::FromHours(kNonceExpirationTimeInHours))) {
+ nonce_ = base::GenerateGUID();
mark a. foltz 2017/03/03 23:25:51 I thought there was a different nonce for each att
ryanchung 2017/03/06 22:57:46 Ideally, each connection attempt uses a difference
+ nonce_generation_time_ = base::Time::Now();
+ }
+}
+
CastSocket::CastSocket(const std::string& owner_extension_id)
: ApiResource(owner_extension_id) {
}
@@ -134,6 +153,7 @@ CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id,
DCHECK(net_log_);
net_log_source_.type = net::NetLogSourceType::SOCKET;
net_log_source_.id = net_log_->NextID();
+ EnsureNonceTimely();
}
CastSocketImpl::~CastSocketImpl() {
@@ -235,7 +255,7 @@ bool CastSocketImpl::VerifyChannelPolicy(const AuthResult& result) {
bool CastSocketImpl::VerifyChallengeReply() {
DCHECK(peer_cert_);
AuthResult result =
- AuthenticateChallengeReply(*challenge_reply_, *peer_cert_);
+ AuthenticateChallengeReply(*challenge_reply_, *peer_cert_, nonce_);
logger_->LogSocketChallengeReplyEvent(channel_id_, result);
if (result.success()) {
VLOG(1) << result.error_message;
@@ -450,7 +470,7 @@ int CastSocketImpl::DoAuthChallengeSend() {
SetConnectState(proto::CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE);
CastMessage challenge_message;
- CreateAuthChallengeMessage(&challenge_message);
+ CreateAuthChallengeMessage(&challenge_message, nonce_);
VLOG_WITH_CONNECTION(1) << "Sending challenge: "
<< CastMessageToString(challenge_message);
@@ -618,6 +638,7 @@ void CastSocketImpl::SetErrorState(ChannelError error_state) {
logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_));
delegate_->OnError(error_state_);
}
+
} // namespace cast_channel
} // namespace api
} // namespace extensions
« no previous file with comments | « extensions/browser/api/cast_channel/cast_socket.h ('k') | extensions/browser/api/cast_channel/cast_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698