Skip to content

Commit

Permalink
fix fwup_public_keys including bad arg
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcarstens committed Mar 15, 2021
1 parent 75599ca commit d129597
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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

0 comments on commit d129597

Please sign in to comment.