From 8dcd6865c21bc0489c5216aece9f2fb355a59a15 Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Sun, 3 Aug 2025 09:39:40 +0000 Subject: [PATCH] There's no way to know if CHOICE id is "more interesting" than existing one, so I guess the best way is to show both. Closes GitHub issue #102. --- .vscode/launch.json | 16 +++++++++++++++- defs.js | 6 ++++-- examples/crl-rfc5280.b64.dump | 8 ++++---- examples/ed25519.cer.dump | 8 ++++---- examples/ldapmessage.b64.dump | 2 +- examples/sig-p256-der.p7m.dump | 12 ++++++------ package.json | 1 + 7 files changed, 35 insertions(+), 18 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 771869a..b1bdaf9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -42,7 +42,21 @@ { "type": "node", "request": "launch", - "name": "dumpASN1 cert", + "name": "dumpASN1 X.509", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/dumpASN1.js", + "args": [ + "examples/ed25519.cer", + "1.3.6.1.5.5.7.0.18", + "Certificate" + ] + }, + { + "type": "node", + "request": "launch", + "name": "dumpASN1 CRL", "skipFiles": [ "/**" ], diff --git a/defs.js b/defs.js index a16a546..4d9e709 100644 --- a/defs.js +++ b/defs.js @@ -35,7 +35,8 @@ function translate(def, tn, stats) { c = translate(c); if (tn == c.type.name || tn == c.name) { def = Object.assign({}, def); - if (c.id) def.id = c.id; + if (c.id) // show the CHOICE id, but add it to existing one if present + def.id = def.id ? def.id + ' ' + c.id : c.id; def.type = c.type.name ? c.type : c; break; } @@ -95,7 +96,8 @@ export class Defs { type = def.content[j++]; if (!type || typeof type != 'object') break; if (type?.type?.type) - type = type.type; + // type = type.type; + type = Object.assign({}, type.type, {id: type.id}); if (type.type == 'defined') { let t2 = translate(type, tn); if (t2.type.name == tn) break; // exact match diff --git a/examples/crl-rfc5280.b64.dump b/examples/crl-rfc5280.b64.dump index dde082f..206db10 100644 --- a/examples/crl-rfc5280.b64.dump +++ b/examples/crl-rfc5280.b64.dump @@ -4,7 +4,7 @@ CertificateList SEQUENCE @0+352 (constructed): (3 elem) signature AlgorithmIdentifier SEQUENCE @10+13 (constructed): (2 elem) algorithm OBJECT_IDENTIFIER @12+9: 1.2.840.113549.1.1.5|sha1WithRSAEncryption|PKCS #1 parameters ANY NULL @23+0 - issuer Name SEQUENCE @25+67 (constructed): (3 elem) + issuer rdnSequence Name SEQUENCE @25+67 (constructed): (3 elem) RelativeDistinguishedName SET @27+19 (constructed): (1 elem) AttributeTypeAndValue SEQUENCE @29+17 (constructed): (2 elem) type AttributeType OBJECT_IDENTIFIER @31+10: 0.9.2342.19200300.100.1.25|domainComponent|Men are from Mars, this OID is from Pluto @@ -17,12 +17,12 @@ CertificateList SEQUENCE @0+352 (constructed): (3 elem) AttributeTypeAndValue SEQUENCE @75+17 (constructed): (2 elem) type AttributeType OBJECT_IDENTIFIER @77+3: 2.5.4.3|commonName|X.520 DN component value AttributeValue [?] PrintableString @82+10: Example CA - utcTime Time UTCTime @94+13: 2005-02-05 12:00:00 UTC - utcTime Time UTCTime @109+13: 2005-02-06 12:00:00 UTC + thisUpdate utcTime Time UTCTime @94+13: 2005-02-05 12:00:00 UTC + nextUpdate utcTime Time UTCTime @109+13: 2005-02-06 12:00:00 UTC revokedCertificates SEQUENCE @124+34 (constructed): (1 elem) SEQUENCE @126+32 (constructed): (3 elem) userCertificate CertificateSerialNumber INTEGER @128+1: 18 - utcTime Time UTCTime @131+13: 2004-11-19 15:57:03 UTC + revocationDate utcTime Time UTCTime @131+13: 2004-11-19 15:57:03 UTC crlEntryExtensions Extensions SEQUENCE @146+12 (constructed): (1 elem) Extension SEQUENCE @148+10 (constructed): (2 elem) extnID OBJECT_IDENTIFIER @150+3: 2.5.29.21|cRLReason|X.509 extension diff --git a/examples/ed25519.cer.dump b/examples/ed25519.cer.dump index 158ea6a..665a0e2 100644 --- a/examples/ed25519.cer.dump +++ b/examples/ed25519.cer.dump @@ -5,7 +5,7 @@ Certificate SEQUENCE @0+383 (constructed): (3 elem) serialNumber CertificateSerialNumber INTEGER @13+20: (159 bit)|711090297755414526861352146244170174161660335942 signature AlgorithmIdentifier SEQUENCE @35+5 (constructed): (1 elem) algorithm OBJECT_IDENTIFIER @37+3: 1.3.101.112|curveEd25519|EdDSA 25519 signature algorithm - issuer Name SEQUENCE @42+53 (constructed): (3 elem) + issuer rdnSequence Name SEQUENCE @42+53 (constructed): (3 elem) RelativeDistinguishedName SET @44+11 (constructed): (1 elem) AttributeTypeAndValue SEQUENCE @46+9 (constructed): (2 elem) type AttributeType OBJECT_IDENTIFIER @48+3: 2.5.4.6|countryName|X.520 DN component @@ -19,9 +19,9 @@ Certificate SEQUENCE @0+383 (constructed): (3 elem) type AttributeType OBJECT_IDENTIFIER @78+3: 2.5.4.3|commonName|X.520 DN component value AttributeValue [?] UTF8String @83+12: Test ed25519 validity Validity SEQUENCE @97+30 (constructed): (2 elem) - utcTime Time UTCTime @99+13: 2020-09-02 13:25:26 UTC - utcTime Time UTCTime @114+13: 2030-09-02 13:25:26 UTC - subject Name SEQUENCE @129+53 (constructed): (3 elem) + notBefore utcTime Time UTCTime @99+13: 2020-09-02 13:25:26 UTC + notAfter utcTime Time UTCTime @114+13: 2030-09-02 13:25:26 UTC + subject rdnSequence Name SEQUENCE @129+53 (constructed): (3 elem) RelativeDistinguishedName SET @131+11 (constructed): (1 elem) AttributeTypeAndValue SEQUENCE @133+9 (constructed): (2 elem) type AttributeType OBJECT_IDENTIFIER @135+3: 2.5.4.6|countryName|X.520 DN component diff --git a/examples/ldapmessage.b64.dump b/examples/ldapmessage.b64.dump index 5ec7643..3b150ee 100644 --- a/examples/ldapmessage.b64.dump +++ b/examples/ldapmessage.b64.dump @@ -1,6 +1,6 @@ LDAPMessage SEQUENCE @0+53 (constructed): (3 elem) messageID MessageID INTEGER @2+1: 5 - delRequest CHOICE Application_10 @5+17: (17 byte)|dc=example,dc=com + protocolOp delRequest CHOICE Application_10 @5+17: (17 byte)|dc=example,dc=com Controls [?] [0] @24+29 (constructed): (1 elem) AttributeTypeAndValue SEQUENCE @26+27 (constructed): (2 elem) type AttributeType [?] OCTET_STRING @28+22: (22 byte)|1.2.840.113556.1.4.805 diff --git a/examples/sig-p256-der.p7m.dump b/examples/sig-p256-der.p7m.dump index 60609ff..d08cb90 100644 --- a/examples/sig-p256-der.p7m.dump +++ b/examples/sig-p256-der.p7m.dump @@ -19,15 +19,15 @@ ContentInfo SEQUENCE @0+10868 (constructed): (2 elem) serialNumber CertificateSerialNumber INTEGER @10117+16: (127 bit)|128087855099855233032551836648087377254 signature AlgorithmIdentifier SEQUENCE @10135+10 (constructed): (1 elem) algorithm OBJECT_IDENTIFIER @10137+8: 1.2.840.10045.4.3.2|ecdsaWithSHA256|ANSI X9.62 ECDSA algorithm with SHA256 - issuer Name SEQUENCE @10147+15 (constructed): (1 elem) + issuer rdnSequence Name SEQUENCE @10147+15 (constructed): (1 elem) RelativeDistinguishedName SET @10149+13 (constructed): (1 elem) AttributeTypeAndValue SEQUENCE @10151+11 (constructed): (2 elem) type AttributeType OBJECT_IDENTIFIER @10153+3: 2.5.4.3|commonName|X.520 DN component value AttributeValue [?] UTF8String @10158+4: Test validity Validity SEQUENCE @10164+30 (constructed): (2 elem) - utcTime Time UTCTime @10166+13: 2018-07-16 14:56:35 UTC - utcTime Time UTCTime @10181+13: 2019-07-16 14:56:35 UTC - subject Name SEQUENCE @10196+15 (constructed): (1 elem) + notBefore utcTime Time UTCTime @10166+13: 2018-07-16 14:56:35 UTC + notAfter utcTime Time UTCTime @10181+13: 2019-07-16 14:56:35 UTC + subject rdnSequence Name SEQUENCE @10196+15 (constructed): (1 elem) RelativeDistinguishedName SET @10198+13 (constructed): (1 elem) AttributeTypeAndValue SEQUENCE @10200+11 (constructed): (2 elem) type AttributeType OBJECT_IDENTIFIER @10202+3: 2.5.4.3|commonName|X.520 DN component @@ -62,8 +62,8 @@ ContentInfo SEQUENCE @0+10868 (constructed): (2 elem) signerInfos SignerInfos SET @10474+394 (constructed): (1 elem) SignerInfo SEQUENCE @10478+390 (constructed): (6 elem) version CMSVersion INTEGER @10482+1: 1 - issuerAndSerialNumber SignerIdentifier SEQUENCE @10485+35 (constructed): (2 elem) - rdnSequence Name SEQUENCE @10487+15 (constructed): (1 elem) + sid issuerAndSerialNumber SignerIdentifier SEQUENCE @10485+35 (constructed): (2 elem) + issuer rdnSequence Name SEQUENCE @10487+15 (constructed): (1 elem) RelativeDistinguishedName SET @10489+13 (constructed): (1 elem) AttributeTypeAndValue SEQUENCE @10491+11 (constructed): (2 elem) type AttributeType OBJECT_IDENTIFIER @10493+3: 2.5.4.3|commonName|X.520 DN component diff --git a/package.json b/package.json index a7e6260..7481a29 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "engines": { "node": ">=14.6.0" }, + "packageManager": "pnpm@7.33.7", "devDependencies": { "@eslint/eslintrc": "^3.3.1", "@eslint/js": "^9.32.0", -- 2.51.2