Open James-E-A opened 2 months ago
You need to provide all the required ASN.1 definitions to the compiler for your module to compile.
You can check the existing x.509 related ASN.1 definitions already provided in the pycrate_asn1dir
subdirectory, and see if one already has all the definitions for compiling the ALGORITHM
object.
You need to provide all the required ASN.1 definitions to the compiler for your module to compile.
Even when I include the file that exports the definitions I need manually with -i
, I'm still getting a problem:
python .venv\Scripts\pycrate_asn1compile.py -i pycrate\pycrate_asn1dir\IETF_PKI_RFC5958\AlgorithmInformation-2009.asn -i HelloX509.asn1 HelloX509 -o HelloX509
pycrate_asn1c.err.ASN1ProcTextErr: sa-null-with-null-Algorithm: ASN1RefType to SIGNATURE-ALGORITHM, undefined
-- File based on https://github.com/pycrate-org/pycrate/blob/9093d3875caf2adc7833724edfc71a2321909d74/pycrate_asn1dir/IETF_PKI_RFC5958/CryptographicMessageSyntaxAlgorithms-2009.asn
-- and https://github.com/pycrate-org/pycrate/blob/9093d3875caf2adc7833724edfc71a2321909d74/pycrate_asn1dir/IETF_PKI_RFC5958/AlgorithmInformation-2009.asn#L89
HelloX509 DEFINITIONS ::=
BEGIN
-- EXPORTS All
IMPORTS
ParamOptions, DIGEST-ALGORITHM, SIGNATURE-ALGORITHM,
PUBLIC-KEY, KEY-DERIVATION, KEY-WRAP, MAC-ALGORITHM,
KEY-AGREE, KEY-TRANSPORT, CONTENT-ENCRYPTION, ALGORITHM,
AlgorithmIdentifier
FROM AlgorithmInformation-2009 {
iso(1) identified-organization(3) dod(6) internet(1) security(5)
mechanisms(5) pkix(7) id-mod(0)
id-mod-algorithmInformation-02(58)}
id-null-with-null OBJECT IDENTIFIER ::= {iso(1) standard(0) 20248 digital-signature-methods(1) null-with-null(1)}
sa-null-with-null SIGNATURE-ALGORITHM ::= {
IDENTIFIER id-null-with-null
PARAMS ARE absent
}
END -- HelloX509
And to defuse any possible X-Y problem that might be here: my ultimate goal is to use pycrate as a library to serialize and deserialize CMS messages that have been encrypted with algorithms that have not been standardized yet; I'm only trying to start with the simplest possible "custom algorithm" as a test to make sure I've got the fundamentals of extending pycrate down first.
OK, my recommendation would be to copy the entire IETF_PKI_RFC5958
subdirectory in your home. Add your new file into it, delete the load_mod.txt
and load_obj.txt
files, and compile the entire directory with:
pycrate_asn1compile.py -i $subdir -j
If it succeeds, your new value null-with-null-Algorithm
should be available in the module out.py
produced. Let me know if it works on your side, thx.
copy the entire
IETF_PKI_RFC5958
subdirectory in your home. Add your new file into it, delete theload_mod.txt
andload_obj.txt
files, and compile the entire directory with [-i $subdir -j
]
When I try exactly that, I get this error:
(venv) C:\…>python .venv\Scripts\pycrate_asn1compile.py -i IETF_PKI_RFC5958 -j
.venv\Scripts\pycrate_asn1compile.py, args error: unable to open input file IETF_PKI_RFC5958AlgorithmInformation-2009.asn
[Errno 2] No such file or directory: 'IETF_PKI_RFC5958AlgorithmInformation-2009.asn'
and out.py
is created, but left completely empty.
(I tested, and I get this same error even if I don't delete the TXT files...)
Maybe add a /
after the subdir name passed as argument.
On my side, I get:
mich@HPMitch:~/src$ cp -r pycrate/pycrate_asn1dir/IETF_PKI_RFC5958/ .
mich@HPMitch:~/src$ rm IETF_PKI_RFC5958/*.txt
mich@HPMitch:~/src$ pycrate_asn1compile.py -j -i IETF_PKI_RFC5958/
[proc] [IETF_PKI_RFC5958/PKIX1Implicit-2009.asn] module PKIX1Implicit-2009 (oid: [1, 3, 6, 1, 5, 5, 7, 0, 59]): 108 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/AlgorithmInformation-2009.asn] module AlgorithmInformation-2009 (oid: [1, 3, 6, 1, 5, 5, 7, 0, 58]): 16 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/CryptographicMessageSyntax-2009.asn] module CryptographicMessageSyntax-2009 (oid: [1, 2, 840, 113549, 1, 9, 16, 0, 41]): 108 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/PKIX1Explicit-2009.asn] module PKIX1Explicit-2009 (oid: [1, 3, 6, 1, 5, 5, 7, 0, 51]): 84 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/PKIXAttributeCertificate-2009.asn] module PKIXAttributeCertificate-2009 (oid: [1, 3, 6, 1, 5, 5, 7, 0, 47]): 54 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/PKIX-CommonTypes-2009.asn] module PKIX-CommonTypes-2009 (oid: [1, 3, 6, 1, 5, 5, 7, 0, 57]): 10 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/AttributeCertificateVersion1-2009.asn] module AttributeCertificateVersion1-2009 (oid: [1, 2, 840, 113549, 1, 9, 16, 0, 49]): 6 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/CryptographicMessageSyntaxAlgorithms-2009.asn] module CryptographicMessageSyntaxAlgorithms-2009 (oid: [1, 2, 840, 113549, 1, 9, 16, 0, 37]): 44 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/SecureMimeMessageV3dot1-2009.asn] module SecureMimeMessageV3dot1-2009 (oid: [1, 2, 840, 113549, 1, 9, 16, 0, 39]): 15 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/PKIX-X400Address-2009.asn] module PKIX-X400Address-2009 (oid: [1, 3, 6, 1, 5, 5, 7, 0, 60]): 74 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/PKIXAlgs-2009.asn] module PKIXAlgs-2009 (oid: [1, 3, 6, 1, 5, 5, 7, 0, 56]): 75 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/PKIX1-PSS-OAEP-Algorithms-2009.asn] module PKIX1-PSS-OAEP-Algorithms-2009 (oid: [1, 3, 6, 1, 5, 5, 7, 0, 54]): 45 ASN.1 assignments found
[proc] [IETF_PKI_RFC5958/AsymmetricKeyPackageModuleV1.asn] module AsymmetricKeyPackageModuleV1 (oid: [1, 2, 840, 113549, 1, 9, 16, 0, 50]): 18 ASN.1 assignments found
--- compilation cycle ---
WNG: AlgorithmInformation-2009.AlgorithmIdentifier, untagged OPEN / ANY in SEQUENCE with parameters
WNG: AlgorithmInformation-2009.SMIMECapability, untagged OPEN / ANY in SEQUENCE with parameters
--- compilation cycle ---
--- compilation cycle ---
--- compilation cycle ---
--- compilation cycle ---
WNG: PKIX1Explicit-2009.SIGNED.algorithmIdentifier, untagged OPEN / ANY in SEQUENCE with parameters
--- compilation cycle ---
--- compilation cycle ---
--- verifications ---
[proc] ASN.1 modules processed: ['PKIX1Implicit-2009', 'AlgorithmInformation-2009', 'CryptographicMessageSyntax-2009', 'PKIX1Explicit-2009', 'PKIXAttributeCertificate-2009', 'PKIX-CommonTypes-2009', 'AttributeCertificateVersion1-2009', 'CryptographicMessageSyntaxAlgorithms-2009', 'SecureMimeMessageV3dot1-2009', 'PKIX-X400Address-2009', 'PKIXAlgs-2009', 'PKIX1-PSS-OAEP-Algorithms-2009', 'AsymmetricKeyPackageModuleV1']
[proc] ASN.1 objects compiled: 241 types, 62 sets, 341 values
[proc] done
mich@HPMitch:~/src$ ls -l out.*
-rw-r--r-- 1 mich mich 185038 Sep 28 09:36 out.json
-rw-r--r-- 1 mich mich 800737 Sep 28 09:36 out.py
I'm trying to compile this very small ASN.1 definition as a test, which only declares a new and extremely boring signature algorithm:
However, when I try to use the compilation script with
-i
as the Wiki recommends, I get this error:Why isn't this import working?