diff --git a/ChangeLog.txt b/ChangeLog.txt index 7ff3d36d..73f0610b 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,19 @@ ChangeLog for jsrsasign +add SigningCertificateV2 for CMSParser and issue fix +* Changes from 10.1.1 to 10.1.2 release (2020-11-21) + - src/asn1cms.js + - CMSParser + - getAttribute updated to support + SigningCertificateV2 + - add setSigningCertificateV2 method + - add getESSCertIDv2 method + - change sortflag of result parameter to true in + CMSParser.getCertificateSet + - test/qunit-do-asn1cms.html + - updated to follow above + CMSSignedData and TimeStamp parser bugfix * Changes from 10.1.0 to 10.1.1 release (2020-11-20) - src/asn1tsp.js diff --git a/api/files.html b/api/files.html index e50412a6..8e2addf6 100644 --- a/api/files.html +++ b/api/files.html @@ -559,7 +559,7 @@
+ESSCertIDv2 ::= SEQUENCE { + hashAlgorithm AlgorithmIdentifier + DEFAULT {algorithm id-sha256}, + certHash Hash, + issuerSerial IssuerSerial OPTIONAL } +Hash ::= OCTET STRING +IssuerSerial ::= SEQUENCE { + issuer GeneralNames, + serialNumber CertificateSerialNumber } ++ + +
parser = new KJUR.asn1.cms.CMSParser(); +parser.getESSCertID("30...") → +{ + hash: "3f2d...", + alg: "sha512", + issuer: {str: "/C=JP/O=T1"}, + serial: {hex: "12ab..."} +}+ + + + +
parser = new KJUR.asn1.cms.CMSParser(); +pAttr = { + attr: "signingCertificateV2" + valhex: '...' +}; +parser.setSigningCertificateV2(pAttr); +pAttr → { + attr: "signingCertificateV2", + array: [{ + hash: "123456...", + alg: "sha256", + issuer: { + array: [[{type:"C",value:"JP",ds:"prn"},...]], + str: "/C=JP/O=T1" + }, + serial: {hex: "123456..."} + }] +}+ + + + +
1 /* asn1cms-2.0.2.js (c) 2013-2020 Kenji Urushima | kjur.github.io/jsrsasign/license +1 /* asn1cms-2.0.3.js (c) 2013-2020 Kenji Urushima | kjur.github.io/jsrsasign/license 2 */ 3 /* 4 * asn1cms.js - ASN.1 DER encoder and verifier classes for Cryptographic Message Syntax(CMS) @@ -23,7 +23,7 @@ 16 * @fileOverview 17 * @name asn1cms-1.0.js 18 * @author Kenji Urushima kenji.urushima@gmail.com - 19 * @version jsrsasign 10.1.1 asn1cms 2.0.2 (2020-Nov-20) + 19 * @version jsrsasign 10.1.2 asn1cms 2.0.3 (2020-Nov-21) 20 * @since jsrsasign 4.2.4 21 * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a> 22 */ @@ -2719,348 +2719,478 @@ 2712 * Following attribute type are supported in the 2713 * latest version: 2714 * <ul> -2715 * <li>contentType</li> -2716 * <li>messageDigest</li> -2717 * <li>signingTime</li> -2718 * <li>signingCertificate</li> -2719 * </ul> -2720 * -2721 * @example -2722 * parser = new KJUR.asn1.cms.CMSParser(); -2723 * parser.getAttribute("30...") → -2724 * {attr: "contentType", type: "tstinfo"} -2725 */ -2726 this.getAttribute = function(h) { -2727 var pResult = {}; -2728 var aIdx = _getChildIdx(h, 0); -2729 -2730 var attrTypeOID = _ASN1HEX.getOID(h, aIdx[0]); -2731 var attrType = KJUR.asn1.x509.OID.oid2name(attrTypeOID); -2732 pResult.attr = attrType; -2733 -2734 var hSet = _getTLV(h, aIdx[1]); -2735 var aSetIdx = _getChildIdx(hSet, 0); -2736 if (aSetIdx.length == 1) { -2737 pResult.valhex = _getTLV(hSet, aSetIdx[0]); -2738 } else { -2739 var a = []; -2740 for (var i = 0; i < aSetIdx.length; i++) { -2741 a.push(_getTLV(hSet, aSetIdx[i])); -2742 } -2743 pResult.valhex = a; -2744 } -2745 -2746 if (attrType == "contentType") { -2747 this.setContentType(pResult); -2748 } else if (attrType == "messageDigest") { -2749 this.setMessageDigest(pResult); -2750 } else if (attrType == "signingTime") { -2751 this.setSigningTime(pResult); -2752 } else if (attrType == "signingCertificate") { -2753 this.setSigningCertificate(pResult); -2754 } -2755 -2756 return pResult; -2757 }; -2758 -2759 /** -2760 * set ContentType attribute<br/> -2761 * @name setContentType -2762 * @memberOf KJUR.asn1.cms.CMSParser# -2763 * @function -2764 * @param {Array} pAttr JSON object of attribute parameter -2765 * @see KJUR.asn1.cms.CMSParser#getAttribute -2766 * -2767 * @description -2768 * This sets an attribute as ContentType defined in -2769 * RFC 5652 -2770 * <a href="https://tools.ietf.org/html/rfc5652#section-5.1"> -2771 * section 5</a>. -2772 * -2773 * @example -2774 * parser = new KJUR.asn1.cms.CMSParser(); -2775 * pAttr = { -2776 * attr: "contentType" -2777 * valhex: '060b2a864886f70d0109100104' -2778 * }; -2779 * parser.setContentInfo(pAttr); -2780 * pAttr → { -2781 * attr: "contentType" -2782 * type: "tstinfo" -2783 * } -2784 */ -2785 this.setContentType = function(pAttr) { -2786 var contentType = _ASN1HEX.getOIDName(pAttr.valhex, 0, null); -2787 if (contentType != null) { -2788 pAttr.type = contentType; -2789 delete pAttr.valhex; -2790 } -2791 }; -2792 -2793 /** -2794 * set SigningTime attribute<br/> -2795 * @name setSigningTime -2796 * @memberOf KJUR.asn1.cms.CMSParser# -2797 * @function -2798 * @param {Array} pAttr JSON object of attribute parameter -2799 * @see KJUR.asn1.cms.CMSParser#getAttribute -2800 * -2801 * @description -2802 * This sets an attribute as SigningTime defined in -2803 * RFC 5652 -2804 * <a href="https://tools.ietf.org/html/rfc5652#section-5.1"> -2805 * section 5</a>. -2806 * -2807 * @example -2808 * parser = new KJUR.asn1.cms.CMSParser(); -2809 * pAttr = { -2810 * attr: "signingTime" -2811 * valhex: '170d3230313233313233353935395a' -2812 * }; -2813 * parser.setSigningTime(pAttr); -2814 * pAttr → { -2815 * attr: "signingTime", -2816 * str: "2012315959Z" -2817 * } -2818 */ -2819 this.setSigningTime = function(pAttr) { -2820 var hSigningTime = _getV(pAttr.valhex, 0); -2821 var signingTime = hextoutf8(hSigningTime); -2822 pAttr.str = signingTime; -2823 delete pAttr.valhex; -2824 }; -2825 -2826 /** -2827 * set MessageDigest attribute<br/> -2828 * @name setMessageDigest -2829 * @memberOf KJUR.asn1.cms.CMSParser# -2830 * @function -2831 * @param {Array} pAttr JSON object of attribute parameter -2832 * @see KJUR.asn1.cms.CMSParser#getAttribute -2833 * -2834 * @description -2835 * This sets an attribute as SigningTime defined in -2836 * RFC 5652 -2837 * <a href="https://tools.ietf.org/html/rfc5652#section-5.1"> -2838 * section 5</a>. -2839 * -2840 * @example -2841 * parser = new KJUR.asn1.cms.CMSParser(); -2842 * pAttr = { -2843 * attr: "messageDigest" -2844 * valhex: '0403123456' -2845 * }; -2846 * parser.setMessageDigest(pAttr); -2847 * pAttr → { -2848 * attr: "messageDigest", -2849 * hex: "123456" -2850 * } -2851 */ -2852 this.setMessageDigest = function(pAttr) { -2853 var hMD = _getV(pAttr.valhex, 0); -2854 pAttr.hex = hMD; -2855 delete pAttr.valhex; -2856 }; -2857 -2858 /** -2859 * set SigningCertificate attribute<br/> -2860 * @name setSigningCertificate -2861 * @memberOf KJUR.asn1.cms.CMSParser# -2862 * @function -2863 * @param {Array} pAttr JSON object of attribute parameter -2864 * @see KJUR.asn1.cms.CMSParser#getAttribute -2865 * -2866 * @description -2867 * This sets an attribute as SigningCertificate defined in -2868 * <a href="https://tools.ietf.org/html/rfc5035#section-5"> -2869 * RFC 5035 section 5</a>. -2870 * -2871 * @example -2872 * parser = new KJUR.asn1.cms.CMSParser(); -2873 * pAttr = { -2874 * attr: "signingCertificate" -2875 * valhex: '...' -2876 * }; -2877 * parser.setSigningCertificate(pAttr); -2878 * pAttr → { -2879 * attr: "signingCertificate", -2880 * array: [{ -2881 * hash: "123456...", -2882 * issuer: { -2883 * array: [[{type:"C",value:"JP",ds:"prn"},...]], -2884 * str: "/C=JP/O=T1" -2885 * }, -2886 * serial: {hex: "123456..."} -2887 * }] -2888 * } -2889 */ -2890 this.setSigningCertificate = function(pAttr) { -2891 var aIdx = _getChildIdx(pAttr.valhex, 0); -2892 if (aIdx.length > 0) { -2893 var hCerts = _getTLV(pAttr.valhex, aIdx[0]); -2894 var aCertIdx = _getChildIdx(hCerts, 0); -2895 var a = []; -2896 for (var i = 0; i < aCertIdx.length; i++) { -2897 var hESSCertID = _getTLV(hCerts, aCertIdx[i]); -2898 var pESSCertID = this.getESSCertID(hESSCertID); -2899 a.push(pESSCertID); -2900 } -2901 pAttr.array = a; -2902 } -2903 -2904 if (aIdx.length > 1) { -2905 var hPolicies = _getTLV(pAttr.valhex, aIdx[1]); -2906 pAttr.polhex = hPolicies; -2907 } -2908 delete pAttr.valhex; -2909 }; -2910 -2911 /** -2912 * parse ASN.1 ESSCertID<br/> -2913 * @name getESSCertID -2914 * @memberOf KJUR.asn1.cms.CMSParser# -2915 * @function -2916 * @param {String} h hexadecimal string of ASN.1 ESSCertID -2917 * @return {Array} array of JSON object of ESSCertID parameter -2918 * @see KJUR.asn1.cms.ESSCertID -2919 * -2920 * @description -2921 * This method parses ASN.1 ESSCertID defined in -2922 * <a href="https://tools.ietf.org/html/rfc5035#section-6"> -2923 * RFC 5035 section 6</a>. -2924 * <pre> -2925 * ESSCertID ::= SEQUENCE { -2926 * certHash Hash, -2927 * issuerSerial IssuerSerial OPTIONAL } -2928 * IssuerSerial ::= SEQUENCE { -2929 * issuer GeneralNames, -2930 * serialNumber CertificateSerialNumber } -2931 * </pre> -2932 * -2933 * @example -2934 * parser = new KJUR.asn1.cms.CMSParser(); -2935 * parser.getESSCertID("30...") → -2936 * { hash: "12ab...", -2937 * issuer: { -2938 * array: [[{type:"C",value:"JP",ds:"prn"}],...], -2939 * str: "/C=JP/O=T1" -2940 * }, -2941 * serial: {hex: "12ab..."} } -2942 */ -2943 this.getESSCertID = function(h) { -2944 var pResult = {}; -2945 var aIdx = _getChildIdx(h, 0); -2946 -2947 if (aIdx.length > 0) { -2948 var hCertHash = _getV(h, aIdx[0]); -2949 pResult.hash = hCertHash; -2950 } -2951 -2952 if (aIdx.length > 1) { -2953 var hIssuerSerial = _getTLV(h, aIdx[1]); -2954 var pIssuerSerial = -2955 this.getIssuerSerial(hIssuerSerial); -2956 -2957 if (pIssuerSerial.serial != undefined) -2958 pResult.serial = pIssuerSerial.serial; -2959 -2960 if (pIssuerSerial.issuer != undefined) -2961 pResult.issuer = pIssuerSerial.issuer; -2962 } -2963 -2964 return pResult; -2965 }; -2966 -2967 /** -2968 * parse ASN.1 IssuerSerial<br/> -2969 * @name getIssuerSerial -2970 * @memberOf KJUR.asn1.cms.CMSParser# -2971 * @function -2972 * @param {String} h hexadecimal string of ASN.1 IssuerSerial -2973 * @return {Array} array of JSON object of IssuerSerial parameter -2974 * @see KJUR.asn1.cms.IssuerSerial -2975 * @see KJUR.asn1.x509.X500Name -2976 * -2977 * @description -2978 * This method parses ASN.1 IssuerSerial defined in -2979 * <a href="https://tools.ietf.org/html/rfc5035#section-6"> -2980 * RFC 5035 section 6</a>. -2981 * <pre> -2982 * IssuerSerial ::= SEQUENCE { -2983 * issuer GeneralNames, -2984 * serialNumber CertificateSerialNumber } -2985 * </pre> -2986 * -2987 * @example -2988 * parser = new KJUR.asn1.cms.CMSParser(); -2989 * parser.getIssuerSerial("30...") → -2990 * { issuer: { -2991 * array: [[{type:"C",value:"JP",ds:"prn"}],...], -2992 * str: "/C=JP/O=T1", -2993 * }, -2994 * serial: {hex: "12ab..."} } -2995 */ -2996 this.getIssuerSerial = function(h) { -2997 var pResult = {}; -2998 var aIdx = _getChildIdx(h, 0); -2999 -3000 var hIssuer = _getTLV(h, aIdx[0]); -3001 var pIssuerGN = _x509obj.getGeneralNames(hIssuer); -3002 var pIssuerName = pIssuerGN[0].dn; -3003 pResult.issuer = pIssuerName; -3004 -3005 var hSerial = _getV(h, aIdx[1]); -3006 pResult.serial = {hex: hSerial}; -3007 -3008 return pResult; -3009 }; -3010 -3011 /** -3012 * parse ASN.1 CertificateSet<br/> -3013 * @name getCertificateSet -3014 * @memberOf KJUR.asn1.cms.CMSParser# -3015 * @function -3016 * @param {String} h hexadecimal string of ASN.1 CertificateSet -3017 * @return {Array} array of JSON object of CertificateSet parameter -3018 * @see KJUR.asn1.cms.CertificateSet -3019 * -3020 * @description -3021 * This method parses ASN.1 IssuerSerial defined in -3022 * <a href="https://tools.ietf.org/html/rfc5652#section-10.2.3"> -3023 * RFC 5652 CMS section 10.2.3</a> and -3024 * <a href="https://tools.ietf.org/html/rfc5652#section-10.2.2"> -3025 * section 10.2.2</a>. -3026 * <pre> -3027 * CertificateSet ::= SET OF CertificateChoices -3028 * CertificateChoices ::= CHOICE { -3029 * certificate Certificate, -3030 * extendedCertificate [0] IMPLICIT ExtendedCertificate, -- Obsolete -3031 * v1AttrCert [1] IMPLICIT AttributeCertificateV1, -- Obsolete -3032 * v2AttrCert [2] IMPLICIT AttributeCertificateV2, -3033 * other [3] IMPLICIT OtherCertificateFormat } -3034 * OtherCertificateFormat ::= SEQUENCE { -3035 * otherCertFormat OBJECT IDENTIFIER, -3036 * otherCert ANY DEFINED BY otherCertFormat } -3037 * </pre> -3038 * Currently only "certificate" is supported in -3039 * CertificateChoices. -3040 * -3041 * @example -3042 * parser = new KJUR.asn1.cms.CMSParser(); -3043 * parser.getCertificateSet("a0...") → -3044 * [ "-----BEGIN CERTIFICATE...", ... ] -3045 */ -3046 this.getCertificateSet = function(h) { -3047 var aIdx = _getChildIdx(h, 0); -3048 var a = []; -3049 for (var i = 0; i < aIdx.length; i++) { -3050 var hCert = _getTLV(h, aIdx[i]); -3051 if (hCert.substr(0, 2) == "30") { -3052 var pem = hextopem(hCert, "CERTIFICATE"); -3053 a.push(pem); -3054 } -3055 } -3056 return a; -3057 }; -3058 }; -3059