From d1295973115240c498388cc7b776932b9baca290 Mon Sep 17 00:00:00 2001 From: Jon Carstens Date: Mon, 15 Mar 2021 09:53:54 -0600 Subject: [PATCH] fix fwup_public_keys including bad arg --- lib/nerves_hub_link/configurator.ex | 12 ++++++++++-- test/nerves_hub_link/configurator_test.exs | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/nerves_hub_link/configurator.ex b/lib/nerves_hub_link/configurator.ex index a9a5ed6..d7dde7e 100644 --- a/lib/nerves_hub_link/configurator.ex +++ b/lib/nerves_hub_link/configurator.ex @@ -105,7 +105,15 @@ 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.") @@ -113,6 +121,6 @@ defmodule NervesHubLink.Configurator do 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 diff --git a/test/nerves_hub_link/configurator_test.exs b/test/nerves_hub_link/configurator_test.exs index d519371..b70bd6f 100644 --- a/test/nerves_hub_link/configurator_test.exs +++ b/test/nerves_hub_link/configurator_test.exs @@ -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