TML is based on the peer to peer standard protocol BEEP (Blocks Extensible Exchange Protocol), defined in RFC3080 and RFC3081.
The main advantage the BEEP protocol has is that it solves many common problems that the network protocol designer will have to face while designing an application protocol. Securing a connection to avoid other parties to access data exchanged by BEEP peers is one of them.
The idea behind the TLS profile is to enable user level applications to activate the TLS profile for a given connection. Using the libTml library API has no difference about using a connection that is secured from one that is not.
All examples in this section contain only code lines to explain a special aspect of the API. Important things like error handling are left out in favor of better readability.
Create a connection to a remote peer
Secure the connection already created
Then use the connection, as usual, sending command / data over it
From the application programmer's point of view there is no difference from using a connection secured to one that is not.
A TML_ON_ACCEPT_TLS_REQUEST_CB_FUNC() handler should be defined to control if an incoming TLS requests is accepted
A TML_ON_CERTIFICATE_FILE_LOCATION_CB_FUNC() handler should be defined to control which certificate file is to be used
A TML_ON_CERTIFICATE_PRIVATE_KEY_LOCATION_CB_FUNC() handler should be defined to control which private key file is to be used
Now use previous handlers to configure how TLS profile is supported for the current TML Library instance
Listener initialisation
Now your listener is prepared to receive incoming connections and enable TLS on them.
Now we have successfully configured the TLS profile.For listener side we need to create a certificate/private key pair. Currently libTML TLS support is built using OpenSSL (http://www.openssl.org). This SSL toolkit comes with some tools to create such files. Here is an example to create a test certificate and a private key that can be used for testing purposes.
Create a 1024 bits private key using:
openssl genrsa 1024 > TmlTestTls.key
Now create the public certificate reusing previously created key as follows:
openssl req -new -x509 -nodes -sha1 -days 3650 -key TmlTestTls.key > TmlTestTls.crt
Once finished, you can check certificate data using:
openssl x509 -noout -fingerprint -text < TmlTestTls.crt