Setting secure websocket server on Mac

I am trying to set up a secure local websocket server on a mac using swift. I think I am able to get a non-secure server running (still untested). But I am unable to find any documentation that points to how to set up a secure connection (say uses TLS 1.2) if I have an ssl cert, an intermediate cert (both pem files) and the private key for that cert.

Any insight would be great.

Any code samples that show setting up a local secure websocket server that makes use of certificates and private keys would be even better.

Replies

IMPORTANT Before going further, read TLS for App Developers, because I’m going to assume its concepts and terminology.

I think I am able to get a non-secure server running (still untested).

Why haven’t yet tested it?

In situations like this, it’s best to get things working over TCP before you start monkeying with TLS.

Is your TCP-based server uses Network framework’s built-in WebSocket support? That is, NWListener and NWConnection? Or some third-party WebSocket library?

This matters because the Network framework way of doing TLS is different from approaches used by older libraries.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I tested my server without TLS and it works. It uses NWConnection and NWListener - no other third party libraries are involved. I have a pfx file to enable TLS but can extract the certs and private key if needed and use those as well. But it's not clear to me how to incorporate those into the NWConnection/NWListener/NWParameters framework.

@eskimo Would appreciate your feedback on the above question. Thanks.