diff --git a/ChangeLog.txt b/ChangeLog.txt index aec5e5af..8ed77d8c 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,9 +1,18 @@ ChangeLog for jsrsasign -* Changes from 10.5.7 to next release - - x509.js +OCSP CertID and X509 class update +* Changes from 10.5.7 to 10.5.8 (2022-Feb-25) + - src/asn1ocsp.js + - CertID class refactoring + - CertID.getParamByCerts method added + - src/x509.js + - DEPRECATED getPublicKeyHex method (use getSPKI instead) + - getSPKI, getSPKIValue method added + - getExtCRLDistributionPointsURI bugfix - API document fix + - test/qunit-do-{asn1ocsp,x509-ext,x509,x509-v1}.html + - test case update and bugfix for above updates. X509CRL.findRevCert bugfix for empty revCerts * Changes from 10.5.6 to 10.5.7 (2022-Feb-19) diff --git a/README.md b/README.md index 1abddf4c..8df99e08 100755 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ HIGHLIGHTS - no dependency to other library - no dependency to [W3C Web Cryptography API](https://www.w3.org/TR/WebCryptoAPI/) nor [OpenSSL](https://www.openssl.org/) - no dependency on newer ECMAScirpt function. So old browsers also supported. -- very popular crypto library with [0.6M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2022-02-04) +- very popular crypto library with [0.6M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2022-02-23) INSTALL ------- diff --git a/api/files.html b/api/files.html index a7f85a97..ebdf3c3c 100644 --- a/api/files.html +++ b/api/files.html @@ -620,7 +620,7 @@
o = new KJUR.asn1.ocsp.CertID(); +o.getParamByCerts("-----BEGIN...", "-----BEGIN...", "sha256") → +{ + alg: "sha256", + issname: "12abcd...", + isskey: "23cdef...", + sbjsn: "57b3..." +}+ + + + +
x = new X509(); -x.getExtOCSPNoCheck(<@@ -3598,11 +3616,11 @@>) → +x.getExtOcspNoCheck(< >) → { extname: "ocspNoCheck" }
x = new X509(); -x.getExtOCSPNonce(<@@ -4958,14 +4976,20 @@>) → +x.getExtOcspNonce(< >) → { extname: "ocspNonce", hex: "1a2b..." }
x = new X509(); -x.readCertPEM(sCertPEM); +x = new X509(sCertPEM); hSPKI = x.getPublicKeyHex(); // return string like "30820122..."+
+SubjectPublicKeyInfo ::= SEQUENCE { + algorithm AlgorithmIdentifier, + subjectPublicKey BIT STRING } ++ + +
x = new X509(sCertPEM); +hSPKI = x.getSPKI(); // return string like "30820122..."+ + + + + + +
+SubjectPublicKeyInfo ::= SEQUENCE { + algorithm AlgorithmIdentifier, + subjectPublicKey BIT STRING } ++ + +
x = new X509(sCertPEM); +hSPKIValue = x.getSPKIValue(); // without BIT STRING Encapusulation.+ + + + + + +
1 /* asn1ocsp-1.1.5.js (c) 2016-2021 Kenji Urushima | kjur.github.io/jsrsasign/license +1 /* asn1ocsp-1.1.6.js (c) 2016-2022 Kenji Urushima | kjur.github.io/jsrsasign/license 2 */ 3 /* 4 * asn1ocsp.js - ASN.1 DER encoder classes for OCSP protocol @@ -23,7 +23,7 @@ 16 * @fileOverview 17 * @name asn1ocsp-1.0.js 18 * @author Kenji Urushima kenji.urushima@gmail.com - 19 * @version jsrsasign 10.4.0 asn1ocsp 1.1.5 (2021-Aug-17) + 19 * @version jsrsasign 10.5.8 asn1ocsp 1.1.6 (2022-Feb-22) 20 * @since jsrsasign 6.1.0 21 * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a> 22 */ @@ -778,1261 +778,1302 @@ 771 _KJUR_crypto = _KJUR.crypto, 772 _hashHex = _KJUR_crypto.Util.hashHex, 773 _X509 = X509, -774 _ASN1HEX = ASN1HEX; -775 -776 _KJUR_asn1_ocsp.CertID.superclass.constructor.call(this); -777 -778 this.dHashAlg = null; -779 this.dIssuerNameHash = null; -780 this.dIssuerKeyHash = null; -781 this.dSerialNumber = null; -782 -783 /** -784 * set CertID ASN.1 object by values.<br/> -785 * @name setByValue -786 * @memberOf KJUR.asn1.ocsp.CertID# -787 * @function -788 * @param {String} issuerNameHashHex hexadecimal string of hash value of issuer name -789 * @param {String} issuerKeyHashHex hexadecimal string of hash value of issuer public key -790 * @param {String} serialNumberHex hexadecimal string of certificate serial number to be verified -791 * @param {String} algName hash algorithm name used for above arguments (ex. "sha1") DEFAULT: sha1 -792 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 -793 * @example -794 * o = new KJUR.asn1.ocsp.CertID(); -795 * o.setByValue("1fac...", "fd3a...", "1234"); // sha1 is used by default -796 * o.setByValue("1fac...", "fd3a...", "1234", "sha256"); -797 */ -798 this.setByValue = function(issuerNameHashHex, issuerKeyHashHex, -799 serialNumberHex, algName) { -800 if (algName === undefined) algName = _DEFAULT_HASH; -801 this.dHashAlg = new _AlgorithmIdentifier({name: algName}); -802 this.dIssuerNameHash = new _DEROctetString({hex: issuerNameHashHex}); -803 this.dIssuerKeyHash = new _DEROctetString({hex: issuerKeyHashHex}); -804 this.dSerialNumber = new _DERInteger({hex: serialNumberHex}); -805 }; -806 -807 /** -808 * set CertID ASN.1 object by PEM certificates.<br/> -809 * @name setByCert -810 * @memberOf KJUR.asn1.ocsp.CertID# -811 * @function -812 * @param {String} issuerCert string of PEM issuer certificate -813 * @param {String} subjectCert string of PEM subject certificate to be verified by OCSP -814 * @param {String} algName hash algorithm name used for above arguments (ex. "sha1") DEFAULT: sha1 -815 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 -816 * -817 * @example -818 * o = new KJUR.asn1.ocsp.CertID(); -819 * o.setByCert("-----BEGIN...", "-----BEGIN..."); // sha1 is used by default -820 * o.setByCert("-----BEGIN...", "-----BEGIN...", "sha256"); -821 */ -822 this.setByCert = function(issuerCert, subjectCert, algName) { -823 if (algName === undefined) algName = _DEFAULT_HASH; -824 -825 var xSbj = new _X509(); -826 xSbj.readCertPEM(subjectCert); -827 var xIss = new _X509(); -828 xIss.readCertPEM(issuerCert); -829 -830 var hISS_SPKI = xIss.getPublicKeyHex(); -831 var issuerKeyHex = _ASN1HEX.getVbyList(hISS_SPKI, 0, [1], "03", true); +774 _ASN1HEX = ASN1HEX, +775 _getVbyList = _ASN1HEX.getVbyList; +776 +777 _KJUR_asn1_ocsp.CertID.superclass.constructor.call(this); +778 +779 this.DEFAULT_HASH = "sha1"; +780 this.params = null; +781 +782 /** +783 * set CertID ASN.1 object by values.<br/> +784 * @name setByValue +785 * @memberOf KJUR.asn1.ocsp.CertID# +786 * @function +787 * @param {String} issuerNameHashHex hexadecimal string of hash value of issuer name +788 * @param {String} issuerKeyHashHex hexadecimal string of hash value of issuer public key +789 * @param {String} serialNumberHex hexadecimal string of certificate serial number to be verified +790 * @param {String} algName hash algorithm name used for above arguments (ex. "sha1") DEFAULT: sha1 +791 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 +792 * @example +793 * o = new KJUR.asn1.ocsp.CertID(); +794 * o.setByValue("1fac...", "fd3a...", "1234"); // sha1 is used by default +795 * o.setByValue("1fac...", "fd3a...", "1234", "sha256"); +796 */ +797 this.setByValue = function(issuerNameHashHex, issuerKeyHashHex, +798 serialNumberHex, algName) { +799 if (algName == undefined) algName = this.DEFAULT_HASH; +800 this.params = { +801 alg: algName, +802 issname: issuerNameHashHex, +803 isskey: issuerKeyHashHex, +804 sbjsn: serialNumberHex +805 }; +806 }; +807 +808 /** +809 * set CertID ASN.1 object by PEM certificates.<br/> +810 * @name setByCert +811 * @memberOf KJUR.asn1.ocsp.CertID# +812 * @function +813 * @param {String} issuerCert string of PEM issuer certificate +814 * @param {String} subjectCert string of PEM subject certificate to be verified by OCSP +815 * @param {String} algName hash algorithm name used for above arguments (ex. "sha1") DEFAULT: sha1 +816 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 +817 * @deprecated since jsrsasign 10.5.7 asn1ocsp 1.1.6. Please use setByParam instead. +818 * +819 * @example +820 * o = new KJUR.asn1.ocsp.CertID(); +821 * o.setByCert("-----BEGIN...", "-----BEGIN..."); // sha1 is used by default +822 * o.setByCert("-----BEGIN...", "-----BEGIN...", "sha256"); +823 */ +824 this.setByCert = function(issuerCert, subjectCert, algName) { +825 if (algName == undefined) algName = this.DEFAULT_HASH; +826 this.params = { +827 alg: algName, +828 issuerCert: issuerCert, +829 subjectCert: subjectCert, +830 }; +831 }; 832 -833 var serialNumberHex = xSbj.getSerialNumberHex(); -834 var issuerNameHashHex = _hashHex(xIss.getSubjectHex(), algName); -835 var issuerKeyHashHex = _hashHex(issuerKeyHex, algName); -836 this.setByValue(issuerNameHashHex, issuerKeyHashHex, -837 serialNumberHex, algName); -838 this.hoge = xSbj.getSerialNumberHex(); -839 }; -840 -841 this.getEncodedHex = function() { -842 if (this.dHashAlg === null && -843 this.dIssuerNameHash === null && -844 this.dIssuerKeyHash === null && -845 this.dSerialNumber === null) -846 throw "not yet set values"; -847 -848 var a = [this.dHashAlg, this.dIssuerNameHash, -849 this.dIssuerKeyHash, this.dSerialNumber]; -850 var seq = new _DERSequence({array: a}); -851 this.hTLV = seq.getEncodedHex(); -852 return this.hTLV; -853 }; -854 -855 if (params !== undefined) { -856 var p = params; -857 if (p.issuerCert !== undefined && -858 p.subjectCert !== undefined) { -859 var alg = _DEFAULT_HASH; -860 if (p.alg === undefined) alg = undefined; -861 this.setByCert(p.issuerCert, p.subjectCert, alg); -862 } else if (p.issname !== undefined && -863 p.isskey !== undefined && -864 p.sbjsn !== undefined) { -865 var alg = _DEFAULT_HASH; -866 if (p.alg === undefined) alg = undefined; -867 this.setByValue(p.issname, p.isskey, p.sbjsn, alg); -868 } else { -869 throw new Error("invalid constructor arguments"); -870 } -871 } -872 }; -873 extendClass(KJUR.asn1.ocsp.CertID, KJUR.asn1.ASN1Object); +833 /** +834 * calculate CertID parameter by certificates.<br/> +835 * @name getParamByCerts +836 * @memberOf KJUR.asn1.ocsp.CertID# +837 * @function +838 * @param {string} issuerCert string of PEM issuer certificate +839 * @param {string} subjectCert string of PEM subject certificate to be verified by OCSP +840 * @param {string} algName hash algorithm name used for above arguments (ex. "sha1") DEFAULT: sha1 +841 * @param {object} associative array with alg, issname, isskey and sbjsn members +842 * @since jsrsasign 10.5.7 asn1ocsp 1.1.6 +843 * +844 * @description +845 * This method calculates issuer name hash, issuer key hash and subject serial +846 * number then returns an associative array with alg, issname, isskey and sbjsn members. +847 * +848 * @example +849 * o = new KJUR.asn1.ocsp.CertID(); +850 * o.getParamByCerts("-----BEGIN...", "-----BEGIN...", "sha256") → +851 * { +852 * alg: "sha256", +853 * issname: "12abcd...", +854 * isskey: "23cdef...", +855 * sbjsn: "57b3..." +856 * } +857 */ +858 this.getParamByCerts = function(issCert, sbjCert, algName) { +859 if (algName == undefined) algName = this.DEFAULT_HASH; +860 var xISS = new _X509(issCert); +861 var xSBJ = new _X509(sbjCert); +862 var issname = _hashHex(xISS.getSubjectHex(), algName); +863 var hSPKI = xISS.getPublicKeyHex(); +864 var isskey = _hashHex(_getVbyList(hSPKI, 0, [1], "03", true), algName); +865 var sbjsn = xSBJ.getSerialNumberHex(); +866 var info = { +867 alg: algName, +868 issname: issname, +869 isskey: isskey, +870 sbjsn: sbjsn +871 }; +872 return info; +873 }; 874 -875 /** -876 * CertStatus ASN.1 class encoder<br/> -877 * @name KJUR.asn1.ocsp.CertStatus -878 * @class CertStatus ASN.1 class encoder -879 * @param {Array} params JSON object for CertStatus parameter -880 * @extends KJUR.asn1.ASN1Object -881 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 -882 * @see KJUR.asn1.ocsp.OCSPResponse -883 * @see KJUR.asn1.ocsp.ResponseBytes -884 * @see KJUR.asn1.ocsp.BasicOCSPResponse -885 * @see KJUR.asn1.ocsp.ResponseData -886 * @see KJUR.asn1.ocsp.SingleResponse -887 * @see KJUR.asn1.ocsp.CertID -888 * @see KJUR.asn1.ocsp.CertStatus -889 * -890 * @description -891 * ASN.1 class of SEQUENCE OF SingleResponse is defined in -892 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. -893 * <pre> -894 * CertStatus ::= CHOICE { -895 * good [0] IMPLICIT NULL, -896 * revoked [1] IMPLICIT RevokedInfo, -897 * unknown [2] IMPLICIT UnknownInfo } -898 * RevokedInfo ::= SEQUENCE { -899 * revocationTime GeneralizedTime, -900 * revocationReason [0] EXPLICIT CRLReason OPTIONAL } -901 * UnknownInfo ::= NULL -902 * CRLReason ::= ENUMERATED { -903 * unspecified (0), -904 * keyCompromise (1), -905 * cACompromise (2), -906 * affiliationChanged (3), -907 * superseded (4), -908 * cessationOfOperation (5), -909 * certificateHold (6), -910 * -- value 7 is not used -911 * removeFromCRL (8), -912 * privilegeWithdrawn (9), -913 * aACompromise (10) } -914 * </pre> -915 * Following properties are available: -916 * <ul> -917 * <li>{String}status - "good", "revoked" or "unknown"</li> -918 * <li>{String}time (OPTION) - revocationTime YYYYMMDDHHmmSSZ (ex. "20200904235959Z")</li> -919 * <li>{Number}reason (OPTION) - revocationReason code number</li> -920 * </ul> -921 * -922 * @example -923 * new KJUR.asn1.ocsp.CertStatus({status: "good"}) -924 * new KJUR.asn1.ocsp.CertStatus({status: "revoked", time: "20200903235959Z"}) -925 * new KJUR.asn1.ocsp.CertStatus({status: "revoked", time: "20200903235959Z", reason: 3}) -926 * new KJUR.asn1.ocsp.CertStatus({status: "unknown"}) -927 */ -928 KJUR.asn1.ocsp.CertStatus = function(params) { -929 KJUR.asn1.ocsp.CertStatus.superclass.constructor.call(this); -930 -931 this.params = null; -932 -933 this.getEncodedHex = function() { -934 var params = this.params; -935 if (params.status == "good") return "8000"; -936 if (params.status == "unknown") return "8200"; -937 if (params.status == "revoked") { -938 var a = [{gentime: {str: params.time}}]; -939 if (params.reason != undefined) { -940 a.push({tag: {tag: 'a0', -941 explicit: true, -942 obj: {'enum': {'int': params.reason}}}}); -943 } -944 var tagParam = {tag: 'a1', explicit: false, obj: {seq: a}}; -945 return KJUR.asn1.ASN1Util.newObject({tag: tagParam}).getEncodedHex(); -946 } -947 throw new Error("bad status"); -948 }; -949 -950 this.setByParam = function(params) { -951 this.params = params; -952 }; -953 -954 if (params !== undefined) this.setByParam(params); -955 }; -956 extendClass(KJUR.asn1.ocsp.CertStatus, KJUR.asn1.ASN1Object); -957 -958 // ---- END OF Classes for OCSP response ----------------------------------- -959 -960 /** -961 * ASN.1 Request class for OCSP<br/> -962 * @name KJUR.asn1.ocsp.Request -963 * @class ASN.1 Request class for OCSP -964 * @param {Array} params associative array of parameters -965 * @extends KJUR.asn1.ASN1Object -966 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 -967 * @description -968 * Request ASN.1 class is defined in -969 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. -970 * singleRequestExtensions is not supported yet in this version such as nonce. -971 * <pre> -972 * Request ::= SEQUENCE { -973 * reqCert CertID, -974 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } -975 * </pre> -976 * @example -977 * // default constructor -978 * o = new KJUR.asn1.ocsp.Request(); -979 * // constructor with certs (sha1 is used by default) -980 * o = new KJUR.asn1.ocsp.Request({issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN..."}); -981 * // constructor with certs and sha256 -982 * o = new KJUR.asn1.ocsp.Request({issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg: "sha256"}); -983 * // constructor with values -984 * o = new KJUR.asn1.ocsp.Request({namehash: "1a...", keyhash: "ad...", serial: "1234", alg: "sha256"}); -985 */ -986 KJUR.asn1.ocsp.Request = function(params) { -987 var _KJUR = KJUR, -988 _KJUR_asn1 = _KJUR.asn1, -989 _DERSequence = _KJUR_asn1.DERSequence, -990 _KJUR_asn1_ocsp = _KJUR_asn1.ocsp; -991 -992 _KJUR_asn1_ocsp.Request.superclass.constructor.call(this); -993 this.dReqCert = null; -994 this.dExt = null; -995 -996 this.getEncodedHex = function() { -997 var a = []; +875 this.getEncodedHex = function() { +876 if (typeof this.params != "object") throw new Error("params not set"); +877 +878 var p = this.params; +879 var issname, isskey, sbjsn, alg; +880 +881 if (p.alg == undefined) { +882 alg = this.DEFAULT_HASH; +883 } else { +884 alg = p.alg; +885 } +886 +887 if (p.issuerCert != undefined && +888 p.subjectCert != undefined) { +889 var info = this.getParamByCerts(p.issuerCert, p.subjectCert, alg); +890 issname = info.issname; +891 isskey = info.isskey; +892 sbjsn = info.sbjsn; +893 } else if (p.issname != undefined && +894 p.isskey != undefined && +895 p.sbjsn != undefined) { +896 issname = p.issname; +897 isskey = p.isskey; +898 sbjsn = p.sbjsn; +899 } else { +900 throw new Error("required param members not defined"); +901 } +902 +903 var dAlg = new _AlgorithmIdentifier({name: alg}); +904 var dIssName = new _DEROctetString({hex: issname}); +905 var dIssKey = new _DEROctetString({hex: isskey}); +906 var dSbjSn = new _DERInteger({hex: sbjsn}); +907 var seq = new _DERSequence({array: [dAlg, dIssName, dIssKey, dSbjSn]}); +908 this.hTLV = seq.getEncodedHex(); +909 return this.hTLV; +910 }; +911 +912 if (params !== undefined) this.setByParam(params); +913 }; +914 extendClass(KJUR.asn1.ocsp.CertID, KJUR.asn1.ASN1Object); +915 +916 /** +917 * CertStatus ASN.1 class encoder<br/> +918 * @name KJUR.asn1.ocsp.CertStatus +919 * @class CertStatus ASN.1 class encoder +920 * @param {Array} params JSON object for CertStatus parameter +921 * @extends KJUR.asn1.ASN1Object +922 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 +923 * @see KJUR.asn1.ocsp.OCSPResponse +924 * @see KJUR.asn1.ocsp.ResponseBytes +925 * @see KJUR.asn1.ocsp.BasicOCSPResponse +926 * @see KJUR.asn1.ocsp.ResponseData +927 * @see KJUR.asn1.ocsp.SingleResponse +928 * @see KJUR.asn1.ocsp.CertID +929 * @see KJUR.asn1.ocsp.CertStatus +930 * +931 * @description +932 * ASN.1 class of SEQUENCE OF SingleResponse is defined in +933 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. +934 * <pre> +935 * CertStatus ::= CHOICE { +936 * good [0] IMPLICIT NULL, +937 * revoked [1] IMPLICIT RevokedInfo, +938 * unknown [2] IMPLICIT UnknownInfo } +939 * RevokedInfo ::= SEQUENCE { +940 * revocationTime GeneralizedTime, +941 * revocationReason [0] EXPLICIT CRLReason OPTIONAL } +942 * UnknownInfo ::= NULL +943 * CRLReason ::= ENUMERATED { +944 * unspecified (0), +945 * keyCompromise (1), +946 * cACompromise (2), +947 * affiliationChanged (3), +948 * superseded (4), +949 * cessationOfOperation (5), +950 * certificateHold (6), +951 * -- value 7 is not used +952 * removeFromCRL (8), +953 * privilegeWithdrawn (9), +954 * aACompromise (10) } +955 * </pre> +956 * Following properties are available: +957 * <ul> +958 * <li>{String}status - "good", "revoked" or "unknown"</li> +959 * <li>{String}time (OPTION) - revocationTime YYYYMMDDHHmmSSZ (ex. "20200904235959Z")</li> +960 * <li>{Number}reason (OPTION) - revocationReason code number</li> +961 * </ul> +962 * +963 * @example +964 * new KJUR.asn1.ocsp.CertStatus({status: "good"}) +965 * new KJUR.asn1.ocsp.CertStatus({status: "revoked", time: "20200903235959Z"}) +966 * new KJUR.asn1.ocsp.CertStatus({status: "revoked", time: "20200903235959Z", reason: 3}) +967 * new KJUR.asn1.ocsp.CertStatus({status: "unknown"}) +968 */ +969 KJUR.asn1.ocsp.CertStatus = function(params) { +970 KJUR.asn1.ocsp.CertStatus.superclass.constructor.call(this); +971 +972 this.params = null; +973 +974 this.getEncodedHex = function() { +975 var params = this.params; +976 if (params.status == "good") return "8000"; +977 if (params.status == "unknown") return "8200"; +978 if (params.status == "revoked") { +979 var a = [{gentime: {str: params.time}}]; +980 if (params.reason != undefined) { +981 a.push({tag: {tag: 'a0', +982 explicit: true, +983 obj: {'enum': {'int': params.reason}}}}); +984 } +985 var tagParam = {tag: 'a1', explicit: false, obj: {seq: a}}; +986 return KJUR.asn1.ASN1Util.newObject({tag: tagParam}).getEncodedHex(); +987 } +988 throw new Error("bad status"); +989 }; +990 +991 this.setByParam = function(params) { +992 this.params = params; +993 }; +994 +995 if (params !== undefined) this.setByParam(params); +996 }; +997 extendClass(KJUR.asn1.ocsp.CertStatus, KJUR.asn1.ASN1Object); 998 -999 // 1. reqCert -1000 if (this.dReqCert === null) -1001 throw "reqCert not set"; -1002 a.push(this.dReqCert); -1003 -1004 // 2. singleRequestExtensions (not supported yet) -1005 -1006 // 3. construct SEQUENCE -1007 var seq = new _DERSequence({array: a}); -1008 this.hTLV = seq.getEncodedHex(); -1009 return this.hTLV; -1010 }; -1011 -1012 if (typeof params !== "undefined") { -1013 var o = new _KJUR_asn1_ocsp.CertID(params); -1014 this.dReqCert = o; -1015 } -1016 }; -1017 extendClass(KJUR.asn1.ocsp.Request, KJUR.asn1.ASN1Object); -1018 -1019 /** -1020 * ASN.1 TBSRequest class for OCSP<br/> -1021 * @name KJUR.asn1.ocsp.TBSRequest -1022 * @class ASN.1 TBSRequest class for OCSP -1023 * @param {Array} params associative array of parameters -1024 * @extends KJUR.asn1.ASN1Object -1025 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 -1026 * @description -1027 * TBSRequest ASN.1 class is defined in -1028 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. -1029 * <pre> -1030 * TBSRequest ::= SEQUENCE { -1031 * version [0] EXPLICIT Version DEFAULT v1, -1032 * requestorName [1] EXPLICIT GeneralName OPTIONAL, -1033 * requestList SEQUENCE OF Request, -1034 * requestExtensions [2] EXPLICIT Extensions OPTIONAL } -1035 * </pre> -1036 * @example -1037 * // default constructor -1038 * o = new KJUR.asn1.ocsp.TBSRequest(); -1039 * // constructor with requestList parameter -1040 * o = new KJUR.asn1.ocsp.TBSRequest({reqList:[ -1041 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg:}, -1042 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg: "sha256"} -1043 * ]}); -1044 */ -1045 KJUR.asn1.ocsp.TBSRequest = function(params) { -1046 var _KJUR = KJUR, -1047 _KJUR_asn1 = _KJUR.asn1, -1048 _DERSequence = _KJUR_asn1.DERSequence, -1049 _KJUR_asn1_ocsp = _KJUR_asn1.ocsp; -1050 -1051 _KJUR_asn1_ocsp.TBSRequest.superclass.constructor.call(this); -1052 this.version = 0; -1053 this.dRequestorName = null; -1054 this.dRequestList = []; -1055 this.dRequestExt = null; -1056 -1057 /** -1058 * set TBSRequest ASN.1 object by array of parameters.<br/> -1059 * @name setRequestListByParam -1060 * @memberOf KJUR.asn1.ocsp.TBSRequest# -1061 * @function -1062 * @param {Array} aParams array of parameters for Request class -1063 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 -1064 * @example -1065 * o = new KJUR.asn1.ocsp.TBSRequest(); -1066 * o.setRequestListByParam([ -1067 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg:}, -1068 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg: "sha256"} -1069 * ]); -1070 */ -1071 this.setRequestListByParam = function(aParams) { -1072 var a = []; -1073 for (var i = 0; i < aParams.length; i++) { -1074 var dReq = new _KJUR_asn1_ocsp.Request(aParams[0]); -1075 a.push(dReq); -1076 } -1077 this.dRequestList = a; -1078 }; -1079 -1080 this.getEncodedHex = function() { -1081 var a = []; -1082 -1083 // 1. version -1084 if (this.version !== 0) -1085 throw "not supported version: " + this.version; -1086 -1087 // 2. requestorName -1088 if (this.dRequestorName !== null) -1089 throw "requestorName not supported"; -1090 -1091 // 3. requestList -1092 var seqRequestList = -1093 new _DERSequence({array: this.dRequestList}); -1094 a.push(seqRequestList); -1095 -1096 // 4. requestExtensions -1097 if (this.dRequestExt !== null) -1098 throw "requestExtensions not supported"; -1099 -1100 // 5. construct SEQUENCE -1101 var seq = new _DERSequence({array: a}); -1102 this.hTLV = seq.getEncodedHex(); -1103 return this.hTLV; -1104 }; -1105 -1106 if (params !== undefined) { -1107 if (params.reqList !== undefined) -1108 this.setRequestListByParam(params.reqList); -1109 } -1110 }; -1111 extendClass(KJUR.asn1.ocsp.TBSRequest, KJUR.asn1.ASN1Object); -1112 -1113 -1114 /** -1115 * ASN.1 OCSPRequest class for OCSP<br/> -1116 * @name KJUR.asn1.ocsp.OCSPRequest -1117 * @class ASN.1 OCSPRequest class for OCSP -1118 * @param {Array} params associative array of parameters -1119 * @extends KJUR.asn1.ASN1Object -1120 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 -1121 * @description -1122 * OCSPRequest ASN.1 class is defined in -1123 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. -1124 * A signed request is not supported yet in this version. -1125 * <pre> -1126 * OCSPRequest ::= SEQUENCE { -1127 * tbsRequest TBSRequest, -1128 * optionalSignature [0] EXPLICIT Signature OPTIONAL } -1129 * </pre> -1130 * @example -1131 * // default constructor -1132 * o = new KJUR.asn1.ocsp.OCSPRequest(); -1133 * // constructor with requestList parameter -1134 * o = new KJUR.asn1.ocsp.OCSPRequest({reqList:[ -1135 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg:}, -1136 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg: "sha256"} -1137 * ]}); -1138 */ -1139 KJUR.asn1.ocsp.OCSPRequest = function(params) { -1140 var _KJUR = KJUR, -1141 _KJUR_asn1 = _KJUR.asn1, -1142 _DERSequence = _KJUR_asn1.DERSequence, -1143 _KJUR_asn1_ocsp = _KJUR_asn1.ocsp; -1144 -1145 _KJUR_asn1_ocsp.OCSPRequest.superclass.constructor.call(this); -1146 this.dTbsRequest = null; -1147 this.dOptionalSignature = null; -1148 -1149 this.getEncodedHex = function() { -1150 var a = []; -1151 -1152 // 1. tbsRequest -1153 if (this.dTbsRequest !== null) { -1154 a.push(this.dTbsRequest); -1155 } else { -1156 throw "tbsRequest not set"; -1157 } -1158 -1159 // 2. optionalSignature -1160 if (this.dOptionalSignature !== null) -1161 throw "optionalSignature not supported"; -1162 -1163 // 3. construct SEQUENCE -1164 var seq = new _DERSequence({array: a}); -1165 this.hTLV = seq.getEncodedHex(); -1166 return this.hTLV; -1167 }; -1168 -1169 if (params !== undefined) { -1170 if (params.reqList !== undefined) { -1171 var o = new _KJUR_asn1_ocsp.TBSRequest(params); -1172 this.dTbsRequest = o; -1173 } -1174 } -1175 }; -1176 extendClass(KJUR.asn1.ocsp.OCSPRequest, KJUR.asn1.ASN1Object); -1177 -1178 /** -1179 * Utility class for OCSP<br/> -1180 * @name KJUR.asn1.ocsp.OCSPUtil -1181 * @class Utility class for OCSP -1182 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 -1183 * @description -1184 * This class provides utility static methods for OCSP. -1185 * <ul> -1186 * <li>{@link KJUR.asn1.ocsp.OCSPUtil.getRequestHex} - generates hexadecimal string of OCSP request</li> -1187 * </ul> -1188 */ -1189 KJUR.asn1.ocsp.OCSPUtil = {}; -1190 -1191 /** -1192 * generates hexadecimal string of OCSP request<br/> -1193 * @name getRequestHex -1194 * @memberOf KJUR.asn1.ocsp.OCSPUtil -1195 * @function -1196 * @param {String} issuerCert string of PEM issuer certificate -1197 * @param {String} subjectCert string of PEM subject certificate to be verified by OCSP -1198 * @param {String} algName hash algorithm name used for above arguments (ex. "sha1") DEFAULT: sha1 -1199 * @return {String} hexadecimal string of generated OCSP request -1200 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 -1201 * @description -1202 * This static method generates hexadecimal string of OCSP request. -1203 * @example -1204 * // generate OCSP request using sha1 algorithnm by default. -1205 * hReq = KJUR.asn1.ocsp.OCSPUtil.getRequestHex("-----BEGIN...", "-----BEGIN..."); -1206 */ -1207 KJUR.asn1.ocsp.OCSPUtil.getRequestHex = function(issuerCert, subjectCert, alg) { -1208 var _KJUR = KJUR, -1209 _KJUR_asn1 = _KJUR.asn1, -1210 _KJUR_asn1_ocsp = _KJUR_asn1.ocsp; -1211 -1212 if (alg === undefined) alg = _KJUR_asn1_ocsp.DEFAULT_HASH; -1213 var param = {alg: alg, issuerCert: issuerCert, subjectCert: subjectCert}; -1214 var o = new _KJUR_asn1_ocsp.OCSPRequest({reqList: [param]}); -1215 return o.getEncodedHex(); +999 // ---- END OF Classes for OCSP response ----------------------------------- +1000 +1001 /** +1002 * ASN.1 Request class for OCSP<br/> +1003 * @name KJUR.asn1.ocsp.Request +1004 * @class ASN.1 Request class for OCSP +1005 * @param {Array} params associative array of parameters +1006 * @extends KJUR.asn1.ASN1Object +1007 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 +1008 * @description +1009 * Request ASN.1 class is defined in +1010 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. +1011 * singleRequestExtensions is not supported yet in this version such as nonce. +1012 * <pre> +1013 * Request ::= SEQUENCE { +1014 * reqCert CertID, +1015 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } +1016 * </pre> +1017 * @example +1018 * // default constructor +1019 * o = new KJUR.asn1.ocsp.Request(); +1020 * // constructor with certs (sha1 is used by default) +1021 * o = new KJUR.asn1.ocsp.Request({issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN..."}); +1022 * // constructor with certs and sha256 +1023 * o = new KJUR.asn1.ocsp.Request({issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg: "sha256"}); +1024 * // constructor with values +1025 * o = new KJUR.asn1.ocsp.Request({namehash: "1a...", keyhash: "ad...", serial: "1234", alg: "sha256"}); +1026 */ +1027 KJUR.asn1.ocsp.Request = function(params) { +1028 var _KJUR = KJUR, +1029 _KJUR_asn1 = _KJUR.asn1, +1030 _DERSequence = _KJUR_asn1.DERSequence, +1031 _KJUR_asn1_ocsp = _KJUR_asn1.ocsp; +1032 +1033 _KJUR_asn1_ocsp.Request.superclass.constructor.call(this); +1034 this.dReqCert = null; +1035 this.dExt = null; +1036 +1037 this.getEncodedHex = function() { +1038 var a = []; +1039 +1040 // 1. reqCert +1041 if (this.dReqCert === null) +1042 throw "reqCert not set"; +1043 a.push(this.dReqCert); +1044 +1045 // 2. singleRequestExtensions (not supported yet) +1046 +1047 // 3. construct SEQUENCE +1048 var seq = new _DERSequence({array: a}); +1049 this.hTLV = seq.getEncodedHex(); +1050 return this.hTLV; +1051 }; +1052 +1053 if (typeof params !== "undefined") { +1054 var o = new _KJUR_asn1_ocsp.CertID(params); +1055 this.dReqCert = o; +1056 } +1057 }; +1058 extendClass(KJUR.asn1.ocsp.Request, KJUR.asn1.ASN1Object); +1059 +1060 /** +1061 * ASN.1 TBSRequest class for OCSP<br/> +1062 * @name KJUR.asn1.ocsp.TBSRequest +1063 * @class ASN.1 TBSRequest class for OCSP +1064 * @param {Array} params associative array of parameters +1065 * @extends KJUR.asn1.ASN1Object +1066 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 +1067 * @description +1068 * TBSRequest ASN.1 class is defined in +1069 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. +1070 * <pre> +1071 * TBSRequest ::= SEQUENCE { +1072 * version [0] EXPLICIT Version DEFAULT v1, +1073 * requestorName [1] EXPLICIT GeneralName OPTIONAL, +1074 * requestList SEQUENCE OF Request, +1075 * requestExtensions [2] EXPLICIT Extensions OPTIONAL } +1076 * </pre> +1077 * @example +1078 * // default constructor +1079 * o = new KJUR.asn1.ocsp.TBSRequest(); +1080 * // constructor with requestList parameter +1081 * o = new KJUR.asn1.ocsp.TBSRequest({reqList:[ +1082 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg:}, +1083 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg: "sha256"} +1084 * ]}); +1085 */ +1086 KJUR.asn1.ocsp.TBSRequest = function(params) { +1087 var _KJUR = KJUR, +1088 _KJUR_asn1 = _KJUR.asn1, +1089 _DERSequence = _KJUR_asn1.DERSequence, +1090 _KJUR_asn1_ocsp = _KJUR_asn1.ocsp; +1091 +1092 _KJUR_asn1_ocsp.TBSRequest.superclass.constructor.call(this); +1093 this.version = 0; +1094 this.dRequestorName = null; +1095 this.dRequestList = []; +1096 this.dRequestExt = null; +1097 +1098 /** +1099 * set TBSRequest ASN.1 object by array of parameters.<br/> +1100 * @name setRequestListByParam +1101 * @memberOf KJUR.asn1.ocsp.TBSRequest# +1102 * @function +1103 * @param {Array} aParams array of parameters for Request class +1104 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 +1105 * @example +1106 * o = new KJUR.asn1.ocsp.TBSRequest(); +1107 * o.setRequestListByParam([ +1108 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg:}, +1109 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg: "sha256"} +1110 * ]); +1111 */ +1112 this.setRequestListByParam = function(aParams) { +1113 var a = []; +1114 for (var i = 0; i < aParams.length; i++) { +1115 var dReq = new _KJUR_asn1_ocsp.Request(aParams[0]); +1116 a.push(dReq); +1117 } +1118 this.dRequestList = a; +1119 }; +1120 +1121 this.getEncodedHex = function() { +1122 var a = []; +1123 +1124 // 1. version +1125 if (this.version !== 0) +1126 throw "not supported version: " + this.version; +1127 +1128 // 2. requestorName +1129 if (this.dRequestorName !== null) +1130 throw "requestorName not supported"; +1131 +1132 // 3. requestList +1133 var seqRequestList = +1134 new _DERSequence({array: this.dRequestList}); +1135 a.push(seqRequestList); +1136 +1137 // 4. requestExtensions +1138 if (this.dRequestExt !== null) +1139 throw "requestExtensions not supported"; +1140 +1141 // 5. construct SEQUENCE +1142 var seq = new _DERSequence({array: a}); +1143 this.hTLV = seq.getEncodedHex(); +1144 return this.hTLV; +1145 }; +1146 +1147 if (params !== undefined) { +1148 if (params.reqList !== undefined) +1149 this.setRequestListByParam(params.reqList); +1150 } +1151 }; +1152 extendClass(KJUR.asn1.ocsp.TBSRequest, KJUR.asn1.ASN1Object); +1153 +1154 +1155 /** +1156 * ASN.1 OCSPRequest class for OCSP<br/> +1157 * @name KJUR.asn1.ocsp.OCSPRequest +1158 * @class ASN.1 OCSPRequest class for OCSP +1159 * @param {Array} params associative array of parameters +1160 * @extends KJUR.asn1.ASN1Object +1161 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 +1162 * @description +1163 * OCSPRequest ASN.1 class is defined in +1164 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. +1165 * A signed request is not supported yet in this version. +1166 * <pre> +1167 * OCSPRequest ::= SEQUENCE { +1168 * tbsRequest TBSRequest, +1169 * optionalSignature [0] EXPLICIT Signature OPTIONAL } +1170 * </pre> +1171 * @example +1172 * // default constructor +1173 * o = new KJUR.asn1.ocsp.OCSPRequest(); +1174 * // constructor with requestList parameter +1175 * o = new KJUR.asn1.ocsp.OCSPRequest({reqList:[ +1176 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg:}, +1177 * {issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg: "sha256"} +1178 * ]}); +1179 */ +1180 KJUR.asn1.ocsp.OCSPRequest = function(params) { +1181 var _KJUR = KJUR, +1182 _KJUR_asn1 = _KJUR.asn1, +1183 _DERSequence = _KJUR_asn1.DERSequence, +1184 _KJUR_asn1_ocsp = _KJUR_asn1.ocsp; +1185 +1186 _KJUR_asn1_ocsp.OCSPRequest.superclass.constructor.call(this); +1187 this.dTbsRequest = null; +1188 this.dOptionalSignature = null; +1189 +1190 this.getEncodedHex = function() { +1191 var a = []; +1192 +1193 // 1. tbsRequest +1194 if (this.dTbsRequest !== null) { +1195 a.push(this.dTbsRequest); +1196 } else { +1197 throw "tbsRequest not set"; +1198 } +1199 +1200 // 2. optionalSignature +1201 if (this.dOptionalSignature !== null) +1202 throw "optionalSignature not supported"; +1203 +1204 // 3. construct SEQUENCE +1205 var seq = new _DERSequence({array: a}); +1206 this.hTLV = seq.getEncodedHex(); +1207 return this.hTLV; +1208 }; +1209 +1210 if (params !== undefined) { +1211 if (params.reqList !== undefined) { +1212 var o = new _KJUR_asn1_ocsp.TBSRequest(params); +1213 this.dTbsRequest = o; +1214 } +1215 } 1216 }; -1217 -1218 /** -1219 * simple parser for OCSPResponse (DEPRECATED)<br/> -1220 * @name getOCSPResponseInfo -1221 * @memberOf KJUR.asn1.ocsp.OCSPUtil -1222 * @function -1223 * @param {String} h hexadecimal string of DER OCSPResponse -1224 * @return {Object} JSON object of parsed OCSPResponse -1225 * @since jsrsasign 6.1.0 asn1ocsp 1.0.1 -1226 * @deprecated since jsrsasign 10.4.0 asn1ocsp 1.1.5 Please use OCSPParser.getOCSPRespnose -1227 * -1228 * @description -1229 * This static method parse a hexadecimal string of DER OCSPResponse and -1230 * returns JSON object of its parsed result. -1231 * Its result has following properties: -1232 * <ul> -1233 * <li>responseStatus - integer of responseStatus</li> -1234 * <li>certStatus - string of certStatus (ex. good, revoked or unknown)</li> -1235 * <li>thisUpdate - string of thisUpdate in Zulu(ex. 20151231235959Z)</li> -1236 * <li>nextUpdate - string of nextUpdate in Zulu(ex. 20151231235959Z)</li> -1237 * </ul> -1238 * NOTE: This method may not work preperly. Please use -1239 * {@link KJUR.asn1.ocsp.OCSPParser#getOCSPResponse}. -1240 * -1241 * @example -1242 * info = KJUR.asn1.ocsp.OCSPUtil.getOCSPResponseInfo("3082..."); -1243 */ -1244 KJUR.asn1.ocsp.OCSPUtil.getOCSPResponseInfo = function(h) { -1245 var _ASN1HEX = ASN1HEX, -1246 _getVbyList = _ASN1HEX.getVbyList, -1247 _getVbyListEx = _ASN1HEX.getVbyListEx, -1248 _getIdxbyList = _ASN1HEX.getIdxbyList, -1249 _getIdxbyListEx = _ASN1HEX.getIdxbyListEx, -1250 _getV = _ASN1HEX.getV; -1251 -1252 var result = {}; -1253 try { -1254 var v = _getVbyListEx(h, 0, [0], "0a"); -1255 result.responseStatus = parseInt(v, 16); -1256 } catch(ex) {}; -1257 if (result.responseStatus !== 0) return result; +1217 extendClass(KJUR.asn1.ocsp.OCSPRequest, KJUR.asn1.ASN1Object); +1218 +1219 /** +1220 * Utility class for OCSP<br/> +1221 * @name KJUR.asn1.ocsp.OCSPUtil +1222 * @class Utility class for OCSP +1223 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 +1224 * @description +1225 * This class provides utility static methods for OCSP. +1226 * <ul> +1227 * <li>{@link KJUR.asn1.ocsp.OCSPUtil.getRequestHex} - generates hexadecimal string of OCSP request</li> +1228 * </ul> +1229 */ +1230 KJUR.asn1.ocsp.OCSPUtil = {}; +1231 +1232 /** +1233 * generates hexadecimal string of OCSP request<br/> +1234 * @name getRequestHex +1235 * @memberOf KJUR.asn1.ocsp.OCSPUtil +1236 * @function +1237 * @param {String} issuerCert string of PEM issuer certificate +1238 * @param {String} subjectCert string of PEM subject certificate to be verified by OCSP +1239 * @param {String} algName hash algorithm name used for above arguments (ex. "sha1") DEFAULT: sha1 +1240 * @return {String} hexadecimal string of generated OCSP request +1241 * @since jsrsasign 6.1.0 asn1ocsp 1.0.0 +1242 * @description +1243 * This static method generates hexadecimal string of OCSP request. +1244 * @example +1245 * // generate OCSP request using sha1 algorithnm by default. +1246 * hReq = KJUR.asn1.ocsp.OCSPUtil.getRequestHex("-----BEGIN...", "-----BEGIN..."); +1247 */ +1248 KJUR.asn1.ocsp.OCSPUtil.getRequestHex = function(issuerCert, subjectCert, alg) { +1249 var _KJUR = KJUR, +1250 _KJUR_asn1 = _KJUR.asn1, +1251 _KJUR_asn1_ocsp = _KJUR_asn1.ocsp; +1252 +1253 if (alg === undefined) alg = _KJUR_asn1_ocsp.DEFAULT_HASH; +1254 var param = {alg: alg, issuerCert: issuerCert, subjectCert: subjectCert}; +1255 var o = new _KJUR_asn1_ocsp.OCSPRequest({reqList: [param]}); +1256 return o.getEncodedHex(); +1257 }; 1258 -1259 try { -1260 // certStatus -1261 var idxCertStatus = _getIdxbyList(h, 0, [1,0,1,0,0,2,0,1]); -1262 if (h.substr(idxCertStatus, 2) === "80") { -1263 result.certStatus = "good"; -1264 } else if (h.substr(idxCertStatus, 2) === "a1") { -1265 result.certStatus = "revoked"; -1266 result.revocationTime = -1267 hextoutf8(_getVbyList(h, idxCertStatus, [0])); -1268 } else if (h.substr(idxCertStatus, 2) === "82") { -1269 result.certStatus = "unknown"; -1270 } -1271 } catch (ex) {}; -1272 -1273 // thisUpdate -1274 try { -1275 var idxThisUpdate = _getIdxbyList(h, 0, [1,0,1,0,0,2,0,2]); -1276 result.thisUpdate = hextoutf8(_getV(h, idxThisUpdate)); -1277 } catch (ex) {}; -1278 -1279 // nextUpdate -1280 try { -1281 var idxEncapNextUpdate = _getIdxbyList(h, 0, [1,0,1,0,0,2,0,3]); -1282 if (h.substr(idxEncapNextUpdate, 2) === "a0") { -1283 result.nextUpdate = -1284 hextoutf8(_getVbyList(h, idxEncapNextUpdate, [0])); -1285 } -1286 } catch (ex) {}; -1287 -1288 return result; -1289 }; -1290 -1291 /** -1292 * OCSP request and response parser<br/> -1293 * @name KJUR.asn1.ocsp.OCSPParser -1294 * @class OCSP request and response parser -1295 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 -1296 * -1297 * @description -1298 * This class provides ASN.1 parser for -1299 * OCSP related ASN.1 data. <br/> -1300 * NOTE: OCSPResponse parser supported from jsrsasign 10.4.0. -1301 * <br/> -1302 * This parser supports following OCSP ASN.1 classes: -1303 * <ul> -1304 * <li>OCSP REQUEST -1305 * <ul> -1306 * <li>OCSPRequest - {@link KJUR.asn1.ocsp.OCSPParser#getOCSPRequest}</li> -1307 * <li>TBSRequest - {@link KJUR.asn1.ocsp.OCSPParser#getTBSRequest}</li> -1308 * <li>SEQUENCE OF Request - {@link KJUR.asn1.ocsp.OCSPParser#getRequestList}</li> -1309 * <li>Request - {@link KJUR.asn1.ocsp.OCSPParser#getRequest}</li> -1310 * </ul> -1311 * </li> -1312 * <li>OCSP RESPONSE -1313 * <ul> -1314 * <li>OCSPResponse - {@link KJUR.asn1.ocsp.OCSPParser#getOCSPResponse}</li> -1315 * <li>ResponseBytes - {@link KJUR.asn1.ocsp.OCSPParser#getResponseBytes}</li> -1316 * <li>BasicOCSPResponse - {@link KJUR.asn1.ocsp.OCSPParser#getBasicOCSPResponse}</li> -1317 * <li>ResponseData - {@link KJUR.asn1.ocsp.OCSPParser#getResponseData}</li> -1318 * <li>ResponderID - {@link KJUR.asn1.ocsp.OCSPParser#getResponderID}</li> -1319 * <li>SEQUENCE OF SingleResponse - {@link KJUR.asn1.ocsp.OCSPParser#getSingleResponseList}</li> -1320 * <li>SingleResponse - {@link KJUR.asn1.ocsp.OCSPParser#getSingleResponse}</li> -1321 * <li>CertStatus - {@link KJUR.asn1.ocsp.OCSPParser#getCertStatus}</li> -1322 * </ul> -1323 * </li> -1324 * <li>common -1325 * <ul> -1326 * <li>CertID - {@link KJUR.asn1.ocsp.OCSPParser#getCertID}</li> -1327 * </ul> -1328 * </li> -1329 * </ul> -1330 */ -1331 KJUR.asn1.ocsp.OCSPParser = function() { -1332 var _Error = Error, -1333 _X509 = X509, -1334 _x509obj = new _X509(), -1335 _ASN1HEX = ASN1HEX, -1336 _getV = _ASN1HEX.getV, -1337 _getTLV = _ASN1HEX.getTLV, -1338 _getIdxbyList = _ASN1HEX.getIdxbyList, -1339 _getVbyList = _ASN1HEX.getVbyList, -1340 _getTLVbyList = _ASN1HEX.getTLVbyList, -1341 _getVbyListEx = _ASN1HEX.getVbyListEx, -1342 _getTLVbyListEx = _ASN1HEX.getTLVbyListEx, -1343 _getChildIdx = _ASN1HEX.getChildIdx; -1344 -1345 /** -1346 * parse ASN.1 OCSPRequest<br/> -1347 * @name getOCSPRequest -1348 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1349 * @function -1350 * @param {String} h hexadecimal string of ASN.1 OCSPRequest -1351 * @return {Array} array of JSON object of OCSPRequest parameter -1352 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 -1353 * -1354 * @description -1355 * This method will parse a hexadecimal string of -1356 * OCSPRequest ASN.1 class is defined in -1357 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. -1358 * <pre> -1359 * OCSPRequest ::= SEQUENCE { -1360 * tbsRequest TBSRequest, -1361 * optionalSignature [0] EXPLICIT Signature OPTIONAL } -1362 * TBSRequest ::= SEQUENCE { -1363 * version [0] EXPLICIT Version DEFAULT v1, -1364 * requestorName [1] EXPLICIT GeneralName OPTIONAL, -1365 * requestList SEQUENCE OF Request, -1366 * requestExtensions [2] EXPLICIT Extensions OPTIONAL } -1367 * Signature ::= SEQUENCE { -1368 * signatureAlgorithm AlgorithmIdentifier, -1369 * signature BIT STRING, -1370 * certs [0] EXPLICIT SEQUENCE OF Certificate -1371 * OPTIONAL} -1372 * </pre> -1373 * Currently Signature in OCSPRequest is not supported. -1374 * <br/> -1375 * -1376 * @see KJUR.asn1.ocsp.OCSPParser#getTBSRequest -1377 * @see KJUR.asn1.ocsp.OCSPRequest -1378 * -1379 * @example -1380 * o = new KJUR.asn1.ocsp.OCSPParser(); -1381 * o.getOCSPRequest("30...") → -1382 * { array: [{ -1383 * "alg": "sha1", -1384 * "issname": "105fa67a80089db5279f35ce830b43889ea3c70d", -1385 * "isskey": "0f80611c823161d52f28e78d4638b42ce1c6d9e2", -1386 * "sbjsn": "0fef62075d715dc5e1d8bd03775c9686" }]} -1387 */ -1388 this.getOCSPRequest = function(h) { -1389 var a = _getChildIdx(h, 0); -1390 -1391 if (a.length != 1 && a.length != 2) { -1392 throw new _Error("wrong number elements: " + a.length); -1393 } -1394 -1395 var result = this.getTBSRequest(_getTLV(h, a[0])); -1396 return result; -1397 }; -1398 -1399 /** -1400 * parse ASN.1 TBSRequest of OCSP<br/> -1401 * @name getTBSRequest -1402 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1403 * @function -1404 * @param {String} h hexadecimal string of ASN.1 TBSRequest of OCSP -1405 * @return {Array} array of JSON object of TBSRequest parameter -1406 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 -1407 * -1408 * @description -1409 * This method will parse -1410 * TBSRequest ASN.1 class is defined in -1411 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. -1412 * <pre> -1413 * TBSRequest ::= SEQUENCE { -1414 * version [0] EXPLICIT Version DEFAULT v1, -1415 * requestorName [1] EXPLICIT GeneralName OPTIONAL, -1416 * requestList SEQUENCE OF Request, -1417 * requestExtensions [2] EXPLICIT Extensions OPTIONAL } -1418 * </pre> +1259 /** +1260 * simple parser for OCSPResponse (DEPRECATED)<br/> +1261 * @name getOCSPResponseInfo +1262 * @memberOf KJUR.asn1.ocsp.OCSPUtil +1263 * @function +1264 * @param {String} h hexadecimal string of DER OCSPResponse +1265 * @return {Object} JSON object of parsed OCSPResponse +1266 * @since jsrsasign 6.1.0 asn1ocsp 1.0.1 +1267 * @deprecated since jsrsasign 10.4.0 asn1ocsp 1.1.5 Please use OCSPParser.getOCSPRespnose +1268 * +1269 * @description +1270 * This static method parse a hexadecimal string of DER OCSPResponse and +1271 * returns JSON object of its parsed result. +1272 * Its result has following properties: +1273 * <ul> +1274 * <li>responseStatus - integer of responseStatus</li> +1275 * <li>certStatus - string of certStatus (ex. good, revoked or unknown)</li> +1276 * <li>thisUpdate - string of thisUpdate in Zulu(ex. 20151231235959Z)</li> +1277 * <li>nextUpdate - string of nextUpdate in Zulu(ex. 20151231235959Z)</li> +1278 * </ul> +1279 * NOTE: This method may not work preperly. Please use +1280 * {@link KJUR.asn1.ocsp.OCSPParser#getOCSPResponse}. +1281 * +1282 * @example +1283 * info = KJUR.asn1.ocsp.OCSPUtil.getOCSPResponseInfo("3082..."); +1284 */ +1285 KJUR.asn1.ocsp.OCSPUtil.getOCSPResponseInfo = function(h) { +1286 var _ASN1HEX = ASN1HEX, +1287 _getVbyList = _ASN1HEX.getVbyList, +1288 _getVbyListEx = _ASN1HEX.getVbyListEx, +1289 _getIdxbyList = _ASN1HEX.getIdxbyList, +1290 _getIdxbyListEx = _ASN1HEX.getIdxbyListEx, +1291 _getV = _ASN1HEX.getV; +1292 +1293 var result = {}; +1294 try { +1295 var v = _getVbyListEx(h, 0, [0], "0a"); +1296 result.responseStatus = parseInt(v, 16); +1297 } catch(ex) {}; +1298 if (result.responseStatus !== 0) return result; +1299 +1300 try { +1301 // certStatus +1302 var idxCertStatus = _getIdxbyList(h, 0, [1,0,1,0,0,2,0,1]); +1303 if (h.substr(idxCertStatus, 2) === "80") { +1304 result.certStatus = "good"; +1305 } else if (h.substr(idxCertStatus, 2) === "a1") { +1306 result.certStatus = "revoked"; +1307 result.revocationTime = +1308 hextoutf8(_getVbyList(h, idxCertStatus, [0])); +1309 } else if (h.substr(idxCertStatus, 2) === "82") { +1310 result.certStatus = "unknown"; +1311 } +1312 } catch (ex) {}; +1313 +1314 // thisUpdate +1315 try { +1316 var idxThisUpdate = _getIdxbyList(h, 0, [1,0,1,0,0,2,0,2]); +1317 result.thisUpdate = hextoutf8(_getV(h, idxThisUpdate)); +1318 } catch (ex) {}; +1319 +1320 // nextUpdate +1321 try { +1322 var idxEncapNextUpdate = _getIdxbyList(h, 0, [1,0,1,0,0,2,0,3]); +1323 if (h.substr(idxEncapNextUpdate, 2) === "a0") { +1324 result.nextUpdate = +1325 hextoutf8(_getVbyList(h, idxEncapNextUpdate, [0])); +1326 } +1327 } catch (ex) {}; +1328 +1329 return result; +1330 }; +1331 +1332 /** +1333 * OCSP request and response parser<br/> +1334 * @name KJUR.asn1.ocsp.OCSPParser +1335 * @class OCSP request and response parser +1336 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 +1337 * +1338 * @description +1339 * This class provides ASN.1 parser for +1340 * OCSP related ASN.1 data. <br/> +1341 * NOTE: OCSPResponse parser supported from jsrsasign 10.4.0. +1342 * <br/> +1343 * This parser supports following OCSP ASN.1 classes: +1344 * <ul> +1345 * <li>OCSP REQUEST +1346 * <ul> +1347 * <li>OCSPRequest - {@link KJUR.asn1.ocsp.OCSPParser#getOCSPRequest}</li> +1348 * <li>TBSRequest - {@link KJUR.asn1.ocsp.OCSPParser#getTBSRequest}</li> +1349 * <li>SEQUENCE OF Request - {@link KJUR.asn1.ocsp.OCSPParser#getRequestList}</li> +1350 * <li>Request - {@link KJUR.asn1.ocsp.OCSPParser#getRequest}</li> +1351 * </ul> +1352 * </li> +1353 * <li>OCSP RESPONSE +1354 * <ul> +1355 * <li>OCSPResponse - {@link KJUR.asn1.ocsp.OCSPParser#getOCSPResponse}</li> +1356 * <li>ResponseBytes - {@link KJUR.asn1.ocsp.OCSPParser#getResponseBytes}</li> +1357 * <li>BasicOCSPResponse - {@link KJUR.asn1.ocsp.OCSPParser#getBasicOCSPResponse}</li> +1358 * <li>ResponseData - {@link KJUR.asn1.ocsp.OCSPParser#getResponseData}</li> +1359 * <li>ResponderID - {@link KJUR.asn1.ocsp.OCSPParser#getResponderID}</li> +1360 * <li>SEQUENCE OF SingleResponse - {@link KJUR.asn1.ocsp.OCSPParser#getSingleResponseList}</li> +1361 * <li>SingleResponse - {@link KJUR.asn1.ocsp.OCSPParser#getSingleResponse}</li> +1362 * <li>CertStatus - {@link KJUR.asn1.ocsp.OCSPParser#getCertStatus}</li> +1363 * </ul> +1364 * </li> +1365 * <li>common +1366 * <ul> +1367 * <li>CertID - {@link KJUR.asn1.ocsp.OCSPParser#getCertID}</li> +1368 * </ul> +1369 * </li> +1370 * </ul> +1371 */ +1372 KJUR.asn1.ocsp.OCSPParser = function() { +1373 var _Error = Error, +1374 _X509 = X509, +1375 _x509obj = new _X509(), +1376 _ASN1HEX = ASN1HEX, +1377 _getV = _ASN1HEX.getV, +1378 _getTLV = _ASN1HEX.getTLV, +1379 _getIdxbyList = _ASN1HEX.getIdxbyList, +1380 _getVbyList = _ASN1HEX.getVbyList, +1381 _getTLVbyList = _ASN1HEX.getTLVbyList, +1382 _getVbyListEx = _ASN1HEX.getVbyListEx, +1383 _getTLVbyListEx = _ASN1HEX.getTLVbyListEx, +1384 _getChildIdx = _ASN1HEX.getChildIdx; +1385 +1386 /** +1387 * parse ASN.1 OCSPRequest<br/> +1388 * @name getOCSPRequest +1389 * @memberOf KJUR.asn1.ocsp.OCSPParser# +1390 * @function +1391 * @param {String} h hexadecimal string of ASN.1 OCSPRequest +1392 * @return {Array} array of JSON object of OCSPRequest parameter +1393 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 +1394 * +1395 * @description +1396 * This method will parse a hexadecimal string of +1397 * OCSPRequest ASN.1 class is defined in +1398 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. +1399 * <pre> +1400 * OCSPRequest ::= SEQUENCE { +1401 * tbsRequest TBSRequest, +1402 * optionalSignature [0] EXPLICIT Signature OPTIONAL } +1403 * TBSRequest ::= SEQUENCE { +1404 * version [0] EXPLICIT Version DEFAULT v1, +1405 * requestorName [1] EXPLICIT GeneralName OPTIONAL, +1406 * requestList SEQUENCE OF Request, +1407 * requestExtensions [2] EXPLICIT Extensions OPTIONAL } +1408 * Signature ::= SEQUENCE { +1409 * signatureAlgorithm AlgorithmIdentifier, +1410 * signature BIT STRING, +1411 * certs [0] EXPLICIT SEQUENCE OF Certificate +1412 * OPTIONAL} +1413 * </pre> +1414 * Currently Signature in OCSPRequest is not supported. +1415 * <br/> +1416 * +1417 * @see KJUR.asn1.ocsp.OCSPParser#getTBSRequest +1418 * @see KJUR.asn1.ocsp.OCSPRequest 1419 * -1420 * @see KJUR.asn1.ocsp.OCSPParser#getOCSPRequest -1421 * @see KJUR.asn1.ocsp.OCSPParser#getRequestList -1422 * @see KJUR.asn1.ocsp.TBSRequest -1423 * -1424 * @example -1425 * o = new KJUR.asn1.ocsp.OCSPParser(); -1426 * o.getTBSRequest("30...") → -1427 * {array: [{ -1428 * "alg": "sha1", -1429 * "issname": "105fa67a80089db5279f35ce830b43889ea3c70d", -1430 * "isskey": "0f80611c823161d52f28e78d4638b42ce1c6d9e2", -1431 * "sbjsn": "0fef62075d715dc5e1d8bd03775c9686" }]} -1432 */ -1433 this.getTBSRequest = function(h) { -1434 var result = {}; -1435 var hReqList = _getTLVbyListEx(h, 0, [0], "30"); -1436 result.array = this.getRequestList(hReqList); -1437 var hExt = _getTLVbyListEx(h, 0, ["[2]", 0], "30"); -1438 if (hExt != null) { -1439 result.ext = _x509obj.getExtParamArray(hExt); -1440 } -1441 -1442 return result; -1443 }; -1444 -1445 /** -1446 * parse ASN.1 SEQUENCE OF Request in OCSP<br/> -1447 * @name getRequestList -1448 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1449 * @function -1450 * @param {String} h hexadecimal string of ASN.1 SEQUENCE OF Request in OCSP -1451 * @return {Array} array of JSON object of Request parameter -1452 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 -1453 * -1454 * @description -1455 * This method will parse a hexadecimal string of -1456 * SEQUENCE OF Request ASN.1 class is defined in -1457 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. -1458 * <br/> -1459 * NOTE: singleRequestExtensions is not supported yet in this version such as nonce. -1460 * <pre> -1461 * TBSRequest ::= SEQUENCE { -1462 * version [0] EXPLICIT Version DEFAULT v1, -1463 * requestorName [1] EXPLICIT GeneralName OPTIONAL, -1464 * requestList SEQUENCE OF Request, -1465 * requestExtensions [2] EXPLICIT Extensions OPTIONAL } -1466 * Request ::= SEQUENCE { -1467 * reqCert CertID, -1468 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } -1469 * </pre> -1470 * -1471 * @see KJUR.asn1.ocsp.OCSPParser#getTBSRequest -1472 * @see KJUR.asn1.ocsp.OCSPParser#getRequest -1473 * @see KJUR.asn1.ocsp.RequestList -1474 * @see KJUR.asn1.ocsp.Request -1475 * -1476 * @example -1477 * o = new KJUR.asn1.ocsp.OCSPParser(); -1478 * o.getRequestList("30...") → -1479 * [{ alg: "sha1" -1480 * issname: "...hex...", -1481 * isskey: "...hex...", -1482 * sbjsn: "...hex...", -1483 * ext: [<<singleRequestExtension parameters>>...] }] -1484 */ -1485 this.getRequestList = function(h) { -1486 var result = []; -1487 var a = _getChildIdx(h, 0); -1488 for (var i = 0; i < a.length; i++) { -1489 var h = _getTLV(h, a[i]); -1490 result.push(this.getRequest(h)); -1491 } -1492 return result; -1493 }; -1494 -1495 /** -1496 * parse ASN.1 Request of OCSP<br/> -1497 * @name getRequest -1498 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1499 * @function -1500 * @param {String} h hexadecimal string of ASN.1 Request of OCSP -1501 * @return JSON object of Request parameter -1502 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 -1503 * -1504 * @description -1505 * This method will parse a hexadecimal string of -1506 * Request ASN.1 class is defined in -1507 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. -1508 * <pre> -1509 * Request ::= SEQUENCE { -1510 * reqCert CertID, -1511 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } -1512 * </pre> -1513 * -1514 * @see KJUR.asn1.ocsp.OCSPParser#getTBSRequest -1515 * @see KJUR.asn1.ocsp.OCSPParser#getRequestList -1516 * @see KJUR.asn1.ocsp.OCSPParser#getCertID -1517 * @see KJUR.asn1.ocsp.RequestList -1518 * @see KJUR.asn1.ocsp.Request -1519 * @see KJUR.asn1.ocsp.CertID -1520 * -1521 * @example -1522 * o = new KJUR.asn1.ocsp.OCSPParser(); -1523 * o.getRequest("30...") → -1524 * { alg: "sha1" -1525 * issname: "...hex...", -1526 * isskey: "...hex...", -1527 * sbjsn: "...hex...", -1528 * ext: [<<singleRequestExtension parameters>>...] } -1529 */ -1530 this.getRequest = function(h) { -1531 var a = _getChildIdx(h, 0); -1532 if (a.length != 1 && a.length != 2) { -1533 throw new _Error("wrong number elements: " + a.length); -1534 } -1535 -1536 var params = this.getCertID(_getTLV(h, a[0])); -1537 -1538 if (a.length == 2) { -1539 var idxExt = _getIdxbyList(h, 0, [1, 0]); -1540 params.ext = _x509obj.getExtParamArray(_getTLV(h, idxExt)); -1541 } -1542 -1543 return params; -1544 }; -1545 -1546 /** -1547 * parse ASN.1 CertID of OCSP<br/> -1548 * @name getCertID -1549 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1550 * @function -1551 * @param {String} h hexadecimal string of CertID -1552 * @return JSON object of CertID parameter -1553 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 +1420 * @example +1421 * o = new KJUR.asn1.ocsp.OCSPParser(); +1422 * o.getOCSPRequest("30...") → +1423 * { array: [{ +1424 * "alg": "sha1", +1425 * "issname": "105fa67a80089db5279f35ce830b43889ea3c70d", +1426 * "isskey": "0f80611c823161d52f28e78d4638b42ce1c6d9e2", +1427 * "sbjsn": "0fef62075d715dc5e1d8bd03775c9686" }]} +1428 */ +1429 this.getOCSPRequest = function(h) { +1430 var a = _getChildIdx(h, 0); +1431 +1432 if (a.length != 1 && a.length != 2) { +1433 throw new _Error("wrong number elements: " + a.length); +1434 } +1435 +1436 var result = this.getTBSRequest(_getTLV(h, a[0])); +1437 return result; +1438 }; +1439 +1440 /** +1441 * parse ASN.1 TBSRequest of OCSP<br/> +1442 * @name getTBSRequest +1443 * @memberOf KJUR.asn1.ocsp.OCSPParser# +1444 * @function +1445 * @param {String} h hexadecimal string of ASN.1 TBSRequest of OCSP +1446 * @return {Array} array of JSON object of TBSRequest parameter +1447 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 +1448 * +1449 * @description +1450 * This method will parse +1451 * TBSRequest ASN.1 class is defined in +1452 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. +1453 * <pre> +1454 * TBSRequest ::= SEQUENCE { +1455 * version [0] EXPLICIT Version DEFAULT v1, +1456 * requestorName [1] EXPLICIT GeneralName OPTIONAL, +1457 * requestList SEQUENCE OF Request, +1458 * requestExtensions [2] EXPLICIT Extensions OPTIONAL } +1459 * </pre> +1460 * +1461 * @see KJUR.asn1.ocsp.OCSPParser#getOCSPRequest +1462 * @see KJUR.asn1.ocsp.OCSPParser#getRequestList +1463 * @see KJUR.asn1.ocsp.TBSRequest +1464 * +1465 * @example +1466 * o = new KJUR.asn1.ocsp.OCSPParser(); +1467 * o.getTBSRequest("30...") → +1468 * {array: [{ +1469 * "alg": "sha1", +1470 * "issname": "105fa67a80089db5279f35ce830b43889ea3c70d", +1471 * "isskey": "0f80611c823161d52f28e78d4638b42ce1c6d9e2", +1472 * "sbjsn": "0fef62075d715dc5e1d8bd03775c9686" }]} +1473 */ +1474 this.getTBSRequest = function(h) { +1475 var result = {}; +1476 var hReqList = _getTLVbyListEx(h, 0, [0], "30"); +1477 result.array = this.getRequestList(hReqList); +1478 var hExt = _getTLVbyListEx(h, 0, ["[2]", 0], "30"); +1479 if (hExt != null) { +1480 result.ext = _x509obj.getExtParamArray(hExt); +1481 } +1482 +1483 return result; +1484 }; +1485 +1486 /** +1487 * parse ASN.1 SEQUENCE OF Request in OCSP<br/> +1488 * @name getRequestList +1489 * @memberOf KJUR.asn1.ocsp.OCSPParser# +1490 * @function +1491 * @param {String} h hexadecimal string of ASN.1 SEQUENCE OF Request in OCSP +1492 * @return {Array} array of JSON object of Request parameter +1493 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 +1494 * +1495 * @description +1496 * This method will parse a hexadecimal string of +1497 * SEQUENCE OF Request ASN.1 class is defined in +1498 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. +1499 * <br/> +1500 * NOTE: singleRequestExtensions is not supported yet in this version such as nonce. +1501 * <pre> +1502 * TBSRequest ::= SEQUENCE { +1503 * version [0] EXPLICIT Version DEFAULT v1, +1504 * requestorName [1] EXPLICIT GeneralName OPTIONAL, +1505 * requestList SEQUENCE OF Request, +1506 * requestExtensions [2] EXPLICIT Extensions OPTIONAL } +1507 * Request ::= SEQUENCE { +1508 * reqCert CertID, +1509 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } +1510 * </pre> +1511 * +1512 * @see KJUR.asn1.ocsp.OCSPParser#getTBSRequest +1513 * @see KJUR.asn1.ocsp.OCSPParser#getRequest +1514 * @see KJUR.asn1.ocsp.RequestList +1515 * @see KJUR.asn1.ocsp.Request +1516 * +1517 * @example +1518 * o = new KJUR.asn1.ocsp.OCSPParser(); +1519 * o.getRequestList("30...") → +1520 * [{ alg: "sha1" +1521 * issname: "...hex...", +1522 * isskey: "...hex...", +1523 * sbjsn: "...hex...", +1524 * ext: [<<singleRequestExtension parameters>>...] }] +1525 */ +1526 this.getRequestList = function(h) { +1527 var result = []; +1528 var a = _getChildIdx(h, 0); +1529 for (var i = 0; i < a.length; i++) { +1530 var h = _getTLV(h, a[i]); +1531 result.push(this.getRequest(h)); +1532 } +1533 return result; +1534 }; +1535 +1536 /** +1537 * parse ASN.1 Request of OCSP<br/> +1538 * @name getRequest +1539 * @memberOf KJUR.asn1.ocsp.OCSPParser# +1540 * @function +1541 * @param {String} h hexadecimal string of ASN.1 Request of OCSP +1542 * @return JSON object of Request parameter +1543 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 +1544 * +1545 * @description +1546 * This method will parse a hexadecimal string of +1547 * Request ASN.1 class is defined in +1548 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. +1549 * <pre> +1550 * Request ::= SEQUENCE { +1551 * reqCert CertID, +1552 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } +1553 * </pre> 1554 * -1555 * @description -1556 * This method will parse a hexadecimal string of -1557 * CertID ASN.1 class is defined in -1558 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. -1559 * <pre> -1560 * CertID ::= SEQUENCE { -1561 * hashAlgorithm AlgorithmIdentifier, -1562 * issuerNameHash OCTET STRING, -- Hash of issuer's DN -1563 * issuerKeyHash OCTET STRING, -- Hash of issuer's public key -1564 * serialNumber CertificateSerialNumber } -1565 * </pre> -1566 * -1567 * @see KJUR.asn1.ocsp.OCSPParser#getRequest -1568 * @see KJUR.asn1.ocsp.OCSPParser#getSingleResponse -1569 * @see KJUR.asn1.ocsp.CertID -1570 * -1571 * @example -1572 * o = new KJUR.asn1.ocsp.OCSPParser(); -1573 * o.getCertID("30...") → -1574 * { alg: "sha1" -1575 * issname: "...hex...", -1576 * isskey: "...hex...", -1577 * sbjsn: "...hex..." } -1578 */ -1579 this.getCertID = function(h) { -1580 var a = _getChildIdx(h, 0); -1581 if (a.length != 4) { -1582 throw new _Error("wrong number elements: " + a.length); -1583 } -1584 -1585 var x = new _X509(); -1586 var result = {}; -1587 result.alg = x.getAlgorithmIdentifierName(_getTLV(h, a[0])); -1588 result.issname = _getV(h, a[1]); -1589 result.isskey = _getV(h, a[2]); -1590 result.sbjsn = _getV(h, a[3]); -1591 -1592 return result; -1593 }; -1594 -1595 /** -1596 * parse ASN.1 OCSPResponse of OCSP<br/> -1597 * @name getOCSPResponse -1598 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1599 * @function -1600 * @param {String} h hexadecimal string of OCSPResponse -1601 * @return JSON object of OCSResponse parameter -1602 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 -1603 * -1604 * @description -1605 * This method will parse a hexadecimal string of -1606 * ASN.1 OCSPResponse defined in -1607 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. -1608 * <pre> -1609 * OCSPResponse ::= SEQUENCE { -1610 * responseStatus OCSPResponseStatus, -1611 * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL } -1612 * OCSPResponseStatus ::= ENUMERATED { -1613 * successful (0), -- Response has valid confirmations -1614 * malformedRequest (1), -- Illegal confirmation request -1615 * internalError (2), -- Internal error in issuer -1616 * tryLater (3), -- Try again later -1617 * -- (4) is not used -1618 * sigRequired (5), -- Must sign the request -1619 * unauthorized (6) -- Request unauthorized } -1620 * </pre> -1621 * -1622 * @see KJUR.asn1.ocsp.OCSPParser#getResponseBytes -1623 * @see KJUR.asn1.ocsp.OCSPResponse -1624 * -1625 * @example -1626 * o = new KJUR.asn1.ocsp.OCSPParser(); -1627 * o.getOCSPResponse("30..") → -1628 * { resstatus: 0, -1629 * restype: "ocspBasic", -1630 * respid: {key: "12ab"}, -1631 * prodat: "20200903235959Z", -1632 * array: [{ -1633 * certid: {alg:"sha1",issname:"12ab",isskey:"12ab",sbjsn:"12ab"}, -1634 * status: {status: "good"}, -1635 * thisupdate: "20200903235959Z" }], -1636 * ext: [{extname: "ocspNonce", hex: "1234abcd"}], -1637 * alg: "SHA256withRSA", -1638 * sighex: "12ab", -1639 * certs: ["3082...", "3082..."] } -1640 */ -1641 this.getOCSPResponse = function(h) { -1642 var a = _getChildIdx(h, 0); -1643 var result; -1644 -1645 var hStatusV = _getV(h, a[0]); -1646 var iStatusV = parseInt(hStatusV); -1647 -1648 if (a.length == 1) return {resstatus: iStatusV}; -1649 -1650 var hResponseBytes = _getTLVbyList(h, 0, [1, 0]); -1651 result = this.getResponseBytes(hResponseBytes); -1652 result.resstatus = iStatusV; -1653 -1654 return result; -1655 }; -1656 -1657 /** -1658 * parse ASN.1 ResponseBytes of OCSP<br/> -1659 * @name getResponseBytes -1660 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1661 * @function -1662 * @param {String} h hexadecimal string of ResponseBytes -1663 * @return JSON object of ResponseBytes parameter -1664 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 +1555 * @see KJUR.asn1.ocsp.OCSPParser#getTBSRequest +1556 * @see KJUR.asn1.ocsp.OCSPParser#getRequestList +1557 * @see KJUR.asn1.ocsp.OCSPParser#getCertID +1558 * @see KJUR.asn1.ocsp.RequestList +1559 * @see KJUR.asn1.ocsp.Request +1560 * @see KJUR.asn1.ocsp.CertID +1561 * +1562 * @example +1563 * o = new KJUR.asn1.ocsp.OCSPParser(); +1564 * o.getRequest("30...") → +1565 * { alg: "sha1" +1566 * issname: "...hex...", +1567 * isskey: "...hex...", +1568 * sbjsn: "...hex...", +1569 * ext: [<<singleRequestExtension parameters>>...] } +1570 */ +1571 this.getRequest = function(h) { +1572 var a = _getChildIdx(h, 0); +1573 if (a.length != 1 && a.length != 2) { +1574 throw new _Error("wrong number elements: " + a.length); +1575 } +1576 +1577 var params = this.getCertID(_getTLV(h, a[0])); +1578 +1579 if (a.length == 2) { +1580 var idxExt = _getIdxbyList(h, 0, [1, 0]); +1581 params.ext = _x509obj.getExtParamArray(_getTLV(h, idxExt)); +1582 } +1583 +1584 return params; +1585 }; +1586 +1587 /** +1588 * parse ASN.1 CertID of OCSP<br/> +1589 * @name getCertID +1590 * @memberOf KJUR.asn1.ocsp.OCSPParser# +1591 * @function +1592 * @param {String} h hexadecimal string of CertID +1593 * @return JSON object of CertID parameter +1594 * @since jsrsasign 9.1.6 asn1ocsp 1.1.0 +1595 * +1596 * @description +1597 * This method will parse a hexadecimal string of +1598 * CertID ASN.1 class is defined in +1599 * <a href="https://tools.ietf.org/html/rfc6960#section-4.1.1">RFC 6960 4.1.1</a>. +1600 * <pre> +1601 * CertID ::= SEQUENCE { +1602 * hashAlgorithm AlgorithmIdentifier, +1603 * issuerNameHash OCTET STRING, -- Hash of issuer's DN +1604 * issuerKeyHash OCTET STRING, -- Hash of issuer's public key +1605 * serialNumber CertificateSerialNumber } +1606 * </pre> +1607 * +1608 * @see KJUR.asn1.ocsp.OCSPParser#getRequest +1609 * @see KJUR.asn1.ocsp.OCSPParser#getSingleResponse +1610 * @see KJUR.asn1.ocsp.CertID +1611 * +1612 * @example +1613 * o = new KJUR.asn1.ocsp.OCSPParser(); +1614 * o.getCertID("30...") → +1615 * { alg: "sha1" +1616 * issname: "...hex...", +1617 * isskey: "...hex...", +1618 * sbjsn: "...hex..." } +1619 */ +1620 this.getCertID = function(h) { +1621 var a = _getChildIdx(h, 0); +1622 if (a.length != 4) { +1623 throw new _Error("wrong number elements: " + a.length); +1624 } +1625 +1626 var x = new _X509(); +1627 var result = {}; +1628 result.alg = x.getAlgorithmIdentifierName(_getTLV(h, a[0])); +1629 result.issname = _getV(h, a[1]); +1630 result.isskey = _getV(h, a[2]); +1631 result.sbjsn = _getV(h, a[3]); +1632 +1633 return result; +1634 }; +1635 +1636 /** +1637 * parse ASN.1 OCSPResponse of OCSP<br/> +1638 * @name getOCSPResponse +1639 * @memberOf KJUR.asn1.ocsp.OCSPParser# +1640 * @function +1641 * @param {String} h hexadecimal string of OCSPResponse +1642 * @return JSON object of OCSResponse parameter +1643 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 +1644 * +1645 * @description +1646 * This method will parse a hexadecimal string of +1647 * ASN.1 OCSPResponse defined in +1648 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. +1649 * <pre> +1650 * OCSPResponse ::= SEQUENCE { +1651 * responseStatus OCSPResponseStatus, +1652 * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL } +1653 * OCSPResponseStatus ::= ENUMERATED { +1654 * successful (0), -- Response has valid confirmations +1655 * malformedRequest (1), -- Illegal confirmation request +1656 * internalError (2), -- Internal error in issuer +1657 * tryLater (3), -- Try again later +1658 * -- (4) is not used +1659 * sigRequired (5), -- Must sign the request +1660 * unauthorized (6) -- Request unauthorized } +1661 * </pre> +1662 * +1663 * @see KJUR.asn1.ocsp.OCSPParser#getResponseBytes +1664 * @see KJUR.asn1.ocsp.OCSPResponse 1665 * -1666 * @description -1667 * This method will parse a hexadecimal string of -1668 * ASN.1 ResponseBytes defined in -1669 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. -1670 * <pre> -1671 * ResponseBytes ::= SEQUENCE { -1672 * responseType OBJECT IDENTIFIER, -1673 * response OCTET STRING } -1674 * id-pkix-ocsp OBJECT IDENTIFIER ::= { id-ad-ocsp } -1675 * id-pkix-ocsp-basic OBJECT IDENTIFIER ::= { id-pkix-ocsp 1 } -1676 * -1677 * BasicOCSPResponse ::= SEQUENCE { -1678 * tbsResponseData ResponseData, -1679 * signatureAlgorithm AlgorithmIdentifier, -1680 * signature BIT STRING, -1681 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } -1682 * </pre> -1683 * -1684 * @see KJUR.asn1.ocsp.OCSPParser#getOCSPResponse -1685 * @see KJUR.asn1.ocsp.OCSPParser#getBasicOCSPResponse -1686 * @see KJUR.asn1.ocsp.ResponseBytes -1687 * -1688 * @example -1689 * o = new KJUR.asn1.ocsp.OCSPParser(); -1690 * o.getResponseBytes("30..") → -1691 * { restype: "ocspBasic", -1692 * ...<<BasicOCSPResponse properties...>>... -1693 */ -1694 this.getResponseBytes = function(h) { -1695 var a = _getChildIdx(h, 0); -1696 var result; +1666 * @example +1667 * o = new KJUR.asn1.ocsp.OCSPParser(); +1668 * o.getOCSPResponse("30..") → +1669 * { resstatus: 0, +1670 * restype: "ocspBasic", +1671 * respid: {key: "12ab"}, +1672 * prodat: "20200903235959Z", +1673 * array: [{ +1674 * certid: {alg:"sha1",issname:"12ab",isskey:"12ab",sbjsn:"12ab"}, +1675 * status: {status: "good"}, +1676 * thisupdate: "20200903235959Z" }], +1677 * ext: [{extname: "ocspNonce", hex: "1234abcd"}], +1678 * alg: "SHA256withRSA", +1679 * sighex: "12ab", +1680 * certs: ["3082...", "3082..."] } +1681 */ +1682 this.getOCSPResponse = function(h) { +1683 var a = _getChildIdx(h, 0); +1684 var result; +1685 +1686 var hStatusV = _getV(h, a[0]); +1687 var iStatusV = parseInt(hStatusV); +1688 +1689 if (a.length == 1) return {resstatus: iStatusV}; +1690 +1691 var hResponseBytes = _getTLVbyList(h, 0, [1, 0]); +1692 result = this.getResponseBytes(hResponseBytes); +1693 result.resstatus = iStatusV; +1694 +1695 return result; +1696 }; 1697 -1698 var hBasicOCSPResponse = _getTLVbyList(h, 0, [1, 0]); -1699 result = this.getBasicOCSPResponse(hBasicOCSPResponse); -1700 -1701 var hResTypeV = _getV(h, a[0]); -1702 result.restype = KJUR.asn1.x509.OID.oid2name(hextooid(hResTypeV)); -1703 -1704 return result; -1705 }; -1706 -1707 /** -1708 * parse ASN.1 BasicOCSPResponse of OCSP<br/> -1709 * @name getBasicOCSPResponse -1710 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1711 * @function -1712 * @param {String} h hexadecimal string of BasicOCSPResponse -1713 * @return JSON object of BasicOCSPResponse parameter -1714 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 -1715 * -1716 * @description -1717 * This method will parse a hexadecimal string of -1718 * BasicOCSPResponse defined in -1719 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. -1720 * <pre> -1721 * BasicOCSPResponse ::= SEQUENCE { -1722 * tbsResponseData ResponseData, -1723 * signatureAlgorithm AlgorithmIdentifier, -1724 * signature BIT STRING, -1725 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } -1726 * </pre> -1727 * -1728 * @see KJUR.asn1.ocsp.OCSPParser#getResponseBytes -1729 * @see KJUR.asn1.ocsp.OCSPParser#getResponseData -1730 * @see KJUR.asn1.ocsp.BasicOCSPResponse -1731 * -1732 * @example -1733 * o = new KJUR.asn1.ocsp.OCSPParser(); -1734 * o.getBasicOCSPResponse("30..") → -1735 * { ...<<ResponseData properties...>>... -1736 * sigalg: "SHA256withRSA", -1737 * sighex: "12abcd...", -1738 * certs: [<<PEMorHEXstringOfCert1>>,...] }); -1739 */ -1740 this.getBasicOCSPResponse = function(h) { -1741 var a = _getChildIdx(h, 0); -1742 var result; -1743 -1744 result = this.getResponseData(_getTLV(h, a[0])); -1745 -1746 var x = new X509(); -1747 result.alg = x.getAlgorithmIdentifierName(_getTLV(h, a[1])); -1748 -1749 var hSigHex = _getV(h, a[2]); -1750 result.sighex = hSigHex.substr(2); -1751 -1752 var hExt = _getVbyListEx(h, 0, ["[0]"]); -1753 if (hExt != null) { -1754 var aCertIdx = _getChildIdx(hExt, 0); -1755 var aCert = []; -1756 for (var i = 0; i < aCertIdx.length; i++) { -1757 var hCert = _getTLV(hExt, aCertIdx[i]); -1758 aCert.push(hCert); -1759 } -1760 result.certs = aCert; -1761 } -1762 -1763 return result; -1764 }; -1765 -1766 /** -1767 * parse ASN.1 ResponseData of OCSP<br/> -1768 * @name getResponseData -1769 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1770 * @function -1771 * @param {String} h hexadecimal string of ResponseData -1772 * @return JSON object of ResponseData parameter -1773 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 -1774 * -1775 * @description -1776 * This method will parse a hexadecimal string of -1777 * ASN.1 ResponseData defined in -1778 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. -1779 * <pre> -1780 * ResponseData ::= SEQUENCE { -1781 * version [0] EXPLICIT Version DEFAULT v1, -1782 * responderID ResponderID, -1783 * producedAt GeneralizedTime, -1784 * responses SEQUENCE OF SingleResponse, -1785 * responseExtensions [1] EXPLICIT Extensions OPTIONAL } -1786 * </pre> -1787 * -1788 * @see KJUR.asn1.ocsp.OCSPParser#getBasicOCSPResponse -1789 * @see KJUR.asn1.ocsp.OCSPParser#getSingleResponse -1790 * @see KJUR.asn1.ocsp.ResponseData -1791 * -1792 * @example -1793 * o = new KJUR.asn1.ocsp.OCSPParser(); -1794 * o.getResponseData("30..") → -1795 * { respid: {key: "12ab..."}, -1796 * prodat: "20200903235959Z", -1797 * array: [<<SingleResponse parameter1>>, ...], -1798 * ext: [ -1799 * {extname:"ocspNonce",hex:"12ab..."}]} -1800 */ -1801 this.getResponseData = function(h) { -1802 var a = _getChildIdx(h, 0); -1803 var alen = a.length; -1804 var result = {}; -1805 var idx = 0; +1698 /** +1699 * parse ASN.1 ResponseBytes of OCSP<br/> +1700 * @name getResponseBytes +1701 * @memberOf KJUR.asn1.ocsp.OCSPParser# +1702 * @function +1703 * @param {String} h hexadecimal string of ResponseBytes +1704 * @return JSON object of ResponseBytes parameter +1705 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 +1706 * +1707 * @description +1708 * This method will parse a hexadecimal string of +1709 * ASN.1 ResponseBytes defined in +1710 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. +1711 * <pre> +1712 * ResponseBytes ::= SEQUENCE { +1713 * responseType OBJECT IDENTIFIER, +1714 * response OCTET STRING } +1715 * id-pkix-ocsp OBJECT IDENTIFIER ::= { id-ad-ocsp } +1716 * id-pkix-ocsp-basic OBJECT IDENTIFIER ::= { id-pkix-ocsp 1 } +1717 * +1718 * BasicOCSPResponse ::= SEQUENCE { +1719 * tbsResponseData ResponseData, +1720 * signatureAlgorithm AlgorithmIdentifier, +1721 * signature BIT STRING, +1722 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } +1723 * </pre> +1724 * +1725 * @see KJUR.asn1.ocsp.OCSPParser#getOCSPResponse +1726 * @see KJUR.asn1.ocsp.OCSPParser#getBasicOCSPResponse +1727 * @see KJUR.asn1.ocsp.ResponseBytes +1728 * +1729 * @example +1730 * o = new KJUR.asn1.ocsp.OCSPParser(); +1731 * o.getResponseBytes("30..") → +1732 * { restype: "ocspBasic", +1733 * ...<<BasicOCSPResponse properties...>>... +1734 */ +1735 this.getResponseBytes = function(h) { +1736 var a = _getChildIdx(h, 0); +1737 var result; +1738 +1739 var hBasicOCSPResponse = _getTLVbyList(h, 0, [1, 0]); +1740 result = this.getBasicOCSPResponse(hBasicOCSPResponse); +1741 +1742 var hResTypeV = _getV(h, a[0]); +1743 result.restype = KJUR.asn1.x509.OID.oid2name(hextooid(hResTypeV)); +1744 +1745 return result; +1746 }; +1747 +1748 /** +1749 * parse ASN.1 BasicOCSPResponse of OCSP<br/> +1750 * @name getBasicOCSPResponse +1751 * @memberOf KJUR.asn1.ocsp.OCSPParser# +1752 * @function +1753 * @param {String} h hexadecimal string of BasicOCSPResponse +1754 * @return JSON object of BasicOCSPResponse parameter +1755 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 +1756 * +1757 * @description +1758 * This method will parse a hexadecimal string of +1759 * BasicOCSPResponse defined in +1760 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. +1761 * <pre> +1762 * BasicOCSPResponse ::= SEQUENCE { +1763 * tbsResponseData ResponseData, +1764 * signatureAlgorithm AlgorithmIdentifier, +1765 * signature BIT STRING, +1766 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } +1767 * </pre> +1768 * +1769 * @see KJUR.asn1.ocsp.OCSPParser#getResponseBytes +1770 * @see KJUR.asn1.ocsp.OCSPParser#getResponseData +1771 * @see KJUR.asn1.ocsp.BasicOCSPResponse +1772 * +1773 * @example +1774 * o = new KJUR.asn1.ocsp.OCSPParser(); +1775 * o.getBasicOCSPResponse("30..") → +1776 * { ...<<ResponseData properties...>>... +1777 * sigalg: "SHA256withRSA", +1778 * sighex: "12abcd...", +1779 * certs: [<<PEMorHEXstringOfCert1>>,...] }); +1780 */ +1781 this.getBasicOCSPResponse = function(h) { +1782 var a = _getChildIdx(h, 0); +1783 var result; +1784 +1785 result = this.getResponseData(_getTLV(h, a[0])); +1786 +1787 var x = new X509(); +1788 result.alg = x.getAlgorithmIdentifierName(_getTLV(h, a[1])); +1789 +1790 var hSigHex = _getV(h, a[2]); +1791 result.sighex = hSigHex.substr(2); +1792 +1793 var hExt = _getVbyListEx(h, 0, ["[0]"]); +1794 if (hExt != null) { +1795 var aCertIdx = _getChildIdx(hExt, 0); +1796 var aCert = []; +1797 for (var i = 0; i < aCertIdx.length; i++) { +1798 var hCert = _getTLV(hExt, aCertIdx[i]); +1799 aCert.push(hCert); +1800 } +1801 result.certs = aCert; +1802 } +1803 +1804 return result; +1805 }; 1806 -1807 // skip to relax interoperability even though explicit DEFAULT -1808 if (h.substr(a[0], 2) == "a0") idx++; -1809 -1810 result.respid = this.getResponderID(_getTLV(h, a[idx++])); -1811 -1812 var hProdAtV = _getV(h, a[idx++]); -1813 result.prodat = hextoutf8(hProdAtV); -1814 -1815 result.array = this.getSingleResponseList(_getTLV(h, a[idx++])); -1816 -1817 if (h.substr(a[alen - 1], 2) == "a1") { -1818 var hExt = _getTLVbyList(h, a[alen - 1], [0]); -1819 var x = new X509(); -1820 result.ext = x.getExtParamArray(hExt); -1821 } -1822 -1823 return result; -1824 }; -1825 -1826 /** -1827 * parse ASN.1 ResponderID of OCSP<br/> -1828 * @name getResponderID -1829 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1830 * @function -1831 * @param {String} h hexadecimal string of ResponderID -1832 * @return JSON object of ResponderID parameter -1833 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 -1834 * @see KJUR.asn1.ocsp.ResponderID -1835 * -1836 * @description -1837 * <pre> -1838 * ResponderID ::= CHOICE { -1839 * byName [1] Name, -1840 * byKey [2] KeyHash } -1841 * KeyHash ::= OCTET STRING -- SHA-1 hash of responder's public key -1842 * (excluding the tag and length fields) -1843 * </pre> -1844 * -1845 * @example -1846 * o = new KJUR.asn1.ocsp.OCSPParser(); -1847 * o.getResponderID("a1..") → {name: {array: [[{type:"C",value:"JP",ds:"prn"}]...]}} -1848 * o.getResponderID("a2..") → {key: "12ab..."} -1849 */ -1850 this.getResponderID = function(h) { -1851 var result = {}; -1852 -1853 if (h.substr(0, 2) == "a2") { -1854 var hKeyV = _getVbyList(h, 0, [0]); -1855 result.key = hKeyV; -1856 } -1857 if (h.substr(0, 2) == "a1") { -1858 var hName = _getTLVbyList(h, 0, [0]); -1859 var x = new X509(); -1860 result.name = x.getX500Name(hName); -1861 } -1862 -1863 return result; -1864 }; -1865 -1866 /** -1867 * parse ASN.1 SEQUENCE OF SingleResponse of OCSP<br/> -1868 * @name getSingleResponseList -1869 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1870 * @function -1871 * @param {String} h hexadecimal string of SEQUENCE OF SingleResponse -1872 * @return array of SingleResponse parameter JSON object -1873 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 -1874 * -1875 * @description -1876 * This method will parse a hexadecimal string of -1877 * ASN.1 class of SEQUENCE OF SingleResponse is defined in -1878 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. -1879 * <pre> -1880 * ResponseData ::= SEQUENCE { -1881 * version [0] EXPLICIT Version DEFAULT v1, -1882 * responderID ResponderID, -1883 * producedAt GeneralizedTime, -1884 * responses SEQUENCE OF SingleResponse, -1885 * responseExtensions [1] EXPLICIT Extensions OPTIONAL } -1886 * SingleResponse ::= SEQUENCE { -1887 * certID CertID, -1888 * certStatus CertStatus, -1889 * thisUpdate GeneralizedTime, -1890 * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL, -1891 * singleExtensions [1] EXPLICIT Extensions OPTIONAL } -1892 * </pre> -1893 * -1894 * @see KJUR.asn1.ocsp.OCSPParse#getResponseData -1895 * @see KJUR.asn1.ocsp.OCSPParse#getSingleResponse -1896 * @see KJUR.asn1.ocsp.OCSPParse#getCertID -1897 * @see KJUR.asn1.ocsp.SingleResponseList -1898 * -1899 * @example -1900 * o = new KJUR.asn1.ocsp.OCSPParser(); -1901 * o.getSingleResponseList("30..") → -1902 * [{ certid: {alg:"sha1",issname:"12ab",isskey:"12ab",sbjsn:"12ab"}, -1903 * status: {status: "good"}, -1904 * thisupdate: "20200903235959Z", -1905 * nextupdate: "20200913235959Z", -1906 * ext: [<<Extension parameters>>...] }] -1907 */ -1908 this.getSingleResponseList = function(h) { -1909 var a = _getChildIdx(h, 0); -1910 var result = []; -1911 -1912 for (var i = 0; i < a.length; i++) { -1913 var p = this.getSingleResponse(_getTLV(h, a[i])); -1914 result.push(p); -1915 } -1916 return result; -1917 }; -1918 -1919 /** -1920 * parse ASN.1 SingleResponse of OCSP<br/> -1921 * @name getSingleResponse -1922 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1923 * @function -1924 * @param {String} h hexadecimal string of SingleResponse -1925 * @return JSON object of SingleResponse parameter -1926 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 -1927 * -1928 * @description -1929 * This method will parse a hexadecimal string of -1930 * ASN.1 class of SingleResponse is defined in -1931 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.1">RFC 6960 4.2.1</a>. -1932 * <pre> -1933 * SingleResponse ::= SEQUENCE { -1934 * certID CertID, -1935 * certStatus CertStatus, -1936 * thisUpdate GeneralizedTime, -1937 * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL, -1938 * singleExtensions [1] EXPLICIT Extensions OPTIONAL } -1939 * </pre> -1940 * -1941 * @see KJUR.asn1.ocsp.OCSPParse#getSingleResponseList -1942 * @see KJUR.asn1.ocsp.OCSPParse#getCertID -1943 * @see KJUR.asn1.ocsp.SingleResponse -1944 * -1945 * @example -1946 * o = new KJUR.asn1.ocsp.OCSPParser(); -1947 * o.getSingleResponse("30..") → -1948 * { certid: {alg:"sha1",issname:"12ab",isskey:"12ab",sbjsn:"12ab"}, -1949 * status: {status: "good"}, -1950 * thisupdate: "20200903235959Z", -1951 * nextupdate: "20200913235959Z", -1952 * ext: [<<Extension parameters>>...] } -1953 */ -1954 this.getSingleResponse = function(h) { -1955 var a = _getChildIdx(h, 0); -1956 var result = {}; -1957 -1958 // 1. CertID -1959 var pCertID = this.getCertID(_getTLV(h, a[0])); -1960 result.certid = pCertID; -1961 -1962 // 2. CertStatus -1963 var pCertStatus = this.getCertStatus(_getTLV(h, a[1])); -1964 result.status = pCertStatus; -1965 -1966 // 3. ThisUpdate(GeneralizedTime) -1967 if (h.substr(a[2], 2) == "18") { -1968 var hThisUpdateV = _getV(h, a[2]); -1969 result.thisupdate = hextoutf8(hThisUpdateV); -1970 } -1971 -1972 // 4. OPTIONAL(nextUpdate, singleExtensions) -1973 for (var i = 3; i < a.length; i++) { -1974 if (h.substr(a[i], 2) == "a0") { // nextUpdate -1975 var hNextUpdateV = _getVbyList(h, a[i], [0], "18"); -1976 result.nextupdate = hextoutf8(hNextUpdateV); -1977 } -1978 if (h.substr(a[i], 2) == "a1") { // singleExtensions -1979 var x = new X509(); -1980 var hExt = _getTLVbyList(h, 0, [i, 0]); -1981 result.ext = x.getExtParamArray(hExt); -1982 } -1983 } -1984 -1985 return result; -1986 }; -1987 -1988 /** -1989 * parse ASN.1 CertStatus of OCSP<br/> -1990 * @name getCertStatus -1991 * @memberOf KJUR.asn1.ocsp.OCSPParser# -1992 * @function -1993 * @param {String} h hexadecimal string of CertStatus -1994 * @return JSON object of CertStatus parameter -1995 * @since jsrsasign 10.4.0 asn1ocsp 1.1.5 -1996 * @see KJUR.asn1.ocsp.CertStatus -1997 * -1998 * @description -1999 * <pre> -2000 * CertStatus ::= CHOICE { -2001 * good [0] IMPLICIT NULL, -2002 * revoked [1] IMPLICIT RevokedInfo, -2003 * unknown [2] IMPLICIT UnknownInfo } -2004 * RevokedInfo ::= SEQUENCE { -2005 * revocationTime GeneralizedTime, -2006 * revocationReason [0] EXPLICIT CRLReason OPTIONAL } -2007 * UnknownInfo ::= NULL -2008 * </pre> -2009 * NOTE: Currently revocationReason not supported. -2010 * -2011 * @example -2012 * o = new KJUR.asn1.ocsp.OCSPParser(); -2013 * o.getCertStatus("8000") → {status: "good"} -2014 * o.getCertStatus("8200") → {status: "unknown"} -2015 * o.getCertStatus("a1..") → {status: "revoked", time: "2021...Z"} -2016 */ -2017 this.getCertStatus = function(h) { -2018 var result = {}; -2019 if (h == "8000") return {status: "good"}; -2020 if (h == "8200") return {status: "unknown"}; -2021 if (h.substr(0, 2) == "a1") { -2022 result.status = "revoked"; -2023 var hTime = _getVbyList(h, 0, [0]); -2024 var sTime = hextoutf8(hTime); -2025 result.time = sTime; -2026 } -2027 return result; -2028 }; -2029 }; -2030 -2031