| 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 bool _socketClosedWrite = false; // The network socket is closed for writing. | 405 bool _socketClosedWrite = false; // The network socket is closed for writing. |
| 406 bool _closedRead = false; // The secure socket has fired an onClosed event. | 406 bool _closedRead = false; // The secure socket has fired an onClosed event. |
| 407 bool _closedWrite = false; // The secure socket has been closed for writing. | 407 bool _closedWrite = false; // The secure socket has been closed for writing. |
| 408 Completer _closeCompleter = new Completer(); // The network socket is gone. | 408 Completer _closeCompleter = new Completer(); // The network socket is gone. |
| 409 _FilterStatus _filterStatus = new _FilterStatus(); | 409 _FilterStatus _filterStatus = new _FilterStatus(); |
| 410 bool _connectPending = true; | 410 bool _connectPending = true; |
| 411 bool _filterPending = false; | 411 bool _filterPending = false; |
| 412 bool _filterActive = false; | 412 bool _filterActive = false; |
| 413 | 413 |
| 414 _SecureFilter _secureFilter = new _SecureFilter(); | 414 _SecureFilter _secureFilter = new _SecureFilter(); |
| 415 int _filterPointer; | |
| 416 String _selectedProtocol; | 415 String _selectedProtocol; |
| 417 | 416 |
| 418 static Future<_RawSecureSocket> connect( | 417 static Future<_RawSecureSocket> connect( |
| 419 host, | 418 host, |
| 420 int requestedPort, | 419 int requestedPort, |
| 421 {bool is_server, | 420 {bool is_server, |
| 422 SecurityContext context, | 421 SecurityContext context, |
| 423 RawSocket socket, | 422 RawSocket socket, |
| 424 StreamSubscription subscription, | 423 StreamSubscription subscription, |
| 425 List<int> bufferedData, | 424 List<int> bufferedData, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 _controller = new StreamController<RawSocketEvent>( | 464 _controller = new StreamController<RawSocketEvent>( |
| 466 sync: true, | 465 sync: true, |
| 467 onListen: _onSubscriptionStateChange, | 466 onListen: _onSubscriptionStateChange, |
| 468 onPause: _onPauseStateChange, | 467 onPause: _onPauseStateChange, |
| 469 onResume: _onPauseStateChange, | 468 onResume: _onPauseStateChange, |
| 470 onCancel: _onSubscriptionStateChange); | 469 onCancel: _onSubscriptionStateChange); |
| 471 _stream = _controller.stream; | 470 _stream = _controller.stream; |
| 472 // Throw an ArgumentError if any field is invalid. After this, all | 471 // Throw an ArgumentError if any field is invalid. After this, all |
| 473 // errors will be reported through the future or the stream. | 472 // errors will be reported through the future or the stream. |
| 474 _secureFilter.init(); | 473 _secureFilter.init(); |
| 475 _filterPointer = _secureFilter._pointer(); | |
| 476 _secureFilter.registerHandshakeCompleteCallback( | 474 _secureFilter.registerHandshakeCompleteCallback( |
| 477 _secureHandshakeCompleteHandler); | 475 _secureHandshakeCompleteHandler); |
| 478 if (onBadCertificate != null) { | 476 if (onBadCertificate != null) { |
| 479 _secureFilter.registerBadCertificateCallback(_onBadCertificateWrapper); | 477 _secureFilter.registerBadCertificateCallback(_onBadCertificateWrapper); |
| 480 } | 478 } |
| 481 _socket.readEventsEnabled = true; | 479 _socket.readEventsEnabled = true; |
| 482 _socket.writeEventsEnabled = false; | 480 _socket.writeEventsEnabled = false; |
| 483 if (_socketSubscription == null) { | 481 if (_socketSubscription == null) { |
| 484 // If a current subscription is provided use this otherwise | 482 // If a current subscription is provided use this otherwise |
| 485 // create a new one. | 483 // create a new one. |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 _secureFilter != null && | 967 _secureFilter != null && |
| 970 _secureFilter.buffers[WRITE_PLAINTEXT].free > 0) { | 968 _secureFilter.buffers[WRITE_PLAINTEXT].free > 0) { |
| 971 _writeEventsEnabled = false; | 969 _writeEventsEnabled = false; |
| 972 _controller.add(RawSocketEvent.WRITE); | 970 _controller.add(RawSocketEvent.WRITE); |
| 973 } | 971 } |
| 974 } | 972 } |
| 975 | 973 |
| 976 Future<_FilterStatus> _pushAllFilterStages() { | 974 Future<_FilterStatus> _pushAllFilterStages() { |
| 977 bool wasInHandshake = _status != CONNECTED; | 975 bool wasInHandshake = _status != CONNECTED; |
| 978 List args = new List(2 + NUM_BUFFERS * 2); | 976 List args = new List(2 + NUM_BUFFERS * 2); |
| 979 args[0] = _filterPointer; | 977 args[0] = _secureFilter._pointer(); |
| 980 args[1] = wasInHandshake; | 978 args[1] = wasInHandshake; |
| 981 var bufs = _secureFilter.buffers; | 979 var bufs = _secureFilter.buffers; |
| 982 for (var i = 0; i < NUM_BUFFERS; ++i) { | 980 for (var i = 0; i < NUM_BUFFERS; ++i) { |
| 983 args[2 * i + 2] = bufs[i].start; | 981 args[2 * i + 2] = bufs[i].start; |
| 984 args[2 * i + 3] = bufs[i].end; | 982 args[2 * i + 3] = bufs[i].end; |
| 985 } | 983 } |
| 986 | 984 |
| 987 return _IOService._dispatch(_SSL_PROCESS_FILTER, args).then((response) { | 985 return _IOService._dispatch(_SSL_PROCESS_FILTER, args).then((response) { |
| 988 if (response.length == 2) { | 986 if (response.length == 2) { |
| 989 if (wasInHandshake) { | 987 if (wasInHandshake) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 String selectedProtocol(); | 1192 String selectedProtocol(); |
| 1195 void rehandshake(); | 1193 void rehandshake(); |
| 1196 void renegotiate(bool useSessionCache, | 1194 void renegotiate(bool useSessionCache, |
| 1197 bool requestClientCertificate, | 1195 bool requestClientCertificate, |
| 1198 bool requireClientCertificate); | 1196 bool requireClientCertificate); |
| 1199 void init(); | 1197 void init(); |
| 1200 X509Certificate get peerCertificate; | 1198 X509Certificate get peerCertificate; |
| 1201 int processBuffer(int bufferIndex); | 1199 int processBuffer(int bufferIndex); |
| 1202 void registerBadCertificateCallback(Function callback); | 1200 void registerBadCertificateCallback(Function callback); |
| 1203 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler); | 1201 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler); |
| 1202 |
| 1203 // This call may cause a reference counted pointer in the native |
| 1204 // implementation to be retained. It should only be called when the resulting |
| 1205 // value is passed to the IO service through a call to dispatch(). |
| 1204 int _pointer(); | 1206 int _pointer(); |
| 1205 | 1207 |
| 1206 List<_ExternalBuffer> get buffers; | 1208 List<_ExternalBuffer> get buffers; |
| 1207 } | 1209 } |
| 1208 | 1210 |
| 1209 /** A secure networking exception caused by a failure in the | 1211 /** A secure networking exception caused by a failure in the |
| 1210 * TLS/SSL protocol. | 1212 * TLS/SSL protocol. |
| 1211 */ | 1213 */ |
| 1212 class TlsException implements IOException { | 1214 class TlsException implements IOException { |
| 1213 final String type; | 1215 final String type; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 /** | 1252 /** |
| 1251 * An exception that happens in the handshake phase of establishing | 1253 * An exception that happens in the handshake phase of establishing |
| 1252 * a secure network connection, when looking up or verifying a | 1254 * a secure network connection, when looking up or verifying a |
| 1253 * certificate. | 1255 * certificate. |
| 1254 */ | 1256 */ |
| 1255 class CertificateException extends TlsException { | 1257 class CertificateException extends TlsException { |
| 1256 const CertificateException([String message = "", | 1258 const CertificateException([String message = "", |
| 1257 OSError osError = null]) | 1259 OSError osError = null]) |
| 1258 : super._("CertificateException", message, osError); | 1260 : super._("CertificateException", message, osError); |
| 1259 } | 1261 } |
| OLD | NEW |