@@ -419,6 +419,49 @@ Options = [{follow_redirect, true}, {max_redirect, 5}],
419419 ReqBody, Options),
420420{ok, Body1} = hackney:body(Ref).</pre>
421421
422+ ### Use SSL/TLS with self signed certificates
423+
424+ Hackney uses CA bundles adapted from Mozilla by
425+ [certifi](https://hex.pm/packages/certifi).
426+ Recognising an organisation specific (self signed) certificates is possible
427+ by providing the necessary `ssl_options'. Note that `ssl_options' overrides all
428+ options passed to the ssl module.
429+
430+ ex (>= Erlang 21):
431+
432+ <pre lang="erlang">
433+ CACertFile = <path_to_self_signed_ca_bundle>,
434+ CrlCheckTimeout = 5000,
435+ SSLOptions = [
436+ {verify, verify_peer},
437+ {versions, ['tlsv1.2']},
438+ {cacertfile, CACertFile},
439+ {crl_check, peer},
440+ {crl_cache, {ssl_crl_cache, {internal, [{http, CrlCheckTimeout}]}}},
441+ {customize_hostname_check,
442+ [{match_fun, public_key:pkix_verify_hostname_match_fun(https)}]}],
443+
444+ Method = get,
445+ URL = "http://my-organisation/",
446+ ReqHeaders = [],
447+ ReqBody = <<>>,
448+ Options = [{ssl_options, SSLoptions}],
449+ {ok, S, H, Ref} = hackney:request(Method, URL, ReqHeaders,
450+ ReqBody, Options),
451+
452+ %% To provide client certificate:
453+
454+ CertFile = <path_to_client_certificate>,
455+ KeyFile = <path_to_client_private_key>,
456+ SSLOptions1 = SSLoptions ++ [
457+ {certfile, CertFile},
458+ {keyfile, KeyFile}
459+ ],
460+ Options1 = [{ssl_options, SSLoptions1}],
461+ {ok, S1, H1, Ref1} = hackney:request(Method, URL, ReqHeaders,
462+ ReqBody, Options1).
463+ </pre>
464+
422465### Proxy a connection
423466
424467#### HTTP Proxy
0 commit comments