diff --git a/defs.js b/defs.js index 8cbfd96..d331efa 100644 --- a/defs.js +++ b/defs.js @@ -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' ], diff --git a/examples/pkcs1.pem b/examples/pkcs1.pem new file mode 100644 index 0000000..7077a97 --- /dev/null +++ b/examples/pkcs1.pem @@ -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----- diff --git a/examples/pkcs8-rsa.pem b/examples/pkcs8-rsa.pem new file mode 100644 index 0000000..39829b5 --- /dev/null +++ b/examples/pkcs8-rsa.pem @@ -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----- diff --git a/index.html b/index.html index 7b7a9f3..15d2759 100644 --- a/index.html +++ b/index.html @@ -46,6 +46,8 @@ + + diff --git a/parseRFC.js b/parseRFC.js index 41e256c..d625388 100755 --- a/parseRFC.js +++ b/parseRFC.js @@ -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, '' ], + [ /AlgorithmIdentifier [{] ALGORITHM-IDENTIFIER:InfoObjectSet [}] ::=(\n [^\n]+)+\n [}]/, 'AlgorithmIdentifier ::= ANY'], + [ /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, '' ], + [ / ::= AlgorithmIdentifier [{]\s+[{][^}]+[}]\s+[}]/g, ' ::= AlgorithmIdentifier' ], + [ /OCTET STRING[(]SIZE[(]0..MAX[)][)]/g, 'OCTET STRING' ], + [ /emptyString EncodingParameters ::= ''H/g, '' ], + [ /[(]CONSTRAINED BY[^)]+[)]/g, '' ], + ], }; // const reWhitespace = /(?:\s|--(?:[}-]?[^\n}-])*(?:\n|--))*/y; @@ -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 += '.'; diff --git a/rfcdef.js b/rfcdef.js index 6d0e5f1..d03ccad 100644 --- a/rfcdef.js +++ b/rfcdef.js @@ -1,4 +1,4 @@ -// content parsed from ASN.1 definitions as found in the following RFCs: 5280 5208 3369 3161 2986 4211 4210 +// content parsed from ASN.1 definitions as found in the following RFCs: 5280 5208 3369 3161 2986 4211 4210 8017 // Copyright (C) The IETF Trust (2008) // as far as I can tell this file is allowed under the following clause: // It is acceptable under the current IETF rules (RFC 5378) to modify extracted code if necessary. @@ -9861,6 +9861,535 @@ return { } } } + }, + "1.2.840.113549.1.1.0.1": { + "name": "PKCS-1", + "oid": "1.2.840.113549.1.1.0.1", + "source": "rfc8017.txt", + "tagDefault": "EXPLICIT", + "imports": { + "2.16.840.1.101.3.4.2": { + "name": "NIST-SHA2", + "oid": "2.16.840.1.101.3.4.2", + "types": [ + "id-sha224", + "id-sha256", + "id-sha384", + "id-sha512", + "id-sha512-224", + "id-sha512-256" + ] + } + }, + "values": { + "pkcs-1": { + "name": "pkcs-1", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1" + }, + "rsaEncryption": { + "name": "rsaEncryption", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.1" + }, + "id-RSAES-OAEP": { + "name": "id-RSAES-OAEP", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.7" + }, + "id-pSpecified": { + "name": "id-pSpecified", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.9" + }, + "id-RSASSA-PSS": { + "name": "id-RSASSA-PSS", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.10" + }, + "md2WithRSAEncryption": { + "name": "md2WithRSAEncryption", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.2" + }, + "md5WithRSAEncryption": { + "name": "md5WithRSAEncryption", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.4" + }, + "sha1WithRSAEncryption": { + "name": "sha1WithRSAEncryption", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.5" + }, + "sha224WithRSAEncryption": { + "name": "sha224WithRSAEncryption", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.14" + }, + "sha256WithRSAEncryption": { + "name": "sha256WithRSAEncryption", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.11" + }, + "sha384WithRSAEncryption": { + "name": "sha384WithRSAEncryption", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.12" + }, + "sha512WithRSAEncryption": { + "name": "sha512WithRSAEncryption", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.13" + }, + "sha512-224WithRSAEncryption": { + "name": "sha512-224WithRSAEncryption", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.15" + }, + "sha512-256WithRSAEncryption": { + "name": "sha512-256WithRSAEncryption", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.16" + }, + "id-sha1": { + "name": "id-sha1", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.3.14.3.2.26" + }, + "id-md2": { + "name": "id-md2", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.2.2" + }, + "id-md5": { + "name": "id-md5", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.2.5" + }, + "id-mgf1": { + "name": "id-mgf1", + "type": { + "name": "OBJECT IDENTIFIER", + "type": "builtin" + }, + "value": "1.2.840.113549.1.1.8" + } + }, + "types": { + "AlgorithmIdentifier": { + "name": "AlgorithmIdentifier", + "type": { + "name": "ANY", + "type": "builtin" + } + }, + "HashAlgorithm": { + "name": "HashAlgorithm", + "type": { + "name": "AlgorithmIdentifier", + "type": "defined" + } + }, + "SHA1Parameters": { + "name": "SHA1Parameters", + "type": { + "name": "NULL", + "type": "defined" + } + }, + "MaskGenAlgorithm": { + "name": "MaskGenAlgorithm", + "type": { + "name": "AlgorithmIdentifier", + "type": "defined" + } + }, + "EncodingParameters": { + "name": "EncodingParameters", + "type": { + "name": "OCTET STRING", + "type": "builtin" + } + }, + "PSourceAlgorithm": { + "name": "PSourceAlgorithm", + "type": { + "name": "AlgorithmIdentifier", + "type": "defined" + } + }, + "RSAPublicKey": { + "name": "RSAPublicKey", + "type": { + "name": "SEQUENCE", + "type": "builtin", + "content": [ + { + "id": "modulus", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "publicExponent", + "name": "INTEGER", + "type": "builtin" + } + ] + } + }, + "RSAPrivateKey": { + "name": "RSAPrivateKey", + "type": { + "name": "SEQUENCE", + "type": "builtin", + "content": [ + { + "id": "version", + "name": "Version", + "type": "defined" + }, + { + "id": "modulus", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "publicExponent", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "privateExponent", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "prime1", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "prime2", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "exponent1", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "exponent2", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "coefficient", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "otherPrimeInfos", + "name": "OtherPrimeInfos", + "type": "defined", + "optional": true + } + ] + } + }, + "Version": { + "name": "Version", + "type": { + "name": "INTEGER", + "type": "builtin", + "content": { + "two-prime": 0, + "multi": 1 + } + } + }, + "OtherPrimeInfos": { + "name": "OtherPrimeInfos", + "type": { + "name": "SEQUENCE", + "type": "builtin", + "typeOf": 1, + "size": [ + 1, + "MAX" + ], + "content": [ + { + "name": "OtherPrimeInfo", + "type": "defined" + } + ] + } + }, + "OtherPrimeInfo": { + "name": "OtherPrimeInfo", + "type": { + "name": "SEQUENCE", + "type": "builtin", + "content": [ + { + "id": "prime", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "exponent", + "name": "INTEGER", + "type": "builtin" + }, + { + "id": "coefficient", + "name": "INTEGER", + "type": "builtin" + } + ] + } + }, + "RSAES-OAEP-params": { + "name": "RSAES-OAEP-params", + "type": { + "name": "SEQUENCE", + "type": "builtin", + "content": [ + { + "id": "hashAlgorithm", + "name": "[0]", + "type": "tag", + "class": "CONTEXT", + "explicit": true, + "content": [ + { + "name": "", + "type": { + "name": "HashAlgorithm", + "type": "defined" + } + } + ], + "default": "sha1" + }, + { + "id": "maskGenAlgorithm", + "name": "[1]", + "type": "tag", + "class": "CONTEXT", + "explicit": true, + "content": [ + { + "name": "", + "type": { + "name": "MaskGenAlgorithm", + "type": "defined" + } + } + ], + "default": "mgf1SHA1" + }, + { + "id": "pSourceAlgorithm", + "name": "[2]", + "type": "tag", + "class": "CONTEXT", + "explicit": true, + "content": [ + { + "name": "", + "type": { + "name": "PSourceAlgorithm", + "type": "defined" + } + } + ], + "default": "pSpecifiedEmpty" + } + ] + } + }, + "RSAES-AlgorithmIdentifier": { + "name": "RSAES-AlgorithmIdentifier", + "type": { + "name": "AlgorithmIdentifier", + "type": "defined" + } + }, + "RSASSA-PSS-params": { + "name": "RSASSA-PSS-params", + "type": { + "name": "SEQUENCE", + "type": "builtin", + "content": [ + { + "id": "hashAlgorithm", + "name": "[0]", + "type": "tag", + "class": "CONTEXT", + "explicit": true, + "content": [ + { + "name": "", + "type": { + "name": "HashAlgorithm", + "type": "defined" + } + } + ], + "default": "sha1" + }, + { + "id": "maskGenAlgorithm", + "name": "[1]", + "type": "tag", + "class": "CONTEXT", + "explicit": true, + "content": [ + { + "name": "", + "type": { + "name": "MaskGenAlgorithm", + "type": "defined" + } + } + ], + "default": "mgf1SHA1" + }, + { + "id": "saltLength", + "name": "[2]", + "type": "tag", + "class": "CONTEXT", + "explicit": true, + "content": [ + { + "name": "", + "type": { + "name": "INTEGER", + "type": "builtin" + } + } + ], + "default": 20 + }, + { + "id": "trailerField", + "name": "[3]", + "type": "tag", + "class": "CONTEXT", + "explicit": true, + "content": [ + { + "name": "", + "type": { + "name": "TrailerField", + "type": "defined" + } + } + ], + "default": "trailerFieldBC" + } + ] + } + }, + "TrailerField": { + "name": "TrailerField", + "type": { + "name": "INTEGER", + "type": "builtin", + "content": { + "trailerFieldBC": 1 + } + } + }, + "RSASSA-AlgorithmIdentifier": { + "name": "RSASSA-AlgorithmIdentifier", + "type": { + "name": "AlgorithmIdentifier", + "type": "defined" + } + }, + "DigestInfo": { + "name": "DigestInfo", + "type": { + "name": "SEQUENCE", + "type": "builtin", + "content": [ + { + "id": "digestAlgorithm", + "name": "DigestAlgorithm", + "type": "defined" + }, + { + "id": "digest", + "name": "OCTET STRING", + "type": "builtin" + } + ] + } + }, + "DigestAlgorithm": { + "name": "DigestAlgorithm", + "type": { + "name": "AlgorithmIdentifier", + "type": "defined" + } + } + } } } ;}); diff --git a/updateRFC.sh b/updateRFC.sh index 6f82192..e2b2cf3 100755 --- a/updateRFC.sh +++ b/updateRFC.sh @@ -1,5 +1,5 @@ #/bin/sh -RFCs="5280 5208 3369 3161 2986 4211 4210" +RFCs="5280 5208 3369 3161 2986 4211 4210 8017" downloadRFC() { URL="https://www.ietf.org/rfc/rfc$1.txt" if [ -x /usr/bin/fetch ]; then