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

Side by Side Diff: net/http/http_network_transaction.cc

Issue 4568002: Remember if a user declines to provide a server with a client certificate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and wtc feedback Created 10 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/ssl_client_auth_cache_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "net/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 request_(NULL), 89 request_(NULL),
90 headers_valid_(false), 90 headers_valid_(false),
91 logged_response_time_(false), 91 logged_response_time_(false),
92 request_headers_(), 92 request_headers_(),
93 read_buf_len_(0), 93 read_buf_len_(0),
94 next_state_(STATE_NONE), 94 next_state_(STATE_NONE),
95 establishing_tunnel_(false) { 95 establishing_tunnel_(false) {
96 session->ssl_config_service()->GetSSLConfig(&ssl_config_); 96 session->ssl_config_service()->GetSSLConfig(&ssl_config_);
97 if (session->http_stream_factory()->next_protos()) 97 if (session->http_stream_factory()->next_protos())
98 ssl_config_.next_protos = *session->http_stream_factory()->next_protos(); 98 ssl_config_.next_protos = *session->http_stream_factory()->next_protos();
99
100 } 99 }
101 100
102 HttpNetworkTransaction::~HttpNetworkTransaction() { 101 HttpNetworkTransaction::~HttpNetworkTransaction() {
103 if (stream_.get()) { 102 if (stream_.get()) {
104 HttpResponseHeaders* headers = GetResponseHeaders(); 103 HttpResponseHeaders* headers = GetResponseHeaders();
105 // TODO(mbelshe): The stream_ should be able to compute whether or not the 104 // TODO(mbelshe): The stream_ should be able to compute whether or not the
106 // stream should be kept alive. No reason to compute here 105 // stream should be kept alive. No reason to compute here
107 // and pass it in. 106 // and pass it in.
108 bool try_to_keep_alive = 107 bool try_to_keep_alive =
109 next_state_ == STATE_NONE && 108 next_state_ == STATE_NONE &&
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 int HttpNetworkTransaction::RestartWithCertificate( 163 int HttpNetworkTransaction::RestartWithCertificate(
165 X509Certificate* client_cert, 164 X509Certificate* client_cert,
166 CompletionCallback* callback) { 165 CompletionCallback* callback) {
167 // In HandleCertificateRequest(), we always tear down existing stream 166 // In HandleCertificateRequest(), we always tear down existing stream
168 // requests to force a new connection. So we shouldn't have one here. 167 // requests to force a new connection. So we shouldn't have one here.
169 DCHECK(!stream_request_.get()); 168 DCHECK(!stream_request_.get());
170 DCHECK(!stream_.get()); 169 DCHECK(!stream_.get());
171 DCHECK_EQ(STATE_NONE, next_state_); 170 DCHECK_EQ(STATE_NONE, next_state_);
172 171
173 ssl_config_.client_cert = client_cert; 172 ssl_config_.client_cert = client_cert;
174 if (client_cert) { 173 session_->ssl_client_auth_cache()->Add(
175 session_->ssl_client_auth_cache()->Add( 174 response_.cert_request_info->host_and_port, client_cert);
176 response_.cert_request_info->host_and_port, client_cert);
177 }
178 ssl_config_.send_client_cert = true; 175 ssl_config_.send_client_cert = true;
179 // Reset the other member variables. 176 // Reset the other member variables.
180 // Note: this is necessary only with SSL renegotiation. 177 // Note: this is necessary only with SSL renegotiation.
181 ResetStateForRestart(); 178 ResetStateForRestart();
182 next_state_ = STATE_CREATE_STREAM; 179 next_state_ = STATE_CREATE_STREAM;
183 int rv = DoLoop(OK); 180 int rv = DoLoop(OK);
184 if (rv == ERR_IO_PENDING) 181 if (rv == ERR_IO_PENDING)
185 user_callback_ = callback; 182 user_callback_ = callback;
186 return rv; 183 return rv;
187 } 184 }
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 // renegotiation. 961 // renegotiation.
965 DCHECK(!stream_request_.get()); 962 DCHECK(!stream_request_.get());
966 stream_->Close(true); 963 stream_->Close(true);
967 stream_.reset(); 964 stream_.reset();
968 } 965 }
969 966
970 // The server is asking for a client certificate during the initial 967 // The server is asking for a client certificate during the initial
971 // handshake. 968 // handshake.
972 stream_request_.reset(); 969 stream_request_.reset();
973 970
974 // If the user selected one of the certificate in client_certs for this 971 // If the user selected one of the certificates in client_certs or declined
975 // server before, use it automatically. 972 // to provide one for this server before, use the past decision
976 X509Certificate* client_cert = session_->ssl_client_auth_cache()->Lookup( 973 // automatically.
977 response_.cert_request_info->host_and_port); 974 scoped_refptr<X509Certificate> client_cert;
975 bool found_cached_cert = session_->ssl_client_auth_cache()->Lookup(
976 response_.cert_request_info->host_and_port, &client_cert);
977 if (!found_cached_cert)
978 return error;
979
980 // Check that the certificate selected is still a certificate the server
981 // is likely to accept, based on the criteria supplied in the
982 // CertificateRequest message.
978 if (client_cert) { 983 if (client_cert) {
979 const std::vector<scoped_refptr<X509Certificate> >& client_certs = 984 const std::vector<scoped_refptr<X509Certificate> >& client_certs =
980 response_.cert_request_info->client_certs; 985 response_.cert_request_info->client_certs;
986 bool cert_still_valid = false;
981 for (size_t i = 0; i < client_certs.size(); ++i) { 987 for (size_t i = 0; i < client_certs.size(); ++i) {
982 if (client_cert->fingerprint().Equals(client_certs[i]->fingerprint())) { 988 if (client_cert->Equals(client_certs[i])) {
983 // TODO(davidben): Add a unit test which covers this path; we need to be 989 cert_still_valid = true;
984 // able to send a legitimate certificate and also bypass/clear the 990 break;
985 // SSL session cache.
986 ssl_config_.client_cert = client_cert;
987 ssl_config_.send_client_cert = true;
988 next_state_ = STATE_CREATE_STREAM;
989 // Reset the other member variables.
990 // Note: this is necessary only with SSL renegotiation.
991 ResetStateForRestart();
992 return OK;
993 } 991 }
994 } 992 }
993
994 if (!cert_still_valid)
995 return error;
995 } 996 }
996 return error; 997
998 // TODO(davidben): Add a unit test which covers this path; we need to be
999 // able to send a legitimate certificate and also bypass/clear the
1000 // SSL session cache.
1001 ssl_config_.client_cert = client_cert;
1002 ssl_config_.send_client_cert = true;
1003 next_state_ = STATE_CREATE_STREAM;
1004 // Reset the other member variables.
1005 // Note: this is necessary only with SSL renegotiation.
1006 ResetStateForRestart();
1007 return OK;
997 } 1008 }
998 1009
999 // This method determines whether it is safe to resend the request after an 1010 // This method determines whether it is safe to resend the request after an
1000 // IO error. It can only be called in response to request header or body 1011 // IO error. It can only be called in response to request header or body
1001 // write errors or response header read errors. It should not be used in 1012 // write errors or response header read errors. It should not be used in
1002 // other cases, such as a Connect error. 1013 // other cases, such as a Connect error.
1003 int HttpNetworkTransaction::HandleIOError(int error) { 1014 int HttpNetworkTransaction::HandleIOError(int error) {
1004 switch (error) { 1015 switch (error) {
1005 // If we try to reuse a connection that the server is in the process of 1016 // If we try to reuse a connection that the server is in the process of
1006 // closing, we may end up successfully writing out our request (or a 1017 // closing, we may end up successfully writing out our request (or a
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 default: 1186 default:
1176 return priority; 1187 return priority;
1177 } 1188 }
1178 } 1189 }
1179 1190
1180 1191
1181 1192
1182 #undef STATE_CASE 1193 #undef STATE_CASE
1183 1194
1184 } // namespace net 1195 } // namespace net
OLDNEW
« no previous file with comments | « net/base/ssl_client_auth_cache_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698