initializeSslAndCreateCtx

Initializes SSL and creates a global SSL_CTX object

This function must be called before any SSL clients can be created

ulong
initializeSslAndCreateCtx
(
const(char*) ca_path
,
const(char*) ca_file = null
)

Parameters

ca_path const(char*)

a directory containing CA certificates in PEM format

ca_file const(char*)

pointer to a file of CA certificates in PEM format, or null. The file can containe several CA certificates.

Return Value

Type: ulong

0 if successful, otherwise returns an error code

Examples

Usage Exmple:

Here is the fundamental code for an HTTPS client. A proper HTTP client would need to parse the HTTP response header to determine how many bytes should be read; this example will always trigger an error after the final bytes are read.

// Check that the code compiles.

void test_ssl_compilation ()
{
    .initializeSslAndCreateCtx("/etc/ssl/certs\0".ptr);

    auto client = new SslClientConnection;

    auto host = "en.wikipedia.org";
    auto url_path = "/wiki/D_(programming_language)";

    try
    {
        client.connect(host, "443");
        client.validateCertificate(host);

        auto request = "GET " ~ url_path ~ " HTTP/1.1\r\nHost: "
            ~ host ~ "\r\nConnection:close\r\n\r\n";

        client.write(request);

        char[500] buffer;

        while (true)
        {
            auto result = client.read(buffer);

            // The HTTP response header will arrive first, followed
            // by the data (a web page in this example)
        }
    }
    catch (SslClientConnection.SslException e)
    {
    }
    return;
}

Meta