Am 03.12.2024 um 03:48 schrieb Curtis:
I'm struggling to update my requestHTTP function call to use TLS. I've
attempted to set the [HTTPClientSettings]|(https://vibed.org/api/
vibe.http.client/HTTPClientSettings) thus:auto settings = new HTTPClientSettings; settings.tlsContextSetup = (scope ctx) { ctx.kind = TLSContextKind.client; }; HTTPClientResponse response = requestHTTP(url, (scope HTTPClientRequest request) { request.method = HTTPMethod.POST; immutable requestBody = EXAMPLE.format(stuff); request.writeBody(cast(ubyte[]) requestBody, JSON_MIME); }, settings);
But I get an error:
Error: function `vibe.stream.tls.TLSContext.kind() const` is not callable using argument types `(TLSContextKind)`: expected 0 argument(s), not 1
What am I missing?
Thanks,
Curtis
The kind
property is read-only and is determined at instantiation time
(in this case it should always be TLSContextKind.client
). What you
typically need to do within the tlsContextSetup
callback, though, is
to set up rules for certificate verification.
On Linux that would typically be done like this, where the exact path
may differ between distributions:
ctx.useTrustedCertificateFile("/etc/ssl/certs/ca-certificates.crt");
If you are dealing with self-signed certificates, you would have to
lower peerValidationMode
to TLSPeerValidationMode.validCert
and then
ideally set the peerValidationCallback
to check if the certificate is
known or signed by your own CA certificate.