Commit 9d04deed authored by dougsteed's avatar dougsteed Committed by Commit bot

Limit lifetime of self-signed certificate used for TLS on Cast channel

BUG=428920

R=mfoltz@chromium.org

Review URL: https://codereview.chromium.org/694123002

Cr-Commit-Position: refs/heads/master@{#308288}
parent 1e043393
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/sys_byteorder.h" #include "base/sys_byteorder.h"
#include "base/time/time.h"
#include "extensions/browser/api/cast_channel/cast_auth_util.h" #include "extensions/browser/api/cast_channel/cast_auth_util.h"
#include "extensions/browser/api/cast_channel/cast_framer.h" #include "extensions/browser/api/cast_channel/cast_framer.h"
#include "extensions/browser/api/cast_channel/cast_message_util.h" #include "extensions/browser/api/cast_channel/cast_message_util.h"
...@@ -49,6 +50,18 @@ namespace { ...@@ -49,6 +50,18 @@ namespace {
// after 9 failed probes. So the total idle time before close is 10 * // after 9 failed probes. So the total idle time before close is 10 *
// kTcpKeepAliveDelaySecs. // kTcpKeepAliveDelaySecs.
const int kTcpKeepAliveDelaySecs = 10; const int kTcpKeepAliveDelaySecs = 10;
const int kMaxSelfSignedCertLifetimeInDays = 2;
std::string FormatTimeForLogging(base::Time time) {
base::Time::Exploded exploded;
time.UTCExplode(&exploded);
return base::StringPrintf(
"%04d-%02d-%02d %02d:%02d:%02d.%03d UTC", exploded.year, exploded.month,
exploded.day_of_month, exploded.hour, exploded.minute, exploded.second,
exploded.millisecond);
}
} // namespace } // namespace
namespace extensions { namespace extensions {
...@@ -177,11 +190,25 @@ bool CastSocketImpl::ExtractPeerCert(std::string* cert) { ...@@ -177,11 +190,25 @@ bool CastSocketImpl::ExtractPeerCert(std::string* cert) {
logger_->LogSocketEvent(channel_id_, proto::SSL_INFO_OBTAINED); logger_->LogSocketEvent(channel_id_, proto::SSL_INFO_OBTAINED);
// Ensure that the peer cert (which is self-signed) doesn't have an excessive
// life-time (i.e. no more than 2 days).
base::Time expiry = ssl_info.cert->valid_expiry();
base::Time lifetimeLimit =
base::Time::Now() +
base::TimeDelta::FromDays(kMaxSelfSignedCertLifetimeInDays);
if (expiry.is_null() || expiry > lifetimeLimit) {
std::string details = FormatTimeForLogging(expiry);
details += " " + ip_endpoint().ToString();
LOG(ERROR) << "Peer cert has excessive lifetime. details=" << details;
logger_->LogSocketEventWithDetails(
channel_id_, proto::SSL_CERT_EXCESSIVE_LIFETIME, details);
return false;
}
bool result = net::X509Certificate::GetDEREncoded( bool result = net::X509Certificate::GetDEREncoded(
ssl_info.cert->os_cert_handle(), cert); ssl_info.cert->os_cert_handle(), cert);
if (result) { if (result) {
VLOG_WITH_CONNECTION(1) << "Successfully extracted peer certificate: " VLOG_WITH_CONNECTION(1) << "Successfully extracted peer certificate";
<< *cert;
} }
logger_->LogSocketEventWithRv( logger_->LogSocketEventWithRv(
......
...@@ -35,6 +35,7 @@ enum EventType { ...@@ -35,6 +35,7 @@ enum EventType {
NOTIFY_ON_MESSAGE = 23; // Message NOTIFY_ON_MESSAGE = 23; // Message
NOTIFY_ON_ERROR = 24; NOTIFY_ON_ERROR = 24;
SOCKET_CLOSED = 25; SOCKET_CLOSED = 25;
SSL_CERT_EXCESSIVE_LIFETIME = 26;
} }
enum ChannelAuth { enum ChannelAuth {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment