vibe.d beta banner
get vibe.d
0.8.1

Asynchronous I/O that doesn’t get in your way, written in D

Module vibe.stream.tls

TLS stream implementation

TLSStream can be used to implement TLS communication on top of a TCP connection. The TLSContextKind of an TLSStream determines if the TLS tunnel is established actively (client) or passively (server).

Example

A simple TLS client

import vibe.core.net;
import vibe.stream.tls;

void sendTLSMessage()
{
	auto conn = connectTCP("127.0.0.1", 1234);
	auto sslctx = createTLSContext(TLSContextKind.client);
	auto stream = createTLSStream(conn, sslctx);
	stream.write("Hello, World!");
	stream.finalize();
	conn.close();
}

Example

Corresponding server

import vibe.core.log;
import vibe.core.net;
import vibe.stream.operations;
import vibe.stream.tls;

void listenForTLS()
{
	auto sslctx = createTLSContext(TLSContextKind.server);
	sslctx.useCertificateChainFile("server.crt");
	sslctx.usePrivateKeyFile("server.key");
	listenTCP(1234, delegate void(TCPConnection conn) nothrow {
		try {
			auto stream = createTLSStream(conn, sslctx);
			logInfo("Got message: %s", stream.readAllUTF8());
			stream.finalize();
		} catch (Exception e) {
			logInfo("Failed to receive encrypted message");
		}
	});
}

Functions

NameDescription
createTLSContext(kind, ver)Creates a new context of the given kind.
createTLSStream(underlying, ctx, peer_name, peer_address)Constructs a new TLS tunnel and infers the stream state from the TLSContextKind.
createTLSStream(underlying, ctx, state, peer_name, peer_address)Constructs a new TLS tunnel, allowing to override the stream state.
createTLSStreamFL(underlying, ctx, state, peer_name, peer_address)Constructs a new TLS stream using manual memory allocator.
setTLSContextFactory(factory)

Interfaces

NameDescription
TLSContextEncapsulates the configuration for an TLS tunnel.
TLSStreamCreates an TLS tunnel within an existing stream.

Structs

NameDescription
TLSCertificateInformationCertificate information
TLSPeerValidationData

Enums

NameDescription
TLSContextKind
TLSPeerValidationModeSpecifies how rigorously TLS peer certificates are validated.
TLSStreamState
TLSVersion

Aliases

NameTypeDescription
TLSALPNCallback@safe string delegate(string[])
TLSPeerValidationCallback@safe bool delegate(scope TLSPeerValidationData)
TLSServerNameCallback@safe TLSContext delegate(string)
Authors

Sönke Ludwig

Copyright

© 2012-2014 RejectedSoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.