{host,
bool sendClientCertificate: false,
String certificateName,
bool onBadCertificate(X509Certificate certificate)}
Takes an already connected socket
and starts client side TLS
handshake to make the communication secure. When the returned
future completes the SecureSocket has completed the TLS
handshake. Using this function requires that the other end of the
connection is prepared for TLS handshake.
If the socket
already has a subscription, this subscription
will no longer receive and events. In most cases calling
pause
on this subscription before starting TLS handshake is
the right thing to do.
If the host
argument is passed it will be used as the host name
for the TLS handshake. If host
is not passed the host name from
the socket
will be used. The host
can be either a String or
an InternetAddress.
Calling this function will not cause a DNS host lookup. If the
host
passed is a String the InternetAddress for the
resulting SecureSocket will have the passed in host
as its
host value and the internet address of the already connected
socket as its address value.
See connect for more information on the arguments.
Source
/**
* Takes an already connected [socket] and starts client side TLS
* handshake to make the communication secure. When the returned
* future completes the [SecureSocket] has completed the TLS
* handshake. Using this function requires that the other end of the
* connection is prepared for TLS handshake.
*
* If the [socket] already has a subscription, this subscription
* will no longer receive and events. In most cases calling
* `pause` on this subscription before starting TLS handshake is
* the right thing to do.
*
* If the [host] argument is passed it will be used as the host name
* for the TLS handshake. If [host] is not passed the host name from
* the [socket] will be used. The [host] can be either a [String] or
* an [InternetAddress].
*
* Calling this function will _not_ cause a DNS host lookup. If the
* [host] passed is a [String] the [InternetAddress] for the
* resulting [SecureSocket] will have the passed in [host] as its
* host value and the internet address of the already connected
* socket as its address value.
*
* See [connect] for more information on the arguments.
*
*/
static Future<SecureSocket> secure(
Socket socket,
{host,
bool sendClientCertificate: false,
String certificateName,
bool onBadCertificate(X509Certificate certificate)}) {
var completer = new Completer();
(socket as dynamic)._detachRaw()
.then((detachedRaw) {
return RawSecureSocket.secure(
detachedRaw[0],
subscription: detachedRaw[1],
host: host,
sendClientCertificate: sendClientCertificate,
onBadCertificate: onBadCertificate);
})
.then((raw) {
completer.complete(new SecureSocket._(raw));
});
return completer.future;
}