Runs a local server which intercepts HTTP requests which can be preloaded to the webview.
Running the local server with a https://0.0.0.0:8888
connnection works*, but results may vary depending on how the certificates actually work.
Local HTML | Remote HTTP |
---|---|
The application starts a local TCP server running at http://0.0.0.0:8888
via the LocalServer
class, which will try to match incoming requests with files found in the bundle. This works for loading a website via a local HTML file, or from a remote domain using HTTP
.
Much of the code was obtained from this article:
Since the assets are serverd over HTTP://
and not HTTPS://
this will cause problems when mixing insecure content.
The following approaches attempt to mitigate the mixed context issue.
- Assets to be loaded locally use a custom scheme
my-app://
along with theWKURLSchemeHandler
- Reuests are proxied via the
ProxyURLProtocol
which does a sort of MITM with content - Manage to locally sign the TCP server to serve secure content?
You can use the following two links to text a file which contains assets with http://0.0.0.0:8888
link
- test http: http://d.dlabs.me/test/example.html
- test https: https://d.dlabs.me/test/example.html
openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 3650 -keyout my.key -out my.cer;
Then we need to convert this to a .der
file:
openssl x509 -in certificate.crt -outform der -out certificate.der
To generate the proper SSL certificates for the server, you can use the following commands:
openssl pkcs12 -legacy -export -out client.p12 -inkey my.key -in certificate.der
- Setting up Netcat
- Networking Proxy Config
- WKDataStore Proxy Configurations
- TLS Configuration (low level)
- Cocoa HTTP Server
- Apple Questions: TLS Stuff (Quinn the Eskimo)
- Creating an identity for a local network
- How to use NWParameters TLS
- Apple Developer: Problems setting up local server
- How to use MIME type
- Custom fonts in WKWebView