Swan Lake Beta2 is here.
import ballerina/http;

// An HTTP listener can be configured to accept new connections that are
// secured via mutual SSL.
// The [`http:ListenerSecureSocket`](https://docs.central.ballerina.io/ballerina/http/latest/records/ListenerSecureSocket) record provides the SSL-related listener configurations.
listener http:Listener securedEP = new(9090,
    secureSocket = {
        key: {
            certFile: "../resource/path/to/public.crt",
            keyFile: "../resource/path/to/private.key"
        },
        // Enables mutual SSL.
        mutualSsl: {
            verifyClient: http:REQUIRE,
            cert: "../resource/path/to/public.crt"
        },
        // Enables the preferred SSL protocol and its versions.
        protocol: {
            name: http:TLS,
            versions: ["TLSv1.2", "TLSv1.1"]
        },
        // Configures the preferred ciphers.
        ciphers: ["TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"]

    }
);

service /foo on securedEP {
    resource function get bar() returns string {
        return "Hello, World!";
    }
}

Service - Mutual SSL

Ballerina supports mutual SSL, which is a certificate-based authentication process in which two parties (the client and server) authenticate each other by verifying the digital certificates. It ensures that both parties are assured of each other’s identity.

For more information on the underlying module, see the HTTP module.

import ballerina/http;
listener http:Listener securedEP = new(9090,
    secureSocket = {
        key: {
            certFile: "../resource/path/to/public.crt",
            keyFile: "../resource/path/to/private.key"
        },

An HTTP listener can be configured to accept new connections that are secured via mutual SSL. The http:ListenerSecureSocket record provides the SSL-related listener configurations.

        mutualSsl: {
            verifyClient: http:REQUIRE,
            cert: "../resource/path/to/public.crt"
        },

Enables mutual SSL.

        protocol: {
            name: http:TLS,
            versions: ["TLSv1.2", "TLSv1.1"]
        },

Enables the preferred SSL protocol and its versions.

        ciphers: ["TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"]

Configures the preferred ciphers.

    }
);
service /foo on securedEP {
    resource function get bar() returns string {
        return "Hello, World!";
    }
}
# You may need to change the certificate file path, private key file path, and
# trusted certificate file path.
bal run http_service_mutual_ssl.bal
[ballerina/http] started HTTPS/WSS listener 0.0.0.0:9090
# To invoke the service, use the cURL commands below.
curl https://localhost:9090/foo/bar --cert /path/to/client-public.crt
    --key /path/to/client-private.key --cacert /path/to/server-public.crt
import ballerina/http;

// An HTTP listener can be configured to accept new connections that are
// secured via mutual SSL.
// The [`http:ListenerSecureSocket`](https://docs.central.ballerina.io/ballerina/http/latest/records/ListenerSecureSocket) record provides the SSL-related listener configurations.
listener http:Listener securedEP = new(9090,
    secureSocket = {
        key: {
            certFile: "../resource/path/to/public.crt",
            keyFile: "../resource/path/to/private.key"
        },
        // Enables mutual SSL.
        mutualSsl: {
            verifyClient: http:REQUIRE,
            cert: "../resource/path/to/public.crt"
        },
        // Enables the preferred SSL protocol and its versions.
        protocol: {
            name: http:TLS,
            versions: ["TLSv1.2", "TLSv1.1"]
        },
        // Configures the preferred ciphers.
        ciphers: ["TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"]

    }
);

service /foo on securedEP {
    resource function get bar() returns string {
        return "Hello, World!";
    }
}

Service - Mutual SSL

Ballerina supports mutual SSL, which is a certificate-based authentication process in which two parties (the client and server) authenticate each other by verifying the digital certificates. It ensures that both parties are assured of each other’s identity.

For more information on the underlying module, see the HTTP module.

import ballerina/http;
listener http:Listener securedEP = new(9090,
    secureSocket = {
        key: {
            certFile: "../resource/path/to/public.crt",
            keyFile: "../resource/path/to/private.key"
        },

An HTTP listener can be configured to accept new connections that are secured via mutual SSL. The http:ListenerSecureSocket record provides the SSL-related listener configurations.

        mutualSsl: {
            verifyClient: http:REQUIRE,
            cert: "../resource/path/to/public.crt"
        },

Enables mutual SSL.

        protocol: {
            name: http:TLS,
            versions: ["TLSv1.2", "TLSv1.1"]
        },

Enables the preferred SSL protocol and its versions.

        ciphers: ["TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"]

Configures the preferred ciphers.

    }
);
service /foo on securedEP {
    resource function get bar() returns string {
        return "Hello, World!";
    }
}
# You may need to change the certificate file path, private key file path, and
# trusted certificate file path.
bal run http_service_mutual_ssl.bal
[ballerina/http] started HTTPS/WSS listener 0.0.0.0:9090
# To invoke the service, use the cURL commands below.
curl https://localhost:9090/foo/bar --cert /path/to/client-public.crt
    --key /path/to/client-private.key --cacert /path/to/server-public.crt

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand