Im am currently writing a project in C using OpenSSL/TLS and I am not very experienced in encryption. I have successfully established unencrypted OpenSSL connections and I am relatively experienced in C/C++. The Project involves the actuation of hardware so the data sent is very repetitive and not confidential (Just a few bytes, like turn commands for a servo or a temperature readout)

Basically I have multiple clients in a local network which I want to securely connect to a local server. The system has to work offline. All I want right now is to establish a connection between the client and the server to prevent unauthorized connections. Authentication and User restriction will be restricted by the application on the server.

I have been looking at Public Key Encryption but from my understanding that requires a connection to the CA which might not be available at all times. How correct is this and what are my alternatives?

A simple C implementation would be helpful too. Thank you

1 Answer 1


TLS is the right protocol for this purpose. There is no need to have an internet connection with TLS (i.e. your requirement to be offline) but you can use TLS either with self-signed certificates (simple but does not scale well) or have your own certificate authority (more complex but scales well).

A simple C implementation would be helpful too.

Using plain OpenSSL for TLS in a proper way is usually not simple. There are many sample implementations on the web but they often suffer from insufficient certificate validation. If you implement it yourself you should make sure that

  • the trust path, expiration etc is checked properly. That's what most samples already do because it can be simple done with OpenSSL. See https://wiki.openssl.org/index.php/SSL/TLS_Client for an example client.
  • the subject of the certificate is checked against the expected one. That's what most examples don't do because it was too complex with older OpenSSL versions. But, not doing this makes you open to man in the middle attacks. See https://wiki.openssl.org/index.php/Hostname_validation for how this can be done.
  • in case of a PKI instead of self-signed certificates the revocation needs checked either against a CRL you need to download from somewhere or against OCSP. This is almost never done and too complex with OpenSSL. I don't know if any sample code for this.
  • The Self Signed Certificate is only required on the Server, correct?
    – Flowx
    Commented Aug 7, 2017 at 9:14
  • @Flowx: the self signed certificate is only required at the server together with the matching private key. But, clients need to know which certificate to expect so they either need to check it against some hard-coded fingerprint or similar or have the certificate explicitly installed as trusted (without the private key). Commented Aug 7, 2017 at 10:09
  • By fingerprint you mean something like a checksum (CRC32) of the Certificate? But then I would have to update that every time the Cert expires or how would you forge a fingerprint? I thought certificates always contain a key pair, is this incorrect?
    – Flowx
    Commented Aug 7, 2017 at 11:27
  • @Flowx: with fingerprinting I mean using some secure hash function like SHA-256. And yes, you need to change this whenever the certificate changes. If you don't want this use a PKI. As I said: self-signed = simple but does not scale, PKI = complex but does scale. Commented Aug 7, 2017 at 11:31
  • In this case, PSK seems like a simpler solution to me. I simply want to prevent other devices to establish a connection with a client. Setting up a PKI seems overkill to me and updating every client would be very tedious after installation. (Physical access)
    – Flowx
    Commented Aug 7, 2017 at 13:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .