{:undefined_import, :KeyUsage, :"PKIX1Implicit-2009"}

I’m trying to use this library (a Mix compile-time wrapper around Erlang’s asn1ct) to read and write CMS-formatted files, among other things.

I added the library to the dependencies and compilers: [:asn1] ++ Mix.compilers to the project-list, ran mix deps.get, then tried to compile it, but I’m getting a fatal error claiming that the KeyUsage field isn’t being exported:

iex -S mix
==> asn1ex
Compiling 1 file (.ex)
warning: :asn1ct.compile/2 defined in application :asn1 is used by the current application but the current application does not depend on :asn1. To fix this, you must do one of:

  1. If :asn1 is part of Erlang/Elixir, you must include it under :extra_applications inside "def application" in your mix.exs

  2. If :asn1 is a dependency, make sure it is listed under "def deps" in your mix.exs

  3. In case you don't want to add a requirement to :asn1, you may optionally skip this warning by adding [xref: [exclude: [:asn1ct]]] to your "def project" in mix.exs

  lib/mix/tasks/compile.asn1.ex:55: Mix.Tasks.Compile.Asn1.run/1

Generated asn1ex app
AlgorithmInformation-2009:10: 'KeyUsage' is not exported from PKIX1Implicit-2009
AlgorithmInformation-2009:95: 'KeyUsage' is not exported from PKIX1Implicit-2009
** (CaseClauseError) no case clause matching: {{:error, [{:structured_error, {:"AlgorithmInformation-2009", 10}, :asn1ct_check, {:undefined_import, :KeyUsage, :"PKIX1Implicit-2009"}}, {:structured_error, {:"AlgorithmInformation-2009", 95}, :asn1ct_check, {:undefined_import, :KeyUsage, :"PKIX1Implicit-2009"}}]}, "rfc5911"}
    (asn1ex 0.0.1) lib/mix/tasks/compile.asn1.ex:173: Mix.Tasks.Compile.Asn1.interpret_result/2
    (asn1ex 0.0.1) lib/mix/tasks/compile.asn1.ex:157: anonymous fn/3 in Mix.Tasks.Compile.Asn1.compile/3
    (elixir 1.13.4) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
    (asn1ex 0.0.1) lib/mix/tasks/compile.asn1.ex:156: Mix.Tasks.Compile.Asn1.compile/3
    (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
    (mix 1.13.4) lib/mix/tasks/compile.all.ex:92: Mix.Tasks.Compile.All.run_compiler/2
    (mix 1.13.4) lib/mix/tasks/compile.all.ex:72: Mix.Tasks.Compile.All.compile/4
    (mix 1.13.4) lib/mix/tasks/compile.all.ex:59: Mix.Tasks.Compile.All.with_logger_app/2

The source code is available here.

As you can see on line 4542 of rfc5912.asn1, even adding an EXPORTS ALL statement to the modue didn’t fix this. I am stumped. It clearly seems like that bit should be exported, and it’s not a circular-dependency issue in the spec, either, because asn1ct is now OK with those:

Earlier versions of the ASN.1 compiler required that modules that were imported from had to be compiled before the module that imported. This caused problems when ASN.1 modules had circular dependencies.

Has anyone got tips for troubleshooting ASN.1 in Elixir, or is able to spot the breakdown in this?

I think you’re going to have to split up the files so each file contains a single module definition. You’ll find that Erlang’s asn1 application’s test suite uses many (all?) of the modules defined in these RFCs, you could try and copy them from there.

1 Like

Hmm, after applying those changes I’m now getting this error:

Compiled BasicAccessControl
Compiled CertificateExtensions
CryptographicMessageSyntaxAlgorithms-2009:120: cap-RC2CBC is not the next item allowed according to the defined syntax
CryptographicMessageSyntaxAlgorithms-2009:286: cap-RC2CBC is not the next item allowed according to the defined syntax
PKIXAlgs-2009:65: "mda-sha224" is not the next item allowed according to the defined syntax
PKIXAlgs-2009:105: "mda-sha224" is not the next item allowed according to the defined syntax
PKIXAlgs-2009:325: "mda-sha224" is not the next item allowed according to the defined syntax
** (CaseClauseError) no case clause matching: {{:error, [{:structured_error, {:"CryptographicMessageSyntaxAlgorithms-2009", 120}, :asn1ct_check, {:syntax_nomatch, 'cap-RC2CBC'}}, {:structured_error, {:"CryptographicMessageSyntaxAlgorithms-2009", 286}, :asn1ct_check, {:syntax_nomatch, 'cap-RC
2CBC'}}, {:structured_error, {:"PKIXAlgs-2009", 65}, :asn1ct_check, {:syntax_nomatch, '"mda-sha224"'}}, {:structured_error, {:"PKIXAlgs-2009", 105}, :asn1ct_check, {:syntax_nomatch, '"mda-sha224"'}}, {:structured_error, {:"PKIXAlgs-2009", 325}, :asn1ct_check, {:syntax_nomatch, '"mda-sha224"'
}}]}, "CryptographicMessageSyntax-2009"}
    (asn1ex 0.0.1) lib/mix/tasks/compile.asn1.ex:173: Mix.Tasks.Compile.Asn1.interpret_result/2
    (asn1ex 0.0.1) lib/mix/tasks/compile.asn1.ex:157: anonymous fn/3 in Mix.Tasks.Compile.Asn1.compile/3
    (elixir 1.13.4) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
    (asn1ex 0.0.1) lib/mix/tasks/compile.asn1.ex:156: Mix.Tasks.Compile.Asn1.compile/3
    (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
    (mix 1.13.4) lib/mix/tasks/compile.all.ex:92: Mix.Tasks.Compile.All.run_compiler/2
    (mix 1.13.4) lib/mix/tasks/compile.all.ex:72: Mix.Tasks.Compile.All.compile/4
    (mix 1.13.4) lib/mix/tasks/compile.all.ex:59: Mix.Tasks.Compile.All.with_logger_app/2

There are quite a few additional files missing, no?

For example, the cap-RC2CBC from the error message (in CryptographicMessageSyntaxAlgorithms-2009) is imported from SecureMimeMessageV3dot1-2009.

Likewise mda-sha224 (in PKIXAlgs-2009) is from PKIX1-PSS-OAEP-Algorithms-2009.

Neither of those modules is present.

1 Like

Thanks for the catch!

After trying to add more and more files piecemeal, I ended up getting stumped and just dumping the entire test suite into my project’s asn1 folder. It’s ugly, but it seems to at least compile successfully now.