Skip to content

Commit

Permalink
Support TLS opts for OTP >= 27 (#35)
Browse files Browse the repository at this point in the history
* Add ssl_option specific code to support OTP > 27

* Use grisp_cryptoauth 2.3.0 to support OTP 27
  • Loading branch information
ziopio authored Jun 27, 2024
1 parent 41cacd5 commit 4de211c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
{profiles, [
{grisp, [
{deps, [
{grisp_cryptoauth, "2.2.0"}
{grisp_cryptoauth, "2.3.0"}
]}
]},
{prod, [
{deps, [
{grisp_cryptoauth, "2.2.0"}
{grisp_cryptoauth, "2.3.0"}
]}
]},
{test, [
Expand Down
27 changes: 27 additions & 0 deletions src/grisp_connect_tls.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ ssl_opts(_) ->

-else.

-if(?OTP_RELEASE >= 27).

ssl_opts(ServerName) ->
case client_chain() of
{error, _Reason} = Error -> Error;
{ok, ClientChain} ->
{ok, [
{verify, verify_peer},
{depth, 99},
{cacerts, certifi:cacerts() ++ server_chain(ServerName)},
{customize_hostname_check, [
{match_fun, public_key:pkix_verify_hostname_match_fun(https)}
]},
{certs_keys, [#{
cert => ClientChain,
key => #{
algorithm => ecdsa,
sign_fun => fun grisp_cryptoauth:sign_fun/3
}
}]}
]}
end.

-else. % ?OTP_RELEASE < 27

ssl_opts(ServerName) ->
case client_chain() of
{error, _Reason} = Error -> Error;
Expand All @@ -61,6 +86,8 @@ ssl_opts(ServerName) ->

-endif.

-endif.

client_chain() ->
ClientCert = grisp_cryptoauth:read_cert(primary, der),
{ok, IssuerId} = public_key:pkix_issuer_id(ClientCert, self),
Expand Down

0 comments on commit 4de211c

Please sign in to comment.