Skip to content

Commit

Permalink
Add very basic PKCS#1 support and RSA key examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
lapo-luchini committed Mar 31, 2024
1 parent 8f048ac commit 2654e9c
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 3 deletions.
1 change: 1 addition & 0 deletions defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Defs.RFC = rfc;
Defs.commonTypes = [
[ 'X.509 certificate', '1.3.6.1.5.5.7.0.18', 'Certificate' ],
[ 'CMS / PKCS#7 envelope', '1.2.840.113549.1.9.16.0.14', 'ContentInfo' ],
[ 'PKCS#1 RSA private key', '1.2.840.113549.1.1.0.1', 'RSAPrivateKey' ],
[ 'PKCS#8 encrypted private key', '1.2.840.113549.1.8.1.1', 'EncryptedPrivateKeyInfo' ],
[ 'PKCS#8 private key', '1.2.840.113549.1.8.1.1', 'PrivateKeyInfo' ],
[ 'PKCS#10 certification request', '1.2.840.113549.1.10.1.1', 'CertificationRequest' ],
Expand Down
18 changes: 18 additions & 0 deletions examples/pkcs1.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PKCS#1 RSA key
$ openssl genrsa -out examples/pkcs8-rsa.pem 1024
$ openssl rsa -in examples/pkcs8-rsa.pem -out examples/pkcs1.pem -traditional
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCmy23ifN9pi5LO4MR3LUhU0v+LZmv78H+jd+R6kFcWZf1qW4yf
KTDkryjjLlIhYqxmzXCqGyaIjj7uJoorWf7KfkxpOuJrh4swJ/WGhCn9i+voW/7T
sOXfDp1yqrEhaQKwdPot1ZAB78TNsecwX/SODTEMCk95jvx1j5cDxPlskwIDAQAB
AoGBAINn4bp+BsVwYMj768y4sDOjyBBbMNfcMbLn0el9rh7HW09fsPnzycFg/iV9
aNdEle6oDAr4OPN8nbeiRVjCHijEnVdHCwAtkKODyuu1ghpZWD0VUC8AEskjX4Bs
Ysl/HjyvvHIRj89gdDFoElgB4GzHKTzeZNJBM5qtUW57zBCBAkEA0A6N5l98MglL
cypWKM7+3DXteWt86mKXYUVF33HY28Z+oUVlU0v8m8XxpoAjkicYnC1JOSSlvWRk
EWlTMgHW5QJBAM06yIHMR6p3apgpwOUp49DbtaQ8NmhCV4NBoFHa+vT2Fk8twOcq
O9OzP4svhKbPNfB4HnxGbmd/+OVT3lySxhcCQHRPPpqD1K0wLwKxrzrfBPDcIOaY
5VsuRIw3KqmQPngWTiIf5lYbi5sVnFLFHZ2Nx58/XcjZKOJopdxp8f1ps9UCQQC3
rOqSsF9bg3DVKllHQAxyepDAolsXSHjGMk/nspJz9mLVDl/dBAFzYLN4QFj6ae0e
gILYOrjIzNHXfQ4/z+SVAkBPebkAzpGFgzVzu6VOGx0Vft/ow3/DKNJSDM58yASp
ootY2TdibrrV/ellNLvuTiku6AEM/8jbHlRsmfxRe0xn
-----END RSA PRIVATE KEY-----
18 changes: 18 additions & 0 deletions examples/pkcs8-rsa.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PKCS#8 RSA key
$ openssl genrsa -out examples/pkcs8-rsa.pem 1024
-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKbLbeJ832mLks7g
xHctSFTS/4tma/vwf6N35HqQVxZl/WpbjJ8pMOSvKOMuUiFirGbNcKobJoiOPu4m
iitZ/sp+TGk64muHizAn9YaEKf2L6+hb/tOw5d8OnXKqsSFpArB0+i3VkAHvxM2x
5zBf9I4NMQwKT3mO/HWPlwPE+WyTAgMBAAECgYEAg2fhun4GxXBgyPvrzLiwM6PI
EFsw19wxsufR6X2uHsdbT1+w+fPJwWD+JX1o10SV7qgMCvg483ydt6JFWMIeKMSd
V0cLAC2Qo4PK67WCGllYPRVQLwASySNfgGxiyX8ePK+8chGPz2B0MWgSWAHgbMcp
PN5k0kEzmq1RbnvMEIECQQDQDo3mX3wyCUtzKlYozv7cNe15a3zqYpdhRUXfcdjb
xn6hRWVTS/ybxfGmgCOSJxicLUk5JKW9ZGQRaVMyAdblAkEAzTrIgcxHqndqmCnA
5Snj0Nu1pDw2aEJXg0GgUdr69PYWTy3A5yo707M/iy+Eps818HgefEZuZ3/45VPe
XJLGFwJAdE8+moPUrTAvArGvOt8E8Nwg5pjlWy5EjDcqqZA+eBZOIh/mVhuLmxWc
UsUdnY3Hnz9dyNko4mil3Gnx/Wmz1QJBALes6pKwX1uDcNUqWUdADHJ6kMCiWxdI
eMYyT+eyknP2YtUOX90EAXNgs3hAWPpp7R6Agtg6uMjM0dd9Dj/P5JUCQE95uQDO
kYWDNXO7pU4bHRV+3+jDf8Mo0lIMznzIBKmii1jZN2JuutX96WU0u+5OKS7oAQz/
yNseVGyZ/FF7TGc=
-----END PRIVATE KEY-----
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ <h1>ASN.1 JavaScript decoder</h1>
<option value="sig-rsa1024-sha1.p7s">PKCS#7/CMS detached signature (old)</option>
<option value="letsencrypt-x3.cer">X.509 certificate: Let's Encrypt X3</option>
<option value="ed25519.cer">X.509 certificate: ed25519 (RFC 8410)</option>
<option value="pkcs1.pem">PKCS#1 RSA key (RFC 8017)</option>
<option value="pkcs8-rsa.pem">PKCS#8 RSA key (RFC 5208)</option>
<option value="pkcs10.pem">PKCS#10 certification request (RFC 2986)</option>
<option value="cmpv2.b64">CMP PKI message (RFC 4210)</option>
</select>
Expand Down
16 changes: 15 additions & 1 deletion parseRFC.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ const
4210: [
[ /^\s+-- .*\r?\n/mg, '' ], // comments
],
8017: [ // this RFC uses a lot of currently unsupported syntax
[ /ALGORITHM-IDENTIFIER ::= CLASS[^-]+--/, '--' ],
[ /\n +\S+ +ALGORITHM-IDENTIFIER[^\n]+(\n [^\n]+)+\n [}]/g, '' ],

Check failure on line 50 in parseRFC.js

View workflow job for this annotation

GitHub Actions / build (latest)

Spaces are hard to count. Use {6}
[ /AlgorithmIdentifier [{] ALGORITHM-IDENTIFIER:InfoObjectSet [}] ::=(\n [^\n]+)+\n [}]/, 'AlgorithmIdentifier ::= ANY'],

Check failure on line 51 in parseRFC.js

View workflow job for this annotation

GitHub Actions / build (latest)

Spaces are hard to count. Use {6}
[ /algorithm +id-[^,\n]+,/g, 'algorithm ANY,' ],
[ / (sha1 HashAlgorithm|mgf1SHA1 MaskGenAlgorithm|pSpecifiedEmpty PSourceAlgorithm|rSAES-OAEP-Default-Identifier RSAES-AlgorithmIdentifier|rSASSA-PSS-Default-Identifier RSASSA-AlgorithmIdentifier) ::= [{](\n( [^\n]+)?)+\n [}]/g, '' ],

Check failure on line 53 in parseRFC.js

View workflow job for this annotation

GitHub Actions / build (latest)

Spaces are hard to count. Use {4}
[ / ::= AlgorithmIdentifier [{]\s+[{][^}]+[}]\s+[}]/g, ' ::= AlgorithmIdentifier' ],
[ /OCTET STRING[(]SIZE[(]0..MAX[)][)]/g, 'OCTET STRING' ],
[ /emptyString EncodingParameters ::= ''H/g, '' ],

Check failure on line 56 in parseRFC.js

View workflow job for this annotation

GitHub Actions / build (latest)

Spaces are hard to count. Use {4}
[ /[(]CONSTRAINED BY[^)]+[)]/g, '' ],
],
};

// const reWhitespace = /(?:\s|--(?:[}-]?[^\n}-])*(?:\n|--))*/y;
Expand Down Expand Up @@ -349,8 +360,11 @@ class Parser {
} else {
if (id in currentMod.values) // defined in local module
val = currentMod.values[id].value;
else
else try {
val = searchImportedValue(id);
} catch (e) {
this.exception(e.message);
}
}
}
if (v.length) v += '.';
Expand Down
Loading

0 comments on commit 2654e9c

Please sign in to comment.