DTLS over UDP on Server and Client Components

From sgcWebSockets 2022.8.0 DTLS over UDP is supported by Server and Client UDP components. This means that now you can send encrypted messages using UDP (like WebSocket or HTTP protocol that work over TLS).

From Wikipedia: Datagram Transport Layer Security (DTLS) is a communications protocol providing security to datagram-based applications by allowing them to communicate in a way designed[1][2] to prevent eavesdropping, tampering, or message forgery. The DTLS protocol is based on the stream-oriented Transport Layer Security (TLS) protocol and is intended to provide similar security guarantees.


Configuration 

The configuration is very similar to other components. There is a new property called DTLSOptions where you can configure the DTLS options like file certificate, private key, certificate verification... To enabled DTLS just set the DTLS property to True before the server starts or before send a message from a client to server.

The certificate must be in PEM format, so if the certificate has a different format, first convert to PEM.

DTLS requires openSSL 1.1+ so the default Indy version that comes with  Rad Studio currently doesn't support it. Only sgcWebSockets Enterprise version supports DTLS (because this version comes with a custom indy version that supports openSSL 1.1 and 3.0).

Server 

  // ... server
  server := TsgcUDPServer.Create(nil);
  server.Port := StrToInt(txtDefaultPort.Text);
  server.Bindings.Clear;
  With server.Bindings.Add do
  begin
    IP := '127.0.0.1';
    Port := 5430;
  end;
  // ... dtls
  server.DTLS := True;
  server.DTLSOptions.CertFile := 'certificate.pem';
  server.DTLSOptions.KeyFile := 'privatekey.pem';
  // ... active
  server.Active := True; 

Client 

    // ... client
    client.Host := '127.0.0.1';
    client.Port := 5430;

    client.DTLS := True;
    client.DTLSOptions.CertFile := 'certificate.pem';
    client.DTLSOptions.KeyFile := 'privatekey.pem';

    client.WriteData('Hello from sgcWebSockets!!!'); 

Demo

Find below a link to a DTLS over UDP demo that shows how it works on windows using the sgcWebSockets library.

File Name: udp_dtls
File Size: 4.4 mb
Download File
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

RTCPeerConnection P2P
Delphi 11.2 iOS ARM Simulator

Related Posts