| 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 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 << SSLConnectionStatusToVersion(ssl_info->connection_status); | 625 << SSLConnectionStatusToVersion(ssl_info->connection_status); |
| 626 return true; | 626 return true; |
| 627 } | 627 } |
| 628 | 628 |
| 629 int SSLClientSocketOpenSSL::Read(IOBuffer* buf, | 629 int SSLClientSocketOpenSSL::Read(IOBuffer* buf, |
| 630 int buf_len, | 630 int buf_len, |
| 631 const CompletionCallback& callback) { | 631 const CompletionCallback& callback) { |
| 632 user_read_buf_ = buf; | 632 user_read_buf_ = buf; |
| 633 user_read_buf_len_ = buf_len; | 633 user_read_buf_len_ = buf_len; |
| 634 | 634 |
| 635 int rv = DoReadLoop(OK); | 635 int rv = DoReadLoop(); |
| 636 | 636 |
| 637 if (rv == ERR_IO_PENDING) { | 637 if (rv == ERR_IO_PENDING) { |
| 638 user_read_callback_ = callback; | 638 user_read_callback_ = callback; |
| 639 } else { | 639 } else { |
| 640 if (rv > 0) | 640 if (rv > 0) |
| 641 was_ever_used_ = true; | 641 was_ever_used_ = true; |
| 642 user_read_buf_ = NULL; | 642 user_read_buf_ = NULL; |
| 643 user_read_buf_len_ = 0; | 643 user_read_buf_len_ = 0; |
| 644 if (rv <= 0) { | 644 if (rv <= 0) { |
| 645 // Failure of a read attempt may indicate a failed false start | 645 // Failure of a read attempt may indicate a failed false start |
| 646 // connection. | 646 // connection. |
| 647 OnHandshakeCompletion(); | 647 OnHandshakeCompletion(); |
| 648 } | 648 } |
| 649 } | 649 } |
| 650 | 650 |
| 651 return rv; | 651 return rv; |
| 652 } | 652 } |
| 653 | 653 |
| 654 int SSLClientSocketOpenSSL::Write(IOBuffer* buf, | 654 int SSLClientSocketOpenSSL::Write(IOBuffer* buf, |
| 655 int buf_len, | 655 int buf_len, |
| 656 const CompletionCallback& callback) { | 656 const CompletionCallback& callback) { |
| 657 user_write_buf_ = buf; | 657 user_write_buf_ = buf; |
| 658 user_write_buf_len_ = buf_len; | 658 user_write_buf_len_ = buf_len; |
| 659 | 659 |
| 660 int rv = DoWriteLoop(OK); | 660 int rv = DoWriteLoop(); |
| 661 | 661 |
| 662 if (rv == ERR_IO_PENDING) { | 662 if (rv == ERR_IO_PENDING) { |
| 663 user_write_callback_ = callback; | 663 user_write_callback_ = callback; |
| 664 } else { | 664 } else { |
| 665 if (rv > 0) | 665 if (rv > 0) |
| 666 was_ever_used_ = true; | 666 was_ever_used_ = true; |
| 667 user_write_buf_ = NULL; | 667 user_write_buf_ = NULL; |
| 668 user_write_buf_len_ = 0; | 668 user_write_buf_len_ = 0; |
| 669 if (rv < 0) { | 669 if (rv < 0) { |
| 670 // Failure of a write attempt may indicate a failed false start | 670 // Failure of a write attempt may indicate a failed false start |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 // In handshake phase. | 1229 // In handshake phase. |
| 1230 OnHandshakeIOComplete(result); | 1230 OnHandshakeIOComplete(result); |
| 1231 return; | 1231 return; |
| 1232 } | 1232 } |
| 1233 | 1233 |
| 1234 // Network layer received some data, check if client requested to read | 1234 // Network layer received some data, check if client requested to read |
| 1235 // decrypted data. | 1235 // decrypted data. |
| 1236 if (!user_read_buf_.get()) | 1236 if (!user_read_buf_.get()) |
| 1237 return; | 1237 return; |
| 1238 | 1238 |
| 1239 int rv = DoReadLoop(result); | 1239 int rv = DoReadLoop(); |
| 1240 if (rv != ERR_IO_PENDING) | 1240 if (rv != ERR_IO_PENDING) |
| 1241 DoReadCallback(rv); | 1241 DoReadCallback(rv); |
| 1242 } | 1242 } |
| 1243 | 1243 |
| 1244 int SSLClientSocketOpenSSL::DoHandshakeLoop(int last_io_result) { | 1244 int SSLClientSocketOpenSSL::DoHandshakeLoop(int last_io_result) { |
| 1245 int rv = last_io_result; | 1245 int rv = last_io_result; |
| 1246 do { | 1246 do { |
| 1247 // Default to STATE_NONE for next state. | 1247 // Default to STATE_NONE for next state. |
| 1248 // (This is a quirk carried over from the windows | 1248 // (This is a quirk carried over from the windows |
| 1249 // implementation. It makes reading the logs a bit harder.) | 1249 // implementation. It makes reading the logs a bit harder.) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 // In general we exit the loop if rv is ERR_IO_PENDING. In this | 1281 // In general we exit the loop if rv is ERR_IO_PENDING. In this |
| 1282 // special case we keep looping even if rv is ERR_IO_PENDING because | 1282 // special case we keep looping even if rv is ERR_IO_PENDING because |
| 1283 // the transport IO may allow DoHandshake to make progress. | 1283 // the transport IO may allow DoHandshake to make progress. |
| 1284 rv = OK; // This causes us to stay in the loop. | 1284 rv = OK; // This causes us to stay in the loop. |
| 1285 } | 1285 } |
| 1286 } while (rv != ERR_IO_PENDING && next_handshake_state_ != STATE_NONE); | 1286 } while (rv != ERR_IO_PENDING && next_handshake_state_ != STATE_NONE); |
| 1287 | 1287 |
| 1288 return rv; | 1288 return rv; |
| 1289 } | 1289 } |
| 1290 | 1290 |
| 1291 int SSLClientSocketOpenSSL::DoReadLoop(int result) { | 1291 int SSLClientSocketOpenSSL::DoReadLoop() { |
| 1292 if (result < 0) | |
| 1293 return result; | |
| 1294 | |
| 1295 bool network_moved; | 1292 bool network_moved; |
| 1296 int rv; | 1293 int rv; |
| 1297 do { | 1294 do { |
| 1298 rv = DoPayloadRead(); | 1295 rv = DoPayloadRead(); |
| 1299 network_moved = DoTransportIO(); | 1296 network_moved = DoTransportIO(); |
| 1300 } while (rv == ERR_IO_PENDING && network_moved); | 1297 } while (rv == ERR_IO_PENDING && network_moved); |
| 1301 | 1298 |
| 1302 return rv; | 1299 return rv; |
| 1303 } | 1300 } |
| 1304 | 1301 |
| 1305 int SSLClientSocketOpenSSL::DoWriteLoop(int result) { | 1302 int SSLClientSocketOpenSSL::DoWriteLoop() { |
| 1306 if (result < 0) | |
| 1307 return result; | |
| 1308 | |
| 1309 bool network_moved; | 1303 bool network_moved; |
| 1310 int rv; | 1304 int rv; |
| 1311 do { | 1305 do { |
| 1312 rv = DoPayloadWrite(); | 1306 rv = DoPayloadWrite(); |
| 1313 network_moved = DoTransportIO(); | 1307 network_moved = DoTransportIO(); |
| 1314 } while (rv == ERR_IO_PENDING && network_moved); | 1308 } while (rv == ERR_IO_PENDING && network_moved); |
| 1315 | 1309 |
| 1316 return rv; | 1310 return rv; |
| 1317 } | 1311 } |
| 1318 | 1312 |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 ct::SCT_STATUS_LOG_UNKNOWN)); | 1774 ct::SCT_STATUS_LOG_UNKNOWN)); |
| 1781 } | 1775 } |
| 1782 } | 1776 } |
| 1783 | 1777 |
| 1784 scoped_refptr<X509Certificate> | 1778 scoped_refptr<X509Certificate> |
| 1785 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { | 1779 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { |
| 1786 return server_cert_; | 1780 return server_cert_; |
| 1787 } | 1781 } |
| 1788 | 1782 |
| 1789 } // namespace net | 1783 } // namespace net |
| OLD | NEW |