diff --git a/ChangeLog.txt b/ChangeLog.txt index 66c7626f..e1602f4c 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,13 @@ ChangeLog for jsrsasign +Time stamp package update +* Changes from 10.5.18 to 10.5.19 (2022-Apr-23) + - src/asn1tsp.js + - TimeStampResp class update to statusinfo member + will be optional. If omitted, it will be "granted" by default. + - API manual update for more detail + Time stamp package update * Changes from 10.5.17 to 10.5.18 (2022-Apr-22) - src/asn1tsp.js diff --git a/README.md b/README.md index 8fc82b99..420454d2 100755 --- a/README.md +++ b/README.md @@ -39,7 +39,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-04-02) +- very popular crypto library with [0.6M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2022-04-20) INSTALL ------- diff --git a/api/files.html b/api/files.html index 38711132..9349d23e 100644 --- a/api/files.html +++ b/api/files.html @@ -643,7 +643,7 @@
var json = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq("302602..."); -// resulted DUMP of above 'json': -{ - messageImprint: { +@@ -1171,6 +1170,12 @@var parser = new KJUR.asn1.tsp.TSPParser(); +parser.getTimeStampReq("302602...") → +{ messageImprint: { alg: 'sha256', // MessageImprint hashAlg hash: 'a1a2a3a4...'}, // MessageImprint hashValue - policy: '1.2.3.4.5', // tsaPolicy (OPTION) - nonce: '9abcf318...', // nonce (OPTION) - certreq: true } // certReq (OPTION)+ policy: '1.2.3.4.5', // tsaPolicy (OPTION) + nonce: '9abcf318...', // nonce (OPTION) + certreq: true } // certReq (OPTION)
-TimeStampResp ::= SEQUENCE { - status PKIStatusInfo, - timeStampToken TimeStampToken OPTIONAL } -
TimeStampResp ::= SEQUENCE { status PKIStatusInfo, timeStampToken TimeStampToken OPTIONAL } + +TimeStampToken ::= ContentInfo + +TSTInfo ::= SEQUENCE { + version INTEGER { v1(1) }, + policy TSAPolicyId, + messageImprint MessageImprint, + serialNumber INTEGER, + genTime GeneralizedTime, + accuracy Accuracy OPTIONAL, + ordering BOOLEAN DEFAULT FALSE, + nonce INTEGER OPTIONAL, + tsa [0] GeneralName OPTIONAL, + extensions [1] IMPLICIT Extensions OPTIONAL }+ +The constructor argument "params" can be used all of +KJUR.asn1.tsp.TimeStampToken object further more +following members can be specified: +
// by TimeStampToken parameters (statusinfo will be "granted" by default) +new KJUR.asn1.tsp.TimeStampResp({ + version: 1, + hashalgs: ["sha256"], + econtent: { + type: "tstinfo", + content: { + policy: "1.2.3.4.5", + messageImprint: {alg:"sha256", hash:"12ab..."}, + serial: {"int": 3}, + genTime: {millis: true}, // current time with millis + accuracy: { millis: 500 } + } + } + certs: [...], + sinfos: [{ + version: 1, + id: {type:"isssn", cert: ...}, + hashalg: "sha256", + sattrs: {array: [{...}]}, + sigalg: "SHA256withRSA", + signkey: ... + }] +}) +// by TimeStampToken object +new KJUR.asn1.tsp.TimeStampResp({ + tst: new KJUR.asn1.tsp.TimeStapToken(...) +}) +// error case +new KJUR.asn1.tsp.TimeStampResp({statusinfo: "rejection"}) +// finally, encode to hexadecimal string +new KJUR.asn1.tsp.TimeStampResp(...).tohex() → "3082..."+ + +
1 /* asn1tsp-2.0.6.js (c) 2014-2022 Kenji Urushima | kjur.github.io/jsrsasign/license +1 /* asn1tsp-2.0.7.js (c) 2014-2022 Kenji Urushima | kjur.github.io/jsrsasign/license 2 */ 3 /* 4 * asn1tsp.js - ASN.1 DER encoder classes for RFC 3161 Time Stamp Protocol @@ -23,7 +23,7 @@ 16 * @fileOverview 17 * @name asn1tsp-1.0.js 18 * @author Kenji Urushima kenji.urushima@gmail.com - 19 * @version jsrsasign 10.5.18 asn1tsp 2.0.6 (2022-Apr-22) + 19 * @version jsrsasign 10.5.19 asn1tsp 2.0.7 (2022-Apr-23) 20 * @since jsrsasign 4.5.1 21 * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a> 22 */ @@ -471,1053 +471,1132 @@ 464 extendClass(KJUR.asn1.tsp.TimeStampReq, KJUR.asn1.ASN1Object); 465 466 /** -467 * class for TSP TimeStampResp ASN.1 object +467 * class for TSP TimeStampResp ASN.1 object<br/> 468 * @name KJUR.asn1.tsp.TimeStampResp 469 * @class class for TSP TimeStampResp ASN.1 object 470 * @param {Array} params associative array of parameters 471 * @extends KJUR.asn1.ASN1Object 472 * @since jsrsasign 4.6.0 asn1tsp 1.0.0 -473 * @description -474 * <pre> -475 * TimeStampResp ::= SEQUENCE { -476 * status PKIStatusInfo, -477 * timeStampToken TimeStampToken OPTIONAL } -478 * </pre> -479 */ -480 KJUR.asn1.tsp.TimeStampResp = function(params) { -481 var _KJUR = KJUR, -482 _KJUR_asn1 = _KJUR.asn1, -483 _DERSequence = _KJUR_asn1.DERSequence, -484 _ASN1Object = _KJUR_asn1.ASN1Object, -485 _KJUR_asn1_tsp = _KJUR_asn1.tsp, -486 _PKIStatusInfo = _KJUR_asn1_tsp.PKIStatusInfo; -487 -488 _KJUR_asn1_tsp.TimeStampResp.superclass.constructor.call(this); -489 -490 this.params = null; -491 -492 this.tohex = function() { -493 var params = this.params; -494 -495 var a = [new _PKIStatusInfo(params.statusinfo)]; -496 -497 if (params.econtent != undefined) { -498 a.push((new _KJUR_asn1_tsp.TimeStampToken(params)).getContentInfo()); -499 } -500 -501 if (params.tst != undefined && -502 params.tst instanceof _KJUR_asn1.ASN1Object) { -503 a.push(params.tst); -504 } -505 -506 var seq = new _DERSequence({array: a}); -507 return seq.tohex(); -508 }; -509 this.getEncodedHex = function() { return this.tohex(); }; -510 -511 if (params != undefined) this.setByParam(params); -512 }; -513 extendClass(KJUR.asn1.tsp.TimeStampResp, KJUR.asn1.ASN1Object); -514 -515 // --- BEGIN OF RFC 2510 CMP ----------------------------------------------- -516 -517 /** -518 * class for TSP PKIStatusInfo ASN.1 object -519 * @name KJUR.asn1.tsp.PKIStatusInfo -520 * @class class for TSP PKIStatusInfo ASN.1 object -521 * @param {Array} params associative array of parameters -522 * @extends KJUR.asn1.ASN1Object -523 * @since jsrsasign 4.6.0 asn1tsp 1.0.0 -524 * @see KJUR.asn1.tsp.PKIStatus -525 * @see KJUR.asn1.tsp.PKIFreeText -526 * @see KJUR.asn1.tsp.PKIFailureInfo -527 * @see KJUR.asn1.tsp.TSPParser#getPKIStatusInfo -528 * -529 * @description -530 * This class provides ASN.1 PKIStatusInfo encoder -531 * defined in -532 * <a href="https://tools.ietf.org/html/rfc3161#section-2.4.2"> -533 * RFC 3161 section 2.4.2</a>. -534 * <pre> -535 * PKIStatusInfo ::= SEQUENCE { -536 * status PKIStatus, -537 * statusString PKIFreeText OPTIONAL, -538 * failInfo PKIFailureInfo OPTIONAL } -539 * </pre> -540 * -541 * @example -542 * new KJUR.asn1.tsp.PKIStatusInfo("granted") -543 * new KJUR.asn1.tsp.PKIStatusInfo({status: "granted"}) -544 * new KJUR.asn1.tsp.PKIStatusInfo({ -545 * status: 2, // rejection -546 * statusstr: ["unsupported algorithm"], // OPTION -547 * failinfo: 'badAlg' // OPTION -548 * }) -549 */ -550 KJUR.asn1.tsp.PKIStatusInfo = function(params) { -551 var _Error = Error, -552 _KJUR = KJUR, -553 _KJUR_asn1 = _KJUR.asn1, -554 _DERSequence = _KJUR_asn1.DERSequence, -555 _KJUR_asn1_tsp = _KJUR_asn1.tsp, -556 _PKIStatus = _KJUR_asn1_tsp.PKIStatus, -557 _PKIFreeText = _KJUR_asn1_tsp.PKIFreeText, -558 _PKIFailureInfo = _KJUR_asn1_tsp.PKIFailureInfo; -559 -560 _KJUR_asn1_tsp.PKIStatusInfo.superclass.constructor.call(this); -561 -562 this.params = null; -563 -564 this.tohex = function() { -565 var params = this.params; -566 -567 var a = []; -568 if (typeof params == "string") { -569 a.push(new _PKIStatus(params)); -570 } else { -571 if (params.status == undefined) -572 throw new _Error("property 'status' unspecified"); -573 -574 a.push(new _PKIStatus(params.status)); -575 -576 if (params.statusstr != undefined) -577 a.push(new _PKIFreeText(params.statusstr)); -578 -579 if (params.failinfo != undefined) -580 a.push(new _PKIFailureInfo(params.failinfo)); -581 } -582 -583 var seq = new _DERSequence({array: a}); -584 return seq.tohex(); -585 }; -586 this.getEncodedHex = function() { return this.tohex(); }; -587 -588 if (params != undefined) this.setByParam(params); -589 }; -590 extendClass(KJUR.asn1.tsp.PKIStatusInfo, KJUR.asn1.ASN1Object); -591 -592 /** -593 * class for TSP PKIStatus ASN.1 object -594 * @name KJUR.asn1.tsp.PKIStatus -595 * @class class for TSP PKIStatus ASN.1 object -596 * @param {Array} params associative array of parameters -597 * @extends KJUR.asn1.ASN1Object -598 * @since jsrsasign 4.6.0 asn1tsp 1.0.0 -599 * @description -600 * <pre> -601 * PKIStatus ::= INTEGER { -602 * granted (0), -603 * grantedWithMods (1), -604 * rejection (2), -605 * waiting (3), -606 * revocationWarning (4), -607 * revocationNotification (5) } -608 * </pre> -609 * -610 * @example -611 * new KJUR.asn1.tsp.PKIStatus('granted') -612 * new KJUR.asn1.tsp.PKIStatus(2) -613 */ -614 KJUR.asn1.tsp.PKIStatus = function(params) { -615 var _Error = Error, -616 _KJUR = KJUR, -617 _KJUR_asn1 = _KJUR.asn1, -618 _DERInteger = _KJUR_asn1.DERInteger, -619 _KJUR_asn1_tsp = _KJUR_asn1.tsp; -620 -621 _KJUR_asn1_tsp.PKIStatus.superclass.constructor.call(this); -622 -623 var _nameValue = { -624 granted: 0, -625 grantedWithMods: 1, -626 rejection: 2, -627 waiting: 3, -628 revocationWarning: 4, -629 revocationNotification: 5 -630 }; -631 -632 this.params = null; -633 -634 this.tohex = function() { -635 var params = this.params; -636 -637 var dObj, value; +473 * @see KJUR.asn1.tsp.TimeStampToken +474 * @see KJUR.asn1.tsp.PKIStatusInfo +475 * +476 * @description +477 * This is an ASN.1 encoder for TimeStampResp +478 * ASN.1 structure defined in +479 * <a href="https://tools.ietf.org/html/rfc3161#section-2.4.2"> +480 * RFC 3161 TSP section 2.4.2</a>. +481 * +482 * <pre> +483 * TimeStampResp ::= SEQUENCE { +484 * status PKIStatusInfo, +485 * timeStampToken TimeStampToken OPTIONAL } +486 * +487 * TimeStampToken ::= ContentInfo +488 * +489 * TSTInfo ::= SEQUENCE { +490 * version INTEGER { v1(1) }, +491 * policy TSAPolicyId, +492 * messageImprint MessageImprint, +493 * serialNumber INTEGER, +494 * genTime GeneralizedTime, +495 * accuracy Accuracy OPTIONAL, +496 * ordering BOOLEAN DEFAULT FALSE, +497 * nonce INTEGER OPTIONAL, +498 * tsa [0] GeneralName OPTIONAL, +499 * extensions [1] IMPLICIT Extensions OPTIONAL } +500 * </pre> +501 * +502 * The constructor argument "params" can be used all of +503 * {@link KJUR.asn1.tsp.TimeStampToken} object further more +504 * following members can be specified: +505 * <ul> +506 * <li>statusinfo: any {@link KJUR.asn1.tsp.PKIStatusInfo} parameter. +507 * When parameters for TimeStampToken is specified and statusinfo member is omitted, +508 * status will be "granted" by default. (OPTIONAL)</li> +509 * <li>tst: {@link KJUR.asn1.tsp.TimeStampToken} object instead of TimeStampToken members (OPTIONAL)</li> +510 * </ul> +511 * +512 * @example +513 * // by TimeStampToken parameters (statusinfo will be "granted" by default) +514 * new KJUR.asn1.tsp.TimeStampResp({ +515 * version: 1, +516 * hashalgs: ["sha256"], +517 * econtent: { +518 * type: "tstinfo", +519 * content: { +520 * policy: "1.2.3.4.5", +521 * messageImprint: {alg:"sha256", hash:"12ab..."}, +522 * serial: {"int": 3}, +523 * genTime: {millis: true}, // current time with millis +524 * accuracy: { millis: 500 } +525 * } +526 * } +527 * certs: [...], +528 * sinfos: [{ +529 * version: 1, +530 * id: {type:"isssn", cert: ...}, +531 * hashalg: "sha256", +532 * sattrs: {array: [{...}]}, +533 * sigalg: "SHA256withRSA", +534 * signkey: ... +535 * }] +536 * }) +537 * // by TimeStampToken object +538 * new KJUR.asn1.tsp.TimeStampResp({ +539 * tst: new KJUR.asn1.tsp.TimeStapToken(...) +540 * }) +541 * // error case +542 * new KJUR.asn1.tsp.TimeStampResp({statusinfo: "rejection"}) +543 * // finally, encode to hexadecimal string +544 * new KJUR.asn1.tsp.TimeStampResp(...).tohex() → "3082..." +545 */ +546 KJUR.asn1.tsp.TimeStampResp = function(params) { +547 var _KJUR = KJUR, +548 _KJUR_asn1 = _KJUR.asn1, +549 _DERSequence = _KJUR_asn1.DERSequence, +550 _ASN1Object = _KJUR_asn1.ASN1Object, +551 _KJUR_asn1_tsp = _KJUR_asn1.tsp, +552 _PKIStatusInfo = _KJUR_asn1_tsp.PKIStatusInfo; +553 +554 _KJUR_asn1_tsp.TimeStampResp.superclass.constructor.call(this); +555 +556 this.params = null; +557 +558 this.tohex = function() { +559 var params = this.params; +560 +561 var a = []; +562 +563 if (params.econtent != undefined || params.tst != undefined) { +564 // statusInfo +565 if (params.statusinfo != undefined) { +566 a.push(new _PKIStatusInfo(params.statusinfo)); +567 } else { +568 a.push(new _PKIStatusInfo("granted")); +569 } +570 +571 // TimeStampToken +572 if (params.econtent != undefined) { +573 a.push((new _KJUR_asn1_tsp.TimeStampToken(params)).getContentInfo()); +574 } else if (params.tst instanceof _KJUR_asn1.ASN1Object) { +575 a.push(params.tst); +576 } else { +577 throw new Error("improper member tst value"); +578 } +579 } else if (params.statusinfo != undefined) { +580 a.push(new _PKIStatusInfo(params.statusinfo)); +581 } else { +582 throw new Error("parameter for token nor statusinfo not specified"); +583 } +584 +585 var seq = new _DERSequence({array: a}); +586 return seq.tohex(); +587 }; +588 this.getEncodedHex = function() { return this.tohex(); }; +589 +590 if (params != undefined) this.setByParam(params); +591 }; +592 extendClass(KJUR.asn1.tsp.TimeStampResp, KJUR.asn1.ASN1Object); +593 +594 // --- BEGIN OF RFC 2510 CMP ----------------------------------------------- +595 +596 /** +597 * class for TSP PKIStatusInfo ASN.1 object +598 * @name KJUR.asn1.tsp.PKIStatusInfo +599 * @class class for TSP PKIStatusInfo ASN.1 object +600 * @param {Array} params associative array of parameters +601 * @extends KJUR.asn1.ASN1Object +602 * @since jsrsasign 4.6.0 asn1tsp 1.0.0 +603 * @see KJUR.asn1.tsp.PKIStatus +604 * @see KJUR.asn1.tsp.PKIFreeText +605 * @see KJUR.asn1.tsp.PKIFailureInfo +606 * @see KJUR.asn1.tsp.TSPParser#getPKIStatusInfo +607 * +608 * @description +609 * This class provides ASN.1 PKIStatusInfo encoder +610 * defined in +611 * <a href="https://tools.ietf.org/html/rfc3161#section-2.4.2"> +612 * RFC 3161 section 2.4.2</a>. +613 * <pre> +614 * PKIStatusInfo ::= SEQUENCE { +615 * status PKIStatus, +616 * statusString PKIFreeText OPTIONAL, +617 * failInfo PKIFailureInfo OPTIONAL } +618 * </pre> +619 * +620 * @example +621 * new KJUR.asn1.tsp.PKIStatusInfo("granted") +622 * new KJUR.asn1.tsp.PKIStatusInfo({status: "granted"}) +623 * new KJUR.asn1.tsp.PKIStatusInfo({ +624 * status: 2, // rejection +625 * statusstr: ["unsupported algorithm"], // OPTION +626 * failinfo: 'badAlg' // OPTION +627 * }) +628 */ +629 KJUR.asn1.tsp.PKIStatusInfo = function(params) { +630 var _Error = Error, +631 _KJUR = KJUR, +632 _KJUR_asn1 = _KJUR.asn1, +633 _DERSequence = _KJUR_asn1.DERSequence, +634 _KJUR_asn1_tsp = _KJUR_asn1.tsp, +635 _PKIStatus = _KJUR_asn1_tsp.PKIStatus, +636 _PKIFreeText = _KJUR_asn1_tsp.PKIFreeText, +637 _PKIFailureInfo = _KJUR_asn1_tsp.PKIFailureInfo; 638 -639 if (typeof params == "string") { -640 try { -641 value = _nameValue[params]; -642 } catch (ex) { -643 throw new _Error("undefined name: " + params); -644 } -645 } else if (typeof params == "number") { -646 value = params; -647 } else { -648 throw new _Error("unsupported params"); -649 } -650 -651 return (new _DERInteger({"int": value})).tohex(); -652 }; -653 this.getEncodedHex = function() { return this.tohex(); }; +639 _KJUR_asn1_tsp.PKIStatusInfo.superclass.constructor.call(this); +640 +641 this.params = null; +642 +643 this.tohex = function() { +644 var params = this.params; +645 +646 var a = []; +647 if (typeof params == "string") { +648 a.push(new _PKIStatus(params)); +649 } else { +650 if (params.status == undefined) +651 throw new _Error("property 'status' unspecified"); +652 +653 a.push(new _PKIStatus(params.status)); 654 -655 if (params != undefined) this.setByParam(params); -656 }; -657 extendClass(KJUR.asn1.tsp.PKIStatus, KJUR.asn1.ASN1Object); -658 -659 /** -660 * class for TSP PKIFreeText ASN.1 object -661 * @name KJUR.asn1.tsp.PKIFreeText -662 * @class class for TSP PKIFreeText ASN.1 object -663 * @param {Array} params associative array of parameters -664 * @extends KJUR.asn1.ASN1Object -665 * @since jsrsasign 4.6.0 asn1tsp 1.0.0 -666 * @description -667 * This class provides ASN.1 encoder for PKIFreeText -668 * defined in <a href="https://tools.ietf.org/html/rfc4210#section-5.1.1"> -669 * RFC 4210 CMP section 5.1.1</a>. -670 * <pre> -671 * PKIFreeText ::= SEQUENCE { SIZE (1..MAX) OF UTF8String } -672 * </pre> -673 * -674 * @example -675 * new KJUR.asn1.tsp.PKIFreeText([ -676 * "aaa", "bbb", "ccc" -677 * ]) -678 */ -679 KJUR.asn1.tsp.PKIFreeText = function(params) { -680 var _Error = Error, -681 _KJUR = KJUR, -682 _KJUR_asn1 = _KJUR.asn1, -683 _DERSequence = _KJUR_asn1.DERSequence, -684 _DERUTF8String = _KJUR_asn1.DERUTF8String, -685 _KJUR_asn1_tsp = _KJUR_asn1.tsp; -686 -687 _KJUR_asn1_tsp.PKIFreeText.superclass.constructor.call(this); -688 -689 this.params = null; -690 -691 this.tohex = function() { -692 var params = this.params; -693 -694 if (! params instanceof Array) -695 throw new _Error("wrong params: not array"); -696 -697 var a = []; -698 for (var i = 0; i < params.length; i++) { -699 a.push(new _DERUTF8String({str: params[i]})); -700 }; -701 -702 var seq = new _DERSequence({array: a}); -703 return seq.tohex(); -704 }; -705 this.getEncodedHex = function() { return this.tohex(); }; -706 -707 if (params != undefined) this.setByParam(params); -708 }; -709 extendClass(KJUR.asn1.tsp.PKIFreeText, KJUR.asn1.ASN1Object); +655 if (params.statusstr != undefined) +656 a.push(new _PKIFreeText(params.statusstr)); +657 +658 if (params.failinfo != undefined) +659 a.push(new _PKIFailureInfo(params.failinfo)); +660 } +661 +662 var seq = new _DERSequence({array: a}); +663 return seq.tohex(); +664 }; +665 this.getEncodedHex = function() { return this.tohex(); }; +666 +667 if (params != undefined) this.setByParam(params); +668 }; +669 extendClass(KJUR.asn1.tsp.PKIStatusInfo, KJUR.asn1.ASN1Object); +670 +671 /** +672 * class for TSP PKIStatus ASN.1 object +673 * @name KJUR.asn1.tsp.PKIStatus +674 * @class class for TSP PKIStatus ASN.1 object +675 * @param {Array} params associative array of parameters +676 * @extends KJUR.asn1.ASN1Object +677 * @since jsrsasign 4.6.0 asn1tsp 1.0.0 +678 * @description +679 * <pre> +680 * PKIStatus ::= INTEGER { +681 * granted (0), +682 * grantedWithMods (1), +683 * rejection (2), +684 * waiting (3), +685 * revocationWarning (4), +686 * revocationNotification (5) } +687 * </pre> +688 * +689 * @example +690 * new KJUR.asn1.tsp.PKIStatus('granted') +691 * new KJUR.asn1.tsp.PKIStatus(2) +692 */ +693 KJUR.asn1.tsp.PKIStatus = function(params) { +694 var _Error = Error, +695 _KJUR = KJUR, +696 _KJUR_asn1 = _KJUR.asn1, +697 _DERInteger = _KJUR_asn1.DERInteger, +698 _KJUR_asn1_tsp = _KJUR_asn1.tsp; +699 +700 _KJUR_asn1_tsp.PKIStatus.superclass.constructor.call(this); +701 +702 var _nameValue = { +703 granted: 0, +704 grantedWithMods: 1, +705 rejection: 2, +706 waiting: 3, +707 revocationWarning: 4, +708 revocationNotification: 5 +709 }; 710 -711 /** -712 * class for TSP PKIFailureInfo ASN.1 object -713 * @name KJUR.asn1.tsp.PKIFailureInfo -714 * @class class for TSP PKIFailureInfo ASN.1 object -715 * @param {Array} params associative array of parameters -716 * @extends KJUR.asn1.ASN1Object -717 * @since jsrsasign 4.6.0 asn1tsp 1.0.0 -718 * @description -719 * <pre> -720 * PKIFailureInfo ::= BIT STRING { -721 * badAlg (0), -722 * badRequest (2), -723 * badDataFormat (5), -724 * timeNotAvailable (14), -725 * unacceptedPolicy (15), -726 * unacceptedExtension (16), -727 * addInfoNotAvailable (17), -728 * systemFailure (25) } -729 * </pre> -730 * -731 * @example -732 * new KJUR.asn1.tsp.PKIFailureInfo('badAlg') -733 * new KJUR.asn1.tsp.PKIFailureInfo(5) -734 */ -735 KJUR.asn1.tsp.PKIFailureInfo = function(params) { -736 var _Error = Error, -737 _KJUR = KJUR, -738 _KJUR_asn1 = _KJUR.asn1, -739 _DERBitString = _KJUR_asn1.DERBitString, -740 _KJUR_asn1_tsp = _KJUR_asn1.tsp, -741 _PKIFailureInfo = _KJUR_asn1_tsp.PKIFailureInfo; -742 -743 var _nameValue = { -744 badAlg: 0, -745 badRequest: 2, -746 badDataFormat: 5, -747 timeNotAvailable: 14, -748 unacceptedPolicy: 15, -749 unacceptedExtension: 16, -750 addInfoNotAvailable: 17, -751 systemFailure: 25 -752 }; -753 -754 _PKIFailureInfo.superclass.constructor.call(this); -755 -756 this.params = null; -757 -758 this.tohex = function() { -759 var params = this.params; -760 -761 var value; -762 if (typeof params == "string") { -763 try { -764 value = _nameValue[params]; -765 } catch(ex) { -766 throw new _Error("undefined name: " + params); -767 } -768 } else if (typeof params == "number") { -769 value = params; -770 } else { -771 throw new _Error("wrong params"); -772 } -773 return (new _DERBitString({"bin": value.toString(2)})).tohex(); -774 }; -775 this.getEncodedHex = function() { return this.tohex(); }; -776 -777 if (params != undefined) this.setByParam(params); -778 }; -779 extendClass(KJUR.asn1.tsp.PKIFailureInfo, KJUR.asn1.ASN1Object); -780 -781 // --- END OF RFC 2510 CMP ------------------------------------------- -782 -783 /** -784 * abstract class for TimeStampToken generator (DEPRECATED)<br/> -785 * @name KJUR.asn1.tsp.AbstractTSAAdapter -786 * @class abstract class for TimeStampToken generator -787 * @param {Array} params associative array of parameters -788 * @since jsrsasign 4.7.0 asn1tsp 1.0.1 -789 * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0 -790 * -791 * @description -792 * This is abstract class for TimeStampToken generator. -793 */ -794 KJUR.asn1.tsp.AbstractTSAAdapter = function(params) { -795 this.getTSTHex = function(msgHex, hashAlg) { -796 throw "not implemented yet"; -797 }; -798 }; -799 -800 /** -801 * class for simple TimeStampToken generator (DEPRECATED)<br/> -802 * @name KJUR.asn1.tsp.SimpleTSAAdapter -803 * @class class for simple TimeStampToken generator -804 * @extends KJUR.asn1.tsp.AbstractTSAAdapter -805 * @param {Array} params associative array of parameters -806 * @since jsrsasign 4.7.0 asn1tsp 1.0.1 -807 * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0 -808 * -809 * @description -810 * This is a simple TimeStampToken generator class. -811 */ -812 KJUR.asn1.tsp.SimpleTSAAdapter = function(params) { -813 var _KJUR = KJUR, -814 _KJUR_asn1 = _KJUR.asn1, -815 _KJUR_asn1_tsp = _KJUR_asn1.tsp, -816 _hashHex = _KJUR.crypto.Util.hashHex; -817 -818 _KJUR_asn1_tsp.SimpleTSAAdapter.superclass.constructor.call(this); -819 this.params = null; -820 this.serial = 0; +711 this.params = null; +712 +713 this.tohex = function() { +714 var params = this.params; +715 +716 var dObj, value; +717 +718 if (typeof params == "string") { +719 try { +720 value = _nameValue[params]; +721 } catch (ex) { +722 throw new _Error("undefined name: " + params); +723 } +724 } else if (typeof params == "number") { +725 value = params; +726 } else { +727 throw new _Error("unsupported params"); +728 } +729 +730 return (new _DERInteger({"int": value})).tohex(); +731 }; +732 this.getEncodedHex = function() { return this.tohex(); }; +733 +734 if (params != undefined) this.setByParam(params); +735 }; +736 extendClass(KJUR.asn1.tsp.PKIStatus, KJUR.asn1.ASN1Object); +737 +738 /** +739 * class for TSP PKIFreeText ASN.1 object +740 * @name KJUR.asn1.tsp.PKIFreeText +741 * @class class for TSP PKIFreeText ASN.1 object +742 * @param {Array} params associative array of parameters +743 * @extends KJUR.asn1.ASN1Object +744 * @since jsrsasign 4.6.0 asn1tsp 1.0.0 +745 * @description +746 * This class provides ASN.1 encoder for PKIFreeText +747 * defined in <a href="https://tools.ietf.org/html/rfc4210#section-5.1.1"> +748 * RFC 4210 CMP section 5.1.1</a>. +749 * <pre> +750 * PKIFreeText ::= SEQUENCE { SIZE (1..MAX) OF UTF8String } +751 * </pre> +752 * +753 * @example +754 * new KJUR.asn1.tsp.PKIFreeText([ +755 * "aaa", "bbb", "ccc" +756 * ]) +757 */ +758 KJUR.asn1.tsp.PKIFreeText = function(params) { +759 var _Error = Error, +760 _KJUR = KJUR, +761 _KJUR_asn1 = _KJUR.asn1, +762 _DERSequence = _KJUR_asn1.DERSequence, +763 _DERUTF8String = _KJUR_asn1.DERUTF8String, +764 _KJUR_asn1_tsp = _KJUR_asn1.tsp; +765 +766 _KJUR_asn1_tsp.PKIFreeText.superclass.constructor.call(this); +767 +768 this.params = null; +769 +770 this.tohex = function() { +771 var params = this.params; +772 +773 if (! params instanceof Array) +774 throw new _Error("wrong params: not array"); +775 +776 var a = []; +777 for (var i = 0; i < params.length; i++) { +778 a.push(new _DERUTF8String({str: params[i]})); +779 }; +780 +781 var seq = new _DERSequence({array: a}); +782 return seq.tohex(); +783 }; +784 this.getEncodedHex = function() { return this.tohex(); }; +785 +786 if (params != undefined) this.setByParam(params); +787 }; +788 extendClass(KJUR.asn1.tsp.PKIFreeText, KJUR.asn1.ASN1Object); +789 +790 /** +791 * class for TSP PKIFailureInfo ASN.1 object +792 * @name KJUR.asn1.tsp.PKIFailureInfo +793 * @class class for TSP PKIFailureInfo ASN.1 object +794 * @param {Array} params associative array of parameters +795 * @extends KJUR.asn1.ASN1Object +796 * @since jsrsasign 4.6.0 asn1tsp 1.0.0 +797 * @description +798 * <pre> +799 * PKIFailureInfo ::= BIT STRING { +800 * badAlg (0), +801 * badRequest (2), +802 * badDataFormat (5), +803 * timeNotAvailable (14), +804 * unacceptedPolicy (15), +805 * unacceptedExtension (16), +806 * addInfoNotAvailable (17), +807 * systemFailure (25) } +808 * </pre> +809 * +810 * @example +811 * new KJUR.asn1.tsp.PKIFailureInfo('badAlg') +812 * new KJUR.asn1.tsp.PKIFailureInfo(5) +813 */ +814 KJUR.asn1.tsp.PKIFailureInfo = function(params) { +815 var _Error = Error, +816 _KJUR = KJUR, +817 _KJUR_asn1 = _KJUR.asn1, +818 _DERBitString = _KJUR_asn1.DERBitString, +819 _KJUR_asn1_tsp = _KJUR_asn1.tsp, +820 _PKIFailureInfo = _KJUR_asn1_tsp.PKIFailureInfo; 821 -822 this.getTSTHex = function(msgHex, hashAlg) { -823 // messageImprint -824 var hashHex = _hashHex(msgHex, hashAlg); -825 this.params.econtent.content.messageImprint = -826 {alg: hashAlg, hash: hashHex}; -827 -828 // serial -829 this.params.econtent.content.serial = -830 {'int': this.serial++}; -831 -832 // nonce -833 var nonceValue = Math.floor(Math.random() * 1000000000); -834 this.params.econtent.content.nonce = -835 {'int': nonceValue}; +822 var _nameValue = { +823 badAlg: 0, +824 badRequest: 2, +825 badDataFormat: 5, +826 timeNotAvailable: 14, +827 unacceptedPolicy: 15, +828 unacceptedExtension: 16, +829 addInfoNotAvailable: 17, +830 systemFailure: 25 +831 }; +832 +833 _PKIFailureInfo.superclass.constructor.call(this); +834 +835 this.params = null; 836 -837 var obj = -838 new _KJUR_asn1_tsp.TimeStampToken(this.params); -839 return obj.getContentInfoEncodedHex(); -840 }; -841 -842 if (params !== undefined) this.params = params; -843 }; -844 extendClass(KJUR.asn1.tsp.SimpleTSAAdapter, -845 KJUR.asn1.tsp.AbstractTSAAdapter); -846 -847 /** -848 * class for fixed TimeStampToken generator (DEPRECATED)<br/> -849 * @name KJUR.asn1.tsp.FixedTSAAdapter -850 * @class class for fixed TimeStampToken generator -851 * @extends KJUR.asn1.tsp.AbstractTSAAdapter -852 * @param {Array} params associative array of parameters -853 * @since jsrsasign 4.7.0 asn1tsp 1.0.1 -854 * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0 -855 * -856 * @description -857 * This class generates fixed TimeStampToken except messageImprint -858 * for testing purpose. -859 * General TSA generates TimeStampToken which varies following -860 * fields: -861 * <ul> -862 * <li>genTime</li> -863 * <li>serialNumber</li> -864 * <li>nonce</li> -865 * </ul> -866 * Those values are provided by initial parameters. -867 */ -868 KJUR.asn1.tsp.FixedTSAAdapter = function(params) { -869 var _KJUR = KJUR, -870 _KJUR_asn1 = _KJUR.asn1, -871 _KJUR_asn1_tsp = _KJUR_asn1.tsp, -872 _hashHex = _KJUR.crypto.Util.hashHex; -873 -874 _KJUR_asn1_tsp.FixedTSAAdapter.superclass.constructor.call(this); -875 this.params = null; -876 -877 this.getTSTHex = function(msgHex, hashAlg) { -878 // fixed serialNumber -879 // fixed nonce -880 var hashHex = _hashHex(msgHex, hashAlg); -881 this.params.econtent.content.messageImprint = -882 {alg: hashAlg, hash: hashHex}; -883 var obj = new _KJUR_asn1_tsp.TimeStampToken(this.params); -884 return obj.getContentInfoEncodedHex(); -885 }; -886 -887 if (params !== undefined) this.params = params; -888 }; -889 extendClass(KJUR.asn1.tsp.FixedTSAAdapter, -890 KJUR.asn1.tsp.AbstractTSAAdapter); -891 -892 // --- TSP utilities ------------------------------------------------- -893 -894 /** -895 * TSP utiliteis class -896 * @name KJUR.asn1.tsp.TSPUtil -897 * @class TSP utilities class -898 */ -899 KJUR.asn1.tsp.TSPUtil = new function() { -900 }; -901 /** -902 * generate TimeStampToken ASN.1 object specified by JSON parameters (DEPRECATED)<br/> -903 * @name newTimeStampToken -904 * @memberOf KJUR.asn1.tsp.TSPUtil -905 * @function -906 * @param {Array} param JSON parameter to generate TimeStampToken -907 * @return {KJUR.asn1.cms.SignedData} object just generated -908 * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0. Please use TimeStampToken class -909 * @see KJUR.asn1.tsp.TimeStampToken -910 * -911 * @description -912 * @example -913 */ -914 KJUR.asn1.tsp.TSPUtil.newTimeStampToken = function(params) { -915 return new KJUR.asn1.tsp.TimeStampToken(params); -916 }; -917 -918 /** -919 * parse hexadecimal string of TimeStampReq -920 * @name parseTimeStampReq -921 * @memberOf KJUR.asn1.tsp.TSPUtil -922 * @function -923 * @param {String} hexadecimal string of TimeStampReq -924 * @return {Array} JSON object of parsed parameters -925 * @see KJUR.asn1.tsp.TSPParser#getTimeStampReq -926 * @deprecated since jsrsasign 10.5.18 asn1tsp 2.0.6. Please use TSPParser.getTimeStampReq instead. -927 * -928 * @description -929 * This method parses a hexadecimal string of TimeStampReq -930 * and returns parsed their fields: -931 * -932 * @example -933 * var json = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq("302602..."); -934 * // resulted DUMP of above 'json': -935 * { -936 * messageImprint: { -937 * alg: 'sha256', // MessageImprint hashAlg -938 * hash: 'a1a2a3a4...'}, // MessageImprint hashValue -939 * policy: '1.2.3.4.5', // tsaPolicy (OPTION) -940 * nonce: '9abcf318...', // nonce (OPTION) -941 * certreq: true} // certReq (OPTION) -942 */ -943 KJUR.asn1.tsp.TSPUtil.parseTimeStampReq = function(reqHex) { -944 var parser = new KJUR.asn1.tsp.TSPParser(); -945 return parser.getTimeStampReq(reqHex); -946 }; -947 -948 /** -949 * parse hexadecimal string of MessageImprint -950 * @name parseMessageImprint -951 * @memberOf KJUR.asn1.tsp.TSPUtil -952 * @function -953 * @param {String} hexadecimal string of MessageImprint -954 * @return {Array} JSON object of parsed parameters -955 * @see KJUR.asn1.tsp.TSPParser#getMessageImprint -956 * @deprecated since jsrsasign 10.5.18 asn1tsp 2.0.6. Please use TSPParser.getMessageImprint instead. -957 * -958 * @description -959 * This method parses a hexadecimal string of MessageImprint -960 * and returns parsed their fields: -961 * -962 * @example -963 * KJUR.asn1.tsp.TSPUtil.parseMessageImprint("302602...") → -964 * { alg: 'sha256', hash: 'a1a2a3a4...'} -965 */ -966 KJUR.asn1.tsp.TSPUtil.parseMessageImprint = function(miHex) { -967 var parser = new KJUR.asn1.tsp.TSPParser(); -968 return parser.getMessageImprint(miHex); -969 /* -970 var _ASN1HEX = ASN1HEX; -971 var _getChildIdx = _ASN1HEX.getChildIdx; -972 var _getV = _ASN1HEX.getV; -973 var _getIdxbyList = _ASN1HEX.getIdxbyList; -974 var json = {}; -975 -976 if (miHex.substr(0, 2) != "30") -977 throw "head of messageImprint hex shall be '30'"; -978 -979 var idxList = _getChildIdx(miHex, 0); -980 var hashAlgOidIdx = _getIdxbyList(miHex, 0, [0, 0]); -981 var hashAlgHex = _getV(miHex, hashAlgOidIdx); -982 var hashAlgOid = _ASN1HEX.hextooidstr(hashAlgHex); -983 var hashAlgName = KJUR.asn1.x509.OID.oid2name(hashAlgOid); -984 if (hashAlgName == '') -985 throw "hashAlg name undefined: " + hashAlgOid; -986 var hashAlg = hashAlgName; -987 var hashValueIdx = _getIdxbyList(miHex, 0, [1]); -988 -989 json.alg = hashAlg; -990 json.hash = _getV(miHex, hashValueIdx); -991 -992 return json; -993 */ -994 }; -995 -996 /** -997 * class for parsing RFC 3161 TimeStamp protocol data<br/> -998 * @name KJUR.asn1.tsp.TSPParser -999 * @class RFC 3161 TimeStamp protocol parser class -1000 * @since jsrsasign 10.1.0 asn1tsp 2.0.1 -1001 * -1002 * @description -1003 * This is an ASN.1 parser for -1004 * <a href="https://tools.ietf.org/html/rfc3161">RFC 3161</a>. -1005 */ -1006 KJUR.asn1.tsp.TSPParser = function() { -1007 var _Error = Error, -1008 _X509 = X509, -1009 _x509obj = new _X509(), -1010 _ASN1HEX = ASN1HEX, -1011 _getV = _ASN1HEX.getV, -1012 _getTLV = _ASN1HEX.getTLV, -1013 _getIdxbyList = _ASN1HEX.getIdxbyList, -1014 _getTLVbyListEx = _ASN1HEX.getTLVbyListEx, -1015 _getChildIdx = _ASN1HEX.getChildIdx; -1016 var _aSTATUSSTR = [ -1017 "granted", "grantedWithMods", "rejection", "waiting", -1018 "revocationWarning", "revocationNotification" ]; -1019 var _pFAILUREINFO = { -1020 0: "badAlg", 2: "badRequest", 5: "badDataFormat", -1021 14: "timeNotAvailable", 15: "unacceptedPolicy", -1022 16: "unacceptedExtension", 17: "addInfoNotAvailable", -1023 25: "systemFailure" -1024 }; -1025 -1026 /** -1027 * parse ASN.1 TimeStampResp<br/> -1028 * @name getResponse -1029 * @memberOf KJUR.asn1.tsp.TSPParser# -1030 * @function -1031 * @param {String} h hexadecimal string of ASN.1 TimeStampResp -1032 * @return {Array} JSON object of TimeStampResp parameter -1033 * @see KJUR.asn1.tsp.TimeStampResp -1034 * @see KJUR.asn1.tsp.TimeStampToken -1035 * @see KJUR.asn1.cms.CMSParser#getCMSSignedData -1036 * -1037 * @description -1038 * This method parses ASN.1 TimeStampRsp defined in RFC 3161. -1039 * <pre> -1040 * TimeStampResp ::= SEQUENCE { -1041 * status PKIStatusInfo, -1042 * timeStampToken TimeStampToken OPTIONAL } -1043 * </pre> -1044 * When "h" is a TSP error response, -1045 * returned parameter contains "statusinfo" only. -1046 * -1047 * @example -1048 * parser = new KJUR.asn1.tsp.TSPParser(); -1049 * parser.getResponse("30...") → -1050 * { -1051 * statusinfo: 'granted', -1052 * ... // almost the same as CMS SignedData parameters -1053 * econtent: { -1054 * type: "tstinfo", -1055 * content: { // TSTInfo parameter -1056 * policy: '1.2.3.4.5', -1057 * messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'}, -1058 * serial: {'int': 3}, -1059 * genTime: {str: '20131231235959.123Z'}, -1060 * accuracy: {millis: 500}, -1061 * ordering: true, -1062 * nonce: {int: 3} -1063 * } -1064 * }, -1065 * ... -1066 * } -1067 */ -1068 this.getResponse = function(h) { -1069 var aIdx = _getChildIdx(h, 0); -1070 -1071 if (aIdx.length == 1) { -1072 return this.getPKIStatusInfo(_getTLV(h, aIdx[0])); -1073 } else if (aIdx.length > 1) { -1074 var pPKIStatusInfo = this.getPKIStatusInfo(_getTLV(h, aIdx[0])); -1075 var hTST = _getTLV(h, aIdx[1]); -1076 var pResult = this.getToken(hTST); -1077 pResult.statusinfo = pPKIStatusInfo; -1078 return pResult; -1079 } -1080 }; -1081 -1082 /** -1083 * parse ASN.1 TimeStampToken<br/> -1084 * @name getToken -1085 * @memberOf KJUR.asn1.tsp.TSPParser# -1086 * @function -1087 * @param {String} h hexadecimal string of ASN.1 TimeStampToken -1088 * @return {Array} JSON object of TimeStampToken parameter -1089 * @see KJUR.asn1.tsp.TimeStampToken -1090 * @see KJUR.asn1.cms.CMSParser#getCMSSignedData -1091 * @see KJUR.asn1.tsp.TSPParser#setTSTInfo -1092 * -1093 * @description -1094 * This method parses ASN.1 TimeStampRsp defined in RFC 3161. -1095 * This method will parse "h" as CMS SigneData by -1096 * {@link KJUR.asn1.cms.CMSParser#getCMSSignedData}, then -1097 * parse and modify "econtent.content" parameter by -1098 * {@link KJUR.asn1.tsp.TSPParser#setTSTInfo} method. -1099 * -1100 * @example -1101 * parser = new KJUR.asn1.tsp.TSPParser(); -1102 * parser.getToken("30...") → -1103 * { -1104 * ... // almost the same as CMS SignedData parameters -1105 * econtent: { -1106 * type: "tstinfo", -1107 * content: { // TSTInfo parameter -1108 * policy: '1.2.3.4.5', -1109 * messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'}, -1110 * serial: {'int': 3}, -1111 * genTime: {str: '20131231235959.123Z'}, -1112 * accuracy: {millis: 500}, -1113 * ordering: true, -1114 * nonce: {int: 3} -1115 * } -1116 * }, -1117 * ... -1118 * } -1119 */ -1120 this.getToken = function(h) { -1121 var _CMSParser = new KJUR.asn1.cms.CMSParser; -1122 var p = _CMSParser.getCMSSignedData(h); -1123 this.setTSTInfo(p); -1124 return p; -1125 }; -1126 -1127 /** -1128 * set ASN.1 TSTInfo parameter to CMS SignedData parameter<br/> -1129 * @name setTSTInfo -1130 * @memberOf KJUR.asn1.tsp.TSPParser# -1131 * @function -1132 * @param {Array} pCMSSignedData JSON object of CMS SignedData parameter -1133 * @see KJUR.asn1.tsp.TimeStampToken -1134 * @see KJUR.asn1.cms.CMSParser#getCMSSignedData -1135 * -1136 * @description -1137 * This method modifies "econtent.content" of CMS SignedData parameter -1138 * to parsed TSTInfo. -1139 * <pre> -1140 * -1141 * @example -1142 * parser = new KJUR.asn1.tsp.TSPParser(); -1143 * pCMSSignedData = { -1144 * ... // almost the same as CMS SignedData parameters -1145 * econtent: { -1146 * type: "tstinfo", -1147 * content: { hex: "30..." } -1148 * }, -1149 * ... -1150 * }; -1151 * parser.setTSTInfo(pCMSSignedData); -1152 * pCMSSignedData → { -1153 * ... // almost the same as CMS SignedData parameters -1154 * econtent: { -1155 * type: "tstinfo", -1156 * content: { // TSTInfo parameter -1157 * policy: '1.2.3.4.5', -1158 * messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'}, -1159 * serial: {int: 3}, -1160 * genTime: {str: '20131231235959.123Z'}, -1161 * accuracy: {millis: 500}, -1162 * ordering: true, -1163 * nonce: {int: 3} -1164 * } -1165 * }, -1166 * ... -1167 * }; -1168 */ -1169 this.setTSTInfo = function(pCMSSignedData) { -1170 var pEContent = pCMSSignedData.econtent; -1171 if (pEContent.type == "tstinfo") { -1172 var hContent = pEContent.content.hex; -1173 var pTSTInfo = this.getTSTInfo(hContent); -1174 //pTSTInfo.hex_ = hContent; -1175 pEContent.content = pTSTInfo; -1176 } -1177 }; -1178 -1179 /** -1180 * parse ASN.1 TSTInfo<br/> -1181 * @name getTSTInfo -1182 * @memberOf KJUR.asn1.tsp.TSPParser# -1183 * @function -1184 * @param {String} h hexadecimal string of ASN.1 TSTInfo -1185 * @return {Array} JSON object of TSTInfo parameter -1186 * @see KJUR.asn1.tsp.TSTInfo -1187 * -1188 * @description -1189 * This method parses ASN.1 TSTInfo defined in RFC 3161. -1190 * <pre> -1191 * TSTInfo ::= SEQUENCE { -1192 * version INTEGER { v1(1) }, -1193 * policy TSAPolicyId, -1194 * messageImprint MessageImprint, -1195 * serialNumber INTEGER, -1196 * genTime GeneralizedTime, -1197 * accuracy Accuracy OPTIONAL, -1198 * ordering BOOLEAN DEFAULT FALSE, -1199 * nonce INTEGER OPTIONAL, -1200 * tsa [0] GeneralName OPTIONAL, -1201 * extensions [1] IMPLICIT Extensions OPTIONAL } -1202 * </pre> -1203 * -1204 * @example -1205 * parser = new KJUR.asn1.tsp.TSPParser(); -1206 * parser.getTSTInfo("30...") → -1207 * { -1208 * policy: '1.2.3.4.5', -1209 * messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'}, -1210 * serial: {'int': 3}, -1211 * genTime: {str: '20131231235959.123Z'}, -1212 * accuracy: {millis: 500}, -1213 * ordering: true, -1214 * nonce: {int: 3} -1215 * } -1216 */ -1217 this.getTSTInfo = function(h) { -1218 var pResult = {}; -1219 var aIdx = _getChildIdx(h, 0); -1220 -1221 var hPolicy = _getV(h, aIdx[1]); -1222 pResult.policy = hextooid(hPolicy); -1223 -1224 var hMessageImprint = _getTLV(h, aIdx[2]); -1225 pResult.messageImprint = this.getMessageImprint(hMessageImprint); -1226 -1227 var hSerial = _getV(h, aIdx[3]); -1228 pResult.serial = {hex: hSerial}; -1229 -1230 var hGenTime = _getV(h, aIdx[4]); -1231 pResult.genTime = {str: hextoutf8(hGenTime)}; -1232 -1233 var offset = 0; -1234 -1235 if (aIdx.length > 5 && h.substr(aIdx[5], 2) == "30") { -1236 var hAccuracy = _getTLV(h, aIdx[5]); -1237 pResult.accuracy = this.getAccuracy(hAccuracy); -1238 offset++; -1239 } -1240 -1241 if (aIdx.length > 5 + offset && -1242 h.substr(aIdx[5 + offset], 2) == "01") { -1243 var hOrdering = _getV(h, aIdx[5 + offset]); -1244 if (hOrdering == "ff") pResult.ordering = true; -1245 offset++; -1246 } -1247 -1248 if (aIdx.length > 5 + offset && -1249 h.substr(aIdx[5 + offset], 2) == "02") { -1250 var hNonce = _getV(h, aIdx[5 + offset]); -1251 pResult.nonce = {hex: hNonce}; -1252 offset++; -1253 } -1254 -1255 if (aIdx.length > 5 + offset && -1256 h.substr(aIdx[5 + offset], 2) == "a0") { -1257 var hGeneralNames = _getTLV(h, aIdx[5 + offset]); -1258 hGeneralNames = "30" + hGeneralNames.substr(2); -1259 pGeneralNames = _x509obj.getGeneralNames(hGeneralNames); -1260 var pName = pGeneralNames[0].dn; -1261 pResult.tsa = pName; -1262 offset++; -1263 } -1264 -1265 if (aIdx.length > 5 + offset && -1266 h.substr(aIdx[5 + offset], 2) == "a1") { -1267 var hExt = _getTLV(h, aIdx[5 + offset]); -1268 hExt = "30" + hExt.substr(2); -1269 var aExt = _x509obj.getExtParamArray(hExt); -1270 pResult.ext = aExt; -1271 offset++; -1272 } -1273 -1274 return pResult; -1275 }; -1276 -1277 /** -1278 * parse ASN.1 Accuracy<br/> -1279 * @name getAccuracy -1280 * @memberOf KJUR.asn1.tsp.TSPParser# -1281 * @function -1282 * @param {String} h hexadecimal string of ASN.1 Accuracy -1283 * @return {Array} JSON object of Accuracy parameter -1284 * @see KJUR.asn1.tsp.Accuracy -1285 * -1286 * @description -1287 * This method parses ASN.1 Accuracy defined in RFC 3161. -1288 * <pre> -1289 * Accuracy ::= SEQUENCE { -1290 * seconds INTEGER OPTIONAL, -1291 * millis [0] INTEGER (1..999) OPTIONAL, -1292 * micros [1] INTEGER (1..999) OPTIONAL } -1293 * </pre> -1294 * -1295 * @example -1296 * parser = new KJUR.asn1.tsp.TSPParser(); -1297 * parser.getAccuracy("30...") → {millis: 500} -1298 */ -1299 this.getAccuracy = function(h) { -1300 var pResult = {}; -1301 -1302 var aIdx = _getChildIdx(h, 0); -1303 -1304 for (var i = 0; i < aIdx.length; i++) { -1305 var tag = h.substr(aIdx[i], 2); -1306 var hV = _getV(h, aIdx[i]); -1307 var iV = parseInt(hV, 16); +837 this.tohex = function() { +838 var params = this.params; +839 +840 var value; +841 if (typeof params == "string") { +842 try { +843 value = _nameValue[params]; +844 } catch(ex) { +845 throw new _Error("undefined name: " + params); +846 } +847 } else if (typeof params == "number") { +848 value = params; +849 } else { +850 throw new _Error("wrong params"); +851 } +852 return (new _DERBitString({"bin": value.toString(2)})).tohex(); +853 }; +854 this.getEncodedHex = function() { return this.tohex(); }; +855 +856 if (params != undefined) this.setByParam(params); +857 }; +858 extendClass(KJUR.asn1.tsp.PKIFailureInfo, KJUR.asn1.ASN1Object); +859 +860 // --- END OF RFC 2510 CMP ------------------------------------------- +861 +862 /** +863 * abstract class for TimeStampToken generator (DEPRECATED)<br/> +864 * @name KJUR.asn1.tsp.AbstractTSAAdapter +865 * @class abstract class for TimeStampToken generator +866 * @param {Array} params associative array of parameters +867 * @since jsrsasign 4.7.0 asn1tsp 1.0.1 +868 * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0 +869 * +870 * @description +871 * This is abstract class for TimeStampToken generator. +872 */ +873 KJUR.asn1.tsp.AbstractTSAAdapter = function(params) { +874 this.getTSTHex = function(msgHex, hashAlg) { +875 throw "not implemented yet"; +876 }; +877 }; +878 +879 /** +880 * class for simple TimeStampToken generator (DEPRECATED)<br/> +881 * @name KJUR.asn1.tsp.SimpleTSAAdapter +882 * @class class for simple TimeStampToken generator +883 * @extends KJUR.asn1.tsp.AbstractTSAAdapter +884 * @param {Array} params associative array of parameters +885 * @since jsrsasign 4.7.0 asn1tsp 1.0.1 +886 * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0 +887 * +888 * @description +889 * This is a simple TimeStampToken generator class. +890 */ +891 KJUR.asn1.tsp.SimpleTSAAdapter = function(params) { +892 var _KJUR = KJUR, +893 _KJUR_asn1 = _KJUR.asn1, +894 _KJUR_asn1_tsp = _KJUR_asn1.tsp, +895 _hashHex = _KJUR.crypto.Util.hashHex; +896 +897 _KJUR_asn1_tsp.SimpleTSAAdapter.superclass.constructor.call(this); +898 this.params = null; +899 this.serial = 0; +900 +901 this.getTSTHex = function(msgHex, hashAlg) { +902 // messageImprint +903 var hashHex = _hashHex(msgHex, hashAlg); +904 this.params.econtent.content.messageImprint = +905 {alg: hashAlg, hash: hashHex}; +906 +907 // serial +908 this.params.econtent.content.serial = +909 {'int': this.serial++}; +910 +911 // nonce +912 var nonceValue = Math.floor(Math.random() * 1000000000); +913 this.params.econtent.content.nonce = +914 {'int': nonceValue}; +915 +916 var obj = +917 new _KJUR_asn1_tsp.TimeStampToken(this.params); +918 return obj.getContentInfoEncodedHex(); +919 }; +920 +921 if (params !== undefined) this.params = params; +922 }; +923 extendClass(KJUR.asn1.tsp.SimpleTSAAdapter, +924 KJUR.asn1.tsp.AbstractTSAAdapter); +925 +926 /** +927 * class for fixed TimeStampToken generator (DEPRECATED)<br/> +928 * @name KJUR.asn1.tsp.FixedTSAAdapter +929 * @class class for fixed TimeStampToken generator +930 * @extends KJUR.asn1.tsp.AbstractTSAAdapter +931 * @param {Array} params associative array of parameters +932 * @since jsrsasign 4.7.0 asn1tsp 1.0.1 +933 * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0 +934 * +935 * @description +936 * This class generates fixed TimeStampToken except messageImprint +937 * for testing purpose. +938 * General TSA generates TimeStampToken which varies following +939 * fields: +940 * <ul> +941 * <li>genTime</li> +942 * <li>serialNumber</li> +943 * <li>nonce</li> +944 * </ul> +945 * Those values are provided by initial parameters. +946 */ +947 KJUR.asn1.tsp.FixedTSAAdapter = function(params) { +948 var _KJUR = KJUR, +949 _KJUR_asn1 = _KJUR.asn1, +950 _KJUR_asn1_tsp = _KJUR_asn1.tsp, +951 _hashHex = _KJUR.crypto.Util.hashHex; +952 +953 _KJUR_asn1_tsp.FixedTSAAdapter.superclass.constructor.call(this); +954 this.params = null; +955 +956 this.getTSTHex = function(msgHex, hashAlg) { +957 // fixed serialNumber +958 // fixed nonce +959 var hashHex = _hashHex(msgHex, hashAlg); +960 this.params.econtent.content.messageImprint = +961 {alg: hashAlg, hash: hashHex}; +962 var obj = new _KJUR_asn1_tsp.TimeStampToken(this.params); +963 return obj.getContentInfoEncodedHex(); +964 }; +965 +966 if (params !== undefined) this.params = params; +967 }; +968 extendClass(KJUR.asn1.tsp.FixedTSAAdapter, +969 KJUR.asn1.tsp.AbstractTSAAdapter); +970 +971 // --- TSP utilities ------------------------------------------------- +972 +973 /** +974 * TSP utiliteis class +975 * @name KJUR.asn1.tsp.TSPUtil +976 * @class TSP utilities class +977 */ +978 KJUR.asn1.tsp.TSPUtil = new function() { +979 }; +980 /** +981 * generate TimeStampToken ASN.1 object specified by JSON parameters (DEPRECATED)<br/> +982 * @name newTimeStampToken +983 * @memberOf KJUR.asn1.tsp.TSPUtil +984 * @function +985 * @param {Array} param JSON parameter to generate TimeStampToken +986 * @return {KJUR.asn1.cms.SignedData} object just generated +987 * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0. Please use TimeStampToken class +988 * @see KJUR.asn1.tsp.TimeStampToken +989 * +990 * @description +991 * @example +992 */ +993 KJUR.asn1.tsp.TSPUtil.newTimeStampToken = function(params) { +994 return new KJUR.asn1.tsp.TimeStampToken(params); +995 }; +996 +997 /** +998 * parse hexadecimal string of TimeStampReq +999 * @name parseTimeStampReq +1000 * @memberOf KJUR.asn1.tsp.TSPUtil +1001 * @function +1002 * @param {String} hexadecimal string of TimeStampReq +1003 * @return {Array} JSON object of parsed parameters +1004 * @see KJUR.asn1.tsp.TSPParser#getTimeStampReq +1005 * @deprecated since jsrsasign 10.5.18 asn1tsp 2.0.6. Please use TSPParser.getTimeStampReq instead. +1006 * +1007 * @description +1008 * This method parses a hexadecimal string of TimeStampReq +1009 * and returns parsed their fields: +1010 * +1011 * @example +1012 * var json = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq("302602..."); +1013 * // resulted DUMP of above 'json': +1014 * { +1015 * messageImprint: { +1016 * alg: 'sha256', // MessageImprint hashAlg +1017 * hash: 'a1a2a3a4...'}, // MessageImprint hashValue +1018 * policy: '1.2.3.4.5', // tsaPolicy (OPTION) +1019 * nonce: '9abcf318...', // nonce (OPTION) +1020 * certreq: true} // certReq (OPTION) +1021 */ +1022 KJUR.asn1.tsp.TSPUtil.parseTimeStampReq = function(reqHex) { +1023 var parser = new KJUR.asn1.tsp.TSPParser(); +1024 return parser.getTimeStampReq(reqHex); +1025 }; +1026 +1027 /** +1028 * parse hexadecimal string of MessageImprint +1029 * @name parseMessageImprint +1030 * @memberOf KJUR.asn1.tsp.TSPUtil +1031 * @function +1032 * @param {String} hexadecimal string of MessageImprint +1033 * @return {Array} JSON object of parsed parameters +1034 * @see KJUR.asn1.tsp.TSPParser#getMessageImprint +1035 * @deprecated since jsrsasign 10.5.18 asn1tsp 2.0.6. Please use TSPParser.getMessageImprint instead. +1036 * +1037 * @description +1038 * This method parses a hexadecimal string of MessageImprint +1039 * and returns parsed their fields: +1040 * +1041 * @example +1042 * KJUR.asn1.tsp.TSPUtil.parseMessageImprint("302602...") → +1043 * { alg: 'sha256', hash: 'a1a2a3a4...'} +1044 */ +1045 KJUR.asn1.tsp.TSPUtil.parseMessageImprint = function(miHex) { +1046 var parser = new KJUR.asn1.tsp.TSPParser(); +1047 return parser.getMessageImprint(miHex); +1048 /* +1049 var _ASN1HEX = ASN1HEX; +1050 var _getChildIdx = _ASN1HEX.getChildIdx; +1051 var _getV = _ASN1HEX.getV; +1052 var _getIdxbyList = _ASN1HEX.getIdxbyList; +1053 var json = {}; +1054 +1055 if (miHex.substr(0, 2) != "30") +1056 throw "head of messageImprint hex shall be '30'"; +1057 +1058 var idxList = _getChildIdx(miHex, 0); +1059 var hashAlgOidIdx = _getIdxbyList(miHex, 0, [0, 0]); +1060 var hashAlgHex = _getV(miHex, hashAlgOidIdx); +1061 var hashAlgOid = _ASN1HEX.hextooidstr(hashAlgHex); +1062 var hashAlgName = KJUR.asn1.x509.OID.oid2name(hashAlgOid); +1063 if (hashAlgName == '') +1064 throw "hashAlg name undefined: " + hashAlgOid; +1065 var hashAlg = hashAlgName; +1066 var hashValueIdx = _getIdxbyList(miHex, 0, [1]); +1067 +1068 json.alg = hashAlg; +1069 json.hash = _getV(miHex, hashValueIdx); +1070 +1071 return json; +1072 */ +1073 }; +1074 +1075 /** +1076 * class for parsing RFC 3161 TimeStamp protocol data<br/> +1077 * @name KJUR.asn1.tsp.TSPParser +1078 * @class RFC 3161 TimeStamp protocol parser class +1079 * @since jsrsasign 10.1.0 asn1tsp 2.0.1 +1080 * +1081 * @description +1082 * This is an ASN.1 parser for +1083 * <a href="https://tools.ietf.org/html/rfc3161">RFC 3161</a>. +1084 */ +1085 KJUR.asn1.tsp.TSPParser = function() { +1086 var _Error = Error, +1087 _X509 = X509, +1088 _x509obj = new _X509(), +1089 _ASN1HEX = ASN1HEX, +1090 _getV = _ASN1HEX.getV, +1091 _getTLV = _ASN1HEX.getTLV, +1092 _getIdxbyList = _ASN1HEX.getIdxbyList, +1093 _getTLVbyListEx = _ASN1HEX.getTLVbyListEx, +1094 _getChildIdx = _ASN1HEX.getChildIdx; +1095 var _aSTATUSSTR = [ +1096 "granted", "grantedWithMods", "rejection", "waiting", +1097 "revocationWarning", "revocationNotification" ]; +1098 var _pFAILUREINFO = { +1099 0: "badAlg", 2: "badRequest", 5: "badDataFormat", +1100 14: "timeNotAvailable", 15: "unacceptedPolicy", +1101 16: "unacceptedExtension", 17: "addInfoNotAvailable", +1102 25: "systemFailure" +1103 }; +1104 +1105 /** +1106 * parse ASN.1 TimeStampResp<br/> +1107 * @name getResponse +1108 * @memberOf KJUR.asn1.tsp.TSPParser# +1109 * @function +1110 * @param {String} h hexadecimal string of ASN.1 TimeStampResp +1111 * @return {Array} JSON object of TimeStampResp parameter +1112 * @see KJUR.asn1.tsp.TimeStampResp +1113 * @see KJUR.asn1.tsp.TimeStampToken +1114 * @see KJUR.asn1.cms.CMSParser#getCMSSignedData +1115 * +1116 * @description +1117 * This method parses ASN.1 TimeStampRsp defined in RFC 3161. +1118 * <pre> +1119 * TimeStampResp ::= SEQUENCE { +1120 * status PKIStatusInfo, +1121 * timeStampToken TimeStampToken OPTIONAL } +1122 * </pre> +1123 * When "h" is a TSP error response, +1124 * returned parameter contains "statusinfo" only. +1125 * +1126 * @example +1127 * parser = new KJUR.asn1.tsp.TSPParser(); +1128 * parser.getResponse("30...") → +1129 * { +1130 * statusinfo: 'granted', +1131 * ... // almost the same as CMS SignedData parameters +1132 * econtent: { +1133 * type: "tstinfo", +1134 * content: { // TSTInfo parameter +1135 * policy: '1.2.3.4.5', +1136 * messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'}, +1137 * serial: {'int': 3}, +1138 * genTime: {str: '20131231235959.123Z'}, +1139 * accuracy: {millis: 500}, +1140 * ordering: true, +1141 * nonce: {int: 3} +1142 * } +1143 * }, +1144 * ... +1145 * } +1146 */ +1147 this.getResponse = function(h) { +1148 var aIdx = _getChildIdx(h, 0); +1149 +1150 if (aIdx.length == 1) { +1151 return this.getPKIStatusInfo(_getTLV(h, aIdx[0])); +1152 } else if (aIdx.length > 1) { +1153 var pPKIStatusInfo = this.getPKIStatusInfo(_getTLV(h, aIdx[0])); +1154 var hTST = _getTLV(h, aIdx[1]); +1155 var pResult = this.getToken(hTST); +1156 pResult.statusinfo = pPKIStatusInfo; +1157 return pResult; +1158 } +1159 }; +1160 +1161 /** +1162 * parse ASN.1 TimeStampToken<br/> +1163 * @name getToken +1164 * @memberOf KJUR.asn1.tsp.TSPParser# +1165 * @function +1166 * @param {String} h hexadecimal string of ASN.1 TimeStampToken +1167 * @return {Array} JSON object of TimeStampToken parameter +1168 * @see KJUR.asn1.tsp.TimeStampToken +1169 * @see KJUR.asn1.cms.CMSParser#getCMSSignedData +1170 * @see KJUR.asn1.tsp.TSPParser#setTSTInfo +1171 * +1172 * @description +1173 * This method parses ASN.1 TimeStampRsp defined in RFC 3161. +1174 * This method will parse "h" as CMS SigneData by +1175 * {@link KJUR.asn1.cms.CMSParser#getCMSSignedData}, then +1176 * parse and modify "econtent.content" parameter by +1177 * {@link KJUR.asn1.tsp.TSPParser#setTSTInfo} method. +1178 * +1179 * @example +1180 * parser = new KJUR.asn1.tsp.TSPParser(); +1181 * parser.getToken("30...") → +1182 * { +1183 * ... // almost the same as CMS SignedData parameters +1184 * econtent: { +1185 * type: "tstinfo", +1186 * content: { // TSTInfo parameter +1187 * policy: '1.2.3.4.5', +1188 * messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'}, +1189 * serial: {'int': 3}, +1190 * genTime: {str: '20131231235959.123Z'}, +1191 * accuracy: {millis: 500}, +1192 * ordering: true, +1193 * nonce: {int: 3} +1194 * } +1195 * }, +1196 * ... +1197 * } +1198 */ +1199 this.getToken = function(h) { +1200 var _CMSParser = new KJUR.asn1.cms.CMSParser; +1201 var p = _CMSParser.getCMSSignedData(h); +1202 this.setTSTInfo(p); +1203 return p; +1204 }; +1205 +1206 /** +1207 * set ASN.1 TSTInfo parameter to CMS SignedData parameter<br/> +1208 * @name setTSTInfo +1209 * @memberOf KJUR.asn1.tsp.TSPParser# +1210 * @function +1211 * @param {Array} pCMSSignedData JSON object of CMS SignedData parameter +1212 * @see KJUR.asn1.tsp.TimeStampToken +1213 * @see KJUR.asn1.cms.CMSParser#getCMSSignedData +1214 * +1215 * @description +1216 * This method modifies "econtent.content" of CMS SignedData parameter +1217 * to parsed TSTInfo. +1218 * <pre> +1219 * +1220 * @example +1221 * parser = new KJUR.asn1.tsp.TSPParser(); +1222 * pCMSSignedData = { +1223 * ... // almost the same as CMS SignedData parameters +1224 * econtent: { +1225 * type: "tstinfo", +1226 * content: { hex: "30..." } +1227 * }, +1228 * ... +1229 * }; +1230 * parser.setTSTInfo(pCMSSignedData); +1231 * pCMSSignedData → { +1232 * ... // almost the same as CMS SignedData parameters +1233 * econtent: { +1234 * type: "tstinfo", +1235 * content: { // TSTInfo parameter +1236 * policy: '1.2.3.4.5', +1237 * messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'}, +1238 * serial: {int: 3}, +1239 * genTime: {str: '20131231235959.123Z'}, +1240 * accuracy: {millis: 500}, +1241 * ordering: true, +1242 * nonce: {int: 3} +1243 * } +1244 * }, +1245 * ... +1246 * }; +1247 */ +1248 this.setTSTInfo = function(pCMSSignedData) { +1249 var pEContent = pCMSSignedData.econtent; +1250 if (pEContent.type == "tstinfo") { +1251 var hContent = pEContent.content.hex; +1252 var pTSTInfo = this.getTSTInfo(hContent); +1253 //pTSTInfo.hex_ = hContent; +1254 pEContent.content = pTSTInfo; +1255 } +1256 }; +1257 +1258 /** +1259 * parse ASN.1 TSTInfo<br/> +1260 * @name getTSTInfo +1261 * @memberOf KJUR.asn1.tsp.TSPParser# +1262 * @function +1263 * @param {String} h hexadecimal string of ASN.1 TSTInfo +1264 * @return {Array} JSON object of TSTInfo parameter +1265 * @see KJUR.asn1.tsp.TSTInfo +1266 * +1267 * @description +1268 * This method parses ASN.1 TSTInfo defined in RFC 3161. +1269 * <pre> +1270 * TSTInfo ::= SEQUENCE { +1271 * version INTEGER { v1(1) }, +1272 * policy TSAPolicyId, +1273 * messageImprint MessageImprint, +1274 * serialNumber INTEGER, +1275 * genTime GeneralizedTime, +1276 * accuracy Accuracy OPTIONAL, +1277 * ordering BOOLEAN DEFAULT FALSE, +1278 * nonce INTEGER OPTIONAL, +1279 * tsa [0] GeneralName OPTIONAL, +1280 * extensions [1] IMPLICIT Extensions OPTIONAL } +1281 * </pre> +1282 * +1283 * @example +1284 * parser = new KJUR.asn1.tsp.TSPParser(); +1285 * parser.getTSTInfo("30...") → +1286 * { +1287 * policy: '1.2.3.4.5', +1288 * messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'}, +1289 * serial: {'int': 3}, +1290 * genTime: {str: '20131231235959.123Z'}, +1291 * accuracy: {millis: 500}, +1292 * ordering: true, +1293 * nonce: {int: 3} +1294 * } +1295 */ +1296 this.getTSTInfo = function(h) { +1297 var pResult = {}; +1298 var aIdx = _getChildIdx(h, 0); +1299 +1300 var hPolicy = _getV(h, aIdx[1]); +1301 pResult.policy = hextooid(hPolicy); +1302 +1303 var hMessageImprint = _getTLV(h, aIdx[2]); +1304 pResult.messageImprint = this.getMessageImprint(hMessageImprint); +1305 +1306 var hSerial = _getV(h, aIdx[3]); +1307 pResult.serial = {hex: hSerial}; 1308 -1309 if (tag == "02") { -1310 pResult.seconds = iV; -1311 } else if (tag == "80") { -1312 pResult.millis = iV; -1313 } else if (tag == "81") { -1314 pResult.micros = iV; -1315 } -1316 } -1317 -1318 return pResult; -1319 }; -1320 -1321 /** -1322 * parse ASN.1 MessageImprint<br/> -1323 * @name getMessageImprint -1324 * @memberOf KJUR.asn1.tsp.TSPParser# -1325 * @function -1326 * @param {String} h hexadecimal string of ASN.1 MessageImprint -1327 * @return {Array} JSON object of MessageImprint parameter -1328 * @see KJUR.asn1.tsp.MessageImprint -1329 * -1330 * @description -1331 * This method parses ASN.1 MessageImprint defined in RFC 3161. -1332 * -1333 * @example -1334 * parser = new KJUR.asn1.tsp.TSPParser(); -1335 * parser.getMessageImprint("30...") → -1336 * { alg: "sha256", hash: "12ab..." } -1337 */ -1338 this.getMessageImprint = function(h) { -1339 if (h.substr(0, 2) != "30") -1340 throw new Error("head of messageImprint hex shall be x30"); -1341 -1342 var json = {}; -1343 var idxList = _getChildIdx(h, 0); -1344 var hashAlgOidIdx = _getIdxbyList(h, 0, [0, 0]); -1345 var hashAlgHex = _getV(h, hashAlgOidIdx); -1346 var hashAlgOid = _ASN1HEX.hextooidstr(hashAlgHex); -1347 var hashAlgName = KJUR.asn1.x509.OID.oid2name(hashAlgOid); -1348 if (hashAlgName == '') -1349 throw new Error("hashAlg name undefined: " + hashAlgOid); -1350 var hashAlg = hashAlgName; -1351 var hashValueIdx = _getIdxbyList(h, 0, [1]); -1352 -1353 json.alg = hashAlg; -1354 json.hash = _getV(h, hashValueIdx); +1309 var hGenTime = _getV(h, aIdx[4]); +1310 pResult.genTime = {str: hextoutf8(hGenTime)}; +1311 +1312 var offset = 0; +1313 +1314 if (aIdx.length > 5 && h.substr(aIdx[5], 2) == "30") { +1315 var hAccuracy = _getTLV(h, aIdx[5]); +1316 pResult.accuracy = this.getAccuracy(hAccuracy); +1317 offset++; +1318 } +1319 +1320 if (aIdx.length > 5 + offset && +1321 h.substr(aIdx[5 + offset], 2) == "01") { +1322 var hOrdering = _getV(h, aIdx[5 + offset]); +1323 if (hOrdering == "ff") pResult.ordering = true; +1324 offset++; +1325 } +1326 +1327 if (aIdx.length > 5 + offset && +1328 h.substr(aIdx[5 + offset], 2) == "02") { +1329 var hNonce = _getV(h, aIdx[5 + offset]); +1330 pResult.nonce = {hex: hNonce}; +1331 offset++; +1332 } +1333 +1334 if (aIdx.length > 5 + offset && +1335 h.substr(aIdx[5 + offset], 2) == "a0") { +1336 var hGeneralNames = _getTLV(h, aIdx[5 + offset]); +1337 hGeneralNames = "30" + hGeneralNames.substr(2); +1338 pGeneralNames = _x509obj.getGeneralNames(hGeneralNames); +1339 var pName = pGeneralNames[0].dn; +1340 pResult.tsa = pName; +1341 offset++; +1342 } +1343 +1344 if (aIdx.length > 5 + offset && +1345 h.substr(aIdx[5 + offset], 2) == "a1") { +1346 var hExt = _getTLV(h, aIdx[5 + offset]); +1347 hExt = "30" + hExt.substr(2); +1348 var aExt = _x509obj.getExtParamArray(hExt); +1349 pResult.ext = aExt; +1350 offset++; +1351 } +1352 +1353 return pResult; +1354 }; 1355 -1356 return json; -1357 }; -1358 -1359 /** -1360 * parse ASN.1 PKIStatusInfo<br/> -1361 * @name getPKIStatusInfo -1362 * @memberOf KJUR.asn1.tsp.TSPParser# -1363 * @function -1364 * @param {String} h hexadecimal string of ASN.1 PKIStatusInfo -1365 * @return {Array} JSON object of PKIStatusInfo parameter -1366 * @see KJUR.asn1.tsp.PKIStatusInfo -1367 * -1368 * @description -1369 * This method parses ASN.1 PKIStatusInfo defined in RFC 3161. -1370 * -1371 * @example -1372 * parser = new KJUR.asn1.tsp.TSPParser(); -1373 * parser.getPKIStatusInfo("30...") → -1374 * { status: "rejection", -1375 * statusstr: ["unsupported algorithm"], -1376 * failinfo: "badAlg" } +1356 /** +1357 * parse ASN.1 Accuracy<br/> +1358 * @name getAccuracy +1359 * @memberOf KJUR.asn1.tsp.TSPParser# +1360 * @function +1361 * @param {String} h hexadecimal string of ASN.1 Accuracy +1362 * @return {Array} JSON object of Accuracy parameter +1363 * @see KJUR.asn1.tsp.Accuracy +1364 * +1365 * @description +1366 * This method parses ASN.1 Accuracy defined in RFC 3161. +1367 * <pre> +1368 * Accuracy ::= SEQUENCE { +1369 * seconds INTEGER OPTIONAL, +1370 * millis [0] INTEGER (1..999) OPTIONAL, +1371 * micros [1] INTEGER (1..999) OPTIONAL } +1372 * </pre> +1373 * +1374 * @example +1375 * parser = new KJUR.asn1.tsp.TSPParser(); +1376 * parser.getAccuracy("30...") → {millis: 500} 1377 */ -1378 this.getPKIStatusInfo = function(h) { +1378 this.getAccuracy = function(h) { 1379 var pResult = {}; -1380 var aIdx = _getChildIdx(h, 0); -1381 var offset = 0; +1380 +1381 var aIdx = _getChildIdx(h, 0); 1382 -1383 try { -1384 var hStatus = _getV(h, aIdx[0]); -1385 var iStatus = parseInt(hStatus, 16); -1386 pResult.status = _aSTATUSSTR[iStatus]; -1387 } catch(ex) {}; -1388 -1389 if (aIdx.length > 1 && h.substr(aIdx[1], 2) == "30") { -1390 var hPKIFreeText = _getTLV(h, aIdx[1]); -1391 pResult.statusstr = -1392 this.getPKIFreeText(hPKIFreeText); -1393 offset++; -1394 } -1395 -1396 if (aIdx.length > offset && -1397 h.substr(aIdx[1 + offset], 2) == "03") { -1398 var hPKIFailureInfo = _getTLV(h, aIdx[1 + offset]); -1399 pResult.failinfo = -1400 this.getPKIFailureInfo(hPKIFailureInfo); -1401 } -1402 -1403 return pResult; -1404 }; -1405 -1406 /** -1407 * parse ASN.1 PKIFreeText<br/> -1408 * @name getPKIFreeText -1409 * @memberOf KJUR.asn1.tsp.TSPParser# -1410 * @function -1411 * @param {String} h hexadecimal string of ASN.1 PKIFreeText -1412 * @return {Array} array of string -1413 * @since jsrsasign 10.1.3 asn1tsp 2.0.3 -1414 * @see KJUR.asn1.tsp.PKIFreeText -1415 * -1416 * @description -1417 * This method parses ASN.1 PKIFreeText defined in RFC 3161. -1418 * -1419 * @example -1420 * parser = new KJUR.asn1.tsp.TSPParser(); -1421 * parser.getPKIFreeText("300a0c036161610c03616161") → -1422 * ["aaa", "aaa"] -1423 */ -1424 this.getPKIFreeText = function(h) { -1425 var aResult = []; -1426 var aIdx = _getChildIdx(h, 0); -1427 for (var i = 0; i < aIdx.length; i++) { -1428 aResult.push(_ASN1HEX.getString(h, aIdx[i])); -1429 } -1430 return aResult; -1431 }; -1432 -1433 /** -1434 * parse ASN.1 PKIFailureInfo<br/> -1435 * @name getPKIFailureInfo -1436 * @memberOf KJUR.asn1.tsp.TSPParser# -1437 * @function -1438 * @param {String} h hexadecimal string of ASN.1 PKIFailureInfo -1439 * @return {Object} failureInfo string or number -1440 * @since jsrsasign 10.1.3 asn1tsp 2.0.3 -1441 * @see KJUR.asn1.tsp.PKIFailureInfo -1442 * -1443 * @description -1444 * This method parses ASN.1 PKIFailureInfo defined in RFC 3161. -1445 * -1446 * @example -1447 * parser = new KJUR.asn1.tsp.TSPParser(); -1448 * parser.getPKIFailureInfo("03020700") → "badAlg" -1449 * parser.getPKIFailureInfo("03020780") → 1 -1450 * parser.getPKIFailureInfo("030203c8") → "systemFailure" -1451 */ -1452 this.getPKIFailureInfo = function(h) { -1453 var n = _ASN1HEX.getInt(h, 0); -1454 if (_pFAILUREINFO[n] != undefined) { -1455 return _pFAILUREINFO[n]; -1456 } else { -1457 return n; -1458 } -1459 }; -1460 -1461 /** -1462 * parse hexadecimal string of TimeStampReq<br/> -1463 * @name getTimeStampReq -1464 * @memberOf KJUR.asn1.tsp.TSPParser# -1465 * @function -1466 * @param {String} h hexadecimal string of TimeStampReq -1467 * @return {Array} JSON object of parsed parameters -1468 * @see KJUR.asn1.tsp.TSPUtil.parseTimeStampReq -1469 * -1470 * @description -1471 * This method parses a hexadecimal string of TimeStampReq -1472 * and returns parsed their fields: -1473 * -1474 * @example -1475 * var json = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq("302602..."); -1476 * // resulted DUMP of above 'json': -1477 * { -1478 * messageImprint: { -1479 * alg: 'sha256', // MessageImprint hashAlg -1480 * hash: 'a1a2a3a4...'}, // MessageImprint hashValue -1481 * policy: '1.2.3.4.5', // tsaPolicy (OPTION) -1482 * nonce: '9abcf318...', // nonce (OPTION) -1483 * certreq: true } // certReq (OPTION) -1484 */ -1485 this.getTimeStampReq = function(h) { -1486 var json = {}; -1487 json.certreq = false; -1488 -1489 var idxList = _getChildIdx(h, 0); -1490 -1491 if (idxList.length < 2) -1492 throw new Error("TimeStampReq must have at least 2 items"); -1493 -1494 var miHex = _getTLV(h, idxList[1]); -1495 json.messageImprint = KJUR.asn1.tsp.TSPUtil.parseMessageImprint(miHex); -1496 //json.messageImprint = getMessageImprint(miHex); -1497 -1498 for (var i = 2; i < idxList.length; i++) { -1499 var idx = idxList[i]; -1500 var tag = h.substr(idx, 2); -1501 if (tag == "06") { // case OID -1502 var policyHex = _getV(h, idx); -1503 json.policy = _ASN1HEX.hextooidstr(policyHex); -1504 } -1505 if (tag == "02") { // case INTEGER -1506 json.nonce = _getV(h, idx); -1507 } -1508 if (tag == "01") { // case BOOLEAN -1509 json.certreq = true; -1510 } -1511 } -1512 -1513 return json; -1514 }; -1515 }; -1516