-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add behaviour for ssl ping allowing users to specify their own implem…
…entation Signed-off-by: Connor Rigby <[email protected]>
- Loading branch information
1 parent
4781d22
commit 7a83e52
Showing
6 changed files
with
88 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule VintageNet.Connectivity.SSLPing.ConnectOptions do | ||
@moduledoc """ | ||
Implement this behaviour for the use with the SSLPing module. This allows users | ||
to configure how the `:ssl.connect/3` behaves. For example, if using Amazon AWS IOT, | ||
users will want to provide a `:cacerts` option with the list of certs. | ||
""" | ||
|
||
@doc """ | ||
Callback to be called before `:ssl.connect/3`. Implementations should return | ||
the following options in most cases: | ||
* `:cacerts` - List of cacerts to be used in verification. | ||
* `verify: :verify_peer` - Upon connect, verify the other connection. | ||
""" | ||
@callback connect_options() :: [:ssl.tls_client_option()] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule VintageNet.Connectivity.SSLPing.PublicKey do | ||
@moduledoc """ | ||
Insecure connect options for SSLPing connectivity checker. This module | ||
is an example, and should not be used in production devices. It uses | ||
`:public_key.cacerts` which will likely be valid at the time of firmware | ||
creation, however they will become invalid and unable to update in the | ||
future without a firmware upgrade. | ||
""" | ||
|
||
@behaviour VintageNet.Connectivity.SSLPing.ConnectOptions | ||
require Logger | ||
|
||
@doc false | ||
@impl VintageNet.Connectivity.SSLPing.ConnectOptions | ||
if :erlang.system_info(:otp_release) in [~c"21", ~c"22", ~c"23", ~c"24"] do | ||
def connect_options() do | ||
Logger.warning("SSLPing support on OTP 24 is limited due to lack of cacerts") | ||
[] | ||
end | ||
else | ||
def connect_options() do | ||
Logger.warning("SSLPing using :public_key for :cacerts. This is potentially insecure.") | ||
|
||
[ | ||
cacerts: :public_key.cacerts_get(), | ||
verify: :verify_peer | ||
] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters