Erlang ASN.1 otp将'PKCS7'模块p7b文件编译为pem

uttx8gqw  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(151)

I want to encode p7b file with certificate chain to pem I can do it in console with openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer I want to do it with erlang ssl library - looks like otp should already do this without asn.1 test in erlang otp But

1> application:ensure_all_started(ssl).
{ok,[crypto,asn1,public_key,ssl]}

But PKCS7 module undefined - asn.1 was not compiled

2>  'PKCS7':decode('SignedData', Der1).              
** exception error: undefined function 'PKCS7':decode/2

If I download PKCS7.asn manually and try to compile, I'll get error

3> asn1ct:compile('PKCS7.asn')
PKCS7:13: 'Attribute' is not exported from InformationFramework
...
{error,[{structured_error,{'PKCS7',13},
                          asn1ct_check,
                          {undefined_import,'Attribute','InformationFramework'}},
        {structured_error,{'PKCS7',13},

Question 1: Is there any way to compile 'PKCS7' without manual downloading asn.1 modules? I am sure I missed something important, and this file should works automatically as otp lib
Question 2: Maybe there are some simplest way to encode p7b to pem chain?
Is there any documentation for using otp/lib/asn.1?

ttcibm8c

ttcibm8c1#

无需编译ANS.1模块PKCS7。Erlang(Elixir)函数public_key:der_decode/2'ContentInfo'原子作为第一个参数ASN1Type。
( Elixir 代码)

{:ContentInfo, _id, content_info} = :public_key.der_decode(:ContentInfo, p7b_binary)
{:certSet, certificates_set} = elem(content_info, 4)

但问题为什么'PKCS7':decode不工作仍然开放

相关问题