| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A high-level class for communicating securely over a TCP socket, using | 8 * A high-level class for communicating securely over a TCP socket, using |
| 9 * TLS and SSL. The [SecureSocket] exposes both a [Stream] and an | 9 * TLS and SSL. The [SecureSocket] exposes both a [Stream] and an |
| 10 * [IOSink] interface, making it ideal for using together with | 10 * [IOSink] interface, making it ideal for using together with |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 bool _closedRead = false; // The secure socket has fired an onClosed event. | 440 bool _closedRead = false; // The secure socket has fired an onClosed event. |
| 441 bool _closedWrite = false; // The secure socket has been closed for writing. | 441 bool _closedWrite = false; // The secure socket has been closed for writing. |
| 442 Completer _closeCompleter = new Completer(); // The network socket is gone. | 442 Completer _closeCompleter = new Completer(); // The network socket is gone. |
| 443 _FilterStatus _filterStatus = new _FilterStatus(); | 443 _FilterStatus _filterStatus = new _FilterStatus(); |
| 444 bool _connectPending = true; | 444 bool _connectPending = true; |
| 445 bool _filterPending = false; | 445 bool _filterPending = false; |
| 446 bool _filterActive = false; | 446 bool _filterActive = false; |
| 447 | 447 |
| 448 _SecureFilter _secureFilter = new _SecureFilter(); | 448 _SecureFilter _secureFilter = new _SecureFilter(); |
| 449 int _filterPointer; | 449 int _filterPointer; |
| 450 SendPort _filterService; | |
| 451 | 450 |
| 452 static Future<_RawSecureSocket> connect( | 451 static Future<_RawSecureSocket> connect( |
| 453 host, | 452 host, |
| 454 int requestedPort, | 453 int requestedPort, |
| 455 String certificateName, | 454 String certificateName, |
| 456 {bool is_server, | 455 {bool is_server, |
| 457 RawSocket socket, | 456 RawSocket socket, |
| 458 StreamSubscription subscription, | 457 StreamSubscription subscription, |
| 459 List<int> bufferedData, | 458 List<int> bufferedData, |
| 460 bool requestClientCertificate: false, | 459 bool requestClientCertificate: false, |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 _writeEventsEnabled && | 980 _writeEventsEnabled && |
| 982 _pauseCount == 0 && | 981 _pauseCount == 0 && |
| 983 _secureFilter != null && | 982 _secureFilter != null && |
| 984 _secureFilter.buffers[WRITE_PLAINTEXT].free > 0) { | 983 _secureFilter.buffers[WRITE_PLAINTEXT].free > 0) { |
| 985 _writeEventsEnabled = false; | 984 _writeEventsEnabled = false; |
| 986 _controller.add(RawSocketEvent.WRITE); | 985 _controller.add(RawSocketEvent.WRITE); |
| 987 } | 986 } |
| 988 } | 987 } |
| 989 | 988 |
| 990 Future<_FilterStatus> _pushAllFilterStages() { | 989 Future<_FilterStatus> _pushAllFilterStages() { |
| 991 if (_filterService == null) { | 990 bool wasInHandshake = _status != CONNECTED; |
| 992 _filterService = _SecureFilter._newServicePort(); | 991 List args = new List(2 + NUM_BUFFERS * 2); |
| 993 } | 992 args[0] = _filterPointer; |
| 994 List args = [_filterPointer, _status != CONNECTED]; | 993 args[1] = wasInHandshake; |
| 995 var bufs = _secureFilter.buffers; | 994 var bufs = _secureFilter.buffers; |
| 996 for (var i = 0; i < NUM_BUFFERS; ++i) { | 995 for (var i = 0; i < NUM_BUFFERS; ++i) { |
| 997 args.add(bufs[i].start); | 996 args[2 * i + 2] = bufs[i].start; |
| 998 args.add(bufs[i].end); | 997 args[2 * i + 3] = bufs[i].end; |
| 999 } | 998 } |
| 1000 | 999 |
| 1001 return _filterService.call(args).then((response) { | 1000 return IOService.dispatch(SSL_PROCESS_FILTER, args).then((response) { |
| 1002 if (response.length == 2) { | 1001 if (response.length == 2) { |
| 1003 _reportError(new TlsException('${response[1]} error ${response[0]}')); | 1002 _reportError(new TlsException('${response[1]} error ${response[0]}')); |
| 1004 } | 1003 } |
| 1005 bool wasInHandshake = response[1]; | 1004 int start(int index) => response[2 * index]; |
| 1006 int start(int index) => response[2 * index + 2]; | 1005 int end(int index) => response[2 * index + 1]; |
| 1007 int end(int index) => response[2 * index + 3]; | |
| 1008 | 1006 |
| 1009 _FilterStatus status = new _FilterStatus(); | 1007 _FilterStatus status = new _FilterStatus(); |
| 1010 // Compute writeEmpty as "write plaintext buffer and write encrypted | 1008 // Compute writeEmpty as "write plaintext buffer and write encrypted |
| 1011 // buffer were empty when we started and are empty now". | 1009 // buffer were empty when we started and are empty now". |
| 1012 status.writeEmpty = bufs[WRITE_PLAINTEXT].isEmpty && | 1010 status.writeEmpty = bufs[WRITE_PLAINTEXT].isEmpty && |
| 1013 start(WRITE_ENCRYPTED) == end(WRITE_ENCRYPTED); | 1011 start(WRITE_ENCRYPTED) == end(WRITE_ENCRYPTED); |
| 1014 // If we were in handshake when this started, _writeEmpty may be false | 1012 // If we were in handshake when this started, _writeEmpty may be false |
| 1015 // because the handshake wrote data after we checked. | 1013 // because the handshake wrote data after we checked. |
| 1016 if (wasInHandshake) status.writeEmpty = false; | 1014 if (wasInHandshake) status.writeEmpty = false; |
| 1017 | 1015 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 /** | 1266 /** |
| 1269 * An exception that happens in the handshake phase of establishing | 1267 * An exception that happens in the handshake phase of establishing |
| 1270 * a secure network connection, when looking up or verifying a | 1268 * a secure network connection, when looking up or verifying a |
| 1271 * certificate. | 1269 * certificate. |
| 1272 */ | 1270 */ |
| 1273 class CertificateException extends TlsException { | 1271 class CertificateException extends TlsException { |
| 1274 const CertificateException([String message = "", | 1272 const CertificateException([String message = "", |
| 1275 OSError osError = null]) | 1273 OSError osError = null]) |
| 1276 : super._("CertificateException", message, osError); | 1274 : super._("CertificateException", message, osError); |
| 1277 } | 1275 } |
| OLD | NEW |