Is there a way to configure Ktor in an engine / pl...
# ktor
s
Is there a way to configure Ktor in an engine / platform independent way to accept unknown certificates on HTTPS connections? Details in thread.
So, the error I get is (on the JVM):
javax.net.ssl.SSLHandshakeException: (certificate_unknown) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
. I know how to solve that for OkHttp, but I'd like to avoid writing engine-specific code for each target platform.
a
I'm not aware of a general way to handle the certificates though it shouldn't be too hard to replicate.
Can I ask why you need the untrusted cert as opposed to having a trusted one? Often times, even in dev environments, there are ways to do what you need.
s
I'm talking to the REST API of a solar inverter in my house, and that's using an unknown / untrusted certificate.
a
Ahhh, then it may be easier to just configure for each engine or use something like CIO that you can use on each platform. Or, put Caddy web server (caddyserver.com) in front of it with a config like this:
Copy code
example.com {
    reverse_proxy https://upstream-service:port {
        transport http {
            tls_insecure_skip_verify
        }
    }
}
Then you can use dynamic dns and have caddy get an acme cert automatically (no additional config required).
h
What's the usecase to configure it for each engine? You either configure it in your app code, but you often need platform specific engines or configuration anyway. As a library, you should never pre-configure cert handling.
s
Well, in this case I don't need (other) platform-specific configuration, and as the library will only ever talk to that inverter API, also pre-configuring cert handling should be fine.
Thanks @Anonymike, I guess I'll simply go with CIO then!
👍 1
a
Caddy is also a great solution to secure everything down stream and once you have that in your toolbelt I promise you'll use it else where.
💯 2
Cert handling is automated, config is extremely light, and its a 30mb binary with secure defaults. Highly recommend it in front of any application.