Nerves key/hub mix tasks fail because of missing :pubkey_pem module

So I’m using the last version of elixir 1.16 with OTP version 26

Whenever I try to execute a mix task to generate certificates like this:

mix nerves_key.signer create some_signer_name

I get the following error:

** (UndefinedFunctionError) function :pubkey_pem.encode/1 is undefined (module :pubkey_pem is not available)
    (public_key 1.15.1) :pubkey_pem.encode([{:Certificate, <<48, 130, 1, 166, 48, 130, 1, 77, 160, 3, 2, 1, 2, 2, 16, 102, 28, 7, 139, 85, 1, 30, 204, 133, 126, 246, 90, 74, 150, 122, 33, 48, 10, 6, 8, 42, 134, 72, 206, 61, 4, 3, 2, 48, 17, 49, 15, ...>>, :not_encrypted}])
    (public_key 1.15.1) public_key.erl:213: :public_key.pem_encode/1
    (nerves_key 1.2.0) lib/mix/tasks/nerves_key.signer.ex:61: Mix.Tasks.NervesKey.Signer.create/2
    (mix 1.16.0) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.16.0) lib/mix/cli.ex:96: Mix.CLI.run_task/2
    /home/victor/.local/share/mise/installs/elixir/1.16.0-otp-26/bin/mix:2: (file)

Do I need to somehow add that module to the project? Or should I use another version of OTP?

Huh. I hit this. Then I made sure to do export MIX_TARGET=mytarget (in my case rpi4) and I made sure to add :public_key, :crypto to extra_applications to be safe.

Running:

mix nerves_key.signer create nerveskey_prod_signer1`
** (UndefinedFunctionError) function :public_key.generate_key/1 is undefined (module :public_key is not available)
    (public_key 1.14) :public_key.generate_key({:namedCurve, :secp256r1})
    (atecc508a 1.2.2) lib/atecc508a/certificate.ex:77: ATECC508A.Certificate.new_signer/1
    (nerves_key 1.2.0) lib/mix/tasks/nerves_key.signer.ex:60: Mix.Tasks.NervesKey.Signer.create/2
    (mix 1.15.4) lib/mix/task.ex:447: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.15.4) lib/mix/cli.ex:92: Mix.CLI.run_task/2
    /home/lawik/.asdf/installs/elixir/1.15.4-otp-26/bin/mix:2: (file)

In the deployed device on the same project the :public_key module does exist.

Versions:

Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:32:32] [ds:32:32:10] [async-threads:1] [jit:ns]

Elixir 1.15.4 (compiled with Erlang/OTP 26)

I think there are 2 things to look into here:

  • Update to the latest atecc508a - I notice in the report it is 1.2.2 and latest is 1.3.0 as of this writing
    • This may not make a difference, but worth a check
  • Ensure Erlang was compiled with SSL enabled. In some MacOS setups, you might need to do something like brew install openssl and then when compiling, use KERL_CONFIGURE_OPTIONS=$KERL_CONFIGURE_OPTIONS --with-ssl=$(brew prefix openssl) (swap the SSL path if needed for other OS)
1 Like