| Index: sdk/lib/io/secure_socket.dart
|
| diff --git a/sdk/lib/io/secure_socket.dart b/sdk/lib/io/secure_socket.dart
|
| index c6d3cb2d23885a742816a07e99c11cf600af9b54..630da499c4b37ef1c5dd1ed05e6cf5576b6088d2 100644
|
| --- a/sdk/lib/io/secure_socket.dart
|
| +++ b/sdk/lib/io/secure_socket.dart
|
| @@ -29,17 +29,15 @@ abstract class SecureSocket implements Socket {
|
| * the connection or not. The handler should return true
|
| * to continue the [SecureSocket] connection.
|
| */
|
| - static Future<SecureSocket> connect(
|
| - host,
|
| - int port,
|
| + static Future<SecureSocket> connect(host, int port,
|
| {SecurityContext context,
|
| - bool onBadCertificate(X509Certificate certificate),
|
| - List<String> supportedProtocols}) {
|
| - return RawSecureSocket.connect(host,
|
| - port,
|
| - context: context,
|
| - onBadCertificate: onBadCertificate,
|
| - supportedProtocols: supportedProtocols)
|
| + bool onBadCertificate(X509Certificate certificate),
|
| + List<String> supportedProtocols}) {
|
| + return RawSecureSocket
|
| + .connect(host, port,
|
| + context: context,
|
| + onBadCertificate: onBadCertificate,
|
| + supportedProtocols: supportedProtocols)
|
| .then((rawSocket) => new SecureSocket._(rawSocket));
|
| }
|
|
|
| @@ -69,22 +67,19 @@ abstract class SecureSocket implements Socket {
|
| * See [connect] for more information on the arguments.
|
| *
|
| */
|
| - static Future<SecureSocket> secure(
|
| - Socket socket,
|
| + static Future<SecureSocket> secure(Socket socket,
|
| {host,
|
| - SecurityContext context,
|
| - bool onBadCertificate(X509Certificate certificate)}) {
|
| - return ((socket as dynamic/*_Socket*/)._detachRaw() as Future)
|
| + SecurityContext context,
|
| + bool onBadCertificate(X509Certificate certificate)}) {
|
| + return ((socket as dynamic /*_Socket*/)._detachRaw() as Future)
|
| .then<RawSecureSocket>((detachedRaw) {
|
| - return RawSecureSocket.secure(
|
| - detachedRaw[0] as RawSocket,
|
| - subscription: detachedRaw[1] as StreamSubscription<RawSocketEvent>,
|
| - host: host,
|
| - context: context,
|
| - onBadCertificate: onBadCertificate);
|
| - })
|
| - .then<SecureSocket>((raw) => new SecureSocket._(raw));
|
| - }
|
| + return RawSecureSocket.secure(detachedRaw[0] as RawSocket,
|
| + subscription: detachedRaw[1] as StreamSubscription<RawSocketEvent>,
|
| + host: host,
|
| + context: context,
|
| + onBadCertificate: onBadCertificate);
|
| + }).then<SecureSocket>((raw) => new SecureSocket._(raw));
|
| + }
|
|
|
| /**
|
| * Takes an already connected [socket] and starts server side TLS
|
| @@ -108,24 +103,20 @@ abstract class SecureSocket implements Socket {
|
| *
|
| */
|
| static Future<SecureSocket> secureServer(
|
| - Socket socket,
|
| - SecurityContext context,
|
| + Socket socket, SecurityContext context,
|
| {List<int> bufferedData,
|
| - bool requestClientCertificate: false,
|
| - bool requireClientCertificate: false,
|
| - List<String> supportedProtocols}) {
|
| - return ((socket as dynamic/*_Socket*/)._detachRaw() as Future)
|
| + bool requestClientCertificate: false,
|
| + bool requireClientCertificate: false,
|
| + List<String> supportedProtocols}) {
|
| + return ((socket as dynamic /*_Socket*/)._detachRaw() as Future)
|
| .then<RawSecureSocket>((detachedRaw) {
|
| - return RawSecureSocket.secureServer(
|
| - detachedRaw[0] as RawSocket,
|
| - context,
|
| - subscription: detachedRaw[1] as StreamSubscription<RawSocketEvent>,
|
| - bufferedData: bufferedData,
|
| - requestClientCertificate: requestClientCertificate,
|
| - requireClientCertificate: requireClientCertificate,
|
| - supportedProtocols: supportedProtocols);
|
| - })
|
| - .then<SecureSocket>((raw) => new SecureSocket._(raw));
|
| + return RawSecureSocket.secureServer(detachedRaw[0] as RawSocket, context,
|
| + subscription: detachedRaw[1] as StreamSubscription<RawSocketEvent>,
|
| + bufferedData: bufferedData,
|
| + requestClientCertificate: requestClientCertificate,
|
| + requireClientCertificate: requireClientCertificate,
|
| + supportedProtocols: supportedProtocols);
|
| + }).then<SecureSocket>((raw) => new SecureSocket._(raw));
|
| }
|
|
|
| /**
|
| @@ -149,12 +140,12 @@ abstract class SecureSocket implements Socket {
|
| * This repeats the SSL or TLS handshake, with options that allow clearing
|
| * the session cache and requesting a client certificate.
|
| */
|
| - void renegotiate({bool useSessionCache: true,
|
| - bool requestClientCertificate: false,
|
| - bool requireClientCertificate: false});
|
| + void renegotiate(
|
| + {bool useSessionCache: true,
|
| + bool requestClientCertificate: false,
|
| + bool requireClientCertificate: false});
|
| }
|
|
|
| -
|
| /**
|
| * RawSecureSocket provides a secure (SSL or TLS) network connection.
|
| * Client connections to a server are provided by calling
|
| @@ -184,26 +175,18 @@ abstract class RawSecureSocket implements RawSocket {
|
| * the connection or not. The handler should return true
|
| * to continue the [RawSecureSocket] connection.
|
| */
|
| - static Future<RawSecureSocket> connect(
|
| - host,
|
| - int port,
|
| + static Future<RawSecureSocket> connect(host, int port,
|
| {SecurityContext context,
|
| - bool onBadCertificate(X509Certificate certificate),
|
| - List<String> supportedProtocols}) {
|
| + bool onBadCertificate(X509Certificate certificate),
|
| + List<String> supportedProtocols}) {
|
| _RawSecureSocket._verifyFields(
|
| - host,
|
| - port,
|
| - false,
|
| - false,
|
| - false,
|
| - onBadCertificate);
|
| - return RawSocket.connect(host, port)
|
| - .then((socket) {
|
| - return secure(socket,
|
| - context: context,
|
| - onBadCertificate: onBadCertificate,
|
| - supportedProtocols: supportedProtocols);
|
| - });
|
| + host, port, false, false, false, onBadCertificate);
|
| + return RawSocket.connect(host, port).then((socket) {
|
| + return secure(socket,
|
| + context: context,
|
| + onBadCertificate: onBadCertificate,
|
| + supportedProtocols: supportedProtocols);
|
| + });
|
| }
|
|
|
| /**
|
| @@ -234,18 +217,16 @@ abstract class RawSecureSocket implements RawSocket {
|
| * See [connect] for more information on the arguments.
|
| *
|
| */
|
| - static Future<RawSecureSocket> secure(
|
| - RawSocket socket,
|
| + static Future<RawSecureSocket> secure(RawSocket socket,
|
| {StreamSubscription<RawSocketEvent> subscription,
|
| - host,
|
| - SecurityContext context,
|
| - bool onBadCertificate(X509Certificate certificate),
|
| - List<String> supportedProtocols}) {
|
| + host,
|
| + SecurityContext context,
|
| + bool onBadCertificate(X509Certificate certificate),
|
| + List<String> supportedProtocols}) {
|
| socket.readEventsEnabled = false;
|
| socket.writeEventsEnabled = false;
|
| - return _RawSecureSocket.connect(
|
| - host != null ? host : socket.address.host,
|
| - socket.port,
|
| + return _RawSecureSocket.connect(
|
| + host != null ? host : socket.address.host, socket.port,
|
| is_server: false,
|
| socket: socket,
|
| subscription: subscription,
|
| @@ -278,18 +259,15 @@ abstract class RawSecureSocket implements RawSocket {
|
| *
|
| */
|
| static Future<RawSecureSocket> secureServer(
|
| - RawSocket socket,
|
| - SecurityContext context,
|
| + RawSocket socket, SecurityContext context,
|
| {StreamSubscription<RawSocketEvent> subscription,
|
| - List<int> bufferedData,
|
| - bool requestClientCertificate: false,
|
| - bool requireClientCertificate: false,
|
| - List<String> supportedProtocols}) {
|
| + List<int> bufferedData,
|
| + bool requestClientCertificate: false,
|
| + bool requireClientCertificate: false,
|
| + List<String> supportedProtocols}) {
|
| socket.readEventsEnabled = false;
|
| socket.writeEventsEnabled = false;
|
| - return _RawSecureSocket.connect(
|
| - socket.address,
|
| - socket.remotePort,
|
| + return _RawSecureSocket.connect(socket.address, socket.remotePort,
|
| context: context,
|
| is_server: true,
|
| socket: socket,
|
| @@ -307,9 +285,10 @@ abstract class RawSecureSocket implements RawSocket {
|
| * This repeats the SSL or TLS handshake, with options that allow clearing
|
| * the session cache and requesting a client certificate.
|
| */
|
| - void renegotiate({bool useSessionCache: true,
|
| - bool requestClientCertificate: false,
|
| - bool requireClientCertificate: false});
|
| + void renegotiate(
|
| + {bool useSessionCache: true,
|
| + bool requestClientCertificate: false,
|
| + bool requireClientCertificate: false});
|
|
|
| /**
|
| * Get the peer certificate for a connected RawSecureSocket. If this
|
| @@ -326,7 +305,6 @@ abstract class RawSecureSocket implements RawSocket {
|
| String get selectedProtocol;
|
| }
|
|
|
| -
|
| /**
|
| * X509Certificate represents an SSL certificate, with accessors to
|
| * get the fields of the certificate.
|
| @@ -340,11 +318,10 @@ abstract class X509Certificate {
|
| DateTime get endValidity;
|
| }
|
|
|
| -
|
| class _FilterStatus {
|
| - bool progress = false; // The filter read or wrote data to the buffers.
|
| - bool readEmpty = true; // The read buffers and decryption filter are empty.
|
| - bool writeEmpty = true; // The write buffers and encryption filter are empty.
|
| + bool progress = false; // The filter read or wrote data to the buffers.
|
| + bool readEmpty = true; // The read buffers and decryption filter are empty.
|
| + bool writeEmpty = true; // The write buffers and encryption filter are empty.
|
| // These are set if a buffer changes state from empty or full.
|
| bool readPlaintextNoLongerEmpty = false;
|
| bool writePlaintextNoLongerFull = false;
|
| @@ -354,9 +331,8 @@ class _FilterStatus {
|
| _FilterStatus();
|
| }
|
|
|
| -
|
| class _RawSecureSocket extends Stream<RawSocketEvent>
|
| - implements RawSecureSocket {
|
| + implements RawSecureSocket {
|
| // Status states
|
| static final int HANDSHAKE = 201;
|
| static final int CONNECTED = 202;
|
| @@ -371,7 +347,8 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| static final int NUM_BUFFERS = 4;
|
|
|
| // Is a buffer identifier for an encrypted buffer?
|
| - static bool _isBufferEncrypted(int identifier) => identifier >= READ_ENCRYPTED;
|
| + static bool _isBufferEncrypted(int identifier) =>
|
| + identifier >= READ_ENCRYPTED;
|
|
|
| RawSocket _socket;
|
| final Completer<_RawSecureSocket> _handshakeComplete =
|
| @@ -393,10 +370,10 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| bool _readEventsEnabled = true;
|
| int _pauseCount = 0;
|
| bool _pendingReadEvent = false;
|
| - bool _socketClosedRead = false; // The network socket is closed for reading.
|
| - bool _socketClosedWrite = false; // The network socket is closed for writing.
|
| - bool _closedRead = false; // The secure socket has fired an onClosed event.
|
| - bool _closedWrite = false; // The secure socket has been closed for writing.
|
| + bool _socketClosedRead = false; // The network socket is closed for reading.
|
| + bool _socketClosedWrite = false; // The network socket is closed for writing.
|
| + bool _closedRead = false; // The secure socket has fired an onClosed event.
|
| + bool _closedWrite = false; // The secure socket has been closed for writing.
|
| // The network socket is gone.
|
| Completer<RawSecureSocket> _closeCompleter = new Completer<RawSecureSocket>();
|
| _FilterStatus _filterStatus = new _FilterStatus();
|
| @@ -408,37 +385,37 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| String _selectedProtocol;
|
|
|
| static Future<_RawSecureSocket> connect(
|
| - dynamic/*String|InternetAddress*/ host,
|
| - int requestedPort,
|
| + dynamic /*String|InternetAddress*/ host, int requestedPort,
|
| {bool is_server,
|
| - SecurityContext context,
|
| - RawSocket socket,
|
| - StreamSubscription<RawSocketEvent> subscription,
|
| - List<int> bufferedData,
|
| - bool requestClientCertificate: false,
|
| - bool requireClientCertificate: false,
|
| - bool onBadCertificate(X509Certificate certificate),
|
| - List<String> supportedProtocols}) {
|
| - _verifyFields(host, requestedPort, is_server,
|
| - requestClientCertificate, requireClientCertificate,
|
| - onBadCertificate);
|
| + SecurityContext context,
|
| + RawSocket socket,
|
| + StreamSubscription<RawSocketEvent> subscription,
|
| + List<int> bufferedData,
|
| + bool requestClientCertificate: false,
|
| + bool requireClientCertificate: false,
|
| + bool onBadCertificate(X509Certificate certificate),
|
| + List<String> supportedProtocols}) {
|
| + _verifyFields(host, requestedPort, is_server, requestClientCertificate,
|
| + requireClientCertificate, onBadCertificate);
|
| if (host is InternetAddress) host = host.host;
|
| InternetAddress address = socket.address;
|
| if (host != null) {
|
| address = InternetAddress._cloneWithNewHost(address, host);
|
| }
|
| - return new _RawSecureSocket(address,
|
| - requestedPort,
|
| - is_server,
|
| - context,
|
| - socket,
|
| - subscription,
|
| - bufferedData,
|
| - requestClientCertificate,
|
| - requireClientCertificate,
|
| - onBadCertificate,
|
| - supportedProtocols)
|
| - ._handshakeComplete.future;
|
| + return new _RawSecureSocket(
|
| + address,
|
| + requestedPort,
|
| + is_server,
|
| + context,
|
| + socket,
|
| + subscription,
|
| + bufferedData,
|
| + requestClientCertificate,
|
| + requireClientCertificate,
|
| + onBadCertificate,
|
| + supportedProtocols)
|
| + ._handshakeComplete
|
| + .future;
|
| }
|
|
|
| _RawSecureSocket(
|
| @@ -466,8 +443,8 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| // Throw an ArgumentError if any field is invalid. After this, all
|
| // errors will be reported through the future or the stream.
|
| _secureFilter.init();
|
| - _secureFilter.registerHandshakeCompleteCallback(
|
| - _secureHandshakeCompleteHandler);
|
| + _secureFilter
|
| + .registerHandshakeCompleteCallback(_secureHandshakeCompleteHandler);
|
| if (onBadCertificate != null) {
|
| _secureFilter.registerBadCertificateCallback(_onBadCertificateWrapper);
|
| }
|
| @@ -477,35 +454,33 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| // If a current subscription is provided use this otherwise
|
| // create a new one.
|
| _socketSubscription = _socket.listen(_eventDispatcher,
|
| - onError: _reportError,
|
| - onDone: _doneHandler);
|
| + onError: _reportError, onDone: _doneHandler);
|
| } else {
|
| if (_socketSubscription.isPaused) {
|
| _socket.close();
|
| - throw new ArgumentError(
|
| - "Subscription passed to TLS upgrade is paused");
|
| + throw new ArgumentError("Subscription passed to TLS upgrade is paused");
|
| }
|
| // If we are upgrading a socket that is already closed for read,
|
| // report an error as if we received READ_CLOSED during the handshake.
|
| - dynamic s = _socket; // Cast to dynamic to avoid warning.
|
| + dynamic s = _socket; // Cast to dynamic to avoid warning.
|
| if (s._socket.closedReadEventSent) {
|
| _eventDispatcher(RawSocketEvent.READ_CLOSED);
|
| }
|
| _socketSubscription
|
| - ..onData(_eventDispatcher)
|
| - ..onError(_reportError)
|
| - ..onDone(_doneHandler);
|
| + ..onData(_eventDispatcher)
|
| + ..onError(_reportError)
|
| + ..onDone(_doneHandler);
|
| }
|
| try {
|
| var encodedProtocols =
|
| SecurityContext._protocolsToLengthEncoding(supportedProtocols);
|
| - _secureFilter.connect(address.host,
|
| - context,
|
| - is_server,
|
| - requestClientCertificate ||
|
| - requireClientCertificate,
|
| - requireClientCertificate,
|
| - encodedProtocols);
|
| + _secureFilter.connect(
|
| + address.host,
|
| + context,
|
| + is_server,
|
| + requestClientCertificate || requireClientCertificate,
|
| + requireClientCertificate,
|
| + encodedProtocols);
|
| _secureHandshake();
|
| } catch (e, s) {
|
| _reportError(e, s);
|
| @@ -513,22 +488,19 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| }
|
|
|
| StreamSubscription<RawSocketEvent> listen(void onData(RawSocketEvent data),
|
| - {Function onError,
|
| - void onDone(),
|
| - bool cancelOnError}) {
|
| + {Function onError, void onDone(), bool cancelOnError}) {
|
| _sendWriteEvent();
|
| return _stream.listen(onData,
|
| - onError: onError,
|
| - onDone: onDone,
|
| - cancelOnError: cancelOnError);
|
| + onError: onError, onDone: onDone, cancelOnError: cancelOnError);
|
| }
|
|
|
| - static void _verifyFields(host,
|
| - int requestedPort,
|
| - bool is_server,
|
| - bool requestClientCertificate,
|
| - bool requireClientCertificate,
|
| - Function onBadCertificate) {
|
| + static void _verifyFields(
|
| + host,
|
| + int requestedPort,
|
| + bool is_server,
|
| + bool requestClientCertificate,
|
| + bool requireClientCertificate,
|
| + Function onBadCertificate) {
|
| if (host is! String && host is! InternetAddress) {
|
| throw new ArgumentError("host is not a String or an InternetAddress");
|
| }
|
| @@ -547,7 +519,7 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| if (onBadCertificate != null && onBadCertificate is! Function) {
|
| throw new ArgumentError("onBadCertificate is not null or a Function");
|
| }
|
| - }
|
| + }
|
|
|
| int get port => _socket.port;
|
|
|
| @@ -560,8 +532,9 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| }
|
|
|
| int available() {
|
| - return _status != CONNECTED ? 0
|
| - : _secureFilter.buffers[READ_PLAINTEXT].length;
|
| + return _status != CONNECTED
|
| + ? 0
|
| + : _secureFilter.buffers[READ_PLAINTEXT].length;
|
| }
|
|
|
| Future<RawSecureSocket> close() {
|
| @@ -629,14 +602,14 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| bool get readEventsEnabled => _readEventsEnabled;
|
|
|
| void set readEventsEnabled(bool value) {
|
| - _readEventsEnabled = value;
|
| - _scheduleReadEvent();
|
| + _readEventsEnabled = value;
|
| + _scheduleReadEvent();
|
| }
|
|
|
| List<int> read([int length]) {
|
| if (length != null && (length is! int || length < 0)) {
|
| - throw new ArgumentError(
|
| - "Invalid length parameter in SecureSocket.read (length: $length)");
|
| + throw new ArgumentError(
|
| + "Invalid length parameter in SecureSocket.read (length: $length)");
|
| }
|
| if (_closedRead) {
|
| throw new SocketException("Reading from a closed socket");
|
| @@ -652,12 +625,12 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| // Write the data to the socket, and schedule the filter to encrypt it.
|
| int write(List<int> data, [int offset, int bytes]) {
|
| if (bytes != null && (bytes is! int || bytes < 0)) {
|
| - throw new ArgumentError(
|
| - "Invalid bytes parameter in SecureSocket.read (bytes: $bytes)");
|
| + throw new ArgumentError(
|
| + "Invalid bytes parameter in SecureSocket.read (bytes: $bytes)");
|
| }
|
| if (offset != null && (offset is! int || offset < 0)) {
|
| - throw new ArgumentError(
|
| - "Invalid offset parameter in SecureSocket.read (offset: $offset)");
|
| + throw new ArgumentError(
|
| + "Invalid offset parameter in SecureSocket.read (offset: $offset)");
|
| }
|
| if (_closedWrite) {
|
| _controller.addError(new SocketException("Writing to a closed socket"));
|
| @@ -738,7 +711,7 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| }
|
|
|
| void _closeHandler() {
|
| - if (_status == CONNECTED) {
|
| + if (_status == CONNECTED) {
|
| if (_closedRead) return;
|
| _socketClosedRead = true;
|
| if (_filterStatus.readEmpty) {
|
| @@ -753,9 +726,9 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| } else if (_status == HANDSHAKE) {
|
| _socketClosedRead = true;
|
| if (_filterStatus.readEmpty) {
|
| - _reportError(
|
| - new HandshakeException('Connection terminated during handshake'),
|
| - null);
|
| + _reportError(
|
| + new HandshakeException('Connection terminated during handshake'),
|
| + null);
|
| } else {
|
| _secureHandshake();
|
| }
|
| @@ -774,16 +747,16 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| }
|
| }
|
|
|
| - void renegotiate({bool useSessionCache: true,
|
| - bool requestClientCertificate: false,
|
| - bool requireClientCertificate: false}) {
|
| + void renegotiate(
|
| + {bool useSessionCache: true,
|
| + bool requestClientCertificate: false,
|
| + bool requireClientCertificate: false}) {
|
| if (_status != CONNECTED) {
|
| throw new HandshakeException(
|
| "Called renegotiate on a non-connected socket");
|
| }
|
| - _secureFilter.renegotiate(useSessionCache,
|
| - requestClientCertificate,
|
| - requireClientCertificate);
|
| + _secureFilter.renegotiate(
|
| + useSessionCache, requestClientCertificate, requireClientCertificate);
|
| _status = HANDSHAKE;
|
| _filterStatus.writeEmpty = false;
|
| _scheduleFilter();
|
| @@ -810,7 +783,7 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| _pauseCount--;
|
| if (_pauseCount == 0) {
|
| _scheduleReadEvent();
|
| - _sendWriteEvent(); // Can send event synchronously.
|
| + _sendWriteEvent(); // Can send event synchronously.
|
| }
|
| }
|
|
|
| @@ -898,8 +871,8 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| if (bytes > _bufferedData.length - _bufferedDataIndex) {
|
| bytes = _bufferedData.length - _bufferedDataIndex;
|
| }
|
| - var result = _bufferedData.sublist(_bufferedDataIndex,
|
| - _bufferedDataIndex + bytes);
|
| + var result =
|
| + _bufferedData.sublist(_bufferedDataIndex, _bufferedDataIndex + bytes);
|
| _bufferedDataIndex += bytes;
|
| if (_bufferedData.length == _bufferedDataIndex) {
|
| _bufferedData = null;
|
| @@ -925,7 +898,8 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| void _writeSocket() {
|
| if (_socketClosedWrite) return;
|
| var buffer = _secureFilter.buffers[WRITE_ENCRYPTED];
|
| - if (buffer.readToSocket(_socket)) { // Returns true if blocked
|
| + if (buffer.readToSocket(_socket)) {
|
| + // Returns true if blocked
|
| _socket.writeEventsEnabled = true;
|
| }
|
| }
|
| @@ -986,8 +960,8 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| null);
|
| } else {
|
| // If we're connected, throw a TLS error.
|
| - _reportError(new TlsException('${response[1]} error ${response[0]}'),
|
| - null);
|
| + _reportError(
|
| + new TlsException('${response[1]} error ${response[0]}'), null);
|
| }
|
| }
|
| int start(int index) => response[2 * index];
|
| @@ -1048,7 +1022,6 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
|
| }
|
| }
|
|
|
| -
|
| /**
|
| * A circular buffer backed by an external byte array. Accessed from
|
| * both C++ and Dart code in an unsynchronized way, with one reading
|
| @@ -1087,14 +1060,11 @@ class _ExternalBuffer {
|
|
|
| bool get isEmpty => end == start;
|
|
|
| - int get length =>
|
| - start > end ? size + end - start : end - start;
|
| + int get length => start > end ? size + end - start : end - start;
|
|
|
| - int get linearLength =>
|
| - start > end ? size - start : end - start;
|
| + int get linearLength => start > end ? size - start : end - start;
|
|
|
| - int get free =>
|
| - start > end ? start - end - 1 : size + start - end - 1;
|
| + int get free => start > end ? start - end - 1 : size + start - end - 1;
|
|
|
| int get linearFree {
|
| if (start > end) return start - end - 1;
|
| @@ -1114,10 +1084,7 @@ class _ExternalBuffer {
|
| // Loop over zero, one, or two linear data ranges.
|
| while (bytesRead < bytes) {
|
| int toRead = min(bytes - bytesRead, linearLength);
|
| - result.setRange(bytesRead,
|
| - bytesRead + toRead,
|
| - data,
|
| - start);
|
| + result.setRange(bytesRead, bytesRead + toRead, data, start);
|
| advanceStart(toRead);
|
| bytesRead += toRead;
|
| }
|
| @@ -1173,23 +1140,22 @@ class _ExternalBuffer {
|
| }
|
| }
|
|
|
| -
|
| abstract class _SecureFilter {
|
| external factory _SecureFilter();
|
|
|
| - void connect(String hostName,
|
| - SecurityContext context,
|
| - bool is_server,
|
| - bool requestClientCertificate,
|
| - bool requireClientCertificate,
|
| - Uint8List protocols);
|
| + void connect(
|
| + String hostName,
|
| + SecurityContext context,
|
| + bool is_server,
|
| + bool requestClientCertificate,
|
| + bool requireClientCertificate,
|
| + Uint8List protocols);
|
| void destroy();
|
| void handshake();
|
| String selectedProtocol();
|
| void rehandshake();
|
| - void renegotiate(bool useSessionCache,
|
| - bool requestClientCertificate,
|
| - bool requireClientCertificate);
|
| + void renegotiate(bool useSessionCache, bool requestClientCertificate,
|
| + bool requireClientCertificate);
|
| void init();
|
| X509Certificate get peerCertificate;
|
| int processBuffer(int bufferIndex);
|
| @@ -1212,9 +1178,8 @@ class TlsException implements IOException {
|
| final String message;
|
| final OSError osError;
|
|
|
| - const TlsException([String message = "",
|
| - OSError osError = null])
|
| - : this._("TlsException", message, osError);
|
| + const TlsException([String message = "", OSError osError = null])
|
| + : this._("TlsException", message, osError);
|
|
|
| const TlsException._(this.type, this.message, this.osError);
|
|
|
| @@ -1233,25 +1198,21 @@ class TlsException implements IOException {
|
| }
|
| }
|
|
|
| -
|
| /**
|
| * An exception that happens in the handshake phase of establishing
|
| * a secure network connection.
|
| */
|
| class HandshakeException extends TlsException {
|
| - const HandshakeException([String message = "",
|
| - OSError osError = null])
|
| - : super._("HandshakeException", message, osError);
|
| + const HandshakeException([String message = "", OSError osError = null])
|
| + : super._("HandshakeException", message, osError);
|
| }
|
|
|
| -
|
| /**
|
| * An exception that happens in the handshake phase of establishing
|
| * a secure network connection, when looking up or verifying a
|
| * certificate.
|
| */
|
| class CertificateException extends TlsException {
|
| - const CertificateException([String message = "",
|
| - OSError osError = null])
|
| - : super._("CertificateException", message, osError);
|
| + const CertificateException([String message = "", OSError osError = null])
|
| + : super._("CertificateException", message, osError);
|
| }
|
|
|