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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 bool _writeEventsEnabled = true; | 434 bool _writeEventsEnabled = true; |
435 bool _readEventsEnabled = true; | 435 bool _readEventsEnabled = true; |
436 int _pauseCount = 0; | 436 int _pauseCount = 0; |
437 bool _pendingReadEvent = false; | 437 bool _pendingReadEvent = false; |
438 bool _socketClosedRead = false; // The network socket is closed for reading. | 438 bool _socketClosedRead = false; // The network socket is closed for reading. |
439 bool _socketClosedWrite = false; // The network socket is closed for writing. | 439 bool _socketClosedWrite = false; // The network socket is closed for writing. |
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 = false; | 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; | 450 SendPort _filterService; |
451 | 451 |
452 static Future<_RawSecureSocket> connect( | 452 static Future<_RawSecureSocket> connect( |
453 host, | 453 host, |
454 int requestedPort, | 454 int requestedPort, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 if (onBadCertificate != null) { | 519 if (onBadCertificate != null) { |
520 _secureFilter.registerBadCertificateCallback(_onBadCertificateWrapper); | 520 _secureFilter.registerBadCertificateCallback(_onBadCertificateWrapper); |
521 } | 521 } |
522 var futureSocket; | 522 var futureSocket; |
523 if (socket == null) { | 523 if (socket == null) { |
524 futureSocket = RawSocket.connect(address, requestedPort); | 524 futureSocket = RawSocket.connect(address, requestedPort); |
525 } else { | 525 } else { |
526 futureSocket = new Future.value(socket); | 526 futureSocket = new Future.value(socket); |
527 } | 527 } |
528 futureSocket.then((rawSocket) { | 528 futureSocket.then((rawSocket) { |
529 _connectPending = true; | |
530 _socket = rawSocket; | 529 _socket = rawSocket; |
531 _socket.readEventsEnabled = true; | 530 _socket.readEventsEnabled = true; |
532 _socket.writeEventsEnabled = false; | 531 _socket.writeEventsEnabled = false; |
533 if (_socketSubscription == null) { | 532 if (_socketSubscription == null) { |
534 // If a current subscription is provided use this otherwise | 533 // If a current subscription is provided use this otherwise |
535 // create a new one. | 534 // create a new one. |
536 _socketSubscription = _socket.listen(_eventDispatcher, | 535 _socketSubscription = _socket.listen(_eventDispatcher, |
537 onError: _reportError, | 536 onError: _reportError, |
538 onDone: _doneHandler); | 537 onDone: _doneHandler); |
539 } else { | 538 } else { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 void _doneHandler() { | 767 void _doneHandler() { |
769 if (_filterStatus.readEmpty) { | 768 if (_filterStatus.readEmpty) { |
770 _close(); | 769 _close(); |
771 } | 770 } |
772 } | 771 } |
773 | 772 |
774 void _reportError(e) { | 773 void _reportError(e) { |
775 if (_status == CLOSED) { | 774 if (_status == CLOSED) { |
776 return; | 775 return; |
777 } else if (_connectPending) { | 776 } else if (_connectPending) { |
778 // _connectPending is true after the underlying connection has been | 777 // _connectPending is true until the handshake has completed, and the |
779 // made, but before the handshake has completed. | 778 // _handshakeComplete future returned from SecureSocket.connect has |
| 779 // completed. Before this point, we must complete it with an error. |
780 _handshakeComplete.completeError(e); | 780 _handshakeComplete.completeError(e); |
781 } else { | 781 } else { |
782 _controller.addError(e); | 782 _controller.addError(e); |
783 } | 783 } |
784 _close(); | 784 _close(); |
785 } | 785 } |
786 | 786 |
787 void _closeHandler() { | 787 void _closeHandler() { |
788 if (_status == CONNECTED) { | 788 if (_status == CONNECTED) { |
789 if (_closedRead) return; | 789 if (_closedRead) return; |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 /** | 1268 /** |
1269 * An exception that happens in the handshake phase of establishing | 1269 * An exception that happens in the handshake phase of establishing |
1270 * a secure network connection, when looking up or verifying a | 1270 * a secure network connection, when looking up or verifying a |
1271 * certificate. | 1271 * certificate. |
1272 */ | 1272 */ |
1273 class CertificateException extends TlsException { | 1273 class CertificateException extends TlsException { |
1274 const CertificateException([String message = "", | 1274 const CertificateException([String message = "", |
1275 OSError osError = null]) | 1275 OSError osError = null]) |
1276 : super._("CertificateException", message, osError); | 1276 : super._("CertificateException", message, osError); |
1277 } | 1277 } |
OLD | NEW |