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 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 _scheduleFilter(); | 727 _scheduleFilter(); |
728 } | 728 } |
729 | 729 |
730 void _doneHandler() { | 730 void _doneHandler() { |
731 if (_filterStatus.readEmpty) { | 731 if (_filterStatus.readEmpty) { |
732 _close(); | 732 _close(); |
733 } | 733 } |
734 } | 734 } |
735 | 735 |
736 void _reportError(e) { | 736 void _reportError(e) { |
737 if (_connectPending) { | 737 if (_status == CLOSED) { |
| 738 return; |
| 739 } else if (_connectPending) { |
738 // _connectPending is true after the underlying connection has been | 740 // _connectPending is true after the underlying connection has been |
739 // made, but before the handshake has completed. | 741 // made, but before the handshake has completed. |
740 if (e is! TlsException) { | 742 if (e is! TlsException) { |
741 e = new HandshakeException("$e", null); | 743 e = new HandshakeException("$e", null); |
742 } | 744 } |
743 _handshakeComplete.completeError(e); | 745 _handshakeComplete.completeError(e); |
744 } else { | 746 } else { |
745 _controller.addError(e); | 747 _controller.addError(e); |
746 } | 748 } |
747 _close(); | 749 _close(); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 _filterService = _SecureFilter._newServicePort(); | 942 _filterService = _SecureFilter._newServicePort(); |
941 } | 943 } |
942 List args = [_filterPointer, _status != CONNECTED]; | 944 List args = [_filterPointer, _status != CONNECTED]; |
943 var bufs = _secureFilter.buffers; | 945 var bufs = _secureFilter.buffers; |
944 for (var i = 0; i < NUM_BUFFERS; ++i) { | 946 for (var i = 0; i < NUM_BUFFERS; ++i) { |
945 args.add(bufs[i].start); | 947 args.add(bufs[i].start); |
946 args.add(bufs[i].end); | 948 args.add(bufs[i].end); |
947 } | 949 } |
948 | 950 |
949 return _filterService.call(args).then((response) { | 951 return _filterService.call(args).then((response) { |
| 952 if (response.length == 2) { |
| 953 _reportError(new TlsException('${response[1]} error ${response[0]}')); |
| 954 } |
950 bool wasInHandshake = response[1]; | 955 bool wasInHandshake = response[1]; |
951 int start(int index) => response[2 * index + 2]; | 956 int start(int index) => response[2 * index + 2]; |
952 int end(int index) => response[2 * index + 3]; | 957 int end(int index) => response[2 * index + 3]; |
953 | 958 |
954 _FilterStatus status = new _FilterStatus(); | 959 _FilterStatus status = new _FilterStatus(); |
955 // Compute writeEmpty as "write plaintext buffer and write encrypted | 960 // Compute writeEmpty as "write plaintext buffer and write encrypted |
956 // buffer were empty when we started and are empty now". | 961 // buffer were empty when we started and are empty now". |
957 status.writeEmpty = bufs[WRITE_PLAINTEXT].isEmpty && | 962 status.writeEmpty = bufs[WRITE_PLAINTEXT].isEmpty && |
958 start(WRITE_ENCRYPTED) == end(WRITE_ENCRYPTED); | 963 start(WRITE_ENCRYPTED) == end(WRITE_ENCRYPTED); |
959 // If we were in handshake when this started, _writeEmpty may be false | 964 // If we were in handshake when this started, _writeEmpty may be false |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 /** | 1214 /** |
1210 * An exception that happens in the handshake phase of establishing | 1215 * An exception that happens in the handshake phase of establishing |
1211 * a secure network connection, when looking up or verifying a | 1216 * a secure network connection, when looking up or verifying a |
1212 * certificate. | 1217 * certificate. |
1213 */ | 1218 */ |
1214 class CertificateException extends TlsException { | 1219 class CertificateException extends TlsException { |
1215 const CertificateException([String message = "", | 1220 const CertificateException([String message = "", |
1216 OSError osError = null]) | 1221 OSError osError = null]) |
1217 : super._("CertificateException", message, osError); | 1222 : super._("CertificateException", message, osError); |
1218 } | 1223 } |
OLD | NEW |