Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fwup_public_keys including bad arg #81

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/nerves_hub_link/configurator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,22 @@ defmodule NervesHubLink.Configurator do
end

defp add_fwup_public_keys(config) do
fwup_public_keys = NervesHubLink.Certificate.fwup_public_keys()
# NervesHubLink.Certificate.fwup_public_keys() is compiled into the module
# This is a simple workaround to support changing hardcoded binary keys
# in the config and being able to load without recompiling. However, it
# is still suggested to recompile as well which is required for resolve
# public keys referenced by an atom
fwup_public_keys =
for key <- NervesHubLink.Certificate.fwup_public_keys() ++ config.fwup_public_keys,
is_binary(key),
do: key

if fwup_public_keys == [] do
Logger.error("No fwup public keys were configured for nerves_hub_link.")
Logger.error("This means that firmware signatures are not being checked.")
Logger.error("nerves_hub_link will fail to apply firmware updates.")
end

%{config | fwup_public_keys: config.fwup_public_keys ++ fwup_public_keys}
%{config | fwup_public_keys: fwup_public_keys}
end
end
17 changes: 17 additions & 0 deletions test/nerves_hub_link/configurator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@ defmodule NervesHubLink.ConfiguratorTest do
config = NervesHubLink.Configurator.build()
assert Map.has_key?(config.params, "fwup_version")
end

test "only includes binary in fwup_public_keys" do
keys = [
"thisisavalidkey==",
:not_valid,
false,
{:also, :not, :valid},
nil,
1234
]

Application.put_env(:nerves_hub_link, :fwup_public_keys, keys)

config = NervesHubLink.Configurator.build()

assert ["thisisavalidkey=="] == config.fwup_public_keys
end
end