tango.net.SSLSocketConduit

License:

BSD style: see license.txt

Author:

Jeff Davey
class SSLSocketConduit : SocketConduit #
SSLSocketConduit is a sub-class of SocketConduit. It's purpose is to provide SSL encryption at the socket level as well as easily fit into existing Tango network applications that may already be using SocketConduit.
SSLSocketConduit requires the OpenSSL library, and uses a dynamic binding to the library. You can find the library at http://www.openssl.org and a Win32 specific port at http://www.slproweb.com/products/Win32OpenSSL.html.

SSLSocketConduit's have two modes:

1. Client mode, useful for connecting to existing servers, but not accepting new connections. Accepting a new connection will cause the library to stall on a write on connection.

2. Server mode, useful for creating an SSL server, but not connecting to an existing server. Connection will cause the library to stall on a read on connection.

Example

1
2
3
4
5
6
7
8
9
10
auto s1 = new SSLSocketConduit();
if (s1.connect(new InternetAddress("www.yahoo.com", 443)))
{
    char[] cmd = "GET / HTTP/1.0\r\n\r\n";
    s1.write(cmd);
    char[1024] buff;
    uint bytesRead = read(buff);
    if (byteRead != SSLSocketConduit.Eof)
        Stdout.formatln("received: {}", buff[0..bytesRead]);
}
this() [override] #
Create a default Client Mode SSLSocketConduit.
this(SocketType type, ProtocolType protocol, bool create = true) [override] #
Creates a Client Mode SSLSocketConduit
This is overriding the SocketConduit ctor in order to emulate the existing free-list frameowrk.

Specifying anything other than ProtocolType.TCP or SocketType.STREAM will cause an Exception to be thrown.

this(Socket sock, SSLCtx ctx, bool clientMode = true) #
Creates a SSLSocketConduit
This class allows the ability to turn a regular Socket into an SSLSocketConduit. It also gives the ability to change an SSLSocketConduit into Server Mode or ClientMode.

Params:

sockThe socket to wrap in SSL
SSLCtxthe SSL Context as provided by the PKI layer.
clientModeif true the socket will be Client Mode, Server otherwise.
void detach() [override] #
Release this SSLSocketConduit. As per SocketConduit.detach.
SSLSocketConduit allocate() [package, synchronized, static] #
Allocate a SSLSocketConduit from a free-list, rather than creating a new one. As per SocketConduit.allocate
size_t write(void[] src) [override] #
Writes the passed buffer to the underlying socket stream. This will block until socket error.
As per SocketConduit.write
size_t read(void[] dst) [override] #
Reads from the underlying socket stream. If needed, setTimeout will set the max length of time the read will take before returning.
As per SocketConduit.read
bool hadTimeout() [override] #
Returns true if the last read operation timed out.
As per SocketConduit.hadTimeout;
SocketConduit shutdown() [override] #
Shuts down the underlying socket for reading and writing.
As per SocketConduit.shutdown
SocketConduit setTimeout(float timeout) [override] #
Used to set the max timeout on read operations.
As per SocketConduit.setTimeout;
void setCtx(SSLCtx ctx, bool clientMode = true) #
Used in conjuction with the above ctor with the create flag disabled. It is useful for accepting a new socket into a SSLSocketConduit, and then re-using the Server's existing SSLCtx.

Params:

ctxSSLCtx class as provided by PKI
clientModeif true, the socket will be in Client Mode, Server otherwise.