Table of Contents

SSL/TLS Connection

Inetlab.SMPP library supports SSL connection between client and server.

For SmppServer class you can set server certificate and supported SSL/TLS protocols.

For SmppClient class you can specify supported SSL/TLS protocols, and optional client certificate for authentication.

using (SmppServer server = new SmppServer(new IPEndPoint(IPAddress.Any, 7777)))
{
    server.ConnectionOptions.Ssl = new SslConnectionOptions
    {
        EnabledSslProtocols = SslProtocols.Tls12
    };
    server.ConnectionOptions.ServerCertificate = new X509Certificate2("server_certificate.p12", "cert_password");

    await server.StartAsync();

    server.evClientConnected += (sender, client) =>
    {
        //You can validate client certificate and disconnect if it is not valid.

        var subject = client.ClientCertificate.Subject;

        var certificate = client.ClientCertificate as X509Certificate2;
        if (certificate != null)
        {
            bool isValid = certificate.Verify();
        }
        
    };

    using (SmppClient client = new SmppClient())
    {
        client.EnabledSslProtocols = SslProtocols.Tls12;
        //if required you can be authenticated with client certificate
        client.ClientCertificates.Add(new X509Certificate2("client_certificate.p12", "cert_password"));

        if (await client.ConnectAsync("localhost", 7777))
        {
            BindResp bindResp = await client.BindAsync("username", "password");

            if (bindResp.Header.Status == CommandStatus.ESME_ROK)
            {
                var submitResp = await client.SubmitAsync(
                    SMS.ForSubmit()
                        .From("111")
                        .To("436641234567")
                        .Coding(DataCodings.UCS2)
                        .Text("Hello World!"));

                if (submitResp.All(x => x.Header.Status == CommandStatus.ESME_ROK))
                {
                    client.Logger.Info("Message has been sent.");
                }
            }

            await client.DisconnectAsync();
        }
    }
}