OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // OpenSSL binding for SSLClientSocket. The class layout and general principle | 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle |
6 // of operation is derived from SSLClientSocketNSS. | 6 // of operation is derived from SSLClientSocketNSS. |
7 | 7 |
8 #include "net/socket/ssl_client_socket_openssl.h" | 8 #include "net/socket/ssl_client_socket_openssl.h" |
9 | 9 |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1339 // Otherwise, an error occurred (rv <= 0). The error needs to be handled | 1339 // Otherwise, an error occurred (rv <= 0). The error needs to be handled |
1340 // immediately, while the OpenSSL errors are still available in | 1340 // immediately, while the OpenSSL errors are still available in |
1341 // thread-local storage. However, the handled/remapped error code should | 1341 // thread-local storage. However, the handled/remapped error code should |
1342 // only be returned if no application data was already read; if it was, the | 1342 // only be returned if no application data was already read; if it was, the |
1343 // error code should be deferred until the next call of DoPayloadRead. | 1343 // error code should be deferred until the next call of DoPayloadRead. |
1344 // | 1344 // |
1345 // If no data was read, |*next_result| will point to the return value of | 1345 // If no data was read, |*next_result| will point to the return value of |
1346 // this function. If at least some data was read, |*next_result| will point | 1346 // this function. If at least some data was read, |*next_result| will point |
1347 // to |pending_read_error_|, to be returned in a future call to | 1347 // to |pending_read_error_|, to be returned in a future call to |
1348 // DoPayloadRead() (e.g.: after the current data is handled). | 1348 // DoPayloadRead() (e.g.: after the current data is handled). |
1349 int *next_result = &rv; | 1349 int *next_result = &rv; |
davidben
2014/10/14 20:31:06
This logic (and similar logic in SSLClientSocketNS
| |
1350 if (total_bytes_read > 0) { | 1350 if (total_bytes_read > 0) { |
1351 pending_read_error_ = rv; | 1351 pending_read_error_ = rv; |
1352 rv = total_bytes_read; | 1352 rv = total_bytes_read; |
1353 next_result = &pending_read_error_; | 1353 next_result = &pending_read_error_; |
1354 } | 1354 } |
1355 | 1355 |
1356 if (client_auth_cert_needed_) { | 1356 if (client_auth_cert_needed_) { |
1357 *next_result = ERR_SSL_CLIENT_AUTH_CERT_NEEDED; | 1357 *next_result = ERR_SSL_CLIENT_AUTH_CERT_NEEDED; |
1358 } else if (*next_result < 0) { | 1358 } else if (*next_result < 0) { |
1359 int err = SSL_get_error(ssl_, *next_result); | 1359 int err = SSL_get_error(ssl_, *next_result); |
1360 *next_result = MapOpenSSLError(err, err_tracer); | 1360 *next_result = MapOpenSSLError(err, err_tracer); |
1361 | |
1362 // Servers do not reliably send close_notify, so | |
1363 // ERR_CONNECTION_CLOSED cannot be treated as fatal. | |
Ryan Sleevi
2014/10/17 20:53:00
This comment needs explaining (or my flu meds need
davidben
2014/10/20 17:13:24
Done.
| |
1364 if (*next_result == ERR_CONNECTION_CLOSED) | |
1365 *next_result = 0; | |
1366 | |
1361 if (rv > 0 && *next_result == ERR_IO_PENDING) { | 1367 if (rv > 0 && *next_result == ERR_IO_PENDING) { |
1362 // If at least some data was read from SSL_read(), do not treat | 1368 // If at least some data was read from SSL_read(), do not treat |
1363 // insufficient data as an error to return in the next call to | 1369 // insufficient data as an error to return in the next call to |
1364 // DoPayloadRead() - instead, let the call fall through to check | 1370 // DoPayloadRead() - instead, let the call fall through to check |
1365 // SSL_read() again. This is because DoTransportIO() may complete | 1371 // SSL_read() again. This is because DoTransportIO() may complete |
1366 // in between the next call to DoPayloadRead(), and thus it is | 1372 // in between the next call to DoPayloadRead(), and thus it is |
1367 // important to check SSL_read() on subsequent invocations to see | 1373 // important to check SSL_read() on subsequent invocations to see |
1368 // if a complete record may now be read. | 1374 // if a complete record may now be read. |
1369 *next_result = kNoPendingReadResult; | 1375 *next_result = kNoPendingReadResult; |
1370 } | 1376 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1484 if (send_buffer_->BytesRemaining() <= 0) | 1490 if (send_buffer_->BytesRemaining() <= 0) |
1485 send_buffer_ = NULL; | 1491 send_buffer_ = NULL; |
1486 } | 1492 } |
1487 } | 1493 } |
1488 | 1494 |
1489 int SSLClientSocketOpenSSL::TransportReadComplete(int result) { | 1495 int SSLClientSocketOpenSSL::TransportReadComplete(int result) { |
1490 DCHECK(ERR_IO_PENDING != result); | 1496 DCHECK(ERR_IO_PENDING != result); |
1491 // If an EOF, canonicalize to ERR_CONNECTION_CLOSED here so MapOpenSSLError | 1497 // If an EOF, canonicalize to ERR_CONNECTION_CLOSED here so MapOpenSSLError |
1492 // does not report success. | 1498 // does not report success. |
1493 if (result == 0) | 1499 if (result == 0) |
1494 result = ERR_CONNECTION_CLOSED; | 1500 result = ERR_CONNECTION_CLOSED; |
davidben
2014/10/14 20:31:06
It is a little annoying that this fix is undoing t
Ryan Sleevi
2014/10/17 20:53:00
Sorry, I have trouble following you. It might be e
davidben
2014/10/20 17:13:24
I think I agree.
| |
1495 if (result < 0) { | 1501 if (result < 0) { |
1496 DVLOG(1) << "TransportReadComplete result " << result; | 1502 DVLOG(1) << "TransportReadComplete result " << result; |
1497 // Received an error. Save it to be reported in a future read on | 1503 // Received an error. Save it to be reported in a future read on |
1498 // transport_bio_'s peer. | 1504 // transport_bio_'s peer. |
1499 transport_read_error_ = result; | 1505 transport_read_error_ = result; |
1500 } else { | 1506 } else { |
1501 DCHECK(recv_buffer_.get()); | 1507 DCHECK(recv_buffer_.get()); |
1502 int ret = BIO_write(transport_bio_, recv_buffer_->data(), result); | 1508 int ret = BIO_write(transport_bio_, recv_buffer_->data(), result); |
1503 // A write into a memory BIO should always succeed. | 1509 // A write into a memory BIO should always succeed. |
1504 DCHECK_EQ(result, ret); | 1510 DCHECK_EQ(result, ret); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1766 ct::SCT_STATUS_LOG_UNKNOWN)); | 1772 ct::SCT_STATUS_LOG_UNKNOWN)); |
1767 } | 1773 } |
1768 } | 1774 } |
1769 | 1775 |
1770 scoped_refptr<X509Certificate> | 1776 scoped_refptr<X509Certificate> |
1771 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { | 1777 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { |
1772 return server_cert_; | 1778 return server_cert_; |
1773 } | 1779 } |
1774 | 1780 |
1775 } // namespace net | 1781 } // namespace net |
OLD | NEW |