Can we setup a local HTTPS Server in Mac OS X using swift
I want to setup a local HTTP Server running in my Mac OSX machine which should be able to handle requests that are coming from web browser. But I am not sure whether we can setup HTTPS server using swift. In this https://swift.org/server-apis/ there is only info about HTTP but not HTTPS. Any help is very much appreciated
Solution 1:
Yes, Apple's Swift language can be used to create a web server that accepts HTTPS connections. See Going Server-side with Swift Open Source for Apple's introduction to developing servers.
Using Swift, you have access to a range of included and third party SSL/TLS libraries. The language used to write the library is not important, so long as the library offers a C API.
Network.framework and AFNetworking
If you are a developer, consider using Apple's Network framework. The framework claims to provide easier support for secure connections.
Alternatively, look at using the open source project AFNetworking.
Apple's Frameworks
Given you want to focus on Apple's security offerings, you can pick from:
- Apple's Network.framework (in beta at the time of answering)
- Apple's NSURL* family of classes
- Apple's CFNetwork
- Apple's Secure Transport API
Be aware that most of these are ultimately built upon the low level Common Crypto code base.
Transparent Proxy
Consider using an existing web server, such as Nginx, httpd, or Caddy, to act as a transparent proxy in-front of your own service. The existing web server can handle the SSL/TLS security and pass back HTTP requests to your locally running service.
This is a fairly common configuration because it simplifies your service and puts the security burden on a well tested existing front-end server.
Not a developer?
If you are not a developer, consider using a pre-built web server with support for Lets Encrypt (free) TLS certificates. One such server is Caddy:
Caddy is the HTTP/2 web server with automatic HTTPS.