OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/api/cast_channel/cast_socket.h" | 5 #include "extensions/browser/api/cast_channel/cast_socket.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "net/ssl/ssl_config_service.h" | 38 #include "net/ssl/ssl_config_service.h" |
39 #include "net/ssl/ssl_info.h" | 39 #include "net/ssl/ssl_info.h" |
40 | 40 |
41 // Assumes |ip_endpoint_| of type net::IPEndPoint and |channel_auth_| of enum | 41 // Assumes |ip_endpoint_| of type net::IPEndPoint and |channel_auth_| of enum |
42 // type ChannelAuthType are available in the current scope. | 42 // type ChannelAuthType are available in the current scope. |
43 #define VLOG_WITH_CONNECTION(level) VLOG(level) << "[" << \ | 43 #define VLOG_WITH_CONNECTION(level) VLOG(level) << "[" << \ |
44 ip_endpoint_.ToString() << ", auth=" << channel_auth_ << "] " | 44 ip_endpoint_.ToString() << ", auth=" << channel_auth_ << "] " |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 const int kMaxSelfSignedCertLifetimeInDays = 2; | 48 const int kMaxSelfSignedCertLifetimeInDays = 4; |
49 | 49 |
50 std::string FormatTimeForLogging(base::Time time) { | 50 std::string FormatTimeForLogging(base::Time time) { |
51 base::Time::Exploded exploded_time; | 51 base::Time::Exploded exploded_time; |
52 time.UTCExplode(&exploded_time); | 52 time.UTCExplode(&exploded_time); |
53 return base::StringPrintf( | 53 return base::StringPrintf( |
54 "%04d-%02d-%02d %02d:%02d:%02d.%03d UTC", exploded_time.year, | 54 "%04d-%02d-%02d %02d:%02d:%02d.%03d UTC", exploded_time.year, |
55 exploded_time.month, exploded_time.day_of_month, exploded_time.hour, | 55 exploded_time.month, exploded_time.day_of_month, exploded_time.hour, |
56 exploded_time.minute, exploded_time.second, exploded_time.millisecond); | 56 exploded_time.minute, exploded_time.second, exploded_time.millisecond); |
57 } | 57 } |
58 | 58 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 DCHECK(cert); | 190 DCHECK(cert); |
191 DCHECK(peer_cert_.empty()); | 191 DCHECK(peer_cert_.empty()); |
192 net::SSLInfo ssl_info; | 192 net::SSLInfo ssl_info; |
193 if (!socket_->GetSSLInfo(&ssl_info) || !ssl_info.cert.get()) { | 193 if (!socket_->GetSSLInfo(&ssl_info) || !ssl_info.cert.get()) { |
194 return false; | 194 return false; |
195 } | 195 } |
196 | 196 |
197 logger_->LogSocketEvent(channel_id_, proto::SSL_INFO_OBTAINED); | 197 logger_->LogSocketEvent(channel_id_, proto::SSL_INFO_OBTAINED); |
198 | 198 |
199 // Ensure that the peer cert (which is self-signed) doesn't have an excessive | 199 // Ensure that the peer cert (which is self-signed) doesn't have an excessive |
200 // life-time (i.e. no more than 2 days). | 200 // remaining life-time. |
201 base::Time expiry = ssl_info.cert->valid_expiry(); | 201 base::Time expiry = ssl_info.cert->valid_expiry(); |
202 base::Time lifetimeLimit = | 202 base::Time lifetimeLimit = |
203 base::Time::Now() + | 203 base::Time::Now() + |
204 base::TimeDelta::FromDays(kMaxSelfSignedCertLifetimeInDays); | 204 base::TimeDelta::FromDays(kMaxSelfSignedCertLifetimeInDays); |
205 if (expiry.is_null() || expiry > lifetimeLimit) { | 205 if (expiry.is_null() || expiry > lifetimeLimit) { |
206 std::string details = FormatTimeForLogging(expiry); | 206 std::string details = FormatTimeForLogging(expiry); |
207 details += " " + ip_endpoint().ToString(); | 207 details += " " + ip_endpoint().ToString(); |
208 LOG(ERROR) << "Peer cert has excessive lifetime. details=" << details; | 208 LOG(ERROR) << "Peer cert has excessive lifetime. details=" << details; |
209 logger_->LogSocketEventWithDetails( | 209 logger_->LogSocketEventWithDetails( |
210 channel_id_, proto::SSL_CERT_EXCESSIVE_LIFETIME, details); | 210 channel_id_, proto::SSL_CERT_EXCESSIVE_LIFETIME, details); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 void CastSocketImpl::SetErrorState(ChannelError error_state) { | 582 void CastSocketImpl::SetErrorState(ChannelError error_state) { |
583 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; | 583 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; |
584 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); | 584 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); |
585 error_state_ = error_state; | 585 error_state_ = error_state; |
586 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_)); | 586 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_)); |
587 } | 587 } |
588 } // namespace cast_channel | 588 } // namespace cast_channel |
589 } // namespace core_api | 589 } // namespace core_api |
590 } // namespace extensions | 590 } // namespace extensions |
591 #undef VLOG_WITH_CONNECTION | 591 #undef VLOG_WITH_CONNECTION |
OLD | NEW |