diff --git a/ChangeLog.txt b/ChangeLog.txt index 36c0a6db..829ecba4 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,18 @@ ChangeLog for jsrsasign +extend support for distinguished name +* Changes from 10.1.9 to 10.1.10 release (2021-02-14) + - src/asn1x509.js + - AttributeTypeAndValue + - add support for OID and oid name constructor + AttributeTypeAndValue({str: "/streetAddress=foo"}) + AttributeTypeAndValue({str: "/2.5.4.9=foo"}) + - OID.name2oidList + - add givenName + - test/qunit-do-asn1x509.html + - updated to follow above + Add SubjectDirectoryAttributes extension support * Changes from 10.1.8 to 10.1.9 release (2021-02-12) - src/asn1x509.js diff --git a/Makefile b/Makefile index 99a486c3..578bbdea 100644 --- a/Makefile +++ b/Makefile @@ -22,12 +22,54 @@ FILES_MIN = \ min/jwsjs-2.0.min.js \ min/x509crl.min.js \ min/nodeutil-1.0.min.js - + +JSDOC_SRC = \ + asn1hex-1.1.js \ + rsapem-1.1.js \ + rsasign-1.2.js \ + x509-1.1.js \ + keyutil-1.0.js \ + asn1-1.0.js \ + asn1x509-1.0.js \ + asn1cms-1.0.js \ + asn1tsp-1.0.js \ + asn1cades-1.0.js \ + asn1csr-1.0.js \ + asn1ocsp-1.0.js \ + crypto-1.1.js \ + ecdsa-modified-1.0.js \ + ecparam-1.0.js \ + dsa-2.0.js \ + base64x-1.1.js \ + jws-3.3.js \ + jwsjs-2.0.js \ + x509crl.js \ + nodeutil-1.0.js + FILES_EXT_MIN = \ ext/ec-min.js \ ext/rsa-min.js \ ext/rsa2-min.js +JSRUN=jsrun-jsrsasign.sh + +JSDOCOUTDIR1=_tmp + +APIDOCDIR=api + +jsdoc: + rm -rf $(APIDOCDIR) + mkdir $(APIDOCDIR) + ( \ + cd src; \ + ${JSRUN} $(JSDOC_SRC) \ + -d=../$(APIDOCDIR) -v \ + ) + mv $(APIDOCDIR)/symbols/_global_.html $(APIDOCDIR)/symbols/global__.html + find $(APIDOCDIR) -type f -name "*.html" -print0 | xargs -0 sed -i.bak -e "s/_global_/global__/g" + find $(APIDOCDIR) -type f -name "*.html" -print0 | xargs -0 sed -i.bak -e "s/2012-2020/2012-2021/g" + find $(APIDOCDIR) -type f -name "*.html.bak" -exec rm {} \; + all-min: $(FILES_MIN) @echo "all min converted." diff --git a/README.md b/README.md index cc716b8c..aabd76d0 100755 --- a/README.md +++ b/README.md @@ -33,7 +33,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=2021-02-06) +- very popular crypto library with [0.6M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2021-02-12) INSTALL ------- diff --git a/api/files.html b/api/files.html index 88fd6991..c7fc55e4 100644 --- a/api/files.html +++ b/api/files.html @@ -656,7 +656,7 @@
new KJUR.asn1.x509.AttributeTypeAndValue({type:'C',value:'US',ds:'prn'}) +new KJUR.asn1.x509.AttributeTypeAndValue({type:'givenName',value:'John',ds:'prn'}) +new KJUR.asn1.x509.AttributeTypeAndValue({type:'2.5.4.9',value:'71 Bowman St',ds:'prn'}) new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1'}) +new KJUR.asn1.x509.AttributeTypeAndValue({str:'streetAddress=71 Bowman St'}) new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1',rule='prn'}) new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1',rule='utf8'})@@ -689,7 +692,7 @@
KJUR.asn1.x509.OID.atype2obj('CN') → 2.5.4.3 -KJUR.asn1.x509.OID.atype2obj('OU') → 2.5.4.11+
KJUR.asn1.x509.OID.atype2obj('CN') → DERObjectIdentifier of 2.5.4.3 +KJUR.asn1.x509.OID.atype2obj('OU') → DERObjectIdentifier of 2.5.4.11 +KJUR.asn1.x509.OID.atype2obj('streetAddress') → DERObjectIdentifier of 2.5.4.9 +KJUR.asn1.x509.OID.atype2obj('2.5.4.9') → DERObjectIdentifier of 2.5.4.9@@ -847,7 +849,7 @@
1 /* asn1hex-1.2.8.js (c) 2012-2020 Kenji Urushima | kjur.github.com/jsrsasign/license +1 /* asn1hex-1.2.8.js (c) 2012-2021 Kenji Urushima | kjur.github.com/jsrsasign/license 2 */ 3 /* 4 * asn1hex.js - Hexadecimal represented ASN.1 string library diff --git a/api/symbols/src/asn1x509-1.0.js.html b/api/symbols/src/asn1x509-1.0.js.html index 595c349f..d0c12a80 100644 --- a/api/symbols/src/asn1x509-1.0.js.html +++ b/api/symbols/src/asn1x509-1.0.js.html @@ -5,7 +5,7 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -1 /* asn1x509-2.1.7.js (c) 2013-2021 Kenji Urushima | kjur.github.com/jsrsasign/license +1 /* asn1x509-2.1.8.js (c) 2013-2021 Kenji Urushima | kjur.github.com/jsrsasign/license 2 */ 3 /* 4 * asn1x509.js - ASN.1 DER encoder classes for X.509 certificate @@ -23,7 +23,7 @@ 16 * @fileOverview 17 * @name asn1x509-1.0.js 18 * @author Kenji Urushima kenji.urushima@gmail.com - 19 * @version jsrsasign 10.1.9 asn1x509 2.1.7 (2021-Feb-12) + 19 * @version jsrsasign 10.1.10 asn1x509 2.1.8 (2021-Feb-14) 20 * @since jsrsasign 2.1 21 * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a> 22 */ @@ -93,4232 +93,4250 @@ 86 * <li>{@link KJUR.asn1.x509.CertificatePolicies}</li> 87 * <li>{@link KJUR.asn1.x509.CRLNumber}</li> 88 * <li>{@link KJUR.asn1.x509.CRLReason}</li> - 89 * <li>{@link KJUR.asn1.x509.OCSPNonce</li> - 90 * <li>{@link KJUR.asn1.x509.OCSPNoCheck</li> + 89 * <li>{@link KJUR.asn1.x509.OCSPNonce}</li> + 90 * <li>{@link KJUR.asn1.x509.OCSPNoCheck}</li> 91 * <li>{@link KJUR.asn1.x509.AdobeTimeStamp}</li> - 92 * </ul> - 93 * NOTE1: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2.<br/> - 94 * NOTE2: SubjectAltName and IssuerAltName supported since - 95 * jsrsasign 6.2.3 asn1x509 1.0.19.<br/> - 96 * NOTE3: CeritifcatePolicies supported supported since - 97 * jsrsasign 8.0.23 asn1x509 1.1.12<br/> - 98 * @name KJUR.asn1.x509 - 99 * @namespace -100 */ -101 if (typeof KJUR.asn1.x509 == "undefined" || !KJUR.asn1.x509) KJUR.asn1.x509 = {}; -102 -103 // === BEGIN Certificate =================================================== -104 -105 /** -106 * X.509 Certificate class to sign and generate hex encoded certificate -107 * @name KJUR.asn1.x509.Certificate -108 * @class X.509 Certificate class to sign and generate hex encoded certificate -109 * @property {Array} params JSON object of parameters -110 * @param {Array} params JSON object for Certificate parameters -111 * @extends KJUR.asn1.ASN1Object -112 * @description -113 * <br/> -114 * This class provides Certificate ASN.1 class structure -115 * defined in -116 * <a href="https://tools.ietf.org/html/rfc5280#section-4.1"> -117 * RFC 5280 4.1</a>. -118 * <pre> -119 * Certificate ::= SEQUENCE { -120 * tbsCertificate TBSCertificate, -121 * signatureAlgorithm AlgorithmIdentifier, -122 * signatureValue BIT STRING } -123 * </pre> -124 * Parameter "params" JSON object can be -125 * the same as {@link KJUR.asn1.x509.TBSCertificate}. -126 * Then they are used to generate TBSCertificate. -127 * Additionally just for Certificate, following parameters can be used: -128 * <ul> -129 * <li>{TBSCertfificate}tbsobj - -130 * specifies {@link KJUR.asn1.x509.TBSCertificate} -131 * object to be signed if needed. -132 * When this isn't specified, -133 * this will be set from other parametes of TBSCertificate.</li> -134 * <li>{Object}cakey (OPTION) - specifies certificate signing private key. -135 * Parameter "cakey" or "sighex" shall be specified. Following -136 * values can be specified: -137 * <ul> -138 * <li>PKCS#1/5 or PKCS#8 PEM string of private key</li> -139 * <li>RSAKey/DSA/ECDSA key object. {@link KEYUTIL.getKey} is useful -140 * to generate a key object.</li> -141 * </ul> -142 * </li> -143 * <li>{String}sighex (OPTION) - hexadecimal string of signature value -144 * (i.e. ASN.1 value(V) of signatureValue BIT STRING without -145 * unused bits)</li> -146 * </ul> -147 * CAUTION: APIs of this class have been totally updated without -148 * backward compatibility since jsrsasign 9.0.0.<br/> -149 * NOTE1: 'params' can be omitted.<br/> -150 * NOTE2: DSA/ECDSA is also supported for CA signging key from asn1x509 1.0.6. -151 * @example -152 * var cert = new KJUR.asn1.x509.Certificate({ -153 * version: 3, -154 * serial: {hex: "1234..."}, -155 * sigalg: "SHA256withRSAandMGF1", -156 * ... -157 * sighex: "1d3f..." // sign() method won't be called -158 * }); -159 * -160 * // sighex will by calculated by signing with cakey -161 * var cert = new KJUR.asn1.x509.Certificate({ -162 * version: 3, -163 * serial: {hex: "2345..."}, -164 * sigalg: "SHA256withRSA", -165 * ... -166 * cakey: "-----BEGIN PRIVATE KEY..." -167 * }); -168 * -169 * // use TBSCertificate object to sign -170 * var cert = new KJUR.asn1.x509.Certificate({ -171 * tbsobj: <<OBJ>>, -172 * sigalg: "SHA256withRSA", -173 * cakey: "-----BEGIN PRIVATE KEY..." -174 * }); -175 */ -176 KJUR.asn1.x509.Certificate = function(params) { -177 KJUR.asn1.x509.Certificate.superclass.constructor.call(this); -178 var _KJUR = KJUR, -179 _KJUR_asn1 = _KJUR.asn1, -180 _DERBitString = _KJUR_asn1.DERBitString, -181 _DERSequence = _KJUR_asn1.DERSequence, -182 _KJUR_asn1_x509 = _KJUR_asn1.x509, -183 _TBSCertificate = _KJUR_asn1_x509.TBSCertificate, -184 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier; -185 -186 this.params = undefined; -187 -188 /** -189 * set parameter<br/> -190 * @name setByParam -191 * @memberOf KJUR.asn1.x509.Certificate# -192 * @function -193 * @param params {Array} JSON object of certificate parameters -194 * @since jsrsasign 9.0.0 asn1hex 2.0.0 -195 * @description -196 * This method will set parameter -197 * {@link KJUR.asn1.x509.Certificate#params} -198 * to this object. -199 * @example -200 * cert = new KJUR.asn1.x509.Certificate(); -201 * cert.setByParam({ -202 * version: 3, -203 * serial: {hex: "1234..."}, -204 * ... -205 * }); -206 */ -207 this.setByParam = function(params) { -208 this.params = params; -209 }; -210 -211 /** -212 * sign certificate<br/> -213 * @name sign -214 * @memberOf KJUR.asn1.x509.Certificate# -215 * @function -216 * @description -217 * This method signs TBSCertificate with a specified -218 * private key and algorithm by -219 * this.params.cakey and this.params.sigalg parameter. -220 * @example -221 * cert = new KJUR.asn1.x509.Certificate({...}); -222 * cert.sign() -223 */ -224 this.sign = function() { -225 var params = this.params; -226 -227 var sigalg = params.sigalg; -228 if (params.sigalg.name != undefined) -229 sigalg = params.sigalg.name; -230 -231 var hTBS = params.tbsobj.getEncodedHex(); -232 var sig = new KJUR.crypto.Signature({alg: sigalg}); -233 sig.init(params.cakey); -234 sig.updateHex(hTBS); -235 params.sighex = sig.sign(); -236 }; -237 -238 /** -239 * get PEM formatted certificate string after signed -240 * @name getPEM -241 * @memberOf KJUR.asn1.x509.Certificate# -242 * @function -243 * @return PEM formatted string of certificate -244 * @since jsrsasign 9.0.0 asn1hex 2.0.0 -245 * @description -246 * This method returns a string of PEM formatted -247 * certificate. -248 * @example -249 * cert = new KJUR.asn1.x509.Certificate({...}); -250 * cert.getPEM() → -251 * "-----BEGIN CERTIFICATE-----\r\n..." -252 */ -253 this.getPEM = function() { -254 return hextopem(this.getEncodedHex(), "CERTIFICATE"); -255 }; -256 -257 this.getEncodedHex = function() { -258 var params = this.params; -259 -260 if (params.tbsobj == undefined || params.tbsobj == null) { -261 params.tbsobj = new _TBSCertificate(params); -262 } -263 -264 if (params.sighex == undefined && params.cakey != undefined) { -265 this.sign(); -266 } -267 -268 if (params.sighex == undefined) { -269 throw new Error("sighex or cakey parameter not defined"); -270 } -271 -272 var a = []; -273 a.push(params.tbsobj); -274 a.push(new _AlgorithmIdentifier({name: params.sigalg})); -275 a.push(new _DERBitString({hex: "00" + params.sighex})); -276 var seq = new _DERSequence({array: a}); -277 return seq.getEncodedHex(); -278 }; -279 -280 if (params != undefined) this.params = params; -281 }; -282 YAHOO.lang.extend(KJUR.asn1.x509.Certificate, KJUR.asn1.ASN1Object); -283 -284 /** -285 * ASN.1 TBSCertificate structure class<br/> -286 * @name KJUR.asn1.x509.TBSCertificate -287 * @class ASN.1 TBSCertificate structure class -288 * @property {Array} params JSON object of parameters -289 * @param {Array} params JSON object of TBSCertificate parameters -290 * @extends KJUR.asn1.ASN1Object -291 * @see KJUR.asn1.x509.Certificate -292 * -293 * @description -294 * <br/> -295 * NOTE: TBSCertificate class is updated without backward -296 * compatibility from jsrsasign 9.0.0 asn1x509 2.0.0. -297 * Most of methods are removed and parameters can be set -298 * by JSON object. -299 * -300 * @example -301 * new TBSCertificate({ -302 * version: 3, // this can be omitted, the default is 3. -303 * serial: {hex: "1234..."}, // DERInteger parameter -304 * sigalg: "SHA256withRSA", -305 * issuer: {array:[[{type:'O',value:'Test',ds:'prn'}]]}, // X500Name parameter -306 * notbefore: "151231235959Z", // string, passed to Time -307 * notafter: "251231235959Z", // string, passed to Time -308 * subject: {array:[[{type:'O',value:'Test',ds:'prn'}]]}, // X500Name parameter -309 * sbjpubkey: "-----BEGIN...", // KEYUTIL.getKey pubkey parameter -310 * // As for extension parameters, please see extension class -311 * // All extension parameters need to have "extname" parameter additionaly. -312 * ext:[{ -313 * extname:"keyUsage",critical:true, -314 * names:["digitalSignature","keyEncipherment"] -315 * },{ -316 * extname:"cRLDistributionPoints", -317 * array:[{dpname:{full:[{uri:"http://example.com/a1.crl"}]}}] -318 * }, ...] -319 * }) -320 * -321 * var tbsc = new TBSCertificate(); -322 * tbsc.setByParam({version:3,serial:{hex:'1234...'},...}); -323 */ -324 KJUR.asn1.x509.TBSCertificate = function(params) { -325 KJUR.asn1.x509.TBSCertificate.superclass.constructor.call(this); -326 var _KJUR = KJUR, -327 _KJUR_asn1 = _KJUR.asn1, -328 _KJUR_asn1_x509 = _KJUR_asn1.x509, -329 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, -330 _DERInteger = _KJUR_asn1.DERInteger, -331 _DERSequence = _KJUR_asn1.DERSequence, -332 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, -333 _Time = _KJUR_asn1_x509.Time, -334 _X500Name = _KJUR_asn1_x509.X500Name, -335 _Extensions = _KJUR_asn1_x509.Extensions, -336 _SubjectPublicKeyInfo = _KJUR_asn1_x509.SubjectPublicKeyInfo; -337 -338 this.params = null; -339 -340 /** -341 * get array of ASN.1 object for extensions<br/> -342 * @name setByParam -343 * @memberOf KJUR.asn1.x509.TBSCertificate# -344 * @function -345 * @param {Array} JSON object of TBSCertificate parameters -346 * @example -347 * tbsc = new KJUR.asn1.x509.TBSCertificate(); -348 * tbsc.setByParam({version:3, serial:{hex:'1234...'},...}); -349 */ -350 this.setByParam = function(params) { -351 this.params = params; -352 }; -353 -354 this.getEncodedHex = function() { -355 var a = []; -356 var params = this.params; -357 -358 // X.509v3 default if params.version not defined -359 if (params.version != undefined || params.version != 1) { -360 var version = 2; -361 if (params.version != undefined) version = params.version - 1; -362 var obj = -363 new _DERTaggedObject({obj: new _DERInteger({'int': version})}) -364 a.push(obj); -365 } -366 -367 a.push(new _DERInteger(params.serial)); -368 a.push(new _AlgorithmIdentifier({name: params.sigalg})); -369 a.push(new _X500Name(params.issuer)); -370 a.push(new _DERSequence({array:[new _Time(params.notbefore), -371 new _Time(params.notafter)]})); -372 a.push(new _X500Name(params.subject)); -373 a.push(new _SubjectPublicKeyInfo(KEYUTIL.getKey(params.sbjpubkey))); -374 if (params.ext !== undefined && params.ext.length > 0) { -375 a.push(new _DERTaggedObject({tag: "a3", -376 obj: new _Extensions(params.ext)})); -377 } -378 -379 var seq = new KJUR.asn1.DERSequence({array: a}); -380 return seq.getEncodedHex(); -381 }; -382 -383 if (params !== undefined) this.setByParam(params); -384 }; -385 YAHOO.lang.extend(KJUR.asn1.x509.TBSCertificate, KJUR.asn1.ASN1Object); -386 -387 /** -388 * Extensions ASN.1 structure class<br/> -389 * @name KJUR.asn1.x509.Extensions -390 * @class Extensions ASN.1 structure class -391 * @param {Array} aParam array of JSON extension parameter -392 * @extends KJUR.asn1.ASN1Object -393 * @since jsrsasign 9.1.0 asn1x509 2.1.0 -394 * @see KJUR.asn1.x509.TBSCertificate -395 * @see KJUR.asn1.x509.TBSCertList -396 * @see KJUR.asn1.csr.CertificationRequestInfo -397 * @see KJUR.asn1.x509.PrivateExtension -398 * -399 * @description -400 * This class represents -401 * <a href="https://tools.ietf.org/html/rfc5280#section-4.1"> -402 * Extensions defined in RFC 5280 4.1</a> and -403 * <a href="https://tools.ietf.org/html/rfc5280#section-4.1.2.9"> -404 * 4.1.2.9</a>. -405 * <pre> -406 * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension -407 * </pre> -408 * NOTE: From jsrsasign 9.1.1, private extension or -409 * undefined extension have been supported by -410 * {@link KJUR.asn1.x509.PrivateExtension}. -411 * -412 * @example -413 * o = new KJUR.asn1.x509.Extensions([ -414 * {extname:"keyUsage",critical:true,names:["digitalSignature"]}, -415 * {extname:"subjectAltName",array:[{dns:"example.com"}]}, -416 * {extname:"1.2.3.4",extn:{prnstr:"aa"}} // private extension -417 * ]); -418 * o.getEncodedHex() → "30..." -419 */ -420 KJUR.asn1.x509.Extensions = function(aParam) { -421 KJUR.asn1.x509.Extensions.superclass.constructor.call(this); -422 var _KJUR = KJUR, -423 _KJUR_asn1 = _KJUR.asn1, -424 _DERSequence = _KJUR_asn1.DERSequence, -425 _KJUR_asn1_x509 = _KJUR_asn1.x509; -426 this.aParam = []; -427 -428 this.setByParam = function(aParam) { this.aParam = aParam; } -429 -430 this.getEncodedHex = function() { -431 var a = []; -432 for (var i = 0; i < this.aParam.length; i++) { -433 var param = this.aParam[i]; -434 var extname = param.extname; -435 var obj = null; -436 -437 if (param.extn != undefined) { -438 obj = new _KJUR_asn1_x509.PrivateExtension(param); -439 } else if (extname == "subjectKeyIdentifier") { -440 obj = new _KJUR_asn1_x509.SubjectKeyIdentifier(param); -441 } else if (extname == "keyUsage") { -442 obj = new _KJUR_asn1_x509.KeyUsage(param); -443 } else if (extname == "subjectAltName") { -444 obj = new _KJUR_asn1_x509.SubjectAltName(param); -445 } else if (extname == "issuerAltName") { -446 obj = new _KJUR_asn1_x509.IssuerAltName(param); -447 } else if (extname == "basicConstraints") { -448 obj = new _KJUR_asn1_x509.BasicConstraints(param); -449 } else if (extname == "cRLDistributionPoints") { -450 obj = new _KJUR_asn1_x509.CRLDistributionPoints(param); -451 } else if (extname == "certificatePolicies") { -452 obj = new _KJUR_asn1_x509.CertificatePolicies(param); -453 } else if (extname == "authorityKeyIdentifier") { -454 obj = new _KJUR_asn1_x509.AuthorityKeyIdentifier(param); -455 } else if (extname == "extKeyUsage") { -456 obj = new _KJUR_asn1_x509.ExtKeyUsage(param); -457 } else if (extname == "authorityInfoAccess") { -458 obj = new _KJUR_asn1_x509.AuthorityInfoAccess(param); -459 } else if (extname == "cRLNumber") { -460 obj = new _KJUR_asn1_x509.CRLNumber(param); -461 } else if (extname == "cRLReason") { -462 obj = new _KJUR_asn1_x509.CRLReason(param); -463 } else if (extname == "ocspNonce") { -464 obj = new _KJUR_asn1_x509.OCSPNonce(param); -465 } else if (extname == "ocspNoCheck") { -466 obj = new _KJUR_asn1_x509.OCSPNoCheck(param); -467 } else if (extname == "adobeTimeStamp") { -468 obj = new _KJUR_asn1_x509.AdobeTimeStamp(param); -469 } else if (extname == "subjectDirectoryAttributes") { -470 obj = new _KJUR_asn1_x509.SubjectDirectoryAttributes(param); -471 } else { -472 throw new Error("extension not supported:" -473 + JSON.stringify(param)); -474 } -475 if (obj != null) a.push(obj); -476 } -477 -478 var seq = new _DERSequence({array: a}); -479 return seq.getEncodedHex(); -480 }; -481 -482 if (aParam != undefined) this.setByParam(aParam); -483 }; -484 YAHOO.lang.extend(KJUR.asn1.x509.Extensions, KJUR.asn1.ASN1Object); -485 + 92 * <li>{@link KJUR.asn1.x509.SubjectDirectoryAttributes}</li> + 93 * </ul> + 94 * NOTE1: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2.<br/> + 95 * NOTE2: SubjectAltName and IssuerAltName supported since + 96 * jsrsasign 6.2.3 asn1x509 1.0.19.<br/> + 97 * NOTE3: CeritifcatePolicies supported supported since + 98 * jsrsasign 8.0.23 asn1x509 1.1.12<br/> + 99 * @name KJUR.asn1.x509 +100 * @namespace +101 */ +102 if (typeof KJUR.asn1.x509 == "undefined" || !KJUR.asn1.x509) KJUR.asn1.x509 = {}; +103 +104 // === BEGIN Certificate =================================================== +105 +106 /** +107 * X.509 Certificate class to sign and generate hex encoded certificate +108 * @name KJUR.asn1.x509.Certificate +109 * @class X.509 Certificate class to sign and generate hex encoded certificate +110 * @property {Array} params JSON object of parameters +111 * @param {Array} params JSON object for Certificate parameters +112 * @extends KJUR.asn1.ASN1Object +113 * @description +114 * <br/> +115 * This class provides Certificate ASN.1 class structure +116 * defined in +117 * <a href="https://tools.ietf.org/html/rfc5280#section-4.1"> +118 * RFC 5280 4.1</a>. +119 * <pre> +120 * Certificate ::= SEQUENCE { +121 * tbsCertificate TBSCertificate, +122 * signatureAlgorithm AlgorithmIdentifier, +123 * signatureValue BIT STRING } +124 * </pre> +125 * Parameter "params" JSON object can be +126 * the same as {@link KJUR.asn1.x509.TBSCertificate}. +127 * Then they are used to generate TBSCertificate. +128 * Additionally just for Certificate, following parameters can be used: +129 * <ul> +130 * <li>{TBSCertfificate}tbsobj - +131 * specifies {@link KJUR.asn1.x509.TBSCertificate} +132 * object to be signed if needed. +133 * When this isn't specified, +134 * this will be set from other parametes of TBSCertificate.</li> +135 * <li>{Object}cakey (OPTION) - specifies certificate signing private key. +136 * Parameter "cakey" or "sighex" shall be specified. Following +137 * values can be specified: +138 * <ul> +139 * <li>PKCS#1/5 or PKCS#8 PEM string of private key</li> +140 * <li>RSAKey/DSA/ECDSA key object. {@link KEYUTIL.getKey} is useful +141 * to generate a key object.</li> +142 * </ul> +143 * </li> +144 * <li>{String}sighex (OPTION) - hexadecimal string of signature value +145 * (i.e. ASN.1 value(V) of signatureValue BIT STRING without +146 * unused bits)</li> +147 * </ul> +148 * CAUTION: APIs of this class have been totally updated without +149 * backward compatibility since jsrsasign 9.0.0.<br/> +150 * NOTE1: 'params' can be omitted.<br/> +151 * NOTE2: DSA/ECDSA is also supported for CA signging key from asn1x509 1.0.6. +152 * @example +153 * var cert = new KJUR.asn1.x509.Certificate({ +154 * version: 3, +155 * serial: {hex: "1234..."}, +156 * sigalg: "SHA256withRSAandMGF1", +157 * ... +158 * sighex: "1d3f..." // sign() method won't be called +159 * }); +160 * +161 * // sighex will by calculated by signing with cakey +162 * var cert = new KJUR.asn1.x509.Certificate({ +163 * version: 3, +164 * serial: {hex: "2345..."}, +165 * sigalg: "SHA256withRSA", +166 * ... +167 * cakey: "-----BEGIN PRIVATE KEY..." +168 * }); +169 * +170 * // use TBSCertificate object to sign +171 * var cert = new KJUR.asn1.x509.Certificate({ +172 * tbsobj: <<OBJ>>, +173 * sigalg: "SHA256withRSA", +174 * cakey: "-----BEGIN PRIVATE KEY..." +175 * }); +176 */ +177 KJUR.asn1.x509.Certificate = function(params) { +178 KJUR.asn1.x509.Certificate.superclass.constructor.call(this); +179 var _KJUR = KJUR, +180 _KJUR_asn1 = _KJUR.asn1, +181 _DERBitString = _KJUR_asn1.DERBitString, +182 _DERSequence = _KJUR_asn1.DERSequence, +183 _KJUR_asn1_x509 = _KJUR_asn1.x509, +184 _TBSCertificate = _KJUR_asn1_x509.TBSCertificate, +185 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier; +186 +187 this.params = undefined; +188 +189 /** +190 * set parameter<br/> +191 * @name setByParam +192 * @memberOf KJUR.asn1.x509.Certificate# +193 * @function +194 * @param params {Array} JSON object of certificate parameters +195 * @since jsrsasign 9.0.0 asn1hex 2.0.0 +196 * @description +197 * This method will set parameter +198 * {@link KJUR.asn1.x509.Certificate#params} +199 * to this object. +200 * @example +201 * cert = new KJUR.asn1.x509.Certificate(); +202 * cert.setByParam({ +203 * version: 3, +204 * serial: {hex: "1234..."}, +205 * ... +206 * }); +207 */ +208 this.setByParam = function(params) { +209 this.params = params; +210 }; +211 +212 /** +213 * sign certificate<br/> +214 * @name sign +215 * @memberOf KJUR.asn1.x509.Certificate# +216 * @function +217 * @description +218 * This method signs TBSCertificate with a specified +219 * private key and algorithm by +220 * this.params.cakey and this.params.sigalg parameter. +221 * @example +222 * cert = new KJUR.asn1.x509.Certificate({...}); +223 * cert.sign() +224 */ +225 this.sign = function() { +226 var params = this.params; +227 +228 var sigalg = params.sigalg; +229 if (params.sigalg.name != undefined) +230 sigalg = params.sigalg.name; +231 +232 var hTBS = params.tbsobj.getEncodedHex(); +233 var sig = new KJUR.crypto.Signature({alg: sigalg}); +234 sig.init(params.cakey); +235 sig.updateHex(hTBS); +236 params.sighex = sig.sign(); +237 }; +238 +239 /** +240 * get PEM formatted certificate string after signed +241 * @name getPEM +242 * @memberOf KJUR.asn1.x509.Certificate# +243 * @function +244 * @return PEM formatted string of certificate +245 * @since jsrsasign 9.0.0 asn1hex 2.0.0 +246 * @description +247 * This method returns a string of PEM formatted +248 * certificate. +249 * @example +250 * cert = new KJUR.asn1.x509.Certificate({...}); +251 * cert.getPEM() → +252 * "-----BEGIN CERTIFICATE-----\r\n..." +253 */ +254 this.getPEM = function() { +255 return hextopem(this.getEncodedHex(), "CERTIFICATE"); +256 }; +257 +258 this.getEncodedHex = function() { +259 var params = this.params; +260 +261 if (params.tbsobj == undefined || params.tbsobj == null) { +262 params.tbsobj = new _TBSCertificate(params); +263 } +264 +265 if (params.sighex == undefined && params.cakey != undefined) { +266 this.sign(); +267 } +268 +269 if (params.sighex == undefined) { +270 throw new Error("sighex or cakey parameter not defined"); +271 } +272 +273 var a = []; +274 a.push(params.tbsobj); +275 a.push(new _AlgorithmIdentifier({name: params.sigalg})); +276 a.push(new _DERBitString({hex: "00" + params.sighex})); +277 var seq = new _DERSequence({array: a}); +278 return seq.getEncodedHex(); +279 }; +280 +281 if (params != undefined) this.params = params; +282 }; +283 YAHOO.lang.extend(KJUR.asn1.x509.Certificate, KJUR.asn1.ASN1Object); +284 +285 /** +286 * ASN.1 TBSCertificate structure class<br/> +287 * @name KJUR.asn1.x509.TBSCertificate +288 * @class ASN.1 TBSCertificate structure class +289 * @property {Array} params JSON object of parameters +290 * @param {Array} params JSON object of TBSCertificate parameters +291 * @extends KJUR.asn1.ASN1Object +292 * @see KJUR.asn1.x509.Certificate +293 * +294 * @description +295 * <br/> +296 * NOTE: TBSCertificate class is updated without backward +297 * compatibility from jsrsasign 9.0.0 asn1x509 2.0.0. +298 * Most of methods are removed and parameters can be set +299 * by JSON object. +300 * +301 * @example +302 * new TBSCertificate({ +303 * version: 3, // this can be omitted, the default is 3. +304 * serial: {hex: "1234..."}, // DERInteger parameter +305 * sigalg: "SHA256withRSA", +306 * issuer: {array:[[{type:'O',value:'Test',ds:'prn'}]]}, // X500Name parameter +307 * notbefore: "151231235959Z", // string, passed to Time +308 * notafter: "251231235959Z", // string, passed to Time +309 * subject: {array:[[{type:'O',value:'Test',ds:'prn'}]]}, // X500Name parameter +310 * sbjpubkey: "-----BEGIN...", // KEYUTIL.getKey pubkey parameter +311 * // As for extension parameters, please see extension class +312 * // All extension parameters need to have "extname" parameter additionaly. +313 * ext:[{ +314 * extname:"keyUsage",critical:true, +315 * names:["digitalSignature","keyEncipherment"] +316 * },{ +317 * extname:"cRLDistributionPoints", +318 * array:[{dpname:{full:[{uri:"http://example.com/a1.crl"}]}}] +319 * }, ...] +320 * }) +321 * +322 * var tbsc = new TBSCertificate(); +323 * tbsc.setByParam({version:3,serial:{hex:'1234...'},...}); +324 */ +325 KJUR.asn1.x509.TBSCertificate = function(params) { +326 KJUR.asn1.x509.TBSCertificate.superclass.constructor.call(this); +327 var _KJUR = KJUR, +328 _KJUR_asn1 = _KJUR.asn1, +329 _KJUR_asn1_x509 = _KJUR_asn1.x509, +330 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, +331 _DERInteger = _KJUR_asn1.DERInteger, +332 _DERSequence = _KJUR_asn1.DERSequence, +333 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, +334 _Time = _KJUR_asn1_x509.Time, +335 _X500Name = _KJUR_asn1_x509.X500Name, +336 _Extensions = _KJUR_asn1_x509.Extensions, +337 _SubjectPublicKeyInfo = _KJUR_asn1_x509.SubjectPublicKeyInfo; +338 +339 this.params = null; +340 +341 /** +342 * get array of ASN.1 object for extensions<br/> +343 * @name setByParam +344 * @memberOf KJUR.asn1.x509.TBSCertificate# +345 * @function +346 * @param {Array} JSON object of TBSCertificate parameters +347 * @example +348 * tbsc = new KJUR.asn1.x509.TBSCertificate(); +349 * tbsc.setByParam({version:3, serial:{hex:'1234...'},...}); +350 */ +351 this.setByParam = function(params) { +352 this.params = params; +353 }; +354 +355 this.getEncodedHex = function() { +356 var a = []; +357 var params = this.params; +358 +359 // X.509v3 default if params.version not defined +360 if (params.version != undefined || params.version != 1) { +361 var version = 2; +362 if (params.version != undefined) version = params.version - 1; +363 var obj = +364 new _DERTaggedObject({obj: new _DERInteger({'int': version})}) +365 a.push(obj); +366 } +367 +368 a.push(new _DERInteger(params.serial)); +369 a.push(new _AlgorithmIdentifier({name: params.sigalg})); +370 a.push(new _X500Name(params.issuer)); +371 a.push(new _DERSequence({array:[new _Time(params.notbefore), +372 new _Time(params.notafter)]})); +373 a.push(new _X500Name(params.subject)); +374 a.push(new _SubjectPublicKeyInfo(KEYUTIL.getKey(params.sbjpubkey))); +375 if (params.ext !== undefined && params.ext.length > 0) { +376 a.push(new _DERTaggedObject({tag: "a3", +377 obj: new _Extensions(params.ext)})); +378 } +379 +380 var seq = new KJUR.asn1.DERSequence({array: a}); +381 return seq.getEncodedHex(); +382 }; +383 +384 if (params !== undefined) this.setByParam(params); +385 }; +386 YAHOO.lang.extend(KJUR.asn1.x509.TBSCertificate, KJUR.asn1.ASN1Object); +387 +388 /** +389 * Extensions ASN.1 structure class<br/> +390 * @name KJUR.asn1.x509.Extensions +391 * @class Extensions ASN.1 structure class +392 * @param {Array} aParam array of JSON extension parameter +393 * @extends KJUR.asn1.ASN1Object +394 * @since jsrsasign 9.1.0 asn1x509 2.1.0 +395 * @see KJUR.asn1.x509.TBSCertificate +396 * @see KJUR.asn1.x509.TBSCertList +397 * @see KJUR.asn1.csr.CertificationRequestInfo +398 * @see KJUR.asn1.x509.PrivateExtension +399 * +400 * @description +401 * This class represents +402 * <a href="https://tools.ietf.org/html/rfc5280#section-4.1"> +403 * Extensions defined in RFC 5280 4.1</a> and +404 * <a href="https://tools.ietf.org/html/rfc5280#section-4.1.2.9"> +405 * 4.1.2.9</a>. +406 * <pre> +407 * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension +408 * </pre> +409 * NOTE: From jsrsasign 9.1.1, private extension or +410 * undefined extension have been supported by +411 * {@link KJUR.asn1.x509.PrivateExtension}. +412 * +413 * @example +414 * o = new KJUR.asn1.x509.Extensions([ +415 * {extname:"keyUsage",critical:true,names:["digitalSignature"]}, +416 * {extname:"subjectAltName",array:[{dns:"example.com"}]}, +417 * {extname:"1.2.3.4",extn:{prnstr:"aa"}} // private extension +418 * ]); +419 * o.getEncodedHex() → "30..." +420 */ +421 KJUR.asn1.x509.Extensions = function(aParam) { +422 KJUR.asn1.x509.Extensions.superclass.constructor.call(this); +423 var _KJUR = KJUR, +424 _KJUR_asn1 = _KJUR.asn1, +425 _DERSequence = _KJUR_asn1.DERSequence, +426 _KJUR_asn1_x509 = _KJUR_asn1.x509; +427 this.aParam = []; +428 +429 this.setByParam = function(aParam) { this.aParam = aParam; } +430 +431 this.getEncodedHex = function() { +432 var a = []; +433 for (var i = 0; i < this.aParam.length; i++) { +434 var param = this.aParam[i]; +435 var extname = param.extname; +436 var obj = null; +437 +438 if (param.extn != undefined) { +439 obj = new _KJUR_asn1_x509.PrivateExtension(param); +440 } else if (extname == "subjectKeyIdentifier") { +441 obj = new _KJUR_asn1_x509.SubjectKeyIdentifier(param); +442 } else if (extname == "keyUsage") { +443 obj = new _KJUR_asn1_x509.KeyUsage(param); +444 } else if (extname == "subjectAltName") { +445 obj = new _KJUR_asn1_x509.SubjectAltName(param); +446 } else if (extname == "issuerAltName") { +447 obj = new _KJUR_asn1_x509.IssuerAltName(param); +448 } else if (extname == "basicConstraints") { +449 obj = new _KJUR_asn1_x509.BasicConstraints(param); +450 } else if (extname == "cRLDistributionPoints") { +451 obj = new _KJUR_asn1_x509.CRLDistributionPoints(param); +452 } else if (extname == "certificatePolicies") { +453 obj = new _KJUR_asn1_x509.CertificatePolicies(param); +454 } else if (extname == "authorityKeyIdentifier") { +455 obj = new _KJUR_asn1_x509.AuthorityKeyIdentifier(param); +456 } else if (extname == "extKeyUsage") { +457 obj = new _KJUR_asn1_x509.ExtKeyUsage(param); +458 } else if (extname == "authorityInfoAccess") { +459 obj = new _KJUR_asn1_x509.AuthorityInfoAccess(param); +460 } else if (extname == "cRLNumber") { +461 obj = new _KJUR_asn1_x509.CRLNumber(param); +462 } else if (extname == "cRLReason") { +463 obj = new _KJUR_asn1_x509.CRLReason(param); +464 } else if (extname == "ocspNonce") { +465 obj = new _KJUR_asn1_x509.OCSPNonce(param); +466 } else if (extname == "ocspNoCheck") { +467 obj = new _KJUR_asn1_x509.OCSPNoCheck(param); +468 } else if (extname == "adobeTimeStamp") { +469 obj = new _KJUR_asn1_x509.AdobeTimeStamp(param); +470 } else if (extname == "subjectDirectoryAttributes") { +471 obj = new _KJUR_asn1_x509.SubjectDirectoryAttributes(param); +472 } else { +473 throw new Error("extension not supported:" +474 + JSON.stringify(param)); +475 } +476 if (obj != null) a.push(obj); +477 } +478 +479 var seq = new _DERSequence({array: a}); +480 return seq.getEncodedHex(); +481 }; +482 +483 if (aParam != undefined) this.setByParam(aParam); +484 }; +485 YAHOO.lang.extend(KJUR.asn1.x509.Extensions, KJUR.asn1.ASN1Object); 486 -487 // === END TBSCertificate =================================================== -488 -489 // === BEGIN X.509v3 Extensions Related ======================================= -490 -491 /** -492 * base Extension ASN.1 structure class -493 * @name KJUR.asn1.x509.Extension -494 * @class base Extension ASN.1 structure class -495 * @param {Array} params associative array of parameters (ex. {'critical': true}) -496 * @extends KJUR.asn1.ASN1Object -497 * @description -498 * <pre> -499 * Extension ::= SEQUENCE { -500 * extnID OBJECT IDENTIFIER, -501 * critical BOOLEAN DEFAULT FALSE, -502 * extnValue OCTET STRING } -503 * </pre> -504 * @example -505 */ -506 KJUR.asn1.x509.Extension = function(params) { -507 KJUR.asn1.x509.Extension.superclass.constructor.call(this); -508 var asn1ExtnValue = null, -509 _KJUR = KJUR, -510 _KJUR_asn1 = _KJUR.asn1, -511 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, -512 _DEROctetString = _KJUR_asn1.DEROctetString, -513 _DERBitString = _KJUR_asn1.DERBitString, -514 _DERBoolean = _KJUR_asn1.DERBoolean, -515 _DERSequence = _KJUR_asn1.DERSequence; -516 -517 this.getEncodedHex = function() { -518 var asn1Oid = new _DERObjectIdentifier({'oid': this.oid}); -519 var asn1EncapExtnValue = -520 new _DEROctetString({'hex': this.getExtnValueHex()}); -521 -522 var asn1Array = new Array(); -523 asn1Array.push(asn1Oid); -524 if (this.critical) asn1Array.push(new _DERBoolean()); -525 asn1Array.push(asn1EncapExtnValue); -526 -527 var asn1Seq = new _DERSequence({'array': asn1Array}); -528 return asn1Seq.getEncodedHex(); -529 }; -530 -531 this.critical = false; -532 if (params !== undefined) { -533 if (params.critical !== undefined) { -534 this.critical = params.critical; -535 } -536 } -537 }; -538 YAHOO.lang.extend(KJUR.asn1.x509.Extension, KJUR.asn1.ASN1Object); -539 -540 /** -541 * KeyUsage ASN.1 structure class -542 * @name KJUR.asn1.x509.KeyUsage -543 * @class KeyUsage ASN.1 structure class -544 * @param {Array} params associative array of parameters (ex. {'bin': '11', 'critical': true}) -545 * @extends KJUR.asn1.x509.Extension -546 * @description -547 * This class is for <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.3" target="_blank">KeyUsage</a> X.509v3 extension. -548 * <pre> -549 * id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } -550 * KeyUsage ::= BIT STRING { -551 * digitalSignature (0), -552 * nonRepudiation (1), -553 * keyEncipherment (2), -554 * dataEncipherment (3), -555 * keyAgreement (4), -556 * keyCertSign (5), -557 * cRLSign (6), -558 * encipherOnly (7), -559 * decipherOnly (8) } -560 * </pre><br/> -561 * NOTE: 'names' parameter is supprted since jsrsasign 8.0.14. -562 * @example -563 * o = new KJUR.asn1.x509.KeyUsage({bin: "11"}); -564 * o = new KJUR.asn1.x509.KeyUsage({critical: true, bin: "11"}); -565 * o = new KJUR.asn1.x509.KeyUsage({names: ['digitalSignature', 'keyAgreement']}); -566 */ -567 KJUR.asn1.x509.KeyUsage = function(params) { -568 KJUR.asn1.x509.KeyUsage.superclass.constructor.call(this, params); -569 var _KEYUSAGE_NAME = X509.KEYUSAGE_NAME; -570 -571 this.getExtnValueHex = function() { -572 return this.asn1ExtnValue.getEncodedHex(); -573 }; -574 -575 this.oid = "2.5.29.15"; -576 if (params !== undefined) { -577 if (params.bin !== undefined) { -578 this.asn1ExtnValue = new KJUR.asn1.DERBitString(params); -579 } -580 if (params.names !== undefined && -581 params.names.length !== undefined) { -582 var names = params.names; -583 var s = "000000000"; -584 for (var i = 0; i < names.length; i++) { -585 for (var j = 0; j < _KEYUSAGE_NAME.length; j++) { -586 if (names[i] === _KEYUSAGE_NAME[j]) { -587 s = s.substring(0, j) + '1' + -588 s.substring(j + 1, s.length); -589 } -590 } -591 } -592 this.asn1ExtnValue = new KJUR.asn1.DERBitString({bin: s}); -593 } -594 } -595 }; -596 YAHOO.lang.extend(KJUR.asn1.x509.KeyUsage, KJUR.asn1.x509.Extension); -597 -598 /** -599 * BasicConstraints ASN.1 structure class -600 * @name KJUR.asn1.x509.BasicConstraints -601 * @class BasicConstraints ASN.1 structure class -602 * @param {Array} params JSON object for parameters (ex. {cA:true,critical:true}) -603 * @extends KJUR.asn1.x509.Extension -604 * @see {@link X509#getExtBasicConstraints} -605 * @description -606 * This class represents -607 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.9"> -608 * BasicConstraints extension defined in RFC 5280 4.2.1.9</a>. -609 * <pre> -610 * id-ce-basicConstraints OBJECT IDENTIFIER ::= { id-ce 19 } -611 * BasicConstraints ::= SEQUENCE { -612 * cA BOOLEAN DEFAULT FALSE, -613 * pathLenConstraint INTEGER (0..MAX) OPTIONAL } -614 * </pre> -615 * Its constructor can have following parameters: -616 * <ul> -617 * <li>{Boolean}cA - cA flag</li> -618 * <li>{Integer}pathLen - pathLen field value</li> -619 * <li>{Boolean}critical - critical flag</li> -620 * </ul> -621 * @example -622 * new KJUR.asn1.x509.BasicConstraints({ -623 * cA: true, -624 * pathLen: 3, -625 * critical: true -626 * }) -627 */ -628 KJUR.asn1.x509.BasicConstraints = function(params) { -629 KJUR.asn1.x509.BasicConstraints.superclass.constructor.call(this, params); -630 var _KJUR_asn1 = KJUR.asn1, -631 _DERBoolean = _KJUR_asn1.DERBoolean, -632 _DERInteger = _KJUR_asn1.DERInteger, -633 _DERSequence = _KJUR_asn1.DERSequence; -634 -635 var cA = false; -636 var pathLen = -1; -637 -638 this.getExtnValueHex = function() { -639 var asn1Array = new Array(); -640 if (this.cA) asn1Array.push(new _DERBoolean()); -641 if (this.pathLen > -1) -642 asn1Array.push(new _DERInteger({'int': this.pathLen})); -643 var asn1Seq = new _DERSequence({'array': asn1Array}); -644 this.asn1ExtnValue = asn1Seq; -645 return this.asn1ExtnValue.getEncodedHex(); -646 }; -647 -648 this.oid = "2.5.29.19"; -649 this.cA = false; -650 this.pathLen = -1; -651 if (params !== undefined) { -652 if (params.cA !== undefined) { -653 this.cA = params.cA; -654 } -655 if (params.pathLen !== undefined) { -656 this.pathLen = params.pathLen; -657 } -658 } -659 }; -660 YAHOO.lang.extend(KJUR.asn1.x509.BasicConstraints, KJUR.asn1.x509.Extension); -661 -662 /** -663 * CRLDistributionPoints ASN.1 structure class -664 * @name KJUR.asn1.x509.CRLDistributionPoints -665 * @class CRLDistributionPoints ASN.1 structure class -666 * @param {Array} params associative array of parameters (ex. {'uri': 'http://a.com/', 'critical': true}) -667 * @extends KJUR.asn1.x509.Extension -668 * @see {@link X509#getExtCRLDistributionPoints} -669 * @see {@link KJUR.asn1.x509.DistributionPoint} -670 * @see {@link KJUR.asn1.x509.GeneralNames} -671 * @description -672 * This class represents -673 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.13"> -674 * CRLDistributionPoints extension defined in RFC 5280 4.2.1.13</a>. -675 * <pre> -676 * id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::= { id-ce 31 } -677 * CRLDistributionPoints ::= SEQUENCE SIZE (1..MAX) OF DistributionPoint -678 * DistributionPoint ::= SEQUENCE { -679 * distributionPoint [0] DistributionPointName OPTIONAL, -680 * reasons [1] ReasonFlags OPTIONAL, -681 * cRLIssuer [2] GeneralNames OPTIONAL } -682 * DistributionPointName ::= CHOICE { -683 * fullName [0] GeneralNames, -684 * nameRelativeToCRLIssuer [1] RelativeDistinguishedName } -685 * </pre> -686 * Constructor can have following parameter: -687 * <ul> -688 * <li>{Array}array - array of {@link KJUR.asn1.x509.DistributionPoint} parameter</li> -689 * <li>{Boolean}critical - critical flag</li> -690 * </ul> -691 * @example -692 * new KJUR.asn1.x509.CRLDistributionPoints({ -693 * array: [{fulluri: "http://aaa.com/"}, {fulluri: "ldap://aaa.com/"}], -694 * critical: true -695 * }) -696 */ -697 KJUR.asn1.x509.CRLDistributionPoints = function(params) { -698 KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this, params); -699 var _KJUR = KJUR, -700 _KJUR_asn1 = _KJUR.asn1, -701 _KJUR_asn1_x509 = _KJUR_asn1.x509; -702 -703 this.getExtnValueHex = function() { -704 return this.asn1ExtnValue.getEncodedHex(); -705 }; -706 -707 this.setByDPArray = function(dpArray) { -708 var asn1Array = []; -709 for (var i = 0; i < dpArray.length; i++) { -710 if (dpArray[i] instanceof KJUR.asn1.ASN1Object) { -711 asn1Array.push(dpArray[i]); -712 } else { -713 var dp = new _KJUR_asn1_x509.DistributionPoint(dpArray[i]); -714 asn1Array.push(dp); -715 } -716 } -717 this.asn1ExtnValue = new _KJUR_asn1.DERSequence({'array': asn1Array}); -718 }; -719 -720 this.setByOneURI = function(uri) { -721 var dp1 = new _KJUR_asn1_x509.DistributionPoint({fulluri: uri}); -722 this.setByDPArray([dp1]); -723 }; -724 -725 this.oid = "2.5.29.31"; -726 if (params !== undefined) { -727 if (params.array !== undefined) { -728 this.setByDPArray(params.array); -729 } else if (params.uri !== undefined) { -730 this.setByOneURI(params.uri); -731 } -732 } -733 }; -734 YAHOO.lang.extend(KJUR.asn1.x509.CRLDistributionPoints, KJUR.asn1.x509.Extension); -735 -736 /** -737 * DistributionPoint ASN.1 structure class<br/> -738 * @name KJUR.asn1.x509.DistributionPoint -739 * @class DistributionPoint ASN.1 structure class -740 * @param {Array} params JSON object of parameters (OPTIONAL) -741 * @extends KJUR.asn1.ASN1Object -742 * @see {@link KJUR.asn1.x509.CRLDistributionPoints} -743 * @see {@link KJUR.asn1.x509.DistributionPointName} -744 * @see {@link KJUR.asn1.x509.GeneralNames} -745 * @see {@link X509#getDistributionPoint} -746 * @description -747 * This class represents -748 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.13"> -749 * DistributionPoint defined in RFC 5280 4.2.1.13</a>. -750 * <pre> -751 * DistributionPoint ::= SEQUENCE { -752 * distributionPoint [0] DistributionPointName OPTIONAL, -753 * reasons [1] ReasonFlags OPTIONAL, -754 * cRLIssuer [2] GeneralNames OPTIONAL } -755 * </pre> -756 * Constructor can have following parameter: -757 * <ul> -758 * <li>{String}fulluri - uri string for fullName uri. This has the same meaning for '{dpname: {full: [{uri: "..."]}}'.</li> -759 * <li>{Array}dpname - JSON object for {@link KJUR.asn1.x509.DistributionPointName} parameters</li> -760 * <li>{DistrubutionPoint}dpobj - {@link KJUR.asn1.x509.DistributionPointName} object (DEPRECATED)</li> -761 * </ul> -762 * <br/> -763 * NOTE1: Parameter "fulluri" and "dpname" supported -764 * since jsrsasign 9.0.0 asn1x509 2.0.0. -765 * <br/> -766 * NOTE2: The "reasons" and "cRLIssuer" fields are currently -767 * not supported. -768 * @example -769 * new KJUR.asn1.x509.DistributionPoint( -770 * {fulluri: "http://example.com/crl1.crl"}) -771 * new KJUR.asn1.x509.DistributionPoint( -772 * {dpname: {full: [{uri: "http://example.com/crl1.crl"}]}}) -773 * new KJUR.asn1.x509.DistributionPoint( -774 * {dpobj: new DistributionPoint(...)}) -775 */ -776 KJUR.asn1.x509.DistributionPoint = function(params) { -777 KJUR.asn1.x509.DistributionPoint.superclass.constructor.call(this); -778 var asn1DP = null, -779 _KJUR = KJUR, -780 _KJUR_asn1 = _KJUR.asn1, -781 _DistributionPointName = _KJUR_asn1.x509.DistributionPointName; -782 -783 this.getEncodedHex = function() { -784 var seq = new _KJUR_asn1.DERSequence(); -785 if (this.asn1DP != null) { -786 var o1 = new _KJUR_asn1.DERTaggedObject({'explicit': true, -787 'tag': 'a0', -788 'obj': this.asn1DP}); -789 seq.appendASN1Object(o1); -790 } -791 this.hTLV = seq.getEncodedHex(); -792 return this.hTLV; -793 }; -794 -795 if (params !== undefined) { -796 if (params.dpobj !== undefined) { -797 this.asn1DP = params.dpobj; -798 } else if (params.dpname !== undefined) { -799 this.asn1DP = new _DistributionPointName(params.dpname); -800 } else if (params.fulluri !== undefined) { -801 this.asn1DP = new _DistributionPointName({full: [{uri: params.fulluri}]}); -802 } -803 } -804 }; -805 YAHOO.lang.extend(KJUR.asn1.x509.DistributionPoint, KJUR.asn1.ASN1Object); -806 -807 /** -808 * DistributionPointName ASN.1 structure class<br/> -809 * @name KJUR.asn1.x509.DistributionPointName -810 * @class DistributionPointName ASN.1 structure class -811 * @param {Array} params JSON object of parameters or GeneralNames object -812 * @extends KJUR.asn1.ASN1Object -813 * @see {@link KJUR.asn1.x509.CRLDistributionPoints} -814 * @see {@link KJUR.asn1.x509.DistributionPoint} -815 * @see {@link KJUR.asn1.x509.GeneralNames} -816 * @see {@link X509#getDistributionPointName} -817 * @description -818 * This class represents -819 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.13"> -820 * DistributionPointName defined in RFC 5280 4.2.1.13</a>. -821 * <pre> -822 * DistributionPointName ::= CHOICE { -823 * fullName [0] GeneralNames, -824 * nameRelativeToCRLIssuer [1] RelativeDistinguishedName } -825 * </pre> -826 * Constructor can have following parameter: -827 * <ul> -828 * <li>{String}full - JSON object parameter of {@link KJUR.asn1.x509.GeneralNames} for 'fullName' field</li> -829 * <li>{GeneralNames} - {@link KJUR.asn1.x509.GeneralNames} object for 'fullName'</li> -830 * </ul> -831 * NOTE1: 'full' parameter have been suppored since jsrsasign 9.0.0 asn1x509 2.0.0. -832 * <br> -833 * NOTE2: The 'nameRelativeToCRLIssuer' field is currently not supported. -834 * @example -835 * new KJUR.asn1.x509.DistributionPointName({full: <<GeneralNamesParameter>>}) -836 * new KJUR.asn1.x509.DistributionPointName({full: [{uri: <<CDPURI>>}]}) -837 * new KJUR.asn1.x509.DistributionPointName({full: [{dn: <<DN Parameter>>}]} -838 * new KJUR.asn1.x509.DistributionPointName({full: [{uri: "http://example.com/root.crl"}]}) -839 * new KJUR.asn1.x509.DistributionPointName({full: [{dn {str: "/C=US/O=Test"}}]}) -840 * new KJUR.asn1.x509.DistributionPointName(new GeneralNames(...)) -841 */ -842 KJUR.asn1.x509.DistributionPointName = function(params) { -843 KJUR.asn1.x509.DistributionPointName.superclass.constructor.call(this); -844 var asn1Obj = null, -845 type = null, -846 tag = null, -847 asn1V = null, -848 _KJUR = KJUR, -849 _KJUR_asn1 = _KJUR.asn1, -850 _DERTaggedObject = _KJUR_asn1.DERTaggedObject; -851 -852 this.getEncodedHex = function() { -853 if (this.type != "full") -854 throw new Error("currently type shall be 'full': " + this.type); -855 this.asn1Obj = new _DERTaggedObject({'explicit': false, -856 'tag': this.tag, -857 'obj': this.asn1V}); -858 this.hTLV = this.asn1Obj.getEncodedHex(); -859 return this.hTLV; -860 }; -861 -862 if (params !== undefined) { -863 if (_KJUR_asn1.x509.GeneralNames.prototype.isPrototypeOf(params)) { -864 this.type = "full"; -865 this.tag = "a0"; -866 this.asn1V = params; -867 } else if (params.full !== undefined) { -868 this.type = "full"; -869 this.tag = "a0"; -870 this.asn1V = new _KJUR_asn1.x509.GeneralNames(params.full); -871 } else { -872 throw new Error("This class supports GeneralNames only as argument"); -873 } -874 } -875 }; -876 YAHOO.lang.extend(KJUR.asn1.x509.DistributionPointName, KJUR.asn1.ASN1Object); -877 -878 /** -879 * CertificatePolicies ASN.1 structure class -880 * @name KJUR.asn1.x509.CertificatePolicies -881 * @class CertificatePolicies ASN.1 structure class -882 * @param {Array} params associative array of parameters -883 * @extends KJUR.asn1.x509.Extension -884 * @since jsrsasign 8.0.23 asn1x509 1.1.12 -885 * @see KJUR.asn1.x509.CertificatePolicies -886 * @see KJUR.asn1.x509.PolicyInformation -887 * @see KJUR.asn1.x509.PolicyQualifierInfo -888 * @see KJUR.asn1.x509.UserNotice -889 * @see KJUR.asn1.x509.NoticeReference -890 * @see KJUR.asn1.x509.DisplayText -891 * @description -892 * This class represents -893 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> -894 * CertificatePolicies extension defined in RFC 5280 4.2.1.4</a>. -895 * <pre> -896 * id-ce-certificatePolicies OBJECT IDENTIFIER ::= { id-ce 32 } -897 * CertificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation -898 * </pre> -899 * Its constructor can have following parameters: -900 * <ul> -901 * <li>array - array of {@link KJUR.asn1.x509.PolicyInformation} parameter</li> -902 * <li>critical - boolean: critical flag</li> -903 * </ul> -904 * NOTE: Returned JSON value format have been changed without -905 * backward compatibility since jsrsasign 9.0.0 asn1x509 2.0.0. -906 * @example -907 * e1 = new KJUR.asn1.x509.CertificatePolicies({ -908 * array: [ -909 * { policyoid: "1.2.3.4.5", -910 * array: [ -911 * { cps: "https://example.com/repository" }, -912 * { unotice: { -913 * noticeref: { // CA SHOULD NOT use this by RFC -914 * org: {type: "ia5", str: "Sample Org"}, -915 * noticenum: [{int: 5}, {hex: "01af"}] -916 * }, -917 * exptext: {type: "ia5", str: "Sample Policy"} -918 * }} -919 * ] -920 * } -921 * ], -922 * critical: true -923 * }); -924 */ -925 KJUR.asn1.x509.CertificatePolicies = function(params) { -926 KJUR.asn1.x509.CertificatePolicies.superclass.constructor.call(this, params); -927 var _KJUR = KJUR, -928 _KJUR_asn1 = _KJUR.asn1, -929 _KJUR_asn1_x509 = _KJUR_asn1.x509, -930 _DERSequence = _KJUR_asn1.DERSequence, -931 _PolicyInformation = _KJUR_asn1_x509.PolicyInformation; -932 -933 this.params = null; -934 -935 this.getExtnValueHex = function() { -936 var aPI = []; -937 for (var i = 0; i < this.params.array.length; i++) { -938 aPI.push(new _PolicyInformation(this.params.array[i])); -939 } -940 var seq = new _DERSequence({array: aPI}); -941 this.asn1ExtnValue = seq; -942 return this.asn1ExtnValue.getEncodedHex(); -943 }; -944 -945 this.oid = "2.5.29.32"; -946 if (params !== undefined) { -947 this.params = params; -948 } -949 }; -950 YAHOO.lang.extend(KJUR.asn1.x509.CertificatePolicies, KJUR.asn1.x509.Extension); -951 -952 // ===== BEGIN CertificatePolicies related classes ===== -953 /** -954 * PolicyInformation ASN.1 structure class -955 * @name KJUR.asn1.x509.PolicyInformation -956 * @class PolicyInformation ASN.1 structure class -957 * @param {Array} params JSON object of parameters -958 * @extends KJUR.asn1.ASN1Object -959 * @since jsrsasign 8.0.23 asn1x509 1.1.12 -960 * @see KJUR.asn1.x509.CertificatePolicies -961 * @see KJUR.asn1.x509.PolicyInformation -962 * @see KJUR.asn1.x509.PolicyQualifierInfo -963 * @see KJUR.asn1.x509.UserNotice -964 * @see KJUR.asn1.x509.NoticeReference -965 * @see KJUR.asn1.x509.DisplayText -966 * @description -967 * This class represents -968 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> -969 * PolicyInformation defined in RFC 5280 4.2.1.4</a>. -970 * <pre> -971 * PolicyInformation ::= SEQUENCE { -972 * policyIdentifier CertPolicyId, -973 * policyQualifiers SEQUENCE SIZE (1..MAX) OF -974 * PolicyQualifierInfo OPTIONAL } -975 * CertPolicyId ::= OBJECT IDENTIFIER -976 * Its constructor can have following parameters: -977 * <ul> -978 * <li>{String}policyoid - policy OID (ex. "1.2.3.4.5")</li> -979 * <li>{Object}array - array of {@link KJUR.asn1.x509.PolicyQualifierInfo} -980 * parameters (OPTIONAL)</li> -981 * </ul> -982 * @example -983 * new KJUR.asn1.x509.PolicyInformation({ -984 * policyoid: "1.2.3.4.5", -985 * array: [ -986 * { cps: "https://example.com/repository" }, -987 * { unotice: { -988 * noticeref: { // CA SHOULD NOT use this by RFC -989 * org: {type: "ia5", str: "Sample Org"}, -990 * noticenum: [{int: 5}, {hex: "01af"}] -991 * }, -992 * exptext: {type: "ia5", str: "Sample Policy"} -993 * }} -994 * ] -995 * }) -996 */ -997 KJUR.asn1.x509.PolicyInformation = function(params) { -998 KJUR.asn1.x509.PolicyInformation.superclass.constructor.call(this, -999 params); -1000 var _KJUR_asn1 = KJUR.asn1, -1001 _DERSequence = _KJUR_asn1.DERSequence, -1002 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, -1003 _PolicyQualifierInfo = _KJUR_asn1.x509.PolicyQualifierInfo; -1004 -1005 this.params = null; -1006 -1007 this.getEncodedHex = function() { -1008 if (this.params.policyoid === undefined && -1009 this.params.array === undefined) -1010 throw new Error("parameter oid and array missing"); -1011 -1012 // policy oid -1013 var a = [new _DERObjectIdentifier(this.params.policyoid)]; -1014 -1015 // array of ASN1Object of PolicyQualifierInfo -1016 if (this.params.array !== undefined) { -1017 var aPQI = []; -1018 for (var i = 0; i < this.params.array.length; i++) { -1019 aPQI.push(new _PolicyQualifierInfo(this.params.array[i])); -1020 } -1021 if (aPQI.length > 0) { -1022 a.push(new _DERSequence({array: aPQI})); -1023 } -1024 } -1025 -1026 var seq = new _DERSequence({array: a}); -1027 return seq.getEncodedHex(); -1028 }; -1029 -1030 if (params !== undefined) { -1031 this.params = params; -1032 } -1033 }; -1034 YAHOO.lang.extend(KJUR.asn1.x509.PolicyInformation, KJUR.asn1.ASN1Object); -1035 -1036 /** -1037 * PolicyQualifierInfo ASN.1 structure class -1038 * @name KJUR.asn1.x509.PolicyQualifierInfo -1039 * @class PolicyQualifierInfo ASN.1 structure class -1040 * @param {Array} params associative array of parameters -1041 * @extends KJUR.asn1.ASN1Object -1042 * @since jsrsasign 8.0.23 asn1x509 1.1.12 -1043 * @description -1044 * This class represents -1045 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> -1046 * PolicyQualifierInfo defined in RFC 5280 4.2.1.4</a>. -1047 * <pre> -1048 * PolicyQualifierInfo ::= SEQUENCE { -1049 * policyQualifierId PolicyQualifierId, -1050 * qualifier ANY DEFINED BY policyQualifierId } -1051 * PolicyQualifierId ::= OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice ) -1052 * CPSuri ::= IA5String -1053 * </pre> -1054 * Its constructor can have one of following two parameters: -1055 * <ul> -1056 * <li>{String}cps - URI string for CPS</li> -1057 * <li>{Object}unotice - {@link KJUR.asn1.x509.UserNotice} parameter</li> -1058 * </ul> -1059 * @example -1060 * new PolicyQualifierInfo({ -1061 * cps: "https://example.com/repository/cps" -1062 * }) -1063 * -1064 * new PolicyQualifierInfo({ -1065 * unotice: { -1066 * noticeref: { // CA SHOULD NOT use this by RFC -1067 * org: {type: "bmp", str: "Sample Org"}, -1068 * noticenum: [{int: 3}, {hex: "01af"}] -1069 * }, -1070 * exptext: {type: "ia5", str: "Sample Policy"} -1071 * } -1072 * }) -1073 */ -1074 KJUR.asn1.x509.PolicyQualifierInfo = function(params) { -1075 KJUR.asn1.x509.PolicyQualifierInfo.superclass.constructor.call(this, -1076 params); -1077 var _KJUR_asn1 = KJUR.asn1, -1078 _DERSequence = _KJUR_asn1.DERSequence, -1079 _DERIA5String = _KJUR_asn1.DERIA5String, -1080 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, -1081 _UserNotice = _KJUR_asn1.x509.UserNotice; -1082 -1083 this.params = null; -1084 -1085 this.getEncodedHex = function() { -1086 if (this.params.cps !== undefined) { -1087 var seq = new _DERSequence({array: [ -1088 new _DERObjectIdentifier({oid: '1.3.6.1.5.5.7.2.1'}), -1089 new _DERIA5String({str: this.params.cps}) -1090 ]}); -1091 return seq.getEncodedHex(); -1092 } -1093 if (this.params.unotice != undefined) { -1094 var seq = new _DERSequence({array: [ -1095 new _DERObjectIdentifier({oid: '1.3.6.1.5.5.7.2.2'}), -1096 new _UserNotice(this.params.unotice) -1097 ]}); -1098 return seq.getEncodedHex(); -1099 } -1100 }; -1101 -1102 if (params !== undefined) { -1103 this.params = params; -1104 } -1105 }; -1106 YAHOO.lang.extend(KJUR.asn1.x509.PolicyQualifierInfo, KJUR.asn1.ASN1Object); -1107 +487 +488 // === END TBSCertificate =================================================== +489 +490 // === BEGIN X.509v3 Extensions Related ======================================= +491 +492 /** +493 * base Extension ASN.1 structure class +494 * @name KJUR.asn1.x509.Extension +495 * @class base Extension ASN.1 structure class +496 * @param {Array} params associative array of parameters (ex. {'critical': true}) +497 * @extends KJUR.asn1.ASN1Object +498 * @description +499 * <pre> +500 * Extension ::= SEQUENCE { +501 * extnID OBJECT IDENTIFIER, +502 * critical BOOLEAN DEFAULT FALSE, +503 * extnValue OCTET STRING } +504 * </pre> +505 * @example +506 */ +507 KJUR.asn1.x509.Extension = function(params) { +508 KJUR.asn1.x509.Extension.superclass.constructor.call(this); +509 var asn1ExtnValue = null, +510 _KJUR = KJUR, +511 _KJUR_asn1 = _KJUR.asn1, +512 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, +513 _DEROctetString = _KJUR_asn1.DEROctetString, +514 _DERBitString = _KJUR_asn1.DERBitString, +515 _DERBoolean = _KJUR_asn1.DERBoolean, +516 _DERSequence = _KJUR_asn1.DERSequence; +517 +518 this.getEncodedHex = function() { +519 var asn1Oid = new _DERObjectIdentifier({'oid': this.oid}); +520 var asn1EncapExtnValue = +521 new _DEROctetString({'hex': this.getExtnValueHex()}); +522 +523 var asn1Array = new Array(); +524 asn1Array.push(asn1Oid); +525 if (this.critical) asn1Array.push(new _DERBoolean()); +526 asn1Array.push(asn1EncapExtnValue); +527 +528 var asn1Seq = new _DERSequence({'array': asn1Array}); +529 return asn1Seq.getEncodedHex(); +530 }; +531 +532 this.critical = false; +533 if (params !== undefined) { +534 if (params.critical !== undefined) { +535 this.critical = params.critical; +536 } +537 } +538 }; +539 YAHOO.lang.extend(KJUR.asn1.x509.Extension, KJUR.asn1.ASN1Object); +540 +541 /** +542 * KeyUsage ASN.1 structure class +543 * @name KJUR.asn1.x509.KeyUsage +544 * @class KeyUsage ASN.1 structure class +545 * @param {Array} params associative array of parameters (ex. {'bin': '11', 'critical': true}) +546 * @extends KJUR.asn1.x509.Extension +547 * @description +548 * This class is for <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.3" target="_blank">KeyUsage</a> X.509v3 extension. +549 * <pre> +550 * id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } +551 * KeyUsage ::= BIT STRING { +552 * digitalSignature (0), +553 * nonRepudiation (1), +554 * keyEncipherment (2), +555 * dataEncipherment (3), +556 * keyAgreement (4), +557 * keyCertSign (5), +558 * cRLSign (6), +559 * encipherOnly (7), +560 * decipherOnly (8) } +561 * </pre><br/> +562 * NOTE: 'names' parameter is supprted since jsrsasign 8.0.14. +563 * @example +564 * o = new KJUR.asn1.x509.KeyUsage({bin: "11"}); +565 * o = new KJUR.asn1.x509.KeyUsage({critical: true, bin: "11"}); +566 * o = new KJUR.asn1.x509.KeyUsage({names: ['digitalSignature', 'keyAgreement']}); +567 */ +568 KJUR.asn1.x509.KeyUsage = function(params) { +569 KJUR.asn1.x509.KeyUsage.superclass.constructor.call(this, params); +570 var _KEYUSAGE_NAME = X509.KEYUSAGE_NAME; +571 +572 this.getExtnValueHex = function() { +573 return this.asn1ExtnValue.getEncodedHex(); +574 }; +575 +576 this.oid = "2.5.29.15"; +577 if (params !== undefined) { +578 if (params.bin !== undefined) { +579 this.asn1ExtnValue = new KJUR.asn1.DERBitString(params); +580 } +581 if (params.names !== undefined && +582 params.names.length !== undefined) { +583 var names = params.names; +584 var s = "000000000"; +585 for (var i = 0; i < names.length; i++) { +586 for (var j = 0; j < _KEYUSAGE_NAME.length; j++) { +587 if (names[i] === _KEYUSAGE_NAME[j]) { +588 s = s.substring(0, j) + '1' + +589 s.substring(j + 1, s.length); +590 } +591 } +592 } +593 this.asn1ExtnValue = new KJUR.asn1.DERBitString({bin: s}); +594 } +595 } +596 }; +597 YAHOO.lang.extend(KJUR.asn1.x509.KeyUsage, KJUR.asn1.x509.Extension); +598 +599 /** +600 * BasicConstraints ASN.1 structure class +601 * @name KJUR.asn1.x509.BasicConstraints +602 * @class BasicConstraints ASN.1 structure class +603 * @param {Array} params JSON object for parameters (ex. {cA:true,critical:true}) +604 * @extends KJUR.asn1.x509.Extension +605 * @see {@link X509#getExtBasicConstraints} +606 * @description +607 * This class represents +608 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.9"> +609 * BasicConstraints extension defined in RFC 5280 4.2.1.9</a>. +610 * <pre> +611 * id-ce-basicConstraints OBJECT IDENTIFIER ::= { id-ce 19 } +612 * BasicConstraints ::= SEQUENCE { +613 * cA BOOLEAN DEFAULT FALSE, +614 * pathLenConstraint INTEGER (0..MAX) OPTIONAL } +615 * </pre> +616 * Its constructor can have following parameters: +617 * <ul> +618 * <li>{Boolean}cA - cA flag</li> +619 * <li>{Integer}pathLen - pathLen field value</li> +620 * <li>{Boolean}critical - critical flag</li> +621 * </ul> +622 * @example +623 * new KJUR.asn1.x509.BasicConstraints({ +624 * cA: true, +625 * pathLen: 3, +626 * critical: true +627 * }) +628 */ +629 KJUR.asn1.x509.BasicConstraints = function(params) { +630 KJUR.asn1.x509.BasicConstraints.superclass.constructor.call(this, params); +631 var _KJUR_asn1 = KJUR.asn1, +632 _DERBoolean = _KJUR_asn1.DERBoolean, +633 _DERInteger = _KJUR_asn1.DERInteger, +634 _DERSequence = _KJUR_asn1.DERSequence; +635 +636 var cA = false; +637 var pathLen = -1; +638 +639 this.getExtnValueHex = function() { +640 var asn1Array = new Array(); +641 if (this.cA) asn1Array.push(new _DERBoolean()); +642 if (this.pathLen > -1) +643 asn1Array.push(new _DERInteger({'int': this.pathLen})); +644 var asn1Seq = new _DERSequence({'array': asn1Array}); +645 this.asn1ExtnValue = asn1Seq; +646 return this.asn1ExtnValue.getEncodedHex(); +647 }; +648 +649 this.oid = "2.5.29.19"; +650 this.cA = false; +651 this.pathLen = -1; +652 if (params !== undefined) { +653 if (params.cA !== undefined) { +654 this.cA = params.cA; +655 } +656 if (params.pathLen !== undefined) { +657 this.pathLen = params.pathLen; +658 } +659 } +660 }; +661 YAHOO.lang.extend(KJUR.asn1.x509.BasicConstraints, KJUR.asn1.x509.Extension); +662 +663 /** +664 * CRLDistributionPoints ASN.1 structure class +665 * @name KJUR.asn1.x509.CRLDistributionPoints +666 * @class CRLDistributionPoints ASN.1 structure class +667 * @param {Array} params associative array of parameters (ex. {'uri': 'http://a.com/', 'critical': true}) +668 * @extends KJUR.asn1.x509.Extension +669 * @see {@link X509#getExtCRLDistributionPoints} +670 * @see {@link KJUR.asn1.x509.DistributionPoint} +671 * @see {@link KJUR.asn1.x509.GeneralNames} +672 * @description +673 * This class represents +674 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.13"> +675 * CRLDistributionPoints extension defined in RFC 5280 4.2.1.13</a>. +676 * <pre> +677 * id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::= { id-ce 31 } +678 * CRLDistributionPoints ::= SEQUENCE SIZE (1..MAX) OF DistributionPoint +679 * DistributionPoint ::= SEQUENCE { +680 * distributionPoint [0] DistributionPointName OPTIONAL, +681 * reasons [1] ReasonFlags OPTIONAL, +682 * cRLIssuer [2] GeneralNames OPTIONAL } +683 * DistributionPointName ::= CHOICE { +684 * fullName [0] GeneralNames, +685 * nameRelativeToCRLIssuer [1] RelativeDistinguishedName } +686 * </pre> +687 * Constructor can have following parameter: +688 * <ul> +689 * <li>{Array}array - array of {@link KJUR.asn1.x509.DistributionPoint} parameter</li> +690 * <li>{Boolean}critical - critical flag</li> +691 * </ul> +692 * @example +693 * new KJUR.asn1.x509.CRLDistributionPoints({ +694 * array: [{fulluri: "http://aaa.com/"}, {fulluri: "ldap://aaa.com/"}], +695 * critical: true +696 * }) +697 */ +698 KJUR.asn1.x509.CRLDistributionPoints = function(params) { +699 KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this, params); +700 var _KJUR = KJUR, +701 _KJUR_asn1 = _KJUR.asn1, +702 _KJUR_asn1_x509 = _KJUR_asn1.x509; +703 +704 this.getExtnValueHex = function() { +705 return this.asn1ExtnValue.getEncodedHex(); +706 }; +707 +708 this.setByDPArray = function(dpArray) { +709 var asn1Array = []; +710 for (var i = 0; i < dpArray.length; i++) { +711 if (dpArray[i] instanceof KJUR.asn1.ASN1Object) { +712 asn1Array.push(dpArray[i]); +713 } else { +714 var dp = new _KJUR_asn1_x509.DistributionPoint(dpArray[i]); +715 asn1Array.push(dp); +716 } +717 } +718 this.asn1ExtnValue = new _KJUR_asn1.DERSequence({'array': asn1Array}); +719 }; +720 +721 this.setByOneURI = function(uri) { +722 var dp1 = new _KJUR_asn1_x509.DistributionPoint({fulluri: uri}); +723 this.setByDPArray([dp1]); +724 }; +725 +726 this.oid = "2.5.29.31"; +727 if (params !== undefined) { +728 if (params.array !== undefined) { +729 this.setByDPArray(params.array); +730 } else if (params.uri !== undefined) { +731 this.setByOneURI(params.uri); +732 } +733 } +734 }; +735 YAHOO.lang.extend(KJUR.asn1.x509.CRLDistributionPoints, KJUR.asn1.x509.Extension); +736 +737 /** +738 * DistributionPoint ASN.1 structure class<br/> +739 * @name KJUR.asn1.x509.DistributionPoint +740 * @class DistributionPoint ASN.1 structure class +741 * @param {Array} params JSON object of parameters (OPTIONAL) +742 * @extends KJUR.asn1.ASN1Object +743 * @see {@link KJUR.asn1.x509.CRLDistributionPoints} +744 * @see {@link KJUR.asn1.x509.DistributionPointName} +745 * @see {@link KJUR.asn1.x509.GeneralNames} +746 * @see {@link X509#getDistributionPoint} +747 * @description +748 * This class represents +749 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.13"> +750 * DistributionPoint defined in RFC 5280 4.2.1.13</a>. +751 * <pre> +752 * DistributionPoint ::= SEQUENCE { +753 * distributionPoint [0] DistributionPointName OPTIONAL, +754 * reasons [1] ReasonFlags OPTIONAL, +755 * cRLIssuer [2] GeneralNames OPTIONAL } +756 * </pre> +757 * Constructor can have following parameter: +758 * <ul> +759 * <li>{String}fulluri - uri string for fullName uri. This has the same meaning for '{dpname: {full: [{uri: "..."]}}'.</li> +760 * <li>{Array}dpname - JSON object for {@link KJUR.asn1.x509.DistributionPointName} parameters</li> +761 * <li>{DistrubutionPoint}dpobj - {@link KJUR.asn1.x509.DistributionPointName} object (DEPRECATED)</li> +762 * </ul> +763 * <br/> +764 * NOTE1: Parameter "fulluri" and "dpname" supported +765 * since jsrsasign 9.0.0 asn1x509 2.0.0. +766 * <br/> +767 * NOTE2: The "reasons" and "cRLIssuer" fields are currently +768 * not supported. +769 * @example +770 * new KJUR.asn1.x509.DistributionPoint( +771 * {fulluri: "http://example.com/crl1.crl"}) +772 * new KJUR.asn1.x509.DistributionPoint( +773 * {dpname: {full: [{uri: "http://example.com/crl1.crl"}]}}) +774 * new KJUR.asn1.x509.DistributionPoint( +775 * {dpobj: new DistributionPoint(...)}) +776 */ +777 KJUR.asn1.x509.DistributionPoint = function(params) { +778 KJUR.asn1.x509.DistributionPoint.superclass.constructor.call(this); +779 var asn1DP = null, +780 _KJUR = KJUR, +781 _KJUR_asn1 = _KJUR.asn1, +782 _DistributionPointName = _KJUR_asn1.x509.DistributionPointName; +783 +784 this.getEncodedHex = function() { +785 var seq = new _KJUR_asn1.DERSequence(); +786 if (this.asn1DP != null) { +787 var o1 = new _KJUR_asn1.DERTaggedObject({'explicit': true, +788 'tag': 'a0', +789 'obj': this.asn1DP}); +790 seq.appendASN1Object(o1); +791 } +792 this.hTLV = seq.getEncodedHex(); +793 return this.hTLV; +794 }; +795 +796 if (params !== undefined) { +797 if (params.dpobj !== undefined) { +798 this.asn1DP = params.dpobj; +799 } else if (params.dpname !== undefined) { +800 this.asn1DP = new _DistributionPointName(params.dpname); +801 } else if (params.fulluri !== undefined) { +802 this.asn1DP = new _DistributionPointName({full: [{uri: params.fulluri}]}); +803 } +804 } +805 }; +806 YAHOO.lang.extend(KJUR.asn1.x509.DistributionPoint, KJUR.asn1.ASN1Object); +807 +808 /** +809 * DistributionPointName ASN.1 structure class<br/> +810 * @name KJUR.asn1.x509.DistributionPointName +811 * @class DistributionPointName ASN.1 structure class +812 * @param {Array} params JSON object of parameters or GeneralNames object +813 * @extends KJUR.asn1.ASN1Object +814 * @see {@link KJUR.asn1.x509.CRLDistributionPoints} +815 * @see {@link KJUR.asn1.x509.DistributionPoint} +816 * @see {@link KJUR.asn1.x509.GeneralNames} +817 * @see {@link X509#getDistributionPointName} +818 * @description +819 * This class represents +820 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.13"> +821 * DistributionPointName defined in RFC 5280 4.2.1.13</a>. +822 * <pre> +823 * DistributionPointName ::= CHOICE { +824 * fullName [0] GeneralNames, +825 * nameRelativeToCRLIssuer [1] RelativeDistinguishedName } +826 * </pre> +827 * Constructor can have following parameter: +828 * <ul> +829 * <li>{String}full - JSON object parameter of {@link KJUR.asn1.x509.GeneralNames} for 'fullName' field</li> +830 * <li>{GeneralNames} - {@link KJUR.asn1.x509.GeneralNames} object for 'fullName'</li> +831 * </ul> +832 * NOTE1: 'full' parameter have been suppored since jsrsasign 9.0.0 asn1x509 2.0.0. +833 * <br> +834 * NOTE2: The 'nameRelativeToCRLIssuer' field is currently not supported. +835 * @example +836 * new KJUR.asn1.x509.DistributionPointName({full: <<GeneralNamesParameter>>}) +837 * new KJUR.asn1.x509.DistributionPointName({full: [{uri: <<CDPURI>>}]}) +838 * new KJUR.asn1.x509.DistributionPointName({full: [{dn: <<DN Parameter>>}]} +839 * new KJUR.asn1.x509.DistributionPointName({full: [{uri: "http://example.com/root.crl"}]}) +840 * new KJUR.asn1.x509.DistributionPointName({full: [{dn {str: "/C=US/O=Test"}}]}) +841 * new KJUR.asn1.x509.DistributionPointName(new GeneralNames(...)) +842 */ +843 KJUR.asn1.x509.DistributionPointName = function(params) { +844 KJUR.asn1.x509.DistributionPointName.superclass.constructor.call(this); +845 var asn1Obj = null, +846 type = null, +847 tag = null, +848 asn1V = null, +849 _KJUR = KJUR, +850 _KJUR_asn1 = _KJUR.asn1, +851 _DERTaggedObject = _KJUR_asn1.DERTaggedObject; +852 +853 this.getEncodedHex = function() { +854 if (this.type != "full") +855 throw new Error("currently type shall be 'full': " + this.type); +856 this.asn1Obj = new _DERTaggedObject({'explicit': false, +857 'tag': this.tag, +858 'obj': this.asn1V}); +859 this.hTLV = this.asn1Obj.getEncodedHex(); +860 return this.hTLV; +861 }; +862 +863 if (params !== undefined) { +864 if (_KJUR_asn1.x509.GeneralNames.prototype.isPrototypeOf(params)) { +865 this.type = "full"; +866 this.tag = "a0"; +867 this.asn1V = params; +868 } else if (params.full !== undefined) { +869 this.type = "full"; +870 this.tag = "a0"; +871 this.asn1V = new _KJUR_asn1.x509.GeneralNames(params.full); +872 } else { +873 throw new Error("This class supports GeneralNames only as argument"); +874 } +875 } +876 }; +877 YAHOO.lang.extend(KJUR.asn1.x509.DistributionPointName, KJUR.asn1.ASN1Object); +878 +879 /** +880 * CertificatePolicies ASN.1 structure class +881 * @name KJUR.asn1.x509.CertificatePolicies +882 * @class CertificatePolicies ASN.1 structure class +883 * @param {Array} params associative array of parameters +884 * @extends KJUR.asn1.x509.Extension +885 * @since jsrsasign 8.0.23 asn1x509 1.1.12 +886 * @see KJUR.asn1.x509.CertificatePolicies +887 * @see KJUR.asn1.x509.PolicyInformation +888 * @see KJUR.asn1.x509.PolicyQualifierInfo +889 * @see KJUR.asn1.x509.UserNotice +890 * @see KJUR.asn1.x509.NoticeReference +891 * @see KJUR.asn1.x509.DisplayText +892 * @description +893 * This class represents +894 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> +895 * CertificatePolicies extension defined in RFC 5280 4.2.1.4</a>. +896 * <pre> +897 * id-ce-certificatePolicies OBJECT IDENTIFIER ::= { id-ce 32 } +898 * CertificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation +899 * </pre> +900 * Its constructor can have following parameters: +901 * <ul> +902 * <li>array - array of {@link KJUR.asn1.x509.PolicyInformation} parameter</li> +903 * <li>critical - boolean: critical flag</li> +904 * </ul> +905 * NOTE: Returned JSON value format have been changed without +906 * backward compatibility since jsrsasign 9.0.0 asn1x509 2.0.0. +907 * @example +908 * e1 = new KJUR.asn1.x509.CertificatePolicies({ +909 * array: [ +910 * { policyoid: "1.2.3.4.5", +911 * array: [ +912 * { cps: "https://example.com/repository" }, +913 * { unotice: { +914 * noticeref: { // CA SHOULD NOT use this by RFC +915 * org: {type: "ia5", str: "Sample Org"}, +916 * noticenum: [{int: 5}, {hex: "01af"}] +917 * }, +918 * exptext: {type: "ia5", str: "Sample Policy"} +919 * }} +920 * ] +921 * } +922 * ], +923 * critical: true +924 * }); +925 */ +926 KJUR.asn1.x509.CertificatePolicies = function(params) { +927 KJUR.asn1.x509.CertificatePolicies.superclass.constructor.call(this, params); +928 var _KJUR = KJUR, +929 _KJUR_asn1 = _KJUR.asn1, +930 _KJUR_asn1_x509 = _KJUR_asn1.x509, +931 _DERSequence = _KJUR_asn1.DERSequence, +932 _PolicyInformation = _KJUR_asn1_x509.PolicyInformation; +933 +934 this.params = null; +935 +936 this.getExtnValueHex = function() { +937 var aPI = []; +938 for (var i = 0; i < this.params.array.length; i++) { +939 aPI.push(new _PolicyInformation(this.params.array[i])); +940 } +941 var seq = new _DERSequence({array: aPI}); +942 this.asn1ExtnValue = seq; +943 return this.asn1ExtnValue.getEncodedHex(); +944 }; +945 +946 this.oid = "2.5.29.32"; +947 if (params !== undefined) { +948 this.params = params; +949 } +950 }; +951 YAHOO.lang.extend(KJUR.asn1.x509.CertificatePolicies, KJUR.asn1.x509.Extension); +952 +953 // ===== BEGIN CertificatePolicies related classes ===== +954 /** +955 * PolicyInformation ASN.1 structure class +956 * @name KJUR.asn1.x509.PolicyInformation +957 * @class PolicyInformation ASN.1 structure class +958 * @param {Array} params JSON object of parameters +959 * @extends KJUR.asn1.ASN1Object +960 * @since jsrsasign 8.0.23 asn1x509 1.1.12 +961 * @see KJUR.asn1.x509.CertificatePolicies +962 * @see KJUR.asn1.x509.PolicyInformation +963 * @see KJUR.asn1.x509.PolicyQualifierInfo +964 * @see KJUR.asn1.x509.UserNotice +965 * @see KJUR.asn1.x509.NoticeReference +966 * @see KJUR.asn1.x509.DisplayText +967 * @description +968 * This class represents +969 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> +970 * PolicyInformation defined in RFC 5280 4.2.1.4</a>. +971 * <pre> +972 * PolicyInformation ::= SEQUENCE { +973 * policyIdentifier CertPolicyId, +974 * policyQualifiers SEQUENCE SIZE (1..MAX) OF +975 * PolicyQualifierInfo OPTIONAL } +976 * CertPolicyId ::= OBJECT IDENTIFIER +977 * Its constructor can have following parameters: +978 * <ul> +979 * <li>{String}policyoid - policy OID (ex. "1.2.3.4.5")</li> +980 * <li>{Object}array - array of {@link KJUR.asn1.x509.PolicyQualifierInfo} +981 * parameters (OPTIONAL)</li> +982 * </ul> +983 * @example +984 * new KJUR.asn1.x509.PolicyInformation({ +985 * policyoid: "1.2.3.4.5", +986 * array: [ +987 * { cps: "https://example.com/repository" }, +988 * { unotice: { +989 * noticeref: { // CA SHOULD NOT use this by RFC +990 * org: {type: "ia5", str: "Sample Org"}, +991 * noticenum: [{int: 5}, {hex: "01af"}] +992 * }, +993 * exptext: {type: "ia5", str: "Sample Policy"} +994 * }} +995 * ] +996 * }) +997 */ +998 KJUR.asn1.x509.PolicyInformation = function(params) { +999 KJUR.asn1.x509.PolicyInformation.superclass.constructor.call(this, +1000 params); +1001 var _KJUR_asn1 = KJUR.asn1, +1002 _DERSequence = _KJUR_asn1.DERSequence, +1003 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, +1004 _PolicyQualifierInfo = _KJUR_asn1.x509.PolicyQualifierInfo; +1005 +1006 this.params = null; +1007 +1008 this.getEncodedHex = function() { +1009 if (this.params.policyoid === undefined && +1010 this.params.array === undefined) +1011 throw new Error("parameter oid and array missing"); +1012 +1013 // policy oid +1014 var a = [new _DERObjectIdentifier(this.params.policyoid)]; +1015 +1016 // array of ASN1Object of PolicyQualifierInfo +1017 if (this.params.array !== undefined) { +1018 var aPQI = []; +1019 for (var i = 0; i < this.params.array.length; i++) { +1020 aPQI.push(new _PolicyQualifierInfo(this.params.array[i])); +1021 } +1022 if (aPQI.length > 0) { +1023 a.push(new _DERSequence({array: aPQI})); +1024 } +1025 } +1026 +1027 var seq = new _DERSequence({array: a}); +1028 return seq.getEncodedHex(); +1029 }; +1030 +1031 if (params !== undefined) { +1032 this.params = params; +1033 } +1034 }; +1035 YAHOO.lang.extend(KJUR.asn1.x509.PolicyInformation, KJUR.asn1.ASN1Object); +1036 +1037 /** +1038 * PolicyQualifierInfo ASN.1 structure class +1039 * @name KJUR.asn1.x509.PolicyQualifierInfo +1040 * @class PolicyQualifierInfo ASN.1 structure class +1041 * @param {Array} params associative array of parameters +1042 * @extends KJUR.asn1.ASN1Object +1043 * @since jsrsasign 8.0.23 asn1x509 1.1.12 +1044 * @description +1045 * This class represents +1046 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> +1047 * PolicyQualifierInfo defined in RFC 5280 4.2.1.4</a>. +1048 * <pre> +1049 * PolicyQualifierInfo ::= SEQUENCE { +1050 * policyQualifierId PolicyQualifierId, +1051 * qualifier ANY DEFINED BY policyQualifierId } +1052 * PolicyQualifierId ::= OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice ) +1053 * CPSuri ::= IA5String +1054 * </pre> +1055 * Its constructor can have one of following two parameters: +1056 * <ul> +1057 * <li>{String}cps - URI string for CPS</li> +1058 * <li>{Object}unotice - {@link KJUR.asn1.x509.UserNotice} parameter</li> +1059 * </ul> +1060 * @example +1061 * new PolicyQualifierInfo({ +1062 * cps: "https://example.com/repository/cps" +1063 * }) +1064 * +1065 * new PolicyQualifierInfo({ +1066 * unotice: { +1067 * noticeref: { // CA SHOULD NOT use this by RFC +1068 * org: {type: "bmp", str: "Sample Org"}, +1069 * noticenum: [{int: 3}, {hex: "01af"}] +1070 * }, +1071 * exptext: {type: "ia5", str: "Sample Policy"} +1072 * } +1073 * }) +1074 */ +1075 KJUR.asn1.x509.PolicyQualifierInfo = function(params) { +1076 KJUR.asn1.x509.PolicyQualifierInfo.superclass.constructor.call(this, +1077 params); +1078 var _KJUR_asn1 = KJUR.asn1, +1079 _DERSequence = _KJUR_asn1.DERSequence, +1080 _DERIA5String = _KJUR_asn1.DERIA5String, +1081 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, +1082 _UserNotice = _KJUR_asn1.x509.UserNotice; +1083 +1084 this.params = null; +1085 +1086 this.getEncodedHex = function() { +1087 if (this.params.cps !== undefined) { +1088 var seq = new _DERSequence({array: [ +1089 new _DERObjectIdentifier({oid: '1.3.6.1.5.5.7.2.1'}), +1090 new _DERIA5String({str: this.params.cps}) +1091 ]}); +1092 return seq.getEncodedHex(); +1093 } +1094 if (this.params.unotice != undefined) { +1095 var seq = new _DERSequence({array: [ +1096 new _DERObjectIdentifier({oid: '1.3.6.1.5.5.7.2.2'}), +1097 new _UserNotice(this.params.unotice) +1098 ]}); +1099 return seq.getEncodedHex(); +1100 } +1101 }; +1102 +1103 if (params !== undefined) { +1104 this.params = params; +1105 } +1106 }; +1107 YAHOO.lang.extend(KJUR.asn1.x509.PolicyQualifierInfo, KJUR.asn1.ASN1Object); 1108 -1109 /** -1110 * UserNotice ASN.1 structure class -1111 * @name KJUR.asn1.x509.UserNotice -1112 * @class UserNotice ASN.1 structure class -1113 * @param {Array} params associative array of parameters -1114 * @extends KJUR.asn1.ASN1Object -1115 * @since jsrsasign 8.0.23 asn1x509 1.1.12 -1116 * @description -1117 * This class represents -1118 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> -1119 * UserNotice defined in RFC 5280 4.2.1.4</a>. -1120 * <pre> -1121 * UserNotice ::= SEQUENCE { -1122 * noticeRef NoticeReference OPTIONAL, -1123 * explicitText DisplayText OPTIONAL } -1124 * </pre> -1125 * Its constructor can have following two parameters: -1126 * <ul> -1127 * <li>{Object}noticeref - {@link KJUR.asn1.x509.NoticeReference} parameter. -1128 * This SHALL NOT be set for conforming CA by RFC 5280. (OPTIONAL)</li> -1129 * <li>{Object}exptext - explicitText value -1130 * by {@link KJUR.asn1.x509.DisplayText} parameter (OPTIONAL)</li> -1131 * </ul> -1132 * @example -1133 * new UserNotice({ -1134 * noticeref: { -1135 * org: {type: "bmp", str: "Sample Org"}, -1136 * noticenum: [{int: 3}, {hex: "01af"}] -1137 * }, -1138 * exptext: {type: "ia5", str: "Sample Policy"} -1139 * }) -1140 */ -1141 KJUR.asn1.x509.UserNotice = function(params) { -1142 KJUR.asn1.x509.UserNotice.superclass.constructor.call(this, params); -1143 var _DERSequence = KJUR.asn1.DERSequence, -1144 _DERInteger = KJUR.asn1.DERInteger, -1145 _DisplayText = KJUR.asn1.x509.DisplayText, -1146 _NoticeReference = KJUR.asn1.x509.NoticeReference; -1147 -1148 this.params = null; -1149 -1150 this.getEncodedHex = function() { -1151 var a = []; -1152 if (this.params.noticeref !== undefined) { -1153 a.push(new _NoticeReference(this.params.noticeref)); -1154 } -1155 if (this.params.exptext !== undefined) { -1156 a.push(new _DisplayText(this.params.exptext)); -1157 } -1158 var seq = new _DERSequence({array: a}); -1159 return seq.getEncodedHex(); -1160 }; -1161 -1162 if (params !== undefined) { -1163 this.params = params; -1164 } -1165 }; -1166 YAHOO.lang.extend(KJUR.asn1.x509.UserNotice, KJUR.asn1.ASN1Object); -1167 -1168 /** -1169 * NoticeReference ASN.1 structure class -1170 * @name KJUR.asn1.x509.NoticeReference -1171 * @class NoticeReference ASN.1 structure class -1172 * @param {Array} params associative array of parameters -1173 * @extends KJUR.asn1.ASN1Object -1174 * @since jsrsasign 8.0.23 asn1x509 1.1.12 -1175 * @description -1176 * This class represents -1177 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> -1178 * NoticeReference defined in RFC 5280 4.2.1.4</a>. -1179 * <pre> -1180 * NoticeReference ::= SEQUENCE { -1181 * organization DisplayText, -1182 * noticeNumbers SEQUENCE OF INTEGER } -1183 * </pre> -1184 * Its constructor can have following two parameters: -1185 * <ul> -1186 * <li>{Object}org - organization by {@link KJUR.asn1.x509.DisplayText} -1187 * parameter.</li> -1188 * <li>{Object}noticenum - noticeNumbers value by an array of -1189 * {@link KJUR.asn1.DERInteger} parameter</li> -1190 * </ul> -1191 * @example -1192 * new NoticeReference({ -1193 * org: {type: "bmp", str: "Sample Org"}, -1194 * noticenum: [{int: 3}, {hex: "01af"}] -1195 * }) -1196 */ -1197 KJUR.asn1.x509.NoticeReference = function(params) { -1198 KJUR.asn1.x509.NoticeReference.superclass.constructor.call(this, params); -1199 var _DERSequence = KJUR.asn1.DERSequence, -1200 _DERInteger = KJUR.asn1.DERInteger, -1201 _DisplayText = KJUR.asn1.x509.DisplayText; -1202 -1203 this.params = null; -1204 -1205 this.getEncodedHex = function() { -1206 var a = []; -1207 if (this.params.org !== undefined) { -1208 a.push(new _DisplayText(this.params.org)); -1209 } -1210 if (this.params.noticenum !== undefined) { -1211 var aNoticeNum = []; -1212 var aNumParam = this.params.noticenum; -1213 for (var i = 0; i < aNumParam.length; i++) { -1214 aNoticeNum.push(new _DERInteger(aNumParam[i])); -1215 } -1216 a.push(new _DERSequence({array: aNoticeNum})); -1217 } -1218 if (a.length == 0) throw new Error("parameter is empty"); -1219 var seq = new _DERSequence({array: a}); -1220 return seq.getEncodedHex(); -1221 } -1222 -1223 if (params !== undefined) { -1224 this.params = params; -1225 } -1226 }; -1227 YAHOO.lang.extend(KJUR.asn1.x509.NoticeReference, KJUR.asn1.ASN1Object); -1228 -1229 /** -1230 * DisplayText ASN.1 structure class -1231 * @name KJUR.asn1.x509.DisplayText -1232 * @class DisplayText ASN.1 structure class -1233 * @param {Array} params associative array of parameters -1234 * @extends KJUR.asn1.DERAbstractString -1235 * @since jsrsasign 8.0.23 asn1x509 1.1.12 -1236 * @description -1237 * This class represents -1238 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> -1239 * DisplayText defined in RFC 5280 4.2.1.4</a>. -1240 * <pre> -1241 * -- from RFC 5280 Appendix A -1242 * DisplayText ::= CHOICE { -1243 * ia5String IA5String (SIZE (1..200)), -1244 * visibleString VisibleString (SIZE (1..200)), -1245 * bmpString BMPString (SIZE (1..200)), -1246 * utf8String UTF8String (SIZE (1..200)) } -1247 * </pre> -1248 * {@link KJUR.asn1.DERAbstractString} parameters and methods -1249 * can be used. -1250 * Its constructor can also have following parameter: -1251 * <ul> -1252 * <li>{String} type - DirectoryString type of DisplayText. -1253 * "ia5" for IA5String, "vis" for VisibleString, -1254 * "bmp" for BMPString and "utf8" for UTF8String. -1255 * Default is "utf8". (OPTIONAL)</li> -1256 * </ul> -1257 * @example -1258 * new DisplayText({type: "bmp", str: "Sample Org"}) -1259 * new DisplayText({type: "ia5", str: "Sample Org"}) -1260 * new DisplayText({str: "Sample Org"}) -1261 */ -1262 KJUR.asn1.x509.DisplayText = function(params) { -1263 KJUR.asn1.x509.DisplayText.superclass.constructor.call(this, params); -1264 -1265 this.hT = "0c"; // DEFAULT "utf8" -1266 -1267 if (params !== undefined) { -1268 if (params.type === "ia5") { -1269 this.hT = "16"; -1270 } else if (params.type === "vis") { -1271 this.hT = "1a"; -1272 } else if (params.type === "bmp") { -1273 this.hT = "1e"; -1274 } -1275 } -1276 }; -1277 YAHOO.lang.extend(KJUR.asn1.x509.DisplayText, KJUR.asn1.DERAbstractString); -1278 // ===== END CertificatePolicies related classes ===== -1279 -1280 // ===================================================================== -1281 /** -1282 * KeyUsage ASN.1 structure class -1283 * @name KJUR.asn1.x509.ExtKeyUsage -1284 * @class ExtKeyUsage ASN.1 structure class -1285 * @param {Array} params associative array of parameters -1286 * @extends KJUR.asn1.x509.Extension -1287 * @description -1288 * @example -1289 * e1 = new KJUR.asn1.x509.ExtKeyUsage({ -1290 * critical: true, -1291 * array: [ -1292 * {oid: '2.5.29.37.0'}, // anyExtendedKeyUsage -1293 * {name: 'clientAuth'}, -1294 * "1.2.3.4", -1295 * "serverAuth" -1296 * ] -1297 * }); -1298 * // id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 } -1299 * // ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId -1300 * // KeyPurposeId ::= OBJECT IDENTIFIER -1301 */ -1302 KJUR.asn1.x509.ExtKeyUsage = function(params) { -1303 KJUR.asn1.x509.ExtKeyUsage.superclass.constructor.call(this, params); -1304 var _KJUR = KJUR, -1305 _KJUR_asn1 = _KJUR.asn1; -1306 -1307 this.setPurposeArray = function(purposeArray) { -1308 this.asn1ExtnValue = new _KJUR_asn1.DERSequence(); -1309 for (var i = 0; i < purposeArray.length; i++) { -1310 var o = new _KJUR_asn1.DERObjectIdentifier(purposeArray[i]); -1311 this.asn1ExtnValue.appendASN1Object(o); -1312 } -1313 }; -1314 -1315 this.getExtnValueHex = function() { -1316 return this.asn1ExtnValue.getEncodedHex(); -1317 }; -1318 -1319 this.oid = "2.5.29.37"; -1320 if (params !== undefined) { -1321 if (params.array !== undefined) { -1322 this.setPurposeArray(params.array); -1323 } -1324 } -1325 }; -1326 YAHOO.lang.extend(KJUR.asn1.x509.ExtKeyUsage, KJUR.asn1.x509.Extension); -1327 -1328 /** -1329 * AuthorityKeyIdentifier ASN.1 structure class -1330 * @name KJUR.asn1.x509.AuthorityKeyIdentifier -1331 * @class AuthorityKeyIdentifier ASN.1 structure class -1332 * @param {Array} params associative array of parameters (ex. {kid: {hex: '89ab...'}, critical: true}) -1333 * @extends KJUR.asn1.x509.Extension -1334 * @since asn1x509 1.0.8 -1335 * @description -1336 * This class represents ASN.1 structure for <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.1">AuthorityKeyIdentifier in RFC 5280</a>. -1337 * Constructor of this class may have following parameters.: -1338 * <ul> -1339 * <li>kid - When key object (RSA, KJUR.crypto.ECDSA/DSA) or PEM string of issuing authority public key or issuer certificate is specified, key identifier will be automatically calculated by the method specified in RFC 5280. When a hexadecimal string is specifed, kid will be set explicitly by it.</li> -1340 * <li>isscert - When PEM string of authority certificate is specified, both authorityCertIssuer and authorityCertSerialNumber will be set by the certificate.</li> -1341 * <li>issuer - {@link KJUR.asn1.x509.X500Name} parameter to specify issuer name explicitly.</li> -1342 * <li>sn - hexadecimal string to specify serial number explicitly.</li> -1343 * <li>critical - boolean to specify criticality of this extension -1344 * however conforming CA must mark this extension as non-critical in RFC 5280.</li> -1345 * </ul> -1346 * -1347 * <pre> -1348 * d-ce-authorityKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 35 } -1349 * AuthorityKeyIdentifier ::= SEQUENCE { -1350 * keyIdentifier [0] KeyIdentifier OPTIONAL, -1351 * authorityCertIssuer [1] GeneralNames OPTIONAL, -1352 * authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL } -1353 * KeyIdentifier ::= OCTET STRING -1354 * </pre> -1355 * -1356 * @example -1357 * // 1. kid by key object -1358 * keyobj = KEYUTIL.getKey("-----BEGIN PUBLIC KEY..."); -1359 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({kid: keyobj}); -1360 * // 2. kid by PEM string of authority certificate or public key -1361 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({kid: "-----BEGIN..."}); -1362 * // 3. specify kid explicitly -1363 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({kid: "8ab1d3..."}); -1364 * }); -1365 * // 4. issuer and serial number by auhtority PEM certificate -1366 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({isscert: "-----BEGIN..."}); -1367 * // 5. issuer and serial number explicitly -1368 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({ -1369 * issuer: {ldapstr: "O=test,C=US"}, -1370 * sn: {hex: "1ac7..."}}); -1371 * // 6. combination -1372 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({ -1373 * kid: "-----BEGIN CERTIFICATE...", -1374 * isscert: "-----BEGIN CERTIFICATE..."}); -1375 */ -1376 KJUR.asn1.x509.AuthorityKeyIdentifier = function(params) { -1377 KJUR.asn1.x509.AuthorityKeyIdentifier.superclass.constructor.call(this, params); -1378 var _KJUR = KJUR, -1379 _KJUR_asn1 = _KJUR.asn1, -1380 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, -1381 _GeneralNames = _KJUR_asn1.x509.GeneralNames, -1382 _isKey = _KJUR.crypto.Util.isKey; -1383 -1384 this.asn1KID = null; -1385 this.asn1CertIssuer = null; // X500Name hTLV -1386 this.asn1CertSN = null; -1387 -1388 this.getExtnValueHex = function() { -1389 var a = new Array(); -1390 if (this.asn1KID) -1391 a.push(new _DERTaggedObject({'explicit': false, -1392 'tag': '80', -1393 'obj': this.asn1KID})); -1394 -1395 if (this.asn1CertIssuer) -1396 a.push(new _DERTaggedObject({'explicit': false, -1397 'tag': 'a1', -1398 'obj': new _GeneralNames([{dn: this.asn1CertIssuer}])})); -1399 -1400 if (this.asn1CertSN) -1401 a.push(new _DERTaggedObject({'explicit': false, -1402 'tag': '82', -1403 'obj': this.asn1CertSN})); -1404 -1405 var asn1Seq = new _KJUR_asn1.DERSequence({'array': a}); -1406 this.asn1ExtnValue = asn1Seq; -1407 return this.asn1ExtnValue.getEncodedHex(); -1408 }; -1409 -1410 /** -1411 * set keyIdentifier value by DEROctetString parameter, key object or PEM file -1412 * @name setKIDByParam -1413 * @memberOf KJUR.asn1.x509.AuthorityKeyIdentifier# -1414 * @function -1415 * @param {Array} param parameter to set key identifier -1416 * @since asn1x509 1.0.8 -1417 * @description -1418 * This method will set keyIdentifier by param. -1419 * Its key identifier value can be set by following type of param argument: -1420 * <ul> -1421 * <li>{str: "123"} - by raw string</li> -1422 * <li>{hex: "01af..."} - by hexadecimal value</li> -1423 * <li>RSAKey/DSA/ECDSA - by RSAKey, KJUR.crypto.{DSA/ECDSA} public key object. -1424 * key identifier value will be calculated by the method described in -1425 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. -1426 * </li> -1427 * <li>certificate PEM string - extract subjectPublicKeyInfo from specified PEM -1428 * certificate and -1429 * key identifier value will be calculated by the method described in -1430 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. -1431 * <li>PKCS#1/#8 public key PEM string - pem will be converted to a key object and -1432 * to PKCS#8 ASN.1 structure then calculate -1433 * a key identifier value will be calculated by the method described in -1434 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. -1435 * </ul> -1436 * -1437 * NOTE1: Automatic key identifier calculation is supported -1438 * since jsrsasign 8.0.16. -1439 * -1440 * @see KEYUTIL.getKeyID -1441 * -1442 * @example -1443 * o = new KJUR.asn1.x509.AuthorityKeyIdentifier(); -1444 * // set by hexadecimal string -1445 * o.setKIDByParam({hex: '1ad9...'}); -1446 * // set by SubjectPublicKeyInfo of PEM certificate string -1447 * o.setKIDByParam("-----BEGIN CERTIFICATE..."); -1448 * // set by PKCS#8 PEM public key string -1449 * o.setKIDByParam("-----BEGIN PUBLIC KEY..."); -1450 * // set by public key object -1451 * pubkey = KEYUTIL.getKey("-----BEGIN CERTIFICATE..."); -1452 * o.setKIDByParam(pubkey); -1453 */ -1454 this.setKIDByParam = function(param) { -1455 if (param.str !== undefined || -1456 param.hex !== undefined) { -1457 this.asn1KID = new KJUR.asn1.DEROctetString(param); -1458 } else if ((typeof param === "object" && -1459 KJUR.crypto.Util.isKey(param)) || -1460 (typeof param === "string" && -1461 param.indexOf("BEGIN ") != -1)) { -1462 -1463 var keyobj = param; -1464 if (typeof param === "string") { -1465 keyobj = KEYUTIL.getKey(param); -1466 } -1467 -1468 var kid = KEYUTIL.getKeyID(keyobj); -1469 this.asn1KID = new KJUR.asn1.DEROctetString({hex: kid}); -1470 } -1471 }; -1472 -1473 /** -1474 * set authorityCertIssuer value by X500Name parameter -1475 * @name setCertIssuerByParam -1476 * @memberOf KJUR.asn1.x509.AuthorityKeyIdentifier# -1477 * @function -1478 * @param {Array} param parameter to set issuer name -1479 * @since asn1x509 1.0.8 -1480 * @description -1481 * This method will set authorityCertIssuer name by param. -1482 * Issuer name can be set by following type of param argument: -1483 * <ul> -1484 * <li>str/ldapstr/hex/certsubject/certissuer - -1485 * set issuer by {@link KJUR.asn1.x509.X500Name} -1486 * object with specified parameters.</li> -1487 * <li>PEM CERTIFICATE STRING - extract its subject name from -1488 * specified issuer PEM certificate and set. -1489 * </ul> -1490 * NOTE1: Automatic authorityCertIssuer setting by certificate -1491 * is supported since jsrsasign 8.0.16. -1492 * -1493 * @see KJUR.asn1.x509.X500Name -1494 * @see KJUR.asn1.x509.GeneralNames -1495 * @see X509.getSubjectHex -1496 * -1497 * @example -1498 * var o = new KJUR.asn1.x509.AuthorityKeyIdentifier(); -1499 * // 1. set it by string -1500 * o.setCertIssuerByParam({str: '/C=US/O=Test'}); -1501 * // 2. set it by issuer PEM certificate -1502 * o.setCertIssuerByParam("-----BEGIN CERTIFICATE..."); -1503 * -1504 */ -1505 this.setCertIssuerByParam = function(param) { -1506 if (param.str !== undefined || -1507 param.ldapstr !== undefined || -1508 param.hex !== undefined || -1509 param.certsubject !== undefined || -1510 param.certissuer !== undefined) { -1511 this.asn1CertIssuer = new KJUR.asn1.x509.X500Name(param); -1512 } else if (typeof param === "string" && -1513 param.indexOf("BEGIN ") != -1 && -1514 param.indexOf("CERTIFICATE") != -1) { -1515 this.asn1CertIssuer = new KJUR.asn1.x509.X500Name({certissuer: param}); -1516 } -1517 }; -1518 -1519 /** -1520 * set authorityCertSerialNumber value -1521 * @name setCertSerialNumberByParam -1522 * @memberOf KJUR.asn1.x509.AuthorityKeyIdentifier# -1523 * @function -1524 * @param {Object} param parameter to set serial number -1525 * @since asn1x509 1.0.8 -1526 * @description -1527 * This method will set authorityCertSerialNumber by param. -1528 * Serial number can be set by following type of param argument: -1529 * -1530 * <ul> -1531 * <li>{int: 123} - by integer value</li> -1532 * <li>{hex: "01af"} - by hexadecimal integer value</li> -1533 * <li>{bigint: new BigInteger(...)} - by hexadecimal integer value</li> -1534 * <li>PEM CERTIFICATE STRING - extract serial number from issuer certificate and -1535 * set serial number. -1536 * -1537 * NOTE1: Automatic authorityCertSerialNumber setting by certificate -1538 * is supported since jsrsasign 8.0.16. -1539 * -1540 * @see X509.getSerialNumberHex -1541 */ -1542 this.setCertSNByParam = function(param) { -1543 if (param.str !== undefined || -1544 param.bigint !== undefined || -1545 param.hex !== undefined) { -1546 this.asn1CertSN = new KJUR.asn1.DERInteger(param); -1547 } else if (typeof param === "string" && -1548 param.indexOf("BEGIN ") != -1 && -1549 param.indexOf("CERTIFICATE")) { -1550 -1551 var x = new X509(); -1552 x.readCertPEM(param); -1553 var sn = x.getSerialNumberHex(); -1554 this.asn1CertSN = new KJUR.asn1.DERInteger({hex: sn}); -1555 } -1556 }; -1557 -1558 this.oid = "2.5.29.35"; -1559 if (params !== undefined) { -1560 if (params.kid !== undefined) { -1561 this.setKIDByParam(params.kid); -1562 } -1563 if (params.issuer !== undefined) { -1564 this.setCertIssuerByParam(params.issuer); -1565 } -1566 if (params.sn !== undefined) { -1567 this.setCertSNByParam(params.sn); -1568 } -1569 -1570 if (params.issuersn !== undefined && -1571 typeof params.issuersn === "string" && -1572 params.issuersn.indexOf("BEGIN ") != -1 && -1573 params.issuersn.indexOf("CERTIFICATE")) { -1574 this.setCertSNByParam(params.issuersn); -1575 this.setCertIssuerByParam(params.issuersn); -1576 } -1577 } -1578 }; -1579 YAHOO.lang.extend(KJUR.asn1.x509.AuthorityKeyIdentifier, KJUR.asn1.x509.Extension); -1580 -1581 /** -1582 * SubjectKeyIdentifier extension ASN.1 structure class -1583 * @name KJUR.asn1.x509.SubjectKeyIdentifier -1584 * @class SubjectKeyIdentifier ASN.1 structure class -1585 * @param {Array} params associative array of parameters (ex. {kid: {hex: '89ab...'}, critical: true}) -1586 * @extends KJUR.asn1.x509.Extension -1587 * @since asn1x509 1.1.7 jsrsasign 8.0.14 -1588 * @description -1589 * This class represents ASN.1 structure for -1590 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2"> -1591 * SubjectKeyIdentifier in RFC 5280</a>. -1592 * Constructor of this class may have following parameters: -1593 * <ul> -1594 * <li>kid - When key object (RSA, KJUR.crypto.ECDSA/DSA) or PEM string of subject public key or certificate is specified, key identifier will be automatically calculated by the method specified in RFC 5280. When a hexadecimal string is specifed, kid will be set explicitly by it.</li> -1595 * <li>critical - boolean to specify criticality of this extension -1596 * however conforming CA must mark this extension as non-critical in RFC 5280.</li> -1597 * </ul> -1598 * <pre> -1599 * d-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 14 } -1600 * SubjectKeyIdentifier ::= KeyIdentifier -1601 * KeyIdentifier ::= OCTET STRING -1602 * </pre> -1603 * -1604 * @example -1605 * // set by hexadecimal string -1606 * e = new KJUR.asn1.x509.SubjectKeyIdentifier({kid: {hex: '89ab'}}); -1607 * // set by PEM public key or certificate string -1608 * e = new KJUR.asn1.x509.SubjectKeyIdentifier({kid: "-----BEGIN CERTIFICATE..."}); -1609 * // set by public key object -1610 * pubkey = KEYUTIL.getKey("-----BEGIN CERTIFICATE..."); -1611 * e = new KJUR.asn1.x509.SubjectKeyIdentifier({kid: pubkey}); -1612 */ -1613 KJUR.asn1.x509.SubjectKeyIdentifier = function(params) { -1614 KJUR.asn1.x509.SubjectKeyIdentifier.superclass.constructor.call(this, params); -1615 var _KJUR = KJUR, -1616 _KJUR_asn1 = _KJUR.asn1, -1617 _DEROctetString = _KJUR_asn1.DEROctetString; -1618 -1619 this.asn1KID = null; -1620 -1621 this.getExtnValueHex = function() { -1622 this.asn1ExtnValue = this.asn1KID; -1623 return this.asn1ExtnValue.getEncodedHex(); -1624 }; -1625 -1626 /** -1627 * set keyIdentifier value by DEROctetString parameter, key object or PEM file -1628 * @name setKIDByParam -1629 * @memberOf KJUR.asn1.x509.SubjectKeyIdentifier# -1630 * @function -1631 * @param {Array} param array of {@link KJUR.asn1.DERInteger} parameter -1632 * @since asn1x509 1.1.7 jsrsasign 8.0.14 -1633 * @description -1634 * <ul> -1635 * <li>{str: "123"} - by raw string</li> -1636 * <li>{hex: "01af..."} - by hexadecimal value</li> -1637 * <li>RSAKey/DSA/ECDSA - by RSAKey, KJUR.crypto.{DSA/ECDSA} public key object. -1638 * key identifier value will be calculated by the method described in -1639 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. -1640 * </li> -1641 * <li>certificate PEM string - extract subjectPublicKeyInfo from specified PEM -1642 * certificate and -1643 * key identifier value will be calculated by the method described in -1644 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. -1645 * <li>PKCS#1/#8 public key PEM string - pem will be converted to a key object and -1646 * to PKCS#8 ASN.1 structure then calculate -1647 * a key identifier value will be calculated by the method described in -1648 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. -1649 * </ul> -1650 * -1651 * NOTE1: Automatic key identifier calculation is supported -1652 * since jsrsasign 8.0.16. -1653 * -1654 * @see KEYUTIL.getKeyID -1655 * -1656 * @example -1657 * o = new KJUR.asn1.x509.SubjectKeyIdentifier(); -1658 * // set by hexadecimal string -1659 * o.setKIDByParam({hex: '1ad9...'}); -1660 * // set by SubjectPublicKeyInfo of PEM certificate string -1661 * o.setKIDByParam("-----BEGIN CERTIFICATE..."); -1662 * // set by PKCS#8 PEM public key string -1663 * o.setKIDByParam("-----BEGIN PUBLIC KEY..."); -1664 * // set by public key object -1665 * pubkey = KEYUTIL.getKey("-----BEGIN CERTIFICATE..."); -1666 * o.setKIDByParam(pubkey); -1667 */ -1668 this.setKIDByParam = function(param) { -1669 if (param.str !== undefined || -1670 param.hex !== undefined) { -1671 this.asn1KID = new _DEROctetString(param); -1672 } else if ((typeof param === "object" && -1673 KJUR.crypto.Util.isKey(param)) || -1674 (typeof param === "string" && -1675 param.indexOf("BEGIN") != -1)) { -1676 -1677 var keyobj = param; -1678 if (typeof param === "string") { -1679 keyobj = KEYUTIL.getKey(param); -1680 } -1681 -1682 var kid = KEYUTIL.getKeyID(keyobj); -1683 this.asn1KID = new KJUR.asn1.DEROctetString({hex: kid}); -1684 } -1685 }; -1686 -1687 this.oid = "2.5.29.14"; -1688 if (params !== undefined) { -1689 if (params.kid !== undefined) { -1690 this.setKIDByParam(params.kid); -1691 } -1692 } -1693 }; -1694 YAHOO.lang.extend(KJUR.asn1.x509.SubjectKeyIdentifier, KJUR.asn1.x509.Extension); -1695 -1696 /** -1697 * AuthorityInfoAccess ASN.1 structure class -1698 * @name KJUR.asn1.x509.AuthorityInfoAccess -1699 * @class AuthorityInfoAccess ASN.1 structure class -1700 * @param {Array} params JSON object of AuthorityInfoAccess parameters -1701 * @extends KJUR.asn1.x509.Extension -1702 * @since asn1x509 1.0.8 -1703 * @see {@link X509#getExtAuthorityInfoAccess} -1704 * @description -1705 * This class represents -1706 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.2.1"> -1707 * AuthorityInfoAccess extension defined in RFC 5280 4.2.2.1</a>. -1708 * <pre> -1709 * id-pe OBJECT IDENTIFIER ::= { id-pkix 1 } -1710 * id-pe-authorityInfoAccess OBJECT IDENTIFIER ::= { id-pe 1 } -1711 * AuthorityInfoAccessSyntax ::= -1712 * SEQUENCE SIZE (1..MAX) OF AccessDescription -1713 * AccessDescription ::= SEQUENCE { -1714 * accessMethod OBJECT IDENTIFIER, -1715 * accessLocation GeneralName } -1716 * id-ad OBJECT IDENTIFIER ::= { id-pkix 48 } -1717 * id-ad-caIssuers OBJECT IDENTIFIER ::= { id-ad 2 } -1718 * id-ad-ocsp OBJECT IDENTIFIER ::= { id-ad 1 } -1719 * </pre> -1720 * NOTE: Acceptable parameters have been changed since -1721 * from jsrsasign 9.0.0 asn1x509 2.0.0. -1722 * Parameter generated by {@link X509#getAuthorityInfoAccess} -1723 * can be accepted as a argument of this constructor. -1724 * @example -1725 * e1 = new KJUR.asn1.x509.AuthorityInfoAccess({ -1726 * array: [ -1727 * {ocsp: 'http://ocsp.example.org'}, -1728 * {caissuer: 'https://repository.example.org/aaa.crt'} -1729 * ] -1730 * }); -1731 */ -1732 KJUR.asn1.x509.AuthorityInfoAccess = function(params) { -1733 KJUR.asn1.x509.AuthorityInfoAccess.superclass.constructor.call(this, params); -1734 -1735 this.setAccessDescriptionArray = function(aParam) { -1736 var aASN1 = new Array(), -1737 _KJUR = KJUR, -1738 _KJUR_asn1 = _KJUR.asn1, -1739 _DERSequence = _KJUR_asn1.DERSequence, -1740 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, -1741 _GeneralName = _KJUR_asn1.x509.GeneralName; -1742 -1743 for (var i = 0; i < aParam.length; i++) { -1744 var adseq; -1745 var adparam = aParam[i]; -1746 -1747 if (adparam.ocsp !== undefined) { -1748 adseq = new _DERSequence({array: [ -1749 new _DERObjectIdentifier({oid: "1.3.6.1.5.5.7.48.1"}), -1750 new _GeneralName({uri: adparam.ocsp}) -1751 ]}); -1752 } else if (adparam.caissuer !== undefined) { -1753 adseq = new _DERSequence({array: [ -1754 new _DERObjectIdentifier({oid: "1.3.6.1.5.5.7.48.2"}), -1755 new _GeneralName({uri: adparam.caissuer}) -1756 ]}); -1757 } else { -1758 throw new Error("unknown AccessMethod parameter: " + -1759 JSON.stringify(adparam)); -1760 } -1761 aASN1.push(adseq); -1762 } -1763 this.asn1ExtnValue = new _DERSequence({'array':aASN1}); -1764 }; -1765 -1766 this.getExtnValueHex = function() { -1767 return this.asn1ExtnValue.getEncodedHex(); -1768 }; -1769 -1770 this.oid = "1.3.6.1.5.5.7.1.1"; -1771 if (params !== undefined) { -1772 if (params.array !== undefined) { -1773 this.setAccessDescriptionArray(params.array); -1774 } -1775 } -1776 }; -1777 YAHOO.lang.extend(KJUR.asn1.x509.AuthorityInfoAccess, KJUR.asn1.x509.Extension); -1778 -1779 /** -1780 * SubjectAltName ASN.1 structure class<br/> -1781 * @name KJUR.asn1.x509.SubjectAltName -1782 * @class SubjectAltName ASN.1 structure class -1783 * @param {Array} params associative array of parameters -1784 * @extends KJUR.asn1.x509.Extension -1785 * @since jsrsasign 6.2.3 asn1x509 1.0.19 -1786 * @see KJUR.asn1.x509.GeneralNames -1787 * @see KJUR.asn1.x509.GeneralName -1788 * @description -1789 * This class provides X.509v3 SubjectAltName extension. -1790 * <pre> -1791 * id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 } -1792 * SubjectAltName ::= GeneralNames -1793 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName -1794 * GeneralName ::= CHOICE { -1795 * otherName [0] OtherName, -1796 * rfc822Name [1] IA5String, -1797 * dNSName [2] IA5String, -1798 * x400Address [3] ORAddress, -1799 * directoryName [4] Name, -1800 * ediPartyName [5] EDIPartyName, -1801 * uniformResourceIdentifier [6] IA5String, -1802 * iPAddress [7] OCTET STRING, -1803 * registeredID [8] OBJECT IDENTIFIER } -1804 * </pre> -1805 * @example -1806 * e1 = new KJUR.asn1.x509.SubjectAltName({ -1807 * critical: true, -1808 * array: [{uri: 'http://aaa.com/'}, {uri: 'http://bbb.com/'}] -1809 * }); -1810 */ -1811 KJUR.asn1.x509.SubjectAltName = function(params) { -1812 KJUR.asn1.x509.SubjectAltName.superclass.constructor.call(this, params) -1813 -1814 this.setNameArray = function(paramsArray) { -1815 this.asn1ExtnValue = new KJUR.asn1.x509.GeneralNames(paramsArray); -1816 }; -1817 -1818 this.getExtnValueHex = function() { -1819 return this.asn1ExtnValue.getEncodedHex(); -1820 }; -1821 -1822 this.oid = "2.5.29.17"; -1823 if (params !== undefined) { -1824 if (params.array !== undefined) { -1825 this.setNameArray(params.array); -1826 } -1827 } -1828 }; -1829 YAHOO.lang.extend(KJUR.asn1.x509.SubjectAltName, KJUR.asn1.x509.Extension); -1830 -1831 /** -1832 * IssuerAltName ASN.1 structure class<br/> -1833 * @name KJUR.asn1.x509.IssuerAltName -1834 * @class IssuerAltName ASN.1 structure class -1835 * @param {Array} params associative array of parameters -1836 * @extends KJUR.asn1.x509.Extension -1837 * @since jsrsasign 6.2.3 asn1x509 1.0.19 -1838 * @see KJUR.asn1.x509.GeneralNames -1839 * @see KJUR.asn1.x509.GeneralName -1840 * @description -1841 * This class provides X.509v3 IssuerAltName extension. -1842 * <pre> -1843 * id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 18 } -1844 * IssuerAltName ::= GeneralNames -1845 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName -1846 * GeneralName ::= CHOICE { -1847 * otherName [0] OtherName, -1848 * rfc822Name [1] IA5String, -1849 * dNSName [2] IA5String, -1850 * x400Address [3] ORAddress, -1851 * directoryName [4] Name, -1852 * ediPartyName [5] EDIPartyName, -1853 * uniformResourceIdentifier [6] IA5String, -1854 * iPAddress [7] OCTET STRING, -1855 * registeredID [8] OBJECT IDENTIFIER } -1856 * </pre> -1857 * @example -1858 * e1 = new KJUR.asn1.x509.IssuerAltName({ -1859 * critical: true, -1860 * array: [{uri: 'http://aaa.com/'}, {uri: 'http://bbb.com/'}] -1861 * }); -1862 */ -1863 KJUR.asn1.x509.IssuerAltName = function(params) { -1864 KJUR.asn1.x509.IssuerAltName.superclass.constructor.call(this, params) -1865 -1866 this.setNameArray = function(paramsArray) { -1867 this.asn1ExtnValue = new KJUR.asn1.x509.GeneralNames(paramsArray); -1868 }; -1869 -1870 this.getExtnValueHex = function() { -1871 return this.asn1ExtnValue.getEncodedHex(); -1872 }; -1873 -1874 this.oid = "2.5.29.18"; -1875 if (params !== undefined) { -1876 if (params.array !== undefined) { -1877 this.setNameArray(params.array); -1878 } -1879 } -1880 }; -1881 YAHOO.lang.extend(KJUR.asn1.x509.IssuerAltName, KJUR.asn1.x509.Extension); -1882 -1883 /** -1884 * SubjectDirectoryAttributes ASN.1 structure class<br/> -1885 * @name KJUR.asn1.x509.SubjectDirectoryAttributes -1886 * @class SubjectDirectoryAttributes ASN.1 structure class -1887 * @param {Array} params associative array of parameters -1888 * @extends KJUR.asn1.x509.Extension -1889 * @since jsrsasign 10.1.9 asn1x509 2.1.7 -1890 * @description -1891 * This class provides X.509v3 SubjectDirectoryAttributes extension -1892 * defined in <a href="https://tools.ietf.org/html/rfc3739#section-3.3.2"> -1893 * RFC 3739 Qualified Certificate Profile section 3.3.2</a>. -1894 * <pre> -1895 * SubjectDirectoryAttributes ::= Attributes -1896 * Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute -1897 * Attribute ::= SEQUENCE { -1898 * type AttributeType -1899 * values SET OF AttributeValue } -1900 * AttributeType ::= OBJECT IDENTIFIER -1901 * AttributeValue ::= ANY DEFINED BY AttributeType -1902 * </pre> -1903 * @example -1904 * e1 = new KJUR.asn1.x509.SubjectDirectoryAttributes({ -1905 * extname: "subjectDirectoryAttributes", -1906 * array: [ -1907 * { attr: "dateOfBirth", str: "19701231230000Z" }, -1908 * { attr: "placeOfBirth", str: "Tokyo" }, -1909 * { attr: "gender", str: "F" }, -1910 * { attr: "countryOfCitizenship", str: "JP" }, -1911 * { attr: "countryOfResidence", str: "JP" } -1912 * ] -1913 * }); -1914 */ -1915 KJUR.asn1.x509.SubjectDirectoryAttributes = function(params) { -1916 KJUR.asn1.x509.SubjectDirectoryAttributes.superclass.constructor.call(this, params); -1917 var _KJUR_asn1 = KJUR.asn1, -1918 _DERSequence = _KJUR_asn1.DERSequence, -1919 _newObject = _KJUR_asn1.ASN1Util.newObject, -1920 _name2oid = _KJUR_asn1.x509.OID.name2oid; -1921 -1922 this.params = null; -1923 -1924 this.getExtnValueHex = function() { -1925 var a = []; -1926 for (var i = 0; i < this.params.array.length; i++) { -1927 var pAttr = this.params.array[i]; -1928 -1929 var newparam = { -1930 "seq": [ -1931 {"oid": "1.2.3.4"}, -1932 {"set": [{"utf8str": "DE"}]} -1933 ] -1934 }; -1935 -1936 if (pAttr.attr == "dateOfBirth") { -1937 newparam.seq[0].oid = _name2oid(pAttr.attr); -1938 newparam.seq[1].set[0] = {"gentime": pAttr.str}; -1939 } else if (pAttr.attr == "placeOfBirth") { -1940 newparam.seq[0].oid = _name2oid(pAttr.attr); -1941 newparam.seq[1].set[0] = {"utf8str": pAttr.str}; -1942 } else if (pAttr.attr == "gender") { -1943 newparam.seq[0].oid = _name2oid(pAttr.attr); -1944 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; -1945 } else if (pAttr.attr == "countryOfCitizenship") { -1946 newparam.seq[0].oid = _name2oid(pAttr.attr); -1947 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; -1948 } else if (pAttr.attr == "countryOfResidence") { -1949 newparam.seq[0].oid = _name2oid(pAttr.attr); -1950 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; -1951 } else { -1952 throw new Error("unsupported attribute: " + pAttr.attr); -1953 } -1954 a.push(new _newObject(newparam)); -1955 } -1956 var seq = new _DERSequence({array: a}); -1957 this.asn1ExtnValue = seq; -1958 return this.asn1ExtnValue.getEncodedHex(); -1959 }; -1960 -1961 this.oid = "2.5.29.9"; -1962 if (params !== undefined) { -1963 this.params = params; -1964 } -1965 }; -1966 YAHOO.lang.extend(KJUR.asn1.x509.SubjectDirectoryAttributes, KJUR.asn1.x509.Extension); -1967 +1109 +1110 /** +1111 * UserNotice ASN.1 structure class +1112 * @name KJUR.asn1.x509.UserNotice +1113 * @class UserNotice ASN.1 structure class +1114 * @param {Array} params associative array of parameters +1115 * @extends KJUR.asn1.ASN1Object +1116 * @since jsrsasign 8.0.23 asn1x509 1.1.12 +1117 * @description +1118 * This class represents +1119 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> +1120 * UserNotice defined in RFC 5280 4.2.1.4</a>. +1121 * <pre> +1122 * UserNotice ::= SEQUENCE { +1123 * noticeRef NoticeReference OPTIONAL, +1124 * explicitText DisplayText OPTIONAL } +1125 * </pre> +1126 * Its constructor can have following two parameters: +1127 * <ul> +1128 * <li>{Object}noticeref - {@link KJUR.asn1.x509.NoticeReference} parameter. +1129 * This SHALL NOT be set for conforming CA by RFC 5280. (OPTIONAL)</li> +1130 * <li>{Object}exptext - explicitText value +1131 * by {@link KJUR.asn1.x509.DisplayText} parameter (OPTIONAL)</li> +1132 * </ul> +1133 * @example +1134 * new UserNotice({ +1135 * noticeref: { +1136 * org: {type: "bmp", str: "Sample Org"}, +1137 * noticenum: [{int: 3}, {hex: "01af"}] +1138 * }, +1139 * exptext: {type: "ia5", str: "Sample Policy"} +1140 * }) +1141 */ +1142 KJUR.asn1.x509.UserNotice = function(params) { +1143 KJUR.asn1.x509.UserNotice.superclass.constructor.call(this, params); +1144 var _DERSequence = KJUR.asn1.DERSequence, +1145 _DERInteger = KJUR.asn1.DERInteger, +1146 _DisplayText = KJUR.asn1.x509.DisplayText, +1147 _NoticeReference = KJUR.asn1.x509.NoticeReference; +1148 +1149 this.params = null; +1150 +1151 this.getEncodedHex = function() { +1152 var a = []; +1153 if (this.params.noticeref !== undefined) { +1154 a.push(new _NoticeReference(this.params.noticeref)); +1155 } +1156 if (this.params.exptext !== undefined) { +1157 a.push(new _DisplayText(this.params.exptext)); +1158 } +1159 var seq = new _DERSequence({array: a}); +1160 return seq.getEncodedHex(); +1161 }; +1162 +1163 if (params !== undefined) { +1164 this.params = params; +1165 } +1166 }; +1167 YAHOO.lang.extend(KJUR.asn1.x509.UserNotice, KJUR.asn1.ASN1Object); +1168 +1169 /** +1170 * NoticeReference ASN.1 structure class +1171 * @name KJUR.asn1.x509.NoticeReference +1172 * @class NoticeReference ASN.1 structure class +1173 * @param {Array} params associative array of parameters +1174 * @extends KJUR.asn1.ASN1Object +1175 * @since jsrsasign 8.0.23 asn1x509 1.1.12 +1176 * @description +1177 * This class represents +1178 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> +1179 * NoticeReference defined in RFC 5280 4.2.1.4</a>. +1180 * <pre> +1181 * NoticeReference ::= SEQUENCE { +1182 * organization DisplayText, +1183 * noticeNumbers SEQUENCE OF INTEGER } +1184 * </pre> +1185 * Its constructor can have following two parameters: +1186 * <ul> +1187 * <li>{Object}org - organization by {@link KJUR.asn1.x509.DisplayText} +1188 * parameter.</li> +1189 * <li>{Object}noticenum - noticeNumbers value by an array of +1190 * {@link KJUR.asn1.DERInteger} parameter</li> +1191 * </ul> +1192 * @example +1193 * new NoticeReference({ +1194 * org: {type: "bmp", str: "Sample Org"}, +1195 * noticenum: [{int: 3}, {hex: "01af"}] +1196 * }) +1197 */ +1198 KJUR.asn1.x509.NoticeReference = function(params) { +1199 KJUR.asn1.x509.NoticeReference.superclass.constructor.call(this, params); +1200 var _DERSequence = KJUR.asn1.DERSequence, +1201 _DERInteger = KJUR.asn1.DERInteger, +1202 _DisplayText = KJUR.asn1.x509.DisplayText; +1203 +1204 this.params = null; +1205 +1206 this.getEncodedHex = function() { +1207 var a = []; +1208 if (this.params.org !== undefined) { +1209 a.push(new _DisplayText(this.params.org)); +1210 } +1211 if (this.params.noticenum !== undefined) { +1212 var aNoticeNum = []; +1213 var aNumParam = this.params.noticenum; +1214 for (var i = 0; i < aNumParam.length; i++) { +1215 aNoticeNum.push(new _DERInteger(aNumParam[i])); +1216 } +1217 a.push(new _DERSequence({array: aNoticeNum})); +1218 } +1219 if (a.length == 0) throw new Error("parameter is empty"); +1220 var seq = new _DERSequence({array: a}); +1221 return seq.getEncodedHex(); +1222 } +1223 +1224 if (params !== undefined) { +1225 this.params = params; +1226 } +1227 }; +1228 YAHOO.lang.extend(KJUR.asn1.x509.NoticeReference, KJUR.asn1.ASN1Object); +1229 +1230 /** +1231 * DisplayText ASN.1 structure class +1232 * @name KJUR.asn1.x509.DisplayText +1233 * @class DisplayText ASN.1 structure class +1234 * @param {Array} params associative array of parameters +1235 * @extends KJUR.asn1.DERAbstractString +1236 * @since jsrsasign 8.0.23 asn1x509 1.1.12 +1237 * @description +1238 * This class represents +1239 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.4"> +1240 * DisplayText defined in RFC 5280 4.2.1.4</a>. +1241 * <pre> +1242 * -- from RFC 5280 Appendix A +1243 * DisplayText ::= CHOICE { +1244 * ia5String IA5String (SIZE (1..200)), +1245 * visibleString VisibleString (SIZE (1..200)), +1246 * bmpString BMPString (SIZE (1..200)), +1247 * utf8String UTF8String (SIZE (1..200)) } +1248 * </pre> +1249 * {@link KJUR.asn1.DERAbstractString} parameters and methods +1250 * can be used. +1251 * Its constructor can also have following parameter: +1252 * <ul> +1253 * <li>{String} type - DirectoryString type of DisplayText. +1254 * "ia5" for IA5String, "vis" for VisibleString, +1255 * "bmp" for BMPString and "utf8" for UTF8String. +1256 * Default is "utf8". (OPTIONAL)</li> +1257 * </ul> +1258 * @example +1259 * new DisplayText({type: "bmp", str: "Sample Org"}) +1260 * new DisplayText({type: "ia5", str: "Sample Org"}) +1261 * new DisplayText({str: "Sample Org"}) +1262 */ +1263 KJUR.asn1.x509.DisplayText = function(params) { +1264 KJUR.asn1.x509.DisplayText.superclass.constructor.call(this, params); +1265 +1266 this.hT = "0c"; // DEFAULT "utf8" +1267 +1268 if (params !== undefined) { +1269 if (params.type === "ia5") { +1270 this.hT = "16"; +1271 } else if (params.type === "vis") { +1272 this.hT = "1a"; +1273 } else if (params.type === "bmp") { +1274 this.hT = "1e"; +1275 } +1276 } +1277 }; +1278 YAHOO.lang.extend(KJUR.asn1.x509.DisplayText, KJUR.asn1.DERAbstractString); +1279 // ===== END CertificatePolicies related classes ===== +1280 +1281 // ===================================================================== +1282 /** +1283 * KeyUsage ASN.1 structure class +1284 * @name KJUR.asn1.x509.ExtKeyUsage +1285 * @class ExtKeyUsage ASN.1 structure class +1286 * @param {Array} params associative array of parameters +1287 * @extends KJUR.asn1.x509.Extension +1288 * @description +1289 * @example +1290 * e1 = new KJUR.asn1.x509.ExtKeyUsage({ +1291 * critical: true, +1292 * array: [ +1293 * {oid: '2.5.29.37.0'}, // anyExtendedKeyUsage +1294 * {name: 'clientAuth'}, +1295 * "1.2.3.4", +1296 * "serverAuth" +1297 * ] +1298 * }); +1299 * // id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 } +1300 * // ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId +1301 * // KeyPurposeId ::= OBJECT IDENTIFIER +1302 */ +1303 KJUR.asn1.x509.ExtKeyUsage = function(params) { +1304 KJUR.asn1.x509.ExtKeyUsage.superclass.constructor.call(this, params); +1305 var _KJUR = KJUR, +1306 _KJUR_asn1 = _KJUR.asn1; +1307 +1308 this.setPurposeArray = function(purposeArray) { +1309 this.asn1ExtnValue = new _KJUR_asn1.DERSequence(); +1310 for (var i = 0; i < purposeArray.length; i++) { +1311 var o = new _KJUR_asn1.DERObjectIdentifier(purposeArray[i]); +1312 this.asn1ExtnValue.appendASN1Object(o); +1313 } +1314 }; +1315 +1316 this.getExtnValueHex = function() { +1317 return this.asn1ExtnValue.getEncodedHex(); +1318 }; +1319 +1320 this.oid = "2.5.29.37"; +1321 if (params !== undefined) { +1322 if (params.array !== undefined) { +1323 this.setPurposeArray(params.array); +1324 } +1325 } +1326 }; +1327 YAHOO.lang.extend(KJUR.asn1.x509.ExtKeyUsage, KJUR.asn1.x509.Extension); +1328 +1329 /** +1330 * AuthorityKeyIdentifier ASN.1 structure class +1331 * @name KJUR.asn1.x509.AuthorityKeyIdentifier +1332 * @class AuthorityKeyIdentifier ASN.1 structure class +1333 * @param {Array} params associative array of parameters (ex. {kid: {hex: '89ab...'}, critical: true}) +1334 * @extends KJUR.asn1.x509.Extension +1335 * @since asn1x509 1.0.8 +1336 * @description +1337 * This class represents ASN.1 structure for <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.1">AuthorityKeyIdentifier in RFC 5280</a>. +1338 * Constructor of this class may have following parameters.: +1339 * <ul> +1340 * <li>kid - When key object (RSA, KJUR.crypto.ECDSA/DSA) or PEM string of issuing authority public key or issuer certificate is specified, key identifier will be automatically calculated by the method specified in RFC 5280. When a hexadecimal string is specifed, kid will be set explicitly by it.</li> +1341 * <li>isscert - When PEM string of authority certificate is specified, both authorityCertIssuer and authorityCertSerialNumber will be set by the certificate.</li> +1342 * <li>issuer - {@link KJUR.asn1.x509.X500Name} parameter to specify issuer name explicitly.</li> +1343 * <li>sn - hexadecimal string to specify serial number explicitly.</li> +1344 * <li>critical - boolean to specify criticality of this extension +1345 * however conforming CA must mark this extension as non-critical in RFC 5280.</li> +1346 * </ul> +1347 * +1348 * <pre> +1349 * d-ce-authorityKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 35 } +1350 * AuthorityKeyIdentifier ::= SEQUENCE { +1351 * keyIdentifier [0] KeyIdentifier OPTIONAL, +1352 * authorityCertIssuer [1] GeneralNames OPTIONAL, +1353 * authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL } +1354 * KeyIdentifier ::= OCTET STRING +1355 * </pre> +1356 * +1357 * @example +1358 * // 1. kid by key object +1359 * keyobj = KEYUTIL.getKey("-----BEGIN PUBLIC KEY..."); +1360 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({kid: keyobj}); +1361 * // 2. kid by PEM string of authority certificate or public key +1362 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({kid: "-----BEGIN..."}); +1363 * // 3. specify kid explicitly +1364 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({kid: "8ab1d3..."}); +1365 * }); +1366 * // 4. issuer and serial number by auhtority PEM certificate +1367 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({isscert: "-----BEGIN..."}); +1368 * // 5. issuer and serial number explicitly +1369 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({ +1370 * issuer: {ldapstr: "O=test,C=US"}, +1371 * sn: {hex: "1ac7..."}}); +1372 * // 6. combination +1373 * e1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({ +1374 * kid: "-----BEGIN CERTIFICATE...", +1375 * isscert: "-----BEGIN CERTIFICATE..."}); +1376 */ +1377 KJUR.asn1.x509.AuthorityKeyIdentifier = function(params) { +1378 KJUR.asn1.x509.AuthorityKeyIdentifier.superclass.constructor.call(this, params); +1379 var _KJUR = KJUR, +1380 _KJUR_asn1 = _KJUR.asn1, +1381 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, +1382 _GeneralNames = _KJUR_asn1.x509.GeneralNames, +1383 _isKey = _KJUR.crypto.Util.isKey; +1384 +1385 this.asn1KID = null; +1386 this.asn1CertIssuer = null; // X500Name hTLV +1387 this.asn1CertSN = null; +1388 +1389 this.getExtnValueHex = function() { +1390 var a = new Array(); +1391 if (this.asn1KID) +1392 a.push(new _DERTaggedObject({'explicit': false, +1393 'tag': '80', +1394 'obj': this.asn1KID})); +1395 +1396 if (this.asn1CertIssuer) +1397 a.push(new _DERTaggedObject({'explicit': false, +1398 'tag': 'a1', +1399 'obj': new _GeneralNames([{dn: this.asn1CertIssuer}])})); +1400 +1401 if (this.asn1CertSN) +1402 a.push(new _DERTaggedObject({'explicit': false, +1403 'tag': '82', +1404 'obj': this.asn1CertSN})); +1405 +1406 var asn1Seq = new _KJUR_asn1.DERSequence({'array': a}); +1407 this.asn1ExtnValue = asn1Seq; +1408 return this.asn1ExtnValue.getEncodedHex(); +1409 }; +1410 +1411 /** +1412 * set keyIdentifier value by DEROctetString parameter, key object or PEM file +1413 * @name setKIDByParam +1414 * @memberOf KJUR.asn1.x509.AuthorityKeyIdentifier# +1415 * @function +1416 * @param {Array} param parameter to set key identifier +1417 * @since asn1x509 1.0.8 +1418 * @description +1419 * This method will set keyIdentifier by param. +1420 * Its key identifier value can be set by following type of param argument: +1421 * <ul> +1422 * <li>{str: "123"} - by raw string</li> +1423 * <li>{hex: "01af..."} - by hexadecimal value</li> +1424 * <li>RSAKey/DSA/ECDSA - by RSAKey, KJUR.crypto.{DSA/ECDSA} public key object. +1425 * key identifier value will be calculated by the method described in +1426 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. +1427 * </li> +1428 * <li>certificate PEM string - extract subjectPublicKeyInfo from specified PEM +1429 * certificate and +1430 * key identifier value will be calculated by the method described in +1431 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. +1432 * <li>PKCS#1/#8 public key PEM string - pem will be converted to a key object and +1433 * to PKCS#8 ASN.1 structure then calculate +1434 * a key identifier value will be calculated by the method described in +1435 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. +1436 * </ul> +1437 * +1438 * NOTE1: Automatic key identifier calculation is supported +1439 * since jsrsasign 8.0.16. +1440 * +1441 * @see KEYUTIL.getKeyID +1442 * +1443 * @example +1444 * o = new KJUR.asn1.x509.AuthorityKeyIdentifier(); +1445 * // set by hexadecimal string +1446 * o.setKIDByParam({hex: '1ad9...'}); +1447 * // set by SubjectPublicKeyInfo of PEM certificate string +1448 * o.setKIDByParam("-----BEGIN CERTIFICATE..."); +1449 * // set by PKCS#8 PEM public key string +1450 * o.setKIDByParam("-----BEGIN PUBLIC KEY..."); +1451 * // set by public key object +1452 * pubkey = KEYUTIL.getKey("-----BEGIN CERTIFICATE..."); +1453 * o.setKIDByParam(pubkey); +1454 */ +1455 this.setKIDByParam = function(param) { +1456 if (param.str !== undefined || +1457 param.hex !== undefined) { +1458 this.asn1KID = new KJUR.asn1.DEROctetString(param); +1459 } else if ((typeof param === "object" && +1460 KJUR.crypto.Util.isKey(param)) || +1461 (typeof param === "string" && +1462 param.indexOf("BEGIN ") != -1)) { +1463 +1464 var keyobj = param; +1465 if (typeof param === "string") { +1466 keyobj = KEYUTIL.getKey(param); +1467 } +1468 +1469 var kid = KEYUTIL.getKeyID(keyobj); +1470 this.asn1KID = new KJUR.asn1.DEROctetString({hex: kid}); +1471 } +1472 }; +1473 +1474 /** +1475 * set authorityCertIssuer value by X500Name parameter +1476 * @name setCertIssuerByParam +1477 * @memberOf KJUR.asn1.x509.AuthorityKeyIdentifier# +1478 * @function +1479 * @param {Array} param parameter to set issuer name +1480 * @since asn1x509 1.0.8 +1481 * @description +1482 * This method will set authorityCertIssuer name by param. +1483 * Issuer name can be set by following type of param argument: +1484 * <ul> +1485 * <li>str/ldapstr/hex/certsubject/certissuer - +1486 * set issuer by {@link KJUR.asn1.x509.X500Name} +1487 * object with specified parameters.</li> +1488 * <li>PEM CERTIFICATE STRING - extract its subject name from +1489 * specified issuer PEM certificate and set. +1490 * </ul> +1491 * NOTE1: Automatic authorityCertIssuer setting by certificate +1492 * is supported since jsrsasign 8.0.16. +1493 * +1494 * @see KJUR.asn1.x509.X500Name +1495 * @see KJUR.asn1.x509.GeneralNames +1496 * @see X509.getSubjectHex +1497 * +1498 * @example +1499 * var o = new KJUR.asn1.x509.AuthorityKeyIdentifier(); +1500 * // 1. set it by string +1501 * o.setCertIssuerByParam({str: '/C=US/O=Test'}); +1502 * // 2. set it by issuer PEM certificate +1503 * o.setCertIssuerByParam("-----BEGIN CERTIFICATE..."); +1504 * +1505 */ +1506 this.setCertIssuerByParam = function(param) { +1507 if (param.str !== undefined || +1508 param.ldapstr !== undefined || +1509 param.hex !== undefined || +1510 param.certsubject !== undefined || +1511 param.certissuer !== undefined) { +1512 this.asn1CertIssuer = new KJUR.asn1.x509.X500Name(param); +1513 } else if (typeof param === "string" && +1514 param.indexOf("BEGIN ") != -1 && +1515 param.indexOf("CERTIFICATE") != -1) { +1516 this.asn1CertIssuer = new KJUR.asn1.x509.X500Name({certissuer: param}); +1517 } +1518 }; +1519 +1520 /** +1521 * set authorityCertSerialNumber value +1522 * @name setCertSerialNumberByParam +1523 * @memberOf KJUR.asn1.x509.AuthorityKeyIdentifier# +1524 * @function +1525 * @param {Object} param parameter to set serial number +1526 * @since asn1x509 1.0.8 +1527 * @description +1528 * This method will set authorityCertSerialNumber by param. +1529 * Serial number can be set by following type of param argument: +1530 * +1531 * <ul> +1532 * <li>{int: 123} - by integer value</li> +1533 * <li>{hex: "01af"} - by hexadecimal integer value</li> +1534 * <li>{bigint: new BigInteger(...)} - by hexadecimal integer value</li> +1535 * <li>PEM CERTIFICATE STRING - extract serial number from issuer certificate and +1536 * set serial number. +1537 * +1538 * NOTE1: Automatic authorityCertSerialNumber setting by certificate +1539 * is supported since jsrsasign 8.0.16. +1540 * +1541 * @see X509.getSerialNumberHex +1542 */ +1543 this.setCertSNByParam = function(param) { +1544 if (param.str !== undefined || +1545 param.bigint !== undefined || +1546 param.hex !== undefined) { +1547 this.asn1CertSN = new KJUR.asn1.DERInteger(param); +1548 } else if (typeof param === "string" && +1549 param.indexOf("BEGIN ") != -1 && +1550 param.indexOf("CERTIFICATE")) { +1551 +1552 var x = new X509(); +1553 x.readCertPEM(param); +1554 var sn = x.getSerialNumberHex(); +1555 this.asn1CertSN = new KJUR.asn1.DERInteger({hex: sn}); +1556 } +1557 }; +1558 +1559 this.oid = "2.5.29.35"; +1560 if (params !== undefined) { +1561 if (params.kid !== undefined) { +1562 this.setKIDByParam(params.kid); +1563 } +1564 if (params.issuer !== undefined) { +1565 this.setCertIssuerByParam(params.issuer); +1566 } +1567 if (params.sn !== undefined) { +1568 this.setCertSNByParam(params.sn); +1569 } +1570 +1571 if (params.issuersn !== undefined && +1572 typeof params.issuersn === "string" && +1573 params.issuersn.indexOf("BEGIN ") != -1 && +1574 params.issuersn.indexOf("CERTIFICATE")) { +1575 this.setCertSNByParam(params.issuersn); +1576 this.setCertIssuerByParam(params.issuersn); +1577 } +1578 } +1579 }; +1580 YAHOO.lang.extend(KJUR.asn1.x509.AuthorityKeyIdentifier, KJUR.asn1.x509.Extension); +1581 +1582 /** +1583 * SubjectKeyIdentifier extension ASN.1 structure class +1584 * @name KJUR.asn1.x509.SubjectKeyIdentifier +1585 * @class SubjectKeyIdentifier ASN.1 structure class +1586 * @param {Array} params associative array of parameters (ex. {kid: {hex: '89ab...'}, critical: true}) +1587 * @extends KJUR.asn1.x509.Extension +1588 * @since asn1x509 1.1.7 jsrsasign 8.0.14 +1589 * @description +1590 * This class represents ASN.1 structure for +1591 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2"> +1592 * SubjectKeyIdentifier in RFC 5280</a>. +1593 * Constructor of this class may have following parameters: +1594 * <ul> +1595 * <li>kid - When key object (RSA, KJUR.crypto.ECDSA/DSA) or PEM string of subject public key or certificate is specified, key identifier will be automatically calculated by the method specified in RFC 5280. When a hexadecimal string is specifed, kid will be set explicitly by it.</li> +1596 * <li>critical - boolean to specify criticality of this extension +1597 * however conforming CA must mark this extension as non-critical in RFC 5280.</li> +1598 * </ul> +1599 * <pre> +1600 * d-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 14 } +1601 * SubjectKeyIdentifier ::= KeyIdentifier +1602 * KeyIdentifier ::= OCTET STRING +1603 * </pre> +1604 * +1605 * @example +1606 * // set by hexadecimal string +1607 * e = new KJUR.asn1.x509.SubjectKeyIdentifier({kid: {hex: '89ab'}}); +1608 * // set by PEM public key or certificate string +1609 * e = new KJUR.asn1.x509.SubjectKeyIdentifier({kid: "-----BEGIN CERTIFICATE..."}); +1610 * // set by public key object +1611 * pubkey = KEYUTIL.getKey("-----BEGIN CERTIFICATE..."); +1612 * e = new KJUR.asn1.x509.SubjectKeyIdentifier({kid: pubkey}); +1613 */ +1614 KJUR.asn1.x509.SubjectKeyIdentifier = function(params) { +1615 KJUR.asn1.x509.SubjectKeyIdentifier.superclass.constructor.call(this, params); +1616 var _KJUR = KJUR, +1617 _KJUR_asn1 = _KJUR.asn1, +1618 _DEROctetString = _KJUR_asn1.DEROctetString; +1619 +1620 this.asn1KID = null; +1621 +1622 this.getExtnValueHex = function() { +1623 this.asn1ExtnValue = this.asn1KID; +1624 return this.asn1ExtnValue.getEncodedHex(); +1625 }; +1626 +1627 /** +1628 * set keyIdentifier value by DEROctetString parameter, key object or PEM file +1629 * @name setKIDByParam +1630 * @memberOf KJUR.asn1.x509.SubjectKeyIdentifier# +1631 * @function +1632 * @param {Array} param array of {@link KJUR.asn1.DERInteger} parameter +1633 * @since asn1x509 1.1.7 jsrsasign 8.0.14 +1634 * @description +1635 * <ul> +1636 * <li>{str: "123"} - by raw string</li> +1637 * <li>{hex: "01af..."} - by hexadecimal value</li> +1638 * <li>RSAKey/DSA/ECDSA - by RSAKey, KJUR.crypto.{DSA/ECDSA} public key object. +1639 * key identifier value will be calculated by the method described in +1640 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. +1641 * </li> +1642 * <li>certificate PEM string - extract subjectPublicKeyInfo from specified PEM +1643 * certificate and +1644 * key identifier value will be calculated by the method described in +1645 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. +1646 * <li>PKCS#1/#8 public key PEM string - pem will be converted to a key object and +1647 * to PKCS#8 ASN.1 structure then calculate +1648 * a key identifier value will be calculated by the method described in +1649 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2">RFC 5280 4.2.1.2 (1)</a>. +1650 * </ul> +1651 * +1652 * NOTE1: Automatic key identifier calculation is supported +1653 * since jsrsasign 8.0.16. +1654 * +1655 * @see KEYUTIL.getKeyID +1656 * +1657 * @example +1658 * o = new KJUR.asn1.x509.SubjectKeyIdentifier(); +1659 * // set by hexadecimal string +1660 * o.setKIDByParam({hex: '1ad9...'}); +1661 * // set by SubjectPublicKeyInfo of PEM certificate string +1662 * o.setKIDByParam("-----BEGIN CERTIFICATE..."); +1663 * // set by PKCS#8 PEM public key string +1664 * o.setKIDByParam("-----BEGIN PUBLIC KEY..."); +1665 * // set by public key object +1666 * pubkey = KEYUTIL.getKey("-----BEGIN CERTIFICATE..."); +1667 * o.setKIDByParam(pubkey); +1668 */ +1669 this.setKIDByParam = function(param) { +1670 if (param.str !== undefined || +1671 param.hex !== undefined) { +1672 this.asn1KID = new _DEROctetString(param); +1673 } else if ((typeof param === "object" && +1674 KJUR.crypto.Util.isKey(param)) || +1675 (typeof param === "string" && +1676 param.indexOf("BEGIN") != -1)) { +1677 +1678 var keyobj = param; +1679 if (typeof param === "string") { +1680 keyobj = KEYUTIL.getKey(param); +1681 } +1682 +1683 var kid = KEYUTIL.getKeyID(keyobj); +1684 this.asn1KID = new KJUR.asn1.DEROctetString({hex: kid}); +1685 } +1686 }; +1687 +1688 this.oid = "2.5.29.14"; +1689 if (params !== undefined) { +1690 if (params.kid !== undefined) { +1691 this.setKIDByParam(params.kid); +1692 } +1693 } +1694 }; +1695 YAHOO.lang.extend(KJUR.asn1.x509.SubjectKeyIdentifier, KJUR.asn1.x509.Extension); +1696 +1697 /** +1698 * AuthorityInfoAccess ASN.1 structure class +1699 * @name KJUR.asn1.x509.AuthorityInfoAccess +1700 * @class AuthorityInfoAccess ASN.1 structure class +1701 * @param {Array} params JSON object of AuthorityInfoAccess parameters +1702 * @extends KJUR.asn1.x509.Extension +1703 * @since asn1x509 1.0.8 +1704 * @see {@link X509#getExtAuthorityInfoAccess} +1705 * @description +1706 * This class represents +1707 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.2.1"> +1708 * AuthorityInfoAccess extension defined in RFC 5280 4.2.2.1</a>. +1709 * <pre> +1710 * id-pe OBJECT IDENTIFIER ::= { id-pkix 1 } +1711 * id-pe-authorityInfoAccess OBJECT IDENTIFIER ::= { id-pe 1 } +1712 * AuthorityInfoAccessSyntax ::= +1713 * SEQUENCE SIZE (1..MAX) OF AccessDescription +1714 * AccessDescription ::= SEQUENCE { +1715 * accessMethod OBJECT IDENTIFIER, +1716 * accessLocation GeneralName } +1717 * id-ad OBJECT IDENTIFIER ::= { id-pkix 48 } +1718 * id-ad-caIssuers OBJECT IDENTIFIER ::= { id-ad 2 } +1719 * id-ad-ocsp OBJECT IDENTIFIER ::= { id-ad 1 } +1720 * </pre> +1721 * NOTE: Acceptable parameters have been changed since +1722 * from jsrsasign 9.0.0 asn1x509 2.0.0. +1723 * Parameter generated by {@link X509#getAuthorityInfoAccess} +1724 * can be accepted as a argument of this constructor. +1725 * @example +1726 * e1 = new KJUR.asn1.x509.AuthorityInfoAccess({ +1727 * array: [ +1728 * {ocsp: 'http://ocsp.example.org'}, +1729 * {caissuer: 'https://repository.example.org/aaa.crt'} +1730 * ] +1731 * }); +1732 */ +1733 KJUR.asn1.x509.AuthorityInfoAccess = function(params) { +1734 KJUR.asn1.x509.AuthorityInfoAccess.superclass.constructor.call(this, params); +1735 +1736 this.setAccessDescriptionArray = function(aParam) { +1737 var aASN1 = new Array(), +1738 _KJUR = KJUR, +1739 _KJUR_asn1 = _KJUR.asn1, +1740 _DERSequence = _KJUR_asn1.DERSequence, +1741 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, +1742 _GeneralName = _KJUR_asn1.x509.GeneralName; +1743 +1744 for (var i = 0; i < aParam.length; i++) { +1745 var adseq; +1746 var adparam = aParam[i]; +1747 +1748 if (adparam.ocsp !== undefined) { +1749 adseq = new _DERSequence({array: [ +1750 new _DERObjectIdentifier({oid: "1.3.6.1.5.5.7.48.1"}), +1751 new _GeneralName({uri: adparam.ocsp}) +1752 ]}); +1753 } else if (adparam.caissuer !== undefined) { +1754 adseq = new _DERSequence({array: [ +1755 new _DERObjectIdentifier({oid: "1.3.6.1.5.5.7.48.2"}), +1756 new _GeneralName({uri: adparam.caissuer}) +1757 ]}); +1758 } else { +1759 throw new Error("unknown AccessMethod parameter: " + +1760 JSON.stringify(adparam)); +1761 } +1762 aASN1.push(adseq); +1763 } +1764 this.asn1ExtnValue = new _DERSequence({'array':aASN1}); +1765 }; +1766 +1767 this.getExtnValueHex = function() { +1768 return this.asn1ExtnValue.getEncodedHex(); +1769 }; +1770 +1771 this.oid = "1.3.6.1.5.5.7.1.1"; +1772 if (params !== undefined) { +1773 if (params.array !== undefined) { +1774 this.setAccessDescriptionArray(params.array); +1775 } +1776 } +1777 }; +1778 YAHOO.lang.extend(KJUR.asn1.x509.AuthorityInfoAccess, KJUR.asn1.x509.Extension); +1779 +1780 /** +1781 * SubjectAltName ASN.1 structure class<br/> +1782 * @name KJUR.asn1.x509.SubjectAltName +1783 * @class SubjectAltName ASN.1 structure class +1784 * @param {Array} params associative array of parameters +1785 * @extends KJUR.asn1.x509.Extension +1786 * @since jsrsasign 6.2.3 asn1x509 1.0.19 +1787 * @see KJUR.asn1.x509.GeneralNames +1788 * @see KJUR.asn1.x509.GeneralName +1789 * @description +1790 * This class provides X.509v3 SubjectAltName extension. +1791 * <pre> +1792 * id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 } +1793 * SubjectAltName ::= GeneralNames +1794 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName +1795 * GeneralName ::= CHOICE { +1796 * otherName [0] OtherName, +1797 * rfc822Name [1] IA5String, +1798 * dNSName [2] IA5String, +1799 * x400Address [3] ORAddress, +1800 * directoryName [4] Name, +1801 * ediPartyName [5] EDIPartyName, +1802 * uniformResourceIdentifier [6] IA5String, +1803 * iPAddress [7] OCTET STRING, +1804 * registeredID [8] OBJECT IDENTIFIER } +1805 * </pre> +1806 * @example +1807 * e1 = new KJUR.asn1.x509.SubjectAltName({ +1808 * critical: true, +1809 * array: [{uri: 'http://aaa.com/'}, {uri: 'http://bbb.com/'}] +1810 * }); +1811 */ +1812 KJUR.asn1.x509.SubjectAltName = function(params) { +1813 KJUR.asn1.x509.SubjectAltName.superclass.constructor.call(this, params) +1814 +1815 this.setNameArray = function(paramsArray) { +1816 this.asn1ExtnValue = new KJUR.asn1.x509.GeneralNames(paramsArray); +1817 }; +1818 +1819 this.getExtnValueHex = function() { +1820 return this.asn1ExtnValue.getEncodedHex(); +1821 }; +1822 +1823 this.oid = "2.5.29.17"; +1824 if (params !== undefined) { +1825 if (params.array !== undefined) { +1826 this.setNameArray(params.array); +1827 } +1828 } +1829 }; +1830 YAHOO.lang.extend(KJUR.asn1.x509.SubjectAltName, KJUR.asn1.x509.Extension); +1831 +1832 /** +1833 * IssuerAltName ASN.1 structure class<br/> +1834 * @name KJUR.asn1.x509.IssuerAltName +1835 * @class IssuerAltName ASN.1 structure class +1836 * @param {Array} params associative array of parameters +1837 * @extends KJUR.asn1.x509.Extension +1838 * @since jsrsasign 6.2.3 asn1x509 1.0.19 +1839 * @see KJUR.asn1.x509.GeneralNames +1840 * @see KJUR.asn1.x509.GeneralName +1841 * @description +1842 * This class provides X.509v3 IssuerAltName extension. +1843 * <pre> +1844 * id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 18 } +1845 * IssuerAltName ::= GeneralNames +1846 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName +1847 * GeneralName ::= CHOICE { +1848 * otherName [0] OtherName, +1849 * rfc822Name [1] IA5String, +1850 * dNSName [2] IA5String, +1851 * x400Address [3] ORAddress, +1852 * directoryName [4] Name, +1853 * ediPartyName [5] EDIPartyName, +1854 * uniformResourceIdentifier [6] IA5String, +1855 * iPAddress [7] OCTET STRING, +1856 * registeredID [8] OBJECT IDENTIFIER } +1857 * </pre> +1858 * @example +1859 * e1 = new KJUR.asn1.x509.IssuerAltName({ +1860 * critical: true, +1861 * array: [{uri: 'http://aaa.com/'}, {uri: 'http://bbb.com/'}] +1862 * }); +1863 */ +1864 KJUR.asn1.x509.IssuerAltName = function(params) { +1865 KJUR.asn1.x509.IssuerAltName.superclass.constructor.call(this, params) +1866 +1867 this.setNameArray = function(paramsArray) { +1868 this.asn1ExtnValue = new KJUR.asn1.x509.GeneralNames(paramsArray); +1869 }; +1870 +1871 this.getExtnValueHex = function() { +1872 return this.asn1ExtnValue.getEncodedHex(); +1873 }; +1874 +1875 this.oid = "2.5.29.18"; +1876 if (params !== undefined) { +1877 if (params.array !== undefined) { +1878 this.setNameArray(params.array); +1879 } +1880 } +1881 }; +1882 YAHOO.lang.extend(KJUR.asn1.x509.IssuerAltName, KJUR.asn1.x509.Extension); +1883 +1884 /** +1885 * SubjectDirectoryAttributes ASN.1 structure class<br/> +1886 * @name KJUR.asn1.x509.SubjectDirectoryAttributes +1887 * @class SubjectDirectoryAttributes ASN.1 structure class +1888 * @param {Array} params associative array of parameters +1889 * @extends KJUR.asn1.x509.Extension +1890 * @since jsrsasign 10.1.9 asn1x509 2.1.7 +1891 * @description +1892 * This class provides X.509v3 SubjectDirectoryAttributes extension +1893 * defined in <a href="https://tools.ietf.org/html/rfc3739#section-3.3.2"> +1894 * RFC 3739 Qualified Certificate Profile section 3.3.2</a>. +1895 * <pre> +1896 * SubjectDirectoryAttributes ::= Attributes +1897 * Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute +1898 * Attribute ::= SEQUENCE { +1899 * type AttributeType +1900 * values SET OF AttributeValue } +1901 * AttributeType ::= OBJECT IDENTIFIER +1902 * AttributeValue ::= ANY DEFINED BY AttributeType +1903 * </pre> +1904 * @example +1905 * e1 = new KJUR.asn1.x509.SubjectDirectoryAttributes({ +1906 * extname: "subjectDirectoryAttributes", +1907 * array: [ +1908 * { attr: "dateOfBirth", str: "19701231230000Z" }, +1909 * { attr: "placeOfBirth", str: "Tokyo" }, +1910 * { attr: "gender", str: "F" }, +1911 * { attr: "countryOfCitizenship", str: "JP" }, +1912 * { attr: "countryOfResidence", str: "JP" } +1913 * ] +1914 * }); +1915 */ +1916 KJUR.asn1.x509.SubjectDirectoryAttributes = function(params) { +1917 KJUR.asn1.x509.SubjectDirectoryAttributes.superclass.constructor.call(this, params); +1918 var _KJUR_asn1 = KJUR.asn1, +1919 _DERSequence = _KJUR_asn1.DERSequence, +1920 _newObject = _KJUR_asn1.ASN1Util.newObject, +1921 _name2oid = _KJUR_asn1.x509.OID.name2oid; +1922 +1923 this.params = null; +1924 +1925 this.getExtnValueHex = function() { +1926 var a = []; +1927 for (var i = 0; i < this.params.array.length; i++) { +1928 var pAttr = this.params.array[i]; +1929 +1930 var newparam = { +1931 "seq": [ +1932 {"oid": "1.2.3.4"}, +1933 {"set": [{"utf8str": "DE"}]} +1934 ] +1935 }; +1936 +1937 if (pAttr.attr == "dateOfBirth") { +1938 newparam.seq[0].oid = _name2oid(pAttr.attr); +1939 newparam.seq[1].set[0] = {"gentime": pAttr.str}; +1940 } else if (pAttr.attr == "placeOfBirth") { +1941 newparam.seq[0].oid = _name2oid(pAttr.attr); +1942 newparam.seq[1].set[0] = {"utf8str": pAttr.str}; +1943 } else if (pAttr.attr == "gender") { +1944 newparam.seq[0].oid = _name2oid(pAttr.attr); +1945 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; +1946 } else if (pAttr.attr == "countryOfCitizenship") { +1947 newparam.seq[0].oid = _name2oid(pAttr.attr); +1948 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; +1949 } else if (pAttr.attr == "countryOfResidence") { +1950 newparam.seq[0].oid = _name2oid(pAttr.attr); +1951 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; +1952 } else { +1953 throw new Error("unsupported attribute: " + pAttr.attr); +1954 } +1955 a.push(new _newObject(newparam)); +1956 } +1957 var seq = new _DERSequence({array: a}); +1958 this.asn1ExtnValue = seq; +1959 return this.asn1ExtnValue.getEncodedHex(); +1960 }; +1961 +1962 this.oid = "2.5.29.9"; +1963 if (params !== undefined) { +1964 this.params = params; +1965 } +1966 }; +1967 YAHOO.lang.extend(KJUR.asn1.x509.SubjectDirectoryAttributes, KJUR.asn1.x509.Extension); 1968 -1969 /** -1970 * priavte extension ASN.1 structure class<br/> -1971 * @name KJUR.asn1.x509.PrivateExtension -1972 * @class private extension ASN.1 structure class -1973 * @param {Array} params JSON object of private extension -1974 * @extends KJUR.asn1.x509.Extension -1975 * @since jsrsasign 9.1.1 asn1x509 -1976 * @see KJUR.asn1.ASN1Util.newObject -1977 * -1978 * @description -1979 * This class is to represent private extension or -1980 * unsupported extension. -1981 * <pre> -1982 * Extension ::= SEQUENCE { -1983 * extnID OBJECT IDENTIFIER, -1984 * critical BOOLEAN DEFAULT FALSE, -1985 * extnValue OCTET STRING } -1986 * </pre> -1987 * Following properties can be set for JSON parameter: -1988 * <ul> -1989 * <li>{String}extname - string of OID or predefined extension name</li> -1990 * <li>{Boolean}critical - critical flag</li> -1991 * <li>{Object}extn - hexadecimal string or -1992 * of {@link KJUR.asn1.ASN1Util.newObject} -1993 * JSON parameter for extnValue field</li> -1994 * </li> -1995 * </ul> -1996 * -1997 * @example -1998 * // extn by hexadecimal -1999 * new KJUR.asn1.x509.PrivateExtension({ -2000 * extname: "1.2.3.4", -2001 * critical: true, -2002 * extn: "13026161" // means PrintableString "aa" -2003 * }); -2004 * -2005 * // extn by JSON parameter -2006 * new KJUR.asn1.x509.PrivateExtension({ -2007 * extname: "1.2.3.5", -2008 * extn: {seq: [{prnstr:"abc"},{utf8str:"def"}]} -2009 * }); -2010 */ -2011 KJUR.asn1.x509.PrivateExtension = function(params) { -2012 KJUR.asn1.x509.PrivateExtension.superclass.constructor.call(this, params) -2013 -2014 var _KJUR = KJUR, -2015 _isHex = _KJUR.lang.String.isHex, -2016 _KJUR_asn1 = _KJUR.asn1, -2017 _name2oid = _KJUR_asn1.x509.OID.name2oid, -2018 _newObject = _KJUR_asn1.ASN1Util.newObject; -2019 -2020 this.params = null; -2021 -2022 this.setByParam = function(params) { -2023 this.oid = _name2oid(params.extname); -2024 this.params = params; -2025 }; -2026 -2027 this.getExtnValueHex = function() { -2028 if (this.params.extname == undefined || -2029 this.params.extn == undefined) { -2030 throw new Error("extname or extnhex not specified"); -2031 } -2032 -2033 var extn = this.params.extn; -2034 if (typeof extn == "string" && _isHex(extn)) { -2035 return extn; -2036 } else if (typeof extn == "object") { -2037 try { -2038 return _newObject(extn).getEncodedHex(); -2039 } catch(ex) {} -2040 } -2041 throw new Error("unsupported extn value"); -2042 }; -2043 -2044 if (params != undefined) { -2045 this.setByParam(params); -2046 } -2047 }; -2048 YAHOO.lang.extend(KJUR.asn1.x509.PrivateExtension, KJUR.asn1.x509.Extension); -2049 -2050 // === END X.509v3 Extensions Related ======================================= -2051 -2052 // === BEGIN CRL Related =================================================== -2053 /** -2054 * X.509 CRL class to sign and generate hex encoded CRL<br/> -2055 * @name KJUR.asn1.x509.CRL -2056 * @class X.509 CRL class to sign and generate hex encoded certificate -2057 * @property {Array} params JSON object of parameters -2058 * @param {Array} params JSON object of CRL parameters -2059 * @extends KJUR.asn1.ASN1Object -2060 * @since 1.0.3 -2061 * @see KJUR.asn1.x509.TBSCertList -2062 * -2063 * @description -2064 * This class represents CertificateList ASN.1 structur of X.509 CRL -2065 * defined in <a href="https://tools.ietf.org/html/rfc5280#section-5.1"> -2066 * RFC 5280 5.1</a> -2067 * <pre> -2068 * CertificateList ::= SEQUENCE { -2069 * tbsCertList TBSCertList, -2070 * signatureAlgorithm AlgorithmIdentifier, -2071 * signatureValue BIT STRING } -2072 * </pre> -2073 * NOTE: CRL class is updated without backward -2074 * compatibility from jsrsasign 9.1.0 asn1x509 2.1.0. -2075 * Most of methods are removed and parameters can be set -2076 * by JSON object. -2077 * <br/> -2078 * Constructor of this class can accept all -2079 * parameters of {@link KJUR.asn1.x509.TBSCertList}. -2080 * It also accept following parameters additionally: -2081 * <ul> -2082 * <li>{TBSCertList}tbsobj (OPTION) - -2083 * specifies {@link KJUR.asn1.x509.TBSCertList} -2084 * object to be signed if needed. -2085 * When this isn't specified, -2086 * this will be set from other parametes of TBSCertList.</li> -2087 * <li>{Object}cakey (OPTION) - specifies CRL signing private key. -2088 * Parameter "cakey" or "sighex" shall be specified. Following -2089 * values can be specified: -2090 * <ul> -2091 * <li>PKCS#1/5 or PKCS#8 PEM string of private key</li> -2092 * <li>RSAKey/DSA/ECDSA key object. {@link KEYUTIL.getKey} is useful -2093 * to generate a key object.</li> -2094 * </ul> -2095 * </li> -2096 * <li>{String}sighex (OPTION) - hexadecimal string of signature value -2097 * (i.e. ASN.1 value(V) of signatureValue BIT STRING without -2098 * unused bits)</li> -2099 * </ul> -2100 * -2101 * @example -2102 * var crl = new KJUR.asn1.x509.CRL({ -2103 * sigalg: "SHA256withRSA", -2104 * issuer: {str:'/C=JP/O=Test1'}, -2105 * thisupdate: "200821235959Z", -2106 * nextupdate: "200828235959Z", // OPTION -2107 * revcert: [{sn: {hex: "12ab"}, date: "200401235959Z"}], -2108 * ext: [ -2109 * {extname: "cRLNumber", num: {'int': 8}}, -2110 * {extname: "authorityKeyIdentifier", "kid": {hex: "12ab"}} -2111 * ], -2112 * cakey: prvkey -2113 * }); -2114 * crl.getEncodedHex() → "30..." -2115 * crl.getPEM() → "-----BEGIN X509 CRL..." -2116 */ -2117 KJUR.asn1.x509.CRL = function(params) { -2118 KJUR.asn1.x509.CRL.superclass.constructor.call(this); -2119 var _KJUR = KJUR, -2120 _KJUR_asn1 = _KJUR.asn1, -2121 _DERSequence = _KJUR_asn1.DERSequence, -2122 _DERBitString = _KJUR_asn1.DERBitString, -2123 _KJUR_asn1_x509 = _KJUR_asn1.x509, -2124 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, -2125 _TBSCertList = _KJUR_asn1_x509.TBSCertList; -2126 -2127 this.params = undefined; -2128 -2129 this.setByParam = function(params) { -2130 this.params = params; -2131 }; -2132 -2133 /** -2134 * sign CRL<br/> -2135 * @name sign -2136 * @memberOf KJUR.asn1.x509.CRL# -2137 * @function -2138 * @description -2139 * This method signs TBSCertList with a specified -2140 * private key and algorithm by -2141 * this.params.cakey and this.params.sigalg parameter. -2142 * @example -2143 * crl = new KJUR.asn1.x509.CRL({..., cakey:prvkey}); -2144 * crl.sign() -2145 */ -2146 this.sign = function() { -2147 var hTBSCL = (new _TBSCertList(this.params)).getEncodedHex(); -2148 var sig = new KJUR.crypto.Signature({alg: this.params.sigalg}); -2149 sig.init(this.params.cakey); -2150 sig.updateHex(hTBSCL); -2151 var sighex = sig.sign(); -2152 this.params.sighex = sighex; -2153 }; -2154 -2155 /** -2156 * get PEM formatted CRL string after signed<br/> -2157 * @name getPEM -2158 * @memberOf KJUR.asn1.x509.CRL# -2159 * @function -2160 * @return PEM formatted string of CRL -2161 * @since jsrsasign 9.1.0 asn1hex 2.1.0 -2162 * @description -2163 * This method returns a string of PEM formatted -2164 * CRL. -2165 * @example -2166 * crl = new KJUR.asn1.x509.CRL({...}); -2167 * crl.getPEM() → -2168 * "-----BEGIN X509 CRL-----\r\n..." -2169 */ -2170 this.getPEM = function() { -2171 return hextopem(this.getEncodedHex(), "X509 CRL"); -2172 }; -2173 -2174 this.getEncodedHex = function() { -2175 var params = this.params; -2176 -2177 if (params.tbsobj == undefined) { -2178 params.tbsobj = new _TBSCertList(params); -2179 } -2180 -2181 if (params.sighex == undefined && params.cakey != undefined) { -2182 this.sign(); -2183 } -2184 -2185 if (params.sighex == undefined) { -2186 throw new Error("sighex or cakey parameter not defined"); -2187 } -2188 -2189 var a = []; -2190 a.push(params.tbsobj); -2191 a.push(new _AlgorithmIdentifier({name: params.sigalg})); -2192 a.push(new _DERBitString({hex: "00" + params.sighex})); -2193 var seq = new _DERSequence({array: a}); -2194 return seq.getEncodedHex(); -2195 }; -2196 -2197 if (params != undefined) this.params = params; -2198 }; -2199 YAHOO.lang.extend(KJUR.asn1.x509.CRL, KJUR.asn1.ASN1Object); -2200 -2201 /** -2202 * ASN.1 TBSCertList ASN.1 structure class for CRL<br/> -2203 * @name KJUR.asn1.x509.TBSCertList -2204 * @class TBSCertList ASN.1 structure class for CRL -2205 * @property {Array} params JSON object of parameters -2206 * @param {Array} params JSON object of TBSCertList parameters -2207 * @extends KJUR.asn1.ASN1Object -2208 * @since 1.0.3 -2209 * -2210 * @description -2211 * This class represents TBSCertList of CRL defined in -2212 * <a href="https://tools.ietf.org/html/rfc5280#section-5.1"> -2213 * RFC 5280 5.1</a>. -2214 * <pre> -2215 * TBSCertList ::= SEQUENCE { -2216 * version Version OPTIONAL, -2217 * -- if present, MUST be v2 -2218 * signature AlgorithmIdentifier, -2219 * issuer Name, -2220 * thisUpdate Time, -2221 * nextUpdate Time OPTIONAL, -2222 * revokedCertificates SEQUENCE OF SEQUENCE { -2223 * userCertificate CertificateSerialNumber, -2224 * revocationDate Time, -2225 * crlEntryExtensions Extensions OPTIONAL -2226 * -- if present, version MUST be v2 -2227 * } OPTIONAL, -2228 * crlExtensions [0] EXPLICIT Extensions OPTIONAL -2229 * } -2230 * </pre> -2231 * NOTE: TBSCertList class is updated without backward -2232 * compatibility from jsrsasign 9.1.0 asn1x509 2.1.0. -2233 * Most of methods are removed and parameters can be set -2234 * by JSON object. -2235 * <br/> -2236 * Constructor of this class may have following parameters: -2237 * <ul> -2238 * <li>{Integer}version (OPTION) - version number. Omitted by default.</li> -2239 * <li>{String}sigalg - signature algorithm name</li> -2240 * <li>{Array}issuer - issuer parameter of {@link KJUR.asn1.x509.X500Name}</li> -2241 * <li>{String}thisupdate - thisUpdate field value</li> -2242 * <li>{String}nextupdate (OPTION) - thisUpdate field value</li> -2243 * <li>{Array}revcert (OPTION) - revokedCertificates field value as array -2244 * Its element may have following property: -2245 * <ul> -2246 * <li>{Array}sn - serialNumber of userCertificate field specified -2247 * by {@link KJUR.asn1.DERInteger}</li> -2248 * <li>{String}date - revocationDate field specified by -2249 * a string of {@link KJUR.asn1.x509.Time} parameter</li> -2250 * <li>{Array}ext (OPTION) - array of CRL entry extension parameter</li> -2251 * </ul> -2252 * </li> -2253 * </ul> -2254 * -2255 * @example -2256 * var o = new KJUR.asn1.x509.TBSCertList({ -2257 * sigalg: "SHA256withRSA", -2258 * issuer: {array: [[{type:'C',value:'JP',ds:'prn'}], -2259 * [{type:'O',value:'T1',ds:'prn'}]]}, -2260 * thisupdate: "200821235959Z", -2261 * nextupdate: "200828235959Z", // OPTION -2262 * revcert: [ -2263 * {sn: {hex: "12ab"}, date: "200401235959Z", ext: [{extname: "cRLReason", code:1}]}, -2264 * {sn: {hex: "12bc"}, date: "200405235959Z", ext: [{extname: "cRLReason", code:2}]} -2265 * ], -2266 * ext: [ -2267 * {extname: "cRLNumber", num: {'int': 8}}, -2268 * {extname: "authorityKeyIdentifier", "kid": {hex: "12ab"}} -2269 * ] -2270 * }); -2271 * o.getEncodedHex() → "30..." -2272 */ -2273 KJUR.asn1.x509.TBSCertList = function(params) { -2274 KJUR.asn1.x509.TBSCertList.superclass.constructor.call(this); -2275 var _KJUR = KJUR, -2276 _KJUR_asn1 = _KJUR.asn1, -2277 _DERInteger = _KJUR_asn1.DERInteger, -2278 _DERSequence = _KJUR_asn1.DERSequence, -2279 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, -2280 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, -2281 _KJUR_asn1_x509 = _KJUR_asn1.x509, -2282 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, -2283 _Time = _KJUR_asn1_x509.Time, -2284 _Extensions = _KJUR_asn1_x509.Extensions, -2285 _X500Name = _KJUR_asn1_x509.X500Name; -2286 this.params = null; -2287 -2288 /** -2289 * get array of ASN.1 object for extensions<br/> -2290 * @name setByParam -2291 * @memberOf KJUR.asn1.x509.TBSCertList# -2292 * @function -2293 * @param {Array} JSON object of TBSCertList parameters -2294 * @example -2295 * tbsc = new KJUR.asn1.x509.TBSCertificate(); -2296 * tbsc.setByParam({version:3, serial:{hex:'1234...'},...}); -2297 */ -2298 this.setByParam = function(params) { -2299 this.params = params; -2300 }; -2301 -2302 /** -2303 * get DERSequence for revokedCertificates<br/> -2304 * @name getRevCertSequence -2305 * @memberOf KJUR.asn1.x509.TBSCertList# -2306 * @function -2307 * @return {@link KJUR.asn1.DERSequence} of revokedCertificates -2308 */ -2309 this.getRevCertSequence = function() { -2310 var a = []; -2311 var aRevCert = this.params.revcert; -2312 for (var i = 0; i < aRevCert.length; i++) { -2313 var aEntry = [ -2314 new _DERInteger(aRevCert[i].sn), -2315 new _Time(aRevCert[i].date) -2316 ]; -2317 if (aRevCert[i].ext != undefined) { -2318 aEntry.push(new _Extensions(aRevCert[i].ext)); -2319 } -2320 a.push(new _DERSequence({array: aEntry})); -2321 } -2322 return new _DERSequence({array: a}); -2323 }; -2324 -2325 this.getEncodedHex = function() { -2326 var a = []; -2327 var params = this.params; -2328 -2329 if (params.version != undefined) { -2330 var version = params.version - 1; -2331 var obj = new _DERInteger({'int': version}); -2332 a.push(obj); -2333 } -2334 -2335 a.push(new _AlgorithmIdentifier({name: params.sigalg})); -2336 a.push(new _X500Name(params.issuer)); -2337 a.push(new _Time(params.thisupdate)); -2338 if (params.nextupdate != undefined) -2339 a.push(new _Time(params.nextupdate)) -2340 if (params.revcert != undefined) { -2341 a.push(this.getRevCertSequence()); -2342 } -2343 if (params.ext != undefined) { -2344 var dExt = new _Extensions(params.ext); -2345 a.push(new _DERTaggedObject({tag:'a0', -2346 explicit:true, -2347 obj:dExt})); -2348 } -2349 -2350 var seq = new _DERSequence({array: a}); -2351 return seq.getEncodedHex(); -2352 }; -2353 -2354 if (params !== undefined) this.setByParam(params); -2355 }; -2356 YAHOO.lang.extend(KJUR.asn1.x509.TBSCertList, KJUR.asn1.ASN1Object); -2357 -2358 /** -2359 * ASN.1 CRLEntry structure class for CRL (DEPRECATED)<br/> -2360 * @name KJUR.asn1.x509.CRLEntry -2361 * @class ASN.1 CRLEntry structure class for CRL -2362 * @param {Array} params JSON object for CRL entry parameter -2363 * @extends KJUR.asn1.ASN1Object -2364 * @since 1.0.3 -2365 * @see KJUR.asn1.x509.TBSCertList -2366 * @deprecated since jsrsasign 9.1.0 asn1x509 2.1.0 -2367 * @description -2368 * This class is to represent revokedCertificate in TBSCertList. -2369 * However this is no more used by TBSCertList since -2370 * jsrsasign 9.1.0. So this class have been deprecated in -2371 * jsrsasign 9.1.0. -2372 * <pre> -2373 * revokedCertificates SEQUENCE OF SEQUENCE { -2374 * userCertificate CertificateSerialNumber, -2375 * revocationDate Time, -2376 * crlEntryExtensions Extensions OPTIONAL -2377 * -- if present, version MUST be v2 } -2378 * </pre> -2379 * @example -2380 * var e = new KJUR.asn1.x509.CRLEntry({'time': {'str': '130514235959Z'}, 'sn': {'int': 234}}); -2381 */ -2382 KJUR.asn1.x509.CRLEntry = function(params) { -2383 KJUR.asn1.x509.CRLEntry.superclass.constructor.call(this); -2384 var sn = null, -2385 time = null, -2386 _KJUR = KJUR, -2387 _KJUR_asn1 = _KJUR.asn1; -2388 -2389 /** -2390 * set DERInteger parameter for serial number of revoked certificate -2391 * @name setCertSerial -2392 * @memberOf KJUR.asn1.x509.CRLEntry -2393 * @function -2394 * @param {Array} intParam DERInteger parameter for certificate serial number -2395 * @description -2396 * @example -2397 * entry.setCertSerial({'int': 3}); -2398 */ -2399 this.setCertSerial = function(intParam) { -2400 this.sn = new _KJUR_asn1.DERInteger(intParam); -2401 }; -2402 -2403 /** -2404 * set Time parameter for revocation date -2405 * @name setRevocationDate -2406 * @memberOf KJUR.asn1.x509.CRLEntry -2407 * @function -2408 * @param {Array} timeParam Time parameter for revocation date -2409 * @description -2410 * @example -2411 * entry.setRevocationDate({'str': '130508235959Z'}); -2412 */ -2413 this.setRevocationDate = function(timeParam) { -2414 this.time = new _KJUR_asn1.x509.Time(timeParam); -2415 }; -2416 -2417 this.getEncodedHex = function() { -2418 var o = new _KJUR_asn1.DERSequence({"array": [this.sn, this.time]}); -2419 this.TLV = o.getEncodedHex(); -2420 return this.TLV; -2421 }; -2422 -2423 if (params !== undefined) { -2424 if (params.time !== undefined) { -2425 this.setRevocationDate(params.time); -2426 } -2427 if (params.sn !== undefined) { -2428 this.setCertSerial(params.sn); -2429 } -2430 } -2431 }; -2432 YAHOO.lang.extend(KJUR.asn1.x509.CRLEntry, KJUR.asn1.ASN1Object); -2433 -2434 /** -2435 * CRLNumber CRL extension ASN.1 structure class<br/> -2436 * @name KJUR.asn1.x509.CRLNumber -2437 * @class CRLNumber CRL extension ASN.1 structure class -2438 * @extends KJUR.asn1.x509.Extension -2439 * @since jsrsasign 9.1.0 asn1x509 2.1.0 -2440 * @see KJUR.asn1.x509.TBSCertList -2441 * @see KJUR.asn1.x509.Extensions -2442 * @description -2443 * This class represents ASN.1 structure for -2444 * CRLNumber CRL extension defined in -2445 * <a href="https://tools.ietf.org/html/rfc5280#section-5.2.3"> -2446 * RFC 5280 5.2.3</a>. -2447 * <pre> -2448 * id-ce-cRLNumber OBJECT IDENTIFIER ::= { id-ce 20 } -2449 * CRLNumber ::= INTEGER (0..MAX) -2450 * </pre> -2451 * Constructor of this class may have following parameters: -2452 * <ul> -2453 * <li>{String}extname - name "cRLNumber". It is ignored in this class but -2454 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> -2455 * <li>{Object}num - CRLNumber value to specify -2456 * {@link KJUR.asn1.DERInteger} parameter.</li> -2457 * <li>{Boolean}critical - critical flag. Generally false and not specified -2458 * in this class.(OPTION)</li> -2459 * </ul> -2460 * -2461 * @example -2462 * new KJUR.asn1.x509.CRLNumber({extname:'cRLNumber', -2463 * num:{'int':147}}) -2464 */ -2465 KJUR.asn1.x509.CRLNumber = function(params) { -2466 KJUR.asn1.x509.CRLNumber.superclass.constructor.call(this, params); -2467 this.params = undefined; -2468 -2469 this.getExtnValueHex = function() { -2470 this.asn1ExtnValue = new KJUR.asn1.DERInteger(this.params.num); -2471 return this.asn1ExtnValue.getEncodedHex(); -2472 }; -2473 -2474 this.oid = "2.5.29.20"; -2475 if (params != undefined) this.params = params; -2476 }; -2477 YAHOO.lang.extend(KJUR.asn1.x509.CRLNumber, KJUR.asn1.x509.Extension); -2478 -2479 /** -2480 * CRLReason CRL entry extension ASN.1 structure class<br/> -2481 * @name KJUR.asn1.x509.CRLReason -2482 * @class CRLReason CRL entry extension ASN.1 structure class -2483 * @extends KJUR.asn1.x509.Extension -2484 * @since jsrsasign 9.1.0 asn1x509 2.1.0 -2485 * @see KJUR.asn1.x509.TBSCertList -2486 * @see KJUR.asn1.x509.Extensions -2487 * @description -2488 * This class represents ASN.1 structure for -2489 * CRLReason CRL entry extension defined in -2490 * <a href="https://tools.ietf.org/html/rfc5280#section-5.3.1"> -2491 * RFC 5280 5.3.1</a> -2492 * <pre> -2493 * id-ce-cRLReasons OBJECT IDENTIFIER ::= { id-ce 21 } -2494 * -- reasonCode ::= { CRLReason } -2495 * CRLReason ::= ENUMERATED { -2496 * unspecified (0), -2497 * keyCompromise (1), -2498 * cACompromise (2), -2499 * affiliationChanged (3), -2500 * superseded (4), -2501 * cessationOfOperation (5), -2502 * certificateHold (6), -2503 * removeFromCRL (8), -2504 * privilegeWithdrawn (9), -2505 * aACompromise (10) } -2506 * </pre> -2507 * Constructor of this class may have following parameters: -2508 * <ul> -2509 * <li>{String}extname - name "cRLReason". It is ignored in this class but -2510 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> -2511 * <li>{Integer}code - reasonCode value</li> -2512 * <li>{Boolean}critical - critical flag. Generally false and not specified -2513 * in this class.(OPTION)</li> -2514 * </ul> -2515 * -2516 * @example -2517 * new KJUR.asn1.x509.CRLReason({extname:'cRLNumber',code:4}) -2518 */ -2519 KJUR.asn1.x509.CRLReason = function(params) { -2520 KJUR.asn1.x509.CRLReason.superclass.constructor.call(this, params); -2521 this.params = undefined; -2522 -2523 this.getExtnValueHex = function() { -2524 this.asn1ExtnValue = new KJUR.asn1.DEREnumerated(this.params.code); -2525 return this.asn1ExtnValue.getEncodedHex(); -2526 }; -2527 -2528 this.oid = "2.5.29.21"; -2529 if (params != undefined) this.params = params; -2530 }; -2531 YAHOO.lang.extend(KJUR.asn1.x509.CRLReason, KJUR.asn1.x509.Extension); -2532 -2533 // === END CRL Related =================================================== -2534 -2535 // === BEGIN OCSP Related =================================================== -2536 /** -2537 * Nonce OCSP extension ASN.1 structure class<br/> -2538 * @name KJUR.asn1.x509.OCSPNonce -2539 * @class Nonce OCSP extension ASN.1 structure class -2540 * @extends KJUR.asn1.x509.Extension -2541 * @since jsrsasign 9.1.6 asn1x509 2.1.2 -2542 * @param {Array} params JSON object for Nonce extension -2543 * @see KJUR.asn1.ocsp.ResponseData -2544 * @see KJUR.asn1.x509.Extensions -2545 * @see X509#getExtOCSPNonce -2546 * @description -2547 * This class represents -2548 * Nonce OCSP extension value defined in -2549 * <a href="https://tools.ietf.org/html/rfc6960#section-4.4.1"> -2550 * RFC 6960 4.4.1</a> as JSON object. -2551 * <pre> -2552 * id-pkix-ocsp OBJECT IDENTIFIER ::= { id-ad-ocsp } -2553 * id-pkix-ocsp-nonce OBJECT IDENTIFIER ::= { id-pkix-ocsp 2 } -2554 * Nonce ::= OCTET STRING -2555 * </pre> -2556 * Constructor of this class may have following parameters: -2557 * <ul> -2558 * <li>{String}extname - name "ocspNonce". It is ignored in this class but -2559 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> -2560 * <li>{String}hex - hexadecimal string of nonce value</li> -2561 * <li>{Number}int - integer of nonce value. "hex" or "int" needs to be -2562 * specified.</li> -2563 * <li>{Boolean}critical - critical flag. Generally false and not specified -2564 * in this class.(OPTION)</li> -2565 * </ul> -2566 * -2567 * @example -2568 * new KJUR.asn1.x509.OCSPNonce({extname:'ocspNonce', -2569 * hex: '12ab...'}) -2570 */ -2571 KJUR.asn1.x509.OCSPNonce = function(params) { -2572 KJUR.asn1.x509.OCSPNonce.superclass.constructor.call(this, params); -2573 this.params = undefined; -2574 -2575 this.getExtnValueHex = function() { -2576 this.asn1ExtnValue = new KJUR.asn1.DEROctetString(this.params); -2577 return this.asn1ExtnValue.getEncodedHex(); -2578 }; -2579 -2580 this.oid = "1.3.6.1.5.5.7.48.1.2"; -2581 if (params != undefined) this.params = params; -2582 }; -2583 YAHOO.lang.extend(KJUR.asn1.x509.OCSPNonce, KJUR.asn1.x509.Extension); -2584 -2585 /** -2586 * OCSPNoCheck certificate ASN.1 structure class<br/> -2587 * @name KJUR.asn1.x509.OCSPNoCheck -2588 * @class OCSPNoCheck extension ASN.1 structure class -2589 * @extends KJUR.asn1.x509.Extension -2590 * @since jsrsasign 9.1.6 asn1x509 2.1.2 -2591 * @param {Array} params JSON object for OCSPNoCheck extension -2592 * @see KJUR.asn1.x509.Extensions -2593 * @see X509#getExtOCSPNoCheck -2594 * @description -2595 * This class represents -2596 * OCSPNoCheck extension value defined in -2597 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.2.2.1"> -2598 * RFC 6960 4.2.2.2.1</a> as JSON object. -2599 * <pre> -2600 * id-pkix-ocsp-nocheck OBJECT IDENTIFIER ::= { id-pkix-ocsp 5 } -2601 * </pre> -2602 * Constructor of this class may have following parameters: -2603 * <ul> -2604 * <li>{String}extname - name "ocspNoCheck". It is ignored in this class but -2605 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> -2606 * <li>{Boolean}critical - critical flag. Generally false and not specified -2607 * in this class.(OPTION)</li> -2608 * </ul> -2609 * -2610 * @example -2611 * new KJUR.asn1.x509.OCSPNonce({extname:'ocspNoCheck'}) -2612 */ -2613 KJUR.asn1.x509.OCSPNoCheck = function(params) { -2614 KJUR.asn1.x509.OCSPNoCheck.superclass.constructor.call(this, params); -2615 this.params = undefined; -2616 -2617 this.getExtnValueHex = function() { -2618 this.asn1ExtnValue = new KJUR.asn1.DERNull(); -2619 return this.asn1ExtnValue.getEncodedHex(); -2620 }; -2621 -2622 this.oid = "1.3.6.1.5.5.7.48.1.5"; -2623 if (params != undefined) this.params = params; -2624 }; -2625 YAHOO.lang.extend(KJUR.asn1.x509.OCSPNoCheck, KJUR.asn1.x509.Extension); -2626 -2627 // === END OCSP Related =================================================== -2628 -2629 // === BEGIN Other X.509v3 Extensions======================================== -2630 -2631 /** -2632 * AdobeTimeStamp X.509v3 extension ASN.1 encoder class<br/> -2633 * @name KJUR.asn1.x509.AdobeTimeStamp -2634 * @class AdobeTimeStamp X.509v3 extension ASN.1 encoder class -2635 * @extends KJUR.asn1.x509.Extension -2636 * @since jsrsasign 10.0.1 asn1x509 2.1.4 -2637 * @param {Array} params JSON object for AdobeTimeStamp extension parameter -2638 * @see KJUR.asn1.x509.Extensions -2639 * @see X509#getExtAdobeTimeStamp -2640 * @description -2641 * This class represents -2642 * AdobeTimeStamp X.509v3 extension value defined in -2643 * <a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/DigSigDC/oids.html"> -2644 * Adobe site</a> as JSON object. -2645 * <pre> -2646 * adbe- OBJECT IDENTIFIER ::= { adbe(1.2.840.113583) acrobat(1) security(1) x509Ext(9) 1 } -2647 * ::= SEQUENCE { -2648 * version INTEGER { v1(1) }, -- extension version -2649 * location GeneralName (In v1 GeneralName can be only uniformResourceIdentifier) -2650 * requiresAuth boolean (default false), OPTIONAL } -2651 * </pre> -2652 * Constructor of this class may have following parameters: -2653 * <ul> -2654 * <li>{String}uri - RFC 3161 time stamp service URL</li> -2655 * <li>{Boolean}reqauth - authentication required or not</li> -2656 * </ul> -2657 * </pre> -2658 * <br/> -2659 * NOTE: This extesion doesn't seem to have official name. This may be called as "pdfTimeStamp". -2660 * @example -2661 * new KJUR.asn1.x509.AdobeTimesStamp({ -2662 * uri: "http://tsa.example.com/", -2663 * reqauth: true -2664 * } -2665 */ -2666 KJUR.asn1.x509.AdobeTimeStamp = function(params) { -2667 KJUR.asn1.x509.AdobeTimeStamp.superclass.constructor.call(this, params); -2668 -2669 var _KJUR = KJUR, -2670 _KJUR_asn1 = _KJUR.asn1, -2671 _DERInteger = _KJUR_asn1.DERInteger, -2672 _DERBoolean = _KJUR_asn1.DERBoolean, -2673 _DERSequence = _KJUR_asn1.DERSequence, -2674 _GeneralName = _KJUR_asn1.x509.GeneralName; -2675 -2676 this.params = null; -2677 -2678 this.getExtnValueHex = function() { -2679 var params = this.params; -2680 var a = [new _DERInteger(1)]; -2681 a.push(new _GeneralName({uri: params.uri})); -2682 if (params.reqauth != undefined) { -2683 a.push(new _DERBoolean(params.reqauth)); -2684 } -2685 -2686 this.asn1ExtnValue = new _DERSequence({array: a}); -2687 return this.asn1ExtnValue.getEncodedHex(); -2688 }; -2689 -2690 this.oid = "1.2.840.113583.1.1.9.1"; -2691 if (params !== undefined) this.setByParam(params); -2692 }; -2693 YAHOO.lang.extend(KJUR.asn1.x509.AdobeTimeStamp, KJUR.asn1.x509.Extension); -2694 -2695 // === END Other X.509v3 Extensions======================================== -2696 +1969 +1970 /** +1971 * priavte extension ASN.1 structure class<br/> +1972 * @name KJUR.asn1.x509.PrivateExtension +1973 * @class private extension ASN.1 structure class +1974 * @param {Array} params JSON object of private extension +1975 * @extends KJUR.asn1.x509.Extension +1976 * @since jsrsasign 9.1.1 asn1x509 +1977 * @see KJUR.asn1.ASN1Util.newObject +1978 * +1979 * @description +1980 * This class is to represent private extension or +1981 * unsupported extension. +1982 * <pre> +1983 * Extension ::= SEQUENCE { +1984 * extnID OBJECT IDENTIFIER, +1985 * critical BOOLEAN DEFAULT FALSE, +1986 * extnValue OCTET STRING } +1987 * </pre> +1988 * Following properties can be set for JSON parameter: +1989 * <ul> +1990 * <li>{String}extname - string of OID or predefined extension name</li> +1991 * <li>{Boolean}critical - critical flag</li> +1992 * <li>{Object}extn - hexadecimal string or +1993 * of {@link KJUR.asn1.ASN1Util.newObject} +1994 * JSON parameter for extnValue field</li> +1995 * </li> +1996 * </ul> +1997 * +1998 * @example +1999 * // extn by hexadecimal +2000 * new KJUR.asn1.x509.PrivateExtension({ +2001 * extname: "1.2.3.4", +2002 * critical: true, +2003 * extn: "13026161" // means PrintableString "aa" +2004 * }); +2005 * +2006 * // extn by JSON parameter +2007 * new KJUR.asn1.x509.PrivateExtension({ +2008 * extname: "1.2.3.5", +2009 * extn: {seq: [{prnstr:"abc"},{utf8str:"def"}]} +2010 * }); +2011 */ +2012 KJUR.asn1.x509.PrivateExtension = function(params) { +2013 KJUR.asn1.x509.PrivateExtension.superclass.constructor.call(this, params) +2014 +2015 var _KJUR = KJUR, +2016 _isHex = _KJUR.lang.String.isHex, +2017 _KJUR_asn1 = _KJUR.asn1, +2018 _name2oid = _KJUR_asn1.x509.OID.name2oid, +2019 _newObject = _KJUR_asn1.ASN1Util.newObject; +2020 +2021 this.params = null; +2022 +2023 this.setByParam = function(params) { +2024 this.oid = _name2oid(params.extname); +2025 this.params = params; +2026 }; +2027 +2028 this.getExtnValueHex = function() { +2029 if (this.params.extname == undefined || +2030 this.params.extn == undefined) { +2031 throw new Error("extname or extnhex not specified"); +2032 } +2033 +2034 var extn = this.params.extn; +2035 if (typeof extn == "string" && _isHex(extn)) { +2036 return extn; +2037 } else if (typeof extn == "object") { +2038 try { +2039 return _newObject(extn).getEncodedHex(); +2040 } catch(ex) {} +2041 } +2042 throw new Error("unsupported extn value"); +2043 }; +2044 +2045 if (params != undefined) { +2046 this.setByParam(params); +2047 } +2048 }; +2049 YAHOO.lang.extend(KJUR.asn1.x509.PrivateExtension, KJUR.asn1.x509.Extension); +2050 +2051 // === END X.509v3 Extensions Related ======================================= +2052 +2053 // === BEGIN CRL Related =================================================== +2054 /** +2055 * X.509 CRL class to sign and generate hex encoded CRL<br/> +2056 * @name KJUR.asn1.x509.CRL +2057 * @class X.509 CRL class to sign and generate hex encoded certificate +2058 * @property {Array} params JSON object of parameters +2059 * @param {Array} params JSON object of CRL parameters +2060 * @extends KJUR.asn1.ASN1Object +2061 * @since 1.0.3 +2062 * @see KJUR.asn1.x509.TBSCertList +2063 * +2064 * @description +2065 * This class represents CertificateList ASN.1 structur of X.509 CRL +2066 * defined in <a href="https://tools.ietf.org/html/rfc5280#section-5.1"> +2067 * RFC 5280 5.1</a> +2068 * <pre> +2069 * CertificateList ::= SEQUENCE { +2070 * tbsCertList TBSCertList, +2071 * signatureAlgorithm AlgorithmIdentifier, +2072 * signatureValue BIT STRING } +2073 * </pre> +2074 * NOTE: CRL class is updated without backward +2075 * compatibility from jsrsasign 9.1.0 asn1x509 2.1.0. +2076 * Most of methods are removed and parameters can be set +2077 * by JSON object. +2078 * <br/> +2079 * Constructor of this class can accept all +2080 * parameters of {@link KJUR.asn1.x509.TBSCertList}. +2081 * It also accept following parameters additionally: +2082 * <ul> +2083 * <li>{TBSCertList}tbsobj (OPTION) - +2084 * specifies {@link KJUR.asn1.x509.TBSCertList} +2085 * object to be signed if needed. +2086 * When this isn't specified, +2087 * this will be set from other parametes of TBSCertList.</li> +2088 * <li>{Object}cakey (OPTION) - specifies CRL signing private key. +2089 * Parameter "cakey" or "sighex" shall be specified. Following +2090 * values can be specified: +2091 * <ul> +2092 * <li>PKCS#1/5 or PKCS#8 PEM string of private key</li> +2093 * <li>RSAKey/DSA/ECDSA key object. {@link KEYUTIL.getKey} is useful +2094 * to generate a key object.</li> +2095 * </ul> +2096 * </li> +2097 * <li>{String}sighex (OPTION) - hexadecimal string of signature value +2098 * (i.e. ASN.1 value(V) of signatureValue BIT STRING without +2099 * unused bits)</li> +2100 * </ul> +2101 * +2102 * @example +2103 * var crl = new KJUR.asn1.x509.CRL({ +2104 * sigalg: "SHA256withRSA", +2105 * issuer: {str:'/C=JP/O=Test1'}, +2106 * thisupdate: "200821235959Z", +2107 * nextupdate: "200828235959Z", // OPTION +2108 * revcert: [{sn: {hex: "12ab"}, date: "200401235959Z"}], +2109 * ext: [ +2110 * {extname: "cRLNumber", num: {'int': 8}}, +2111 * {extname: "authorityKeyIdentifier", "kid": {hex: "12ab"}} +2112 * ], +2113 * cakey: prvkey +2114 * }); +2115 * crl.getEncodedHex() → "30..." +2116 * crl.getPEM() → "-----BEGIN X509 CRL..." +2117 */ +2118 KJUR.asn1.x509.CRL = function(params) { +2119 KJUR.asn1.x509.CRL.superclass.constructor.call(this); +2120 var _KJUR = KJUR, +2121 _KJUR_asn1 = _KJUR.asn1, +2122 _DERSequence = _KJUR_asn1.DERSequence, +2123 _DERBitString = _KJUR_asn1.DERBitString, +2124 _KJUR_asn1_x509 = _KJUR_asn1.x509, +2125 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, +2126 _TBSCertList = _KJUR_asn1_x509.TBSCertList; +2127 +2128 this.params = undefined; +2129 +2130 this.setByParam = function(params) { +2131 this.params = params; +2132 }; +2133 +2134 /** +2135 * sign CRL<br/> +2136 * @name sign +2137 * @memberOf KJUR.asn1.x509.CRL# +2138 * @function +2139 * @description +2140 * This method signs TBSCertList with a specified +2141 * private key and algorithm by +2142 * this.params.cakey and this.params.sigalg parameter. +2143 * @example +2144 * crl = new KJUR.asn1.x509.CRL({..., cakey:prvkey}); +2145 * crl.sign() +2146 */ +2147 this.sign = function() { +2148 var hTBSCL = (new _TBSCertList(this.params)).getEncodedHex(); +2149 var sig = new KJUR.crypto.Signature({alg: this.params.sigalg}); +2150 sig.init(this.params.cakey); +2151 sig.updateHex(hTBSCL); +2152 var sighex = sig.sign(); +2153 this.params.sighex = sighex; +2154 }; +2155 +2156 /** +2157 * get PEM formatted CRL string after signed<br/> +2158 * @name getPEM +2159 * @memberOf KJUR.asn1.x509.CRL# +2160 * @function +2161 * @return PEM formatted string of CRL +2162 * @since jsrsasign 9.1.0 asn1hex 2.1.0 +2163 * @description +2164 * This method returns a string of PEM formatted +2165 * CRL. +2166 * @example +2167 * crl = new KJUR.asn1.x509.CRL({...}); +2168 * crl.getPEM() → +2169 * "-----BEGIN X509 CRL-----\r\n..." +2170 */ +2171 this.getPEM = function() { +2172 return hextopem(this.getEncodedHex(), "X509 CRL"); +2173 }; +2174 +2175 this.getEncodedHex = function() { +2176 var params = this.params; +2177 +2178 if (params.tbsobj == undefined) { +2179 params.tbsobj = new _TBSCertList(params); +2180 } +2181 +2182 if (params.sighex == undefined && params.cakey != undefined) { +2183 this.sign(); +2184 } +2185 +2186 if (params.sighex == undefined) { +2187 throw new Error("sighex or cakey parameter not defined"); +2188 } +2189 +2190 var a = []; +2191 a.push(params.tbsobj); +2192 a.push(new _AlgorithmIdentifier({name: params.sigalg})); +2193 a.push(new _DERBitString({hex: "00" + params.sighex})); +2194 var seq = new _DERSequence({array: a}); +2195 return seq.getEncodedHex(); +2196 }; +2197 +2198 if (params != undefined) this.params = params; +2199 }; +2200 YAHOO.lang.extend(KJUR.asn1.x509.CRL, KJUR.asn1.ASN1Object); +2201 +2202 /** +2203 * ASN.1 TBSCertList ASN.1 structure class for CRL<br/> +2204 * @name KJUR.asn1.x509.TBSCertList +2205 * @class TBSCertList ASN.1 structure class for CRL +2206 * @property {Array} params JSON object of parameters +2207 * @param {Array} params JSON object of TBSCertList parameters +2208 * @extends KJUR.asn1.ASN1Object +2209 * @since 1.0.3 +2210 * +2211 * @description +2212 * This class represents TBSCertList of CRL defined in +2213 * <a href="https://tools.ietf.org/html/rfc5280#section-5.1"> +2214 * RFC 5280 5.1</a>. +2215 * <pre> +2216 * TBSCertList ::= SEQUENCE { +2217 * version Version OPTIONAL, +2218 * -- if present, MUST be v2 +2219 * signature AlgorithmIdentifier, +2220 * issuer Name, +2221 * thisUpdate Time, +2222 * nextUpdate Time OPTIONAL, +2223 * revokedCertificates SEQUENCE OF SEQUENCE { +2224 * userCertificate CertificateSerialNumber, +2225 * revocationDate Time, +2226 * crlEntryExtensions Extensions OPTIONAL +2227 * -- if present, version MUST be v2 +2228 * } OPTIONAL, +2229 * crlExtensions [0] EXPLICIT Extensions OPTIONAL +2230 * } +2231 * </pre> +2232 * NOTE: TBSCertList class is updated without backward +2233 * compatibility from jsrsasign 9.1.0 asn1x509 2.1.0. +2234 * Most of methods are removed and parameters can be set +2235 * by JSON object. +2236 * <br/> +2237 * Constructor of this class may have following parameters: +2238 * <ul> +2239 * <li>{Integer}version (OPTION) - version number. Omitted by default.</li> +2240 * <li>{String}sigalg - signature algorithm name</li> +2241 * <li>{Array}issuer - issuer parameter of {@link KJUR.asn1.x509.X500Name}</li> +2242 * <li>{String}thisupdate - thisUpdate field value</li> +2243 * <li>{String}nextupdate (OPTION) - thisUpdate field value</li> +2244 * <li>{Array}revcert (OPTION) - revokedCertificates field value as array +2245 * Its element may have following property: +2246 * <ul> +2247 * <li>{Array}sn - serialNumber of userCertificate field specified +2248 * by {@link KJUR.asn1.DERInteger}</li> +2249 * <li>{String}date - revocationDate field specified by +2250 * a string of {@link KJUR.asn1.x509.Time} parameter</li> +2251 * <li>{Array}ext (OPTION) - array of CRL entry extension parameter</li> +2252 * </ul> +2253 * </li> +2254 * </ul> +2255 * +2256 * @example +2257 * var o = new KJUR.asn1.x509.TBSCertList({ +2258 * sigalg: "SHA256withRSA", +2259 * issuer: {array: [[{type:'C',value:'JP',ds:'prn'}], +2260 * [{type:'O',value:'T1',ds:'prn'}]]}, +2261 * thisupdate: "200821235959Z", +2262 * nextupdate: "200828235959Z", // OPTION +2263 * revcert: [ +2264 * {sn: {hex: "12ab"}, date: "200401235959Z", ext: [{extname: "cRLReason", code:1}]}, +2265 * {sn: {hex: "12bc"}, date: "200405235959Z", ext: [{extname: "cRLReason", code:2}]} +2266 * ], +2267 * ext: [ +2268 * {extname: "cRLNumber", num: {'int': 8}}, +2269 * {extname: "authorityKeyIdentifier", "kid": {hex: "12ab"}} +2270 * ] +2271 * }); +2272 * o.getEncodedHex() → "30..." +2273 */ +2274 KJUR.asn1.x509.TBSCertList = function(params) { +2275 KJUR.asn1.x509.TBSCertList.superclass.constructor.call(this); +2276 var _KJUR = KJUR, +2277 _KJUR_asn1 = _KJUR.asn1, +2278 _DERInteger = _KJUR_asn1.DERInteger, +2279 _DERSequence = _KJUR_asn1.DERSequence, +2280 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, +2281 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, +2282 _KJUR_asn1_x509 = _KJUR_asn1.x509, +2283 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, +2284 _Time = _KJUR_asn1_x509.Time, +2285 _Extensions = _KJUR_asn1_x509.Extensions, +2286 _X500Name = _KJUR_asn1_x509.X500Name; +2287 this.params = null; +2288 +2289 /** +2290 * get array of ASN.1 object for extensions<br/> +2291 * @name setByParam +2292 * @memberOf KJUR.asn1.x509.TBSCertList# +2293 * @function +2294 * @param {Array} JSON object of TBSCertList parameters +2295 * @example +2296 * tbsc = new KJUR.asn1.x509.TBSCertificate(); +2297 * tbsc.setByParam({version:3, serial:{hex:'1234...'},...}); +2298 */ +2299 this.setByParam = function(params) { +2300 this.params = params; +2301 }; +2302 +2303 /** +2304 * get DERSequence for revokedCertificates<br/> +2305 * @name getRevCertSequence +2306 * @memberOf KJUR.asn1.x509.TBSCertList# +2307 * @function +2308 * @return {@link KJUR.asn1.DERSequence} of revokedCertificates +2309 */ +2310 this.getRevCertSequence = function() { +2311 var a = []; +2312 var aRevCert = this.params.revcert; +2313 for (var i = 0; i < aRevCert.length; i++) { +2314 var aEntry = [ +2315 new _DERInteger(aRevCert[i].sn), +2316 new _Time(aRevCert[i].date) +2317 ]; +2318 if (aRevCert[i].ext != undefined) { +2319 aEntry.push(new _Extensions(aRevCert[i].ext)); +2320 } +2321 a.push(new _DERSequence({array: aEntry})); +2322 } +2323 return new _DERSequence({array: a}); +2324 }; +2325 +2326 this.getEncodedHex = function() { +2327 var a = []; +2328 var params = this.params; +2329 +2330 if (params.version != undefined) { +2331 var version = params.version - 1; +2332 var obj = new _DERInteger({'int': version}); +2333 a.push(obj); +2334 } +2335 +2336 a.push(new _AlgorithmIdentifier({name: params.sigalg})); +2337 a.push(new _X500Name(params.issuer)); +2338 a.push(new _Time(params.thisupdate)); +2339 if (params.nextupdate != undefined) +2340 a.push(new _Time(params.nextupdate)) +2341 if (params.revcert != undefined) { +2342 a.push(this.getRevCertSequence()); +2343 } +2344 if (params.ext != undefined) { +2345 var dExt = new _Extensions(params.ext); +2346 a.push(new _DERTaggedObject({tag:'a0', +2347 explicit:true, +2348 obj:dExt})); +2349 } +2350 +2351 var seq = new _DERSequence({array: a}); +2352 return seq.getEncodedHex(); +2353 }; +2354 +2355 if (params !== undefined) this.setByParam(params); +2356 }; +2357 YAHOO.lang.extend(KJUR.asn1.x509.TBSCertList, KJUR.asn1.ASN1Object); +2358 +2359 /** +2360 * ASN.1 CRLEntry structure class for CRL (DEPRECATED)<br/> +2361 * @name KJUR.asn1.x509.CRLEntry +2362 * @class ASN.1 CRLEntry structure class for CRL +2363 * @param {Array} params JSON object for CRL entry parameter +2364 * @extends KJUR.asn1.ASN1Object +2365 * @since 1.0.3 +2366 * @see KJUR.asn1.x509.TBSCertList +2367 * @deprecated since jsrsasign 9.1.0 asn1x509 2.1.0 +2368 * @description +2369 * This class is to represent revokedCertificate in TBSCertList. +2370 * However this is no more used by TBSCertList since +2371 * jsrsasign 9.1.0. So this class have been deprecated in +2372 * jsrsasign 9.1.0. +2373 * <pre> +2374 * revokedCertificates SEQUENCE OF SEQUENCE { +2375 * userCertificate CertificateSerialNumber, +2376 * revocationDate Time, +2377 * crlEntryExtensions Extensions OPTIONAL +2378 * -- if present, version MUST be v2 } +2379 * </pre> +2380 * @example +2381 * var e = new KJUR.asn1.x509.CRLEntry({'time': {'str': '130514235959Z'}, 'sn': {'int': 234}}); +2382 */ +2383 KJUR.asn1.x509.CRLEntry = function(params) { +2384 KJUR.asn1.x509.CRLEntry.superclass.constructor.call(this); +2385 var sn = null, +2386 time = null, +2387 _KJUR = KJUR, +2388 _KJUR_asn1 = _KJUR.asn1; +2389 +2390 /** +2391 * set DERInteger parameter for serial number of revoked certificate +2392 * @name setCertSerial +2393 * @memberOf KJUR.asn1.x509.CRLEntry +2394 * @function +2395 * @param {Array} intParam DERInteger parameter for certificate serial number +2396 * @description +2397 * @example +2398 * entry.setCertSerial({'int': 3}); +2399 */ +2400 this.setCertSerial = function(intParam) { +2401 this.sn = new _KJUR_asn1.DERInteger(intParam); +2402 }; +2403 +2404 /** +2405 * set Time parameter for revocation date +2406 * @name setRevocationDate +2407 * @memberOf KJUR.asn1.x509.CRLEntry +2408 * @function +2409 * @param {Array} timeParam Time parameter for revocation date +2410 * @description +2411 * @example +2412 * entry.setRevocationDate({'str': '130508235959Z'}); +2413 */ +2414 this.setRevocationDate = function(timeParam) { +2415 this.time = new _KJUR_asn1.x509.Time(timeParam); +2416 }; +2417 +2418 this.getEncodedHex = function() { +2419 var o = new _KJUR_asn1.DERSequence({"array": [this.sn, this.time]}); +2420 this.TLV = o.getEncodedHex(); +2421 return this.TLV; +2422 }; +2423 +2424 if (params !== undefined) { +2425 if (params.time !== undefined) { +2426 this.setRevocationDate(params.time); +2427 } +2428 if (params.sn !== undefined) { +2429 this.setCertSerial(params.sn); +2430 } +2431 } +2432 }; +2433 YAHOO.lang.extend(KJUR.asn1.x509.CRLEntry, KJUR.asn1.ASN1Object); +2434 +2435 /** +2436 * CRLNumber CRL extension ASN.1 structure class<br/> +2437 * @name KJUR.asn1.x509.CRLNumber +2438 * @class CRLNumber CRL extension ASN.1 structure class +2439 * @extends KJUR.asn1.x509.Extension +2440 * @since jsrsasign 9.1.0 asn1x509 2.1.0 +2441 * @see KJUR.asn1.x509.TBSCertList +2442 * @see KJUR.asn1.x509.Extensions +2443 * @description +2444 * This class represents ASN.1 structure for +2445 * CRLNumber CRL extension defined in +2446 * <a href="https://tools.ietf.org/html/rfc5280#section-5.2.3"> +2447 * RFC 5280 5.2.3</a>. +2448 * <pre> +2449 * id-ce-cRLNumber OBJECT IDENTIFIER ::= { id-ce 20 } +2450 * CRLNumber ::= INTEGER (0..MAX) +2451 * </pre> +2452 * Constructor of this class may have following parameters: +2453 * <ul> +2454 * <li>{String}extname - name "cRLNumber". It is ignored in this class but +2455 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> +2456 * <li>{Object}num - CRLNumber value to specify +2457 * {@link KJUR.asn1.DERInteger} parameter.</li> +2458 * <li>{Boolean}critical - critical flag. Generally false and not specified +2459 * in this class.(OPTION)</li> +2460 * </ul> +2461 * +2462 * @example +2463 * new KJUR.asn1.x509.CRLNumber({extname:'cRLNumber', +2464 * num:{'int':147}}) +2465 */ +2466 KJUR.asn1.x509.CRLNumber = function(params) { +2467 KJUR.asn1.x509.CRLNumber.superclass.constructor.call(this, params); +2468 this.params = undefined; +2469 +2470 this.getExtnValueHex = function() { +2471 this.asn1ExtnValue = new KJUR.asn1.DERInteger(this.params.num); +2472 return this.asn1ExtnValue.getEncodedHex(); +2473 }; +2474 +2475 this.oid = "2.5.29.20"; +2476 if (params != undefined) this.params = params; +2477 }; +2478 YAHOO.lang.extend(KJUR.asn1.x509.CRLNumber, KJUR.asn1.x509.Extension); +2479 +2480 /** +2481 * CRLReason CRL entry extension ASN.1 structure class<br/> +2482 * @name KJUR.asn1.x509.CRLReason +2483 * @class CRLReason CRL entry extension ASN.1 structure class +2484 * @extends KJUR.asn1.x509.Extension +2485 * @since jsrsasign 9.1.0 asn1x509 2.1.0 +2486 * @see KJUR.asn1.x509.TBSCertList +2487 * @see KJUR.asn1.x509.Extensions +2488 * @description +2489 * This class represents ASN.1 structure for +2490 * CRLReason CRL entry extension defined in +2491 * <a href="https://tools.ietf.org/html/rfc5280#section-5.3.1"> +2492 * RFC 5280 5.3.1</a> +2493 * <pre> +2494 * id-ce-cRLReasons OBJECT IDENTIFIER ::= { id-ce 21 } +2495 * -- reasonCode ::= { CRLReason } +2496 * CRLReason ::= ENUMERATED { +2497 * unspecified (0), +2498 * keyCompromise (1), +2499 * cACompromise (2), +2500 * affiliationChanged (3), +2501 * superseded (4), +2502 * cessationOfOperation (5), +2503 * certificateHold (6), +2504 * removeFromCRL (8), +2505 * privilegeWithdrawn (9), +2506 * aACompromise (10) } +2507 * </pre> +2508 * Constructor of this class may have following parameters: +2509 * <ul> +2510 * <li>{String}extname - name "cRLReason". It is ignored in this class but +2511 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> +2512 * <li>{Integer}code - reasonCode value</li> +2513 * <li>{Boolean}critical - critical flag. Generally false and not specified +2514 * in this class.(OPTION)</li> +2515 * </ul> +2516 * +2517 * @example +2518 * new KJUR.asn1.x509.CRLReason({extname:'cRLNumber',code:4}) +2519 */ +2520 KJUR.asn1.x509.CRLReason = function(params) { +2521 KJUR.asn1.x509.CRLReason.superclass.constructor.call(this, params); +2522 this.params = undefined; +2523 +2524 this.getExtnValueHex = function() { +2525 this.asn1ExtnValue = new KJUR.asn1.DEREnumerated(this.params.code); +2526 return this.asn1ExtnValue.getEncodedHex(); +2527 }; +2528 +2529 this.oid = "2.5.29.21"; +2530 if (params != undefined) this.params = params; +2531 }; +2532 YAHOO.lang.extend(KJUR.asn1.x509.CRLReason, KJUR.asn1.x509.Extension); +2533 +2534 // === END CRL Related =================================================== +2535 +2536 // === BEGIN OCSP Related =================================================== +2537 /** +2538 * Nonce OCSP extension ASN.1 structure class<br/> +2539 * @name KJUR.asn1.x509.OCSPNonce +2540 * @class Nonce OCSP extension ASN.1 structure class +2541 * @extends KJUR.asn1.x509.Extension +2542 * @since jsrsasign 9.1.6 asn1x509 2.1.2 +2543 * @param {Array} params JSON object for Nonce extension +2544 * @see KJUR.asn1.ocsp.ResponseData +2545 * @see KJUR.asn1.x509.Extensions +2546 * @see X509#getExtOCSPNonce +2547 * @description +2548 * This class represents +2549 * Nonce OCSP extension value defined in +2550 * <a href="https://tools.ietf.org/html/rfc6960#section-4.4.1"> +2551 * RFC 6960 4.4.1</a> as JSON object. +2552 * <pre> +2553 * id-pkix-ocsp OBJECT IDENTIFIER ::= { id-ad-ocsp } +2554 * id-pkix-ocsp-nonce OBJECT IDENTIFIER ::= { id-pkix-ocsp 2 } +2555 * Nonce ::= OCTET STRING +2556 * </pre> +2557 * Constructor of this class may have following parameters: +2558 * <ul> +2559 * <li>{String}extname - name "ocspNonce". It is ignored in this class but +2560 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> +2561 * <li>{String}hex - hexadecimal string of nonce value</li> +2562 * <li>{Number}int - integer of nonce value. "hex" or "int" needs to be +2563 * specified.</li> +2564 * <li>{Boolean}critical - critical flag. Generally false and not specified +2565 * in this class.(OPTION)</li> +2566 * </ul> +2567 * +2568 * @example +2569 * new KJUR.asn1.x509.OCSPNonce({extname:'ocspNonce', +2570 * hex: '12ab...'}) +2571 */ +2572 KJUR.asn1.x509.OCSPNonce = function(params) { +2573 KJUR.asn1.x509.OCSPNonce.superclass.constructor.call(this, params); +2574 this.params = undefined; +2575 +2576 this.getExtnValueHex = function() { +2577 this.asn1ExtnValue = new KJUR.asn1.DEROctetString(this.params); +2578 return this.asn1ExtnValue.getEncodedHex(); +2579 }; +2580 +2581 this.oid = "1.3.6.1.5.5.7.48.1.2"; +2582 if (params != undefined) this.params = params; +2583 }; +2584 YAHOO.lang.extend(KJUR.asn1.x509.OCSPNonce, KJUR.asn1.x509.Extension); +2585 +2586 /** +2587 * OCSPNoCheck certificate ASN.1 structure class<br/> +2588 * @name KJUR.asn1.x509.OCSPNoCheck +2589 * @class OCSPNoCheck extension ASN.1 structure class +2590 * @extends KJUR.asn1.x509.Extension +2591 * @since jsrsasign 9.1.6 asn1x509 2.1.2 +2592 * @param {Array} params JSON object for OCSPNoCheck extension +2593 * @see KJUR.asn1.x509.Extensions +2594 * @see X509#getExtOCSPNoCheck +2595 * @description +2596 * This class represents +2597 * OCSPNoCheck extension value defined in +2598 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.2.2.1"> +2599 * RFC 6960 4.2.2.2.1</a> as JSON object. +2600 * <pre> +2601 * id-pkix-ocsp-nocheck OBJECT IDENTIFIER ::= { id-pkix-ocsp 5 } +2602 * </pre> +2603 * Constructor of this class may have following parameters: +2604 * <ul> +2605 * <li>{String}extname - name "ocspNoCheck". It is ignored in this class but +2606 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> +2607 * <li>{Boolean}critical - critical flag. Generally false and not specified +2608 * in this class.(OPTION)</li> +2609 * </ul> +2610 * +2611 * @example +2612 * new KJUR.asn1.x509.OCSPNonce({extname:'ocspNoCheck'}) +2613 */ +2614 KJUR.asn1.x509.OCSPNoCheck = function(params) { +2615 KJUR.asn1.x509.OCSPNoCheck.superclass.constructor.call(this, params); +2616 this.params = undefined; +2617 +2618 this.getExtnValueHex = function() { +2619 this.asn1ExtnValue = new KJUR.asn1.DERNull(); +2620 return this.asn1ExtnValue.getEncodedHex(); +2621 }; +2622 +2623 this.oid = "1.3.6.1.5.5.7.48.1.5"; +2624 if (params != undefined) this.params = params; +2625 }; +2626 YAHOO.lang.extend(KJUR.asn1.x509.OCSPNoCheck, KJUR.asn1.x509.Extension); +2627 +2628 // === END OCSP Related =================================================== +2629 +2630 // === BEGIN Other X.509v3 Extensions======================================== +2631 +2632 /** +2633 * AdobeTimeStamp X.509v3 extension ASN.1 encoder class<br/> +2634 * @name KJUR.asn1.x509.AdobeTimeStamp +2635 * @class AdobeTimeStamp X.509v3 extension ASN.1 encoder class +2636 * @extends KJUR.asn1.x509.Extension +2637 * @since jsrsasign 10.0.1 asn1x509 2.1.4 +2638 * @param {Array} params JSON object for AdobeTimeStamp extension parameter +2639 * @see KJUR.asn1.x509.Extensions +2640 * @see X509#getExtAdobeTimeStamp +2641 * @description +2642 * This class represents +2643 * AdobeTimeStamp X.509v3 extension value defined in +2644 * <a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/DigSigDC/oids.html"> +2645 * Adobe site</a> as JSON object. +2646 * <pre> +2647 * adbe- OBJECT IDENTIFIER ::= { adbe(1.2.840.113583) acrobat(1) security(1) x509Ext(9) 1 } +2648 * ::= SEQUENCE { +2649 * version INTEGER { v1(1) }, -- extension version +2650 * location GeneralName (In v1 GeneralName can be only uniformResourceIdentifier) +2651 * requiresAuth boolean (default false), OPTIONAL } +2652 * </pre> +2653 * Constructor of this class may have following parameters: +2654 * <ul> +2655 * <li>{String}uri - RFC 3161 time stamp service URL</li> +2656 * <li>{Boolean}reqauth - authentication required or not</li> +2657 * </ul> +2658 * </pre> +2659 * <br/> +2660 * NOTE: This extesion doesn't seem to have official name. This may be called as "pdfTimeStamp". +2661 * @example +2662 * new KJUR.asn1.x509.AdobeTimesStamp({ +2663 * uri: "http://tsa.example.com/", +2664 * reqauth: true +2665 * } +2666 */ +2667 KJUR.asn1.x509.AdobeTimeStamp = function(params) { +2668 KJUR.asn1.x509.AdobeTimeStamp.superclass.constructor.call(this, params); +2669 +2670 var _KJUR = KJUR, +2671 _KJUR_asn1 = _KJUR.asn1, +2672 _DERInteger = _KJUR_asn1.DERInteger, +2673 _DERBoolean = _KJUR_asn1.DERBoolean, +2674 _DERSequence = _KJUR_asn1.DERSequence, +2675 _GeneralName = _KJUR_asn1.x509.GeneralName; +2676 +2677 this.params = null; +2678 +2679 this.getExtnValueHex = function() { +2680 var params = this.params; +2681 var a = [new _DERInteger(1)]; +2682 a.push(new _GeneralName({uri: params.uri})); +2683 if (params.reqauth != undefined) { +2684 a.push(new _DERBoolean(params.reqauth)); +2685 } +2686 +2687 this.asn1ExtnValue = new _DERSequence({array: a}); +2688 return this.asn1ExtnValue.getEncodedHex(); +2689 }; +2690 +2691 this.oid = "1.2.840.113583.1.1.9.1"; +2692 if (params !== undefined) this.setByParam(params); +2693 }; +2694 YAHOO.lang.extend(KJUR.asn1.x509.AdobeTimeStamp, KJUR.asn1.x509.Extension); +2695 +2696 // === END Other X.509v3 Extensions======================================== 2697 -2698 // === BEGIN X500Name Related ================================================= -2699 /** -2700 * X500Name ASN.1 structure class -2701 * @name KJUR.asn1.x509.X500Name -2702 * @class X500Name ASN.1 structure class -2703 * @param {Array} params associative array of parameters (ex. {'str': '/C=US/O=a'}) -2704 * @extends KJUR.asn1.ASN1Object -2705 * @see KJUR.asn1.x509.X500Name -2706 * @see KJUR.asn1.x509.RDN -2707 * @see KJUR.asn1.x509.AttributeTypeAndValue -2708 * @see X509#getX500Name -2709 * @description -2710 * This class provides DistinguishedName ASN.1 class structure -2711 * defined in <a href="https://tools.ietf.org/html/rfc2253#section-2">RFC 2253 section 2</a>. -2712 * <blockquote><pre> -2713 * DistinguishedName ::= RDNSequence -2714 * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName -2715 * RelativeDistinguishedName ::= SET SIZE (1..MAX) OF -2716 * AttributeTypeAndValue -2717 * AttributeTypeAndValue ::= SEQUENCE { -2718 * type AttributeType, -2719 * value AttributeValue } -2720 * </pre></blockquote> -2721 * <br/> -2722 * Argument for the constructor can be one of following parameters: -2723 * <ul> -2724 * <li>{Array}array - array of {@link KJUR.asn1.x509.RDN} parameter</li> -2725 * <li>`String}str - string for distingish name in OpenSSL One line foramt (ex: /C=US/O=test/CN=test) See <a href="https://github.com/kjur/jsrsasign/wiki/NOTE-distinguished-name-representation-in-jsrsasign">this</a> in detail.</li> -2726 * <li>{String}ldapstr - string for distinguish name in LDAP format (ex: CN=test,O=test,C=US)</li> -2727 * <li>{String}hex - hexadecimal string for ASN.1 distinguish name structure</li> -2728 * <li>{String}certissuer - issuer name in the specified PEM certificate</li> -2729 * <li>{String}certsubject - subject name in the specified PEM certificate</li> -2730 * <li>{String}rule - DirectoryString rule (ex. "prn" or "utf8")</li> -2731 * </ul> -2732 * <br/> -2733 * NOTE1: The "array" and "rule" parameters have been supported -2734 * since jsrsasign 9.0.0 asn1x509 2.0.0. -2735 * <br/> -2736 * NOTE2: Multi-valued RDN in "str" parameter have been -2737 * supported since jsrsasign 6.2.1 asn1x509 1.0.17. -2738 * @example -2739 * // 1. construct with array -2740 * new KJUR.asn1.x509.X500Name({array:[ -2741 * [{type:'C',value:'JP',ds:'prn'}], -2742 * [{type:'O',value:'aaa',ds:'utf8'}, // multi-valued RDN -2743 * {type:'CN',value:'bob@example.com',ds:'ia5'}] -2744 * ]}) -2745 : "/C=US/O=aaa+CN=contact@example.com"}); // multi valued +2698 +2699 // === BEGIN X500Name Related ================================================= +2700 /** +2701 * X500Name ASN.1 structure class +2702 * @name KJUR.asn1.x509.X500Name +2703 * @class X500Name ASN.1 structure class +2704 * @param {Array} params associative array of parameters (ex. {'str': '/C=US/O=a'}) +2705 * @extends KJUR.asn1.ASN1Object +2706 * @see KJUR.asn1.x509.X500Name +2707 * @see KJUR.asn1.x509.RDN +2708 * @see KJUR.asn1.x509.AttributeTypeAndValue +2709 * @see X509#getX500Name +2710 * @description +2711 * This class provides DistinguishedName ASN.1 class structure +2712 * defined in <a href="https://tools.ietf.org/html/rfc2253#section-2">RFC 2253 section 2</a>. +2713 * <blockquote><pre> +2714 * DistinguishedName ::= RDNSequence +2715 * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName +2716 * RelativeDistinguishedName ::= SET SIZE (1..MAX) OF +2717 * AttributeTypeAndValue +2718 * AttributeTypeAndValue ::= SEQUENCE { +2719 * type AttributeType, +2720 * value AttributeValue } +2721 * </pre></blockquote> +2722 * <br/> +2723 * Argument for the constructor can be one of following parameters: +2724 * <ul> +2725 * <li>{Array}array - array of {@link KJUR.asn1.x509.RDN} parameter</li> +2726 * <li>`String}str - string for distingish name in OpenSSL One line foramt (ex: /C=US/O=test/CN=test) See <a href="https://github.com/kjur/jsrsasign/wiki/NOTE-distinguished-name-representation-in-jsrsasign">this</a> in detail.</li> +2727 * <li>{String}ldapstr - string for distinguish name in LDAP format (ex: CN=test,O=test,C=US)</li> +2728 * <li>{String}hex - hexadecimal string for ASN.1 distinguish name structure</li> +2729 * <li>{String}certissuer - issuer name in the specified PEM certificate</li> +2730 * <li>{String}certsubject - subject name in the specified PEM certificate</li> +2731 * <li>{String}rule - DirectoryString rule (ex. "prn" or "utf8")</li> +2732 * </ul> +2733 * <br/> +2734 * NOTE1: The "array" and "rule" parameters have been supported +2735 * since jsrsasign 9.0.0 asn1x509 2.0.0. +2736 * <br/> +2737 * NOTE2: Multi-valued RDN in "str" parameter have been +2738 * supported since jsrsasign 6.2.1 asn1x509 1.0.17. +2739 * @example +2740 * // 1. construct with array +2741 * new KJUR.asn1.x509.X500Name({array:[ +2742 * [{type:'C',value:'JP',ds:'prn'}], +2743 * [{type:'O',value:'aaa',ds:'utf8'}, // multi-valued RDN +2744 * {type:'CN',value:'bob@example.com',ds:'ia5'}] +2745 * ]}) 2746 * // 2. construct with string -2747 * new KJUR.asn1.x509.X500Name({str: "/C=US/O=aaa+CN=contact@example.com"}); // multi valued -2748 * // 3. construct by LDAP string -2749 * new KJUR.asn1.x509.X500Name({ldapstr: "CN=foo@example.com,OU=bbb,C=US"}); -2750 * // 4. construct by ASN.1 hex string -2751 * new KJUR.asn1.x509.X500Name({hex: "304c3120..."}); -2752 * // 5. construct by issuer of PEM certificate -2753 * new KJUR.asn1.x509.X500Name({certsubject: "-----BEGIN CERT..."}); -2754 * // 6. construct by subject of PEM certificate -2755 * new KJUR.asn1.x509.X500Name({certissuer: "-----BEGIN CERT..."}); -2756 * // 7. construct by object (DEPRECATED) -2757 * new KJUR.asn1.x509.X500Name({C:"US",O:"aaa",CN:"http://example.com/"}); -2758 */ -2759 KJUR.asn1.x509.X500Name = function(params) { -2760 KJUR.asn1.x509.X500Name.superclass.constructor.call(this); -2761 this.asn1Array = []; -2762 this.paramArray = []; -2763 this.sRule = "utf8"; -2764 var _KJUR = KJUR, -2765 _KJUR_asn1 = _KJUR.asn1, -2766 _KJUR_asn1_x509 = _KJUR_asn1.x509, -2767 _RDN = _KJUR_asn1_x509.RDN, -2768 _pemtohex = pemtohex; -2769 -2770 /** -2771 * set DN by OpenSSL oneline distinguished name string<br/> -2772 * @name setByString -2773 * @memberOf KJUR.asn1.x509.X500Name# -2774 * @function -2775 * @param {String} dnStr distinguished name by string (ex. /C=US/O=aaa) -2776 * @description -2777 * Sets distinguished name by string. -2778 * dnStr must be formatted as -2779 * "/type0=value0/type1=value1/type2=value2...". -2780 * No need to escape a slash in an attribute value. -2781 * @example -2782 * name = new KJUR.asn1.x509.X500Name(); -2783 * name.setByString("/C=US/O=aaa/OU=bbb/CN=foo@example.com"); -2784 * // no need to escape slash in an attribute value -2785 * name.setByString("/C=US/O=aaa/CN=1980/12/31"); -2786 */ -2787 this.setByString = function(dnStr, sRule) { -2788 if (sRule !== undefined) this.sRule = sRule; -2789 var a = dnStr.split('/'); -2790 a.shift(); -2791 -2792 var a1 = []; -2793 for (var i = 0; i < a.length; i++) { -2794 if (a[i].match(/^[^=]+=.+$/)) { -2795 a1.push(a[i]); -2796 } else { -2797 var lastidx = a1.length - 1; -2798 a1[lastidx] = a1[lastidx] + "/" + a[i]; -2799 } -2800 } -2801 -2802 for (var i = 0; i < a1.length; i++) { -2803 this.asn1Array.push(new _RDN({'str':a1[i], rule:this.sRule})); -2804 } -2805 }; -2806 -2807 /** -2808 * set DN by LDAP(RFC 2253) distinguished name string<br/> -2809 * @name setByLdapString -2810 * @memberOf KJUR.asn1.x509.X500Name# -2811 * @function -2812 * @param {String} dnStr distinguished name by LDAP string (ex. O=aaa,C=US) -2813 * @since jsrsasign 6.2.2 asn1x509 1.0.18 -2814 * @see {@link KJUR.asn1.x509.X500Name.ldapToCompat} -2815 * @description -2816 * @example -2817 * name = new KJUR.asn1.x509.X500Name(); -2818 * name.setByLdapString("CN=foo@example.com,OU=bbb,O=aaa,C=US"); -2819 */ -2820 this.setByLdapString = function(dnStr, sRule) { -2821 if (sRule !== undefined) this.sRule = sRule; -2822 var compat = _KJUR_asn1_x509.X500Name.ldapToCompat(dnStr); -2823 this.setByString(compat, sRule); -2824 }; -2825 -2826 /** -2827 * set DN by associative array<br/> -2828 * @name setByObject -2829 * @memberOf KJUR.asn1.x509.X500Name# -2830 * @function -2831 * @param {Array} dnObj associative array of DN (ex. {C: "US", O: "aaa"}) -2832 * @since jsrsasign 4.9. asn1x509 1.0.13 -2833 * @description -2834 * @example -2835 * name = new KJUR.asn1.x509.X500Name(); -2836 * name.setByObject({C: "US", O: "aaa", CN="http://example.com/"1}); -2837 */ -2838 this.setByObject = function(dnObj, sRule) { -2839 if (sRule !== undefined) this.sRule = sRule; -2840 -2841 // Get all the dnObject attributes and stuff them in the ASN.1 array. -2842 for (var x in dnObj) { -2843 if (dnObj.hasOwnProperty(x)) { -2844 var newRDN = new _RDN({str: x + '=' + dnObj[x], rule: this.sRule}); -2845 // Initialize or push into the ANS1 array. -2846 this.asn1Array ? this.asn1Array.push(newRDN) -2847 : this.asn1Array = [newRDN]; -2848 } -2849 } -2850 }; -2851 -2852 this.setByParam = function(params) { -2853 if (params.rule !== undefined) this.sRule = params.rule; -2854 -2855 if (params.array !== undefined) { -2856 this.paramArray = params.array; -2857 } else { -2858 if (params.str !== undefined) { -2859 this.setByString(params.str); -2860 } else if (params.ldapstr !== undefined) { -2861 this.setByLdapString(params.ldapstr); -2862 } else if (params.hex !== undefined) { -2863 this.hTLV = params.hex; -2864 } else if (params.certissuer !== undefined) { -2865 var x = new X509(); -2866 x.readCertPEM(params.certissuer); -2867 this.hTLV = x.getIssuerHex(); -2868 } else if (params.certsubject !== undefined) { -2869 var x = new X509(); -2870 x.readCertPEM(params.certsubject); -2871 this.hTLV = x.getSubjectHex(); -2872 // If params is an object, then set the ASN1 array -2873 // just using the object attributes. -2874 // This is nice for fields that have lots of special -2875 // characters (i.e. CN: 'https://www.github.com/kjur//'). -2876 } else if (typeof params === "object" && -2877 params.certsubject === undefined && -2878 params.certissuer === undefined) { -2879 this.setByObject(params); -2880 } -2881 } -2882 } -2883 -2884 this.getEncodedHex = function() { -2885 if (typeof this.hTLV == "string") return this.hTLV; -2886 -2887 if (this.asn1Array.length == 0 && this.paramArray.length > 0) { -2888 for (var i = 0; i < this.paramArray.length; i++) { -2889 var param = {array: this.paramArray[i]}; -2890 if (this.sRule != "utf8") param.rule = this.sRule; -2891 var asn1RDN = new _RDN(param); -2892 this.asn1Array.push(asn1RDN); -2893 } -2894 } -2895 -2896 var o = new _KJUR_asn1.DERSequence({"array": this.asn1Array}); -2897 this.hTLV = o.getEncodedHex(); -2898 return this.hTLV; -2899 }; -2900 -2901 if (params !== undefined) this.setByParam(params); -2902 }; -2903 YAHOO.lang.extend(KJUR.asn1.x509.X500Name, KJUR.asn1.ASN1Object); -2904 -2905 /** -2906 * convert OpenSSL compat distinguished name format string to LDAP(RFC 2253) format<br/> -2907 * @name compatToLDAP -2908 * @memberOf KJUR.asn1.x509.X500Name -2909 * @function -2910 * @param {String} s distinguished name string in OpenSSL oneline compat (ex. /C=US/O=test) -2911 * @return {String} distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) -2912 * @since jsrsasign 8.0.19 asn1x509 1.1.20 -2913 * @description -2914 * This static method converts a distinguished name string in OpenSSL compat -2915 * format to LDAP(RFC 2253) format. -2916 * @see <a href="https://github.com/kjur/jsrsasign/wiki/NOTE-distinguished-name-representation-in-jsrsasign">jsrsasign wiki: distinguished name string difference between OpenSSL compat and LDAP(RFC 2253)</a> -2917 * @see <a href="https://www.openssl.org/docs/man1.0.2/man1/openssl-x509.html#NAME-OPTIONS">OpenSSL x509 command manual - NAME OPTIONS</a> -2918 * @example -2919 * KJUR.asn1.x509.X500Name.compatToLDAP("/C=US/O=test") → 'O=test,C=US' -2920 * KJUR.asn1.x509.X500Name.compatToLDAP("/C=US/O=a,a") → 'O=a\,a,C=US' -2921 */ -2922 KJUR.asn1.x509.X500Name.compatToLDAP = function(s) { -2923 if (s.substr(0, 1) !== "/") throw "malformed input"; -2924 -2925 var result = ""; -2926 s = s.substr(1); -2927 -2928 var a = s.split("/"); -2929 a.reverse(); -2930 a = a.map(function(s) {return s.replace(/,/, "\\,")}); -2931 -2932 return a.join(","); -2933 }; -2934 -2935 /** -2936 * convert OpenSSL compat distinguished name format string to LDAP(RFC 2253) format (DEPRECATED)<br/> -2937 * @name onelineToLDAP -2938 * @memberOf KJUR.asn1.x509.X500Name -2939 * @function -2940 * @param {String} s distinguished name string in OpenSSL compat format (ex. /C=US/O=test) -2941 * @return {String} distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) -2942 * @since jsrsasign 6.2.2 asn1x509 1.0.18 -2943 * @see KJUR.asn1.x509.X500Name.compatToLDAP -2944 * @description -2945 * This method is deprecated. Please use -2946 * {@link KJUR.asn1.x509.X500Name.compatToLDAP} instead. -2947 */ -2948 KJUR.asn1.x509.X500Name.onelineToLDAP = function(s) { -2949 return KJUR.asn1.x509.X500Name.compatToLDAP(s); -2950 } -2951 -2952 /** -2953 * convert LDAP(RFC 2253) distinguished name format string to OpenSSL compat format<br/> -2954 * @name ldapToCompat -2955 * @memberOf KJUR.asn1.x509.X500Name -2956 * @function -2957 * @param {String} s distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) -2958 * @return {String} distinguished name string in OpenSSL compat format (ex. /C=US/O=test) -2959 * @since jsrsasign 8.0.19 asn1x509 1.1.10 -2960 * @description -2961 * This static method converts a distinguished name string in -2962 * LDAP(RFC 2253) format to OpenSSL compat format. -2963 * @see <a href="https://github.com/kjur/jsrsasign/wiki/NOTE-distinguished-name-representation-in-jsrsasign">jsrsasign wiki: distinguished name string difference between OpenSSL compat and LDAP(RFC 2253)</a> -2964 * @example -2965 * KJUR.asn1.x509.X500Name.ldapToCompat('O=test,C=US') → '/C=US/O=test' -2966 * KJUR.asn1.x509.X500Name.ldapToCompat('O=a\,a,C=US') → '/C=US/O=a,a' -2967 * KJUR.asn1.x509.X500Name.ldapToCompat('O=a/a,C=US') → '/C=US/O=a\/a' -2968 */ -2969 KJUR.asn1.x509.X500Name.ldapToCompat = function(s) { -2970 var a = s.split(","); -2971 -2972 // join \, -2973 var isBSbefore = false; -2974 var a2 = []; -2975 for (var i = 0; a.length > 0; i++) { -2976 var item = a.shift(); -2977 //console.log("item=" + item); -2978 -2979 if (isBSbefore === true) { -2980 var a2last = a2.pop(); -2981 var newitem = (a2last + "," + item).replace(/\\,/g, ","); -2982 a2.push(newitem); -2983 isBSbefore = false; -2984 } else { -2985 a2.push(item); -2986 } -2987 -2988 if (item.substr(-1, 1) === "\\") isBSbefore = true; -2989 } -2990 -2991 a2 = a2.map(function(s) {return s.replace("/", "\\/")}); -2992 a2.reverse(); -2993 return "/" + a2.join("/"); -2994 }; -2995 -2996 /** -2997 * convert LDAP(RFC 2253) distinguished name format string to OpenSSL compat format (DEPRECATED)<br/> -2998 * @name ldapToOneline -2999 * @memberOf KJUR.asn1.x509.X500Name -3000 * @function -3001 * @param {String} s distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) -3002 * @return {String} distinguished name string in OpenSSL compat format (ex. /C=US/O=test) -3003 * @since jsrsasign 6.2.2 asn1x509 1.0.18 -3004 * @description -3005 * This method is deprecated. Please use -3006 * {@link KJUR.asn1.x509.X500Name.ldapToCompat} instead. -3007 */ -3008 KJUR.asn1.x509.X500Name.ldapToOneline = function(s) { -3009 return KJUR.asn1.x509.X500Name.ldapToCompat(s); -3010 }; -3011 -3012 /** -3013 * RDN (Relative Distinguished Name) ASN.1 structure class -3014 * @name KJUR.asn1.x509.RDN -3015 * @class RDN (Relative Distinguished Name) ASN.1 structure class -3016 * @param {Array} params associative array of parameters (ex. {'str': 'C=US'}) -3017 * @extends KJUR.asn1.ASN1Object -3018 * @see KJUR.asn1.x509.X500Name -3019 * @see KJUR.asn1.x509.RDN -3020 * @see KJUR.asn1.x509.AttributeTypeAndValue -3021 * @description -3022 * This class provides RelativeDistinguishedName ASN.1 class structure -3023 * defined in <a href="https://tools.ietf.org/html/rfc2253#section-2">RFC 2253 section 2</a>. -3024 * <blockquote><pre> -3025 * RelativeDistinguishedName ::= SET SIZE (1..MAX) OF -3026 * AttributeTypeAndValue -3027 * -3028 * AttributeTypeAndValue ::= SEQUENCE { -3029 * type AttributeType, -3030 * value AttributeValue } -3031 * </pre></blockquote> -3032 * <br/> -3033 * NOTE1: The "array" and "rule" parameters have been supported -3034 * since jsrsasign 9.0.0 asn1x509 2.0.0. -3035 * <br/> -3036 * NOTE2: Multi-valued RDN in "str" parameter have been -3037 * supported since jsrsasign 6.2.1 asn1x509 1.0.17. -3038 * @example -3039 * new KJUR.asn1.x509.RDN({array: [ // multi-valued -3040 * {type:"CN",value:"Bob",ds:"prn"}, -3041 * {type:"CN",value:"bob@example.com", ds:"ia5"} -3042 * ]}); -3043 * new KJUR.asn1.x509.RDN({str: "CN=test"}); -3044 * new KJUR.asn1.x509.RDN({str: "O=a+O=bb+O=c"}); // multi-valued -3045 * new KJUR.asn1.x509.RDN({str: "O=a+O=b\\+b+O=c"}); // plus escaped -3046 * new KJUR.asn1.x509.RDN({str: "O=a+O=\"b+b\"+O=c"}); // double quoted -3047 */ -3048 KJUR.asn1.x509.RDN = function(params) { -3049 KJUR.asn1.x509.RDN.superclass.constructor.call(this); -3050 this.asn1Array = []; -3051 this.paramArray = []; -3052 this.sRule = "utf8"; // DEFAULT "utf8" -3053 var _AttributeTypeAndValue = KJUR.asn1.x509.AttributeTypeAndValue; -3054 -3055 this.setByParam = function(params) { -3056 if (params.rule !== undefined) this.sRule = params.rule; -3057 if (params.str !== undefined) { -3058 this.addByMultiValuedString(params.str); -3059 } -3060 if (params.array !== undefined) this.paramArray = params.array; -3061 }; -3062 -3063 /** -3064 * add one AttributeTypeAndValue by string<br/> -3065 * @name addByString -3066 * @memberOf KJUR.asn1.x509.RDN# -3067 * @function -3068 * @param {String} s string of AttributeTypeAndValue -3069 * @return {Object} unspecified -3070 * @description -3071 * This method add one AttributeTypeAndValue to RDN object. -3072 * @example -3073 * rdn = new KJUR.asn1.x509.RDN(); -3074 * rdn.addByString("CN=john"); -3075 * rdn.addByString("serialNumber=1234"); // for multi-valued RDN -3076 */ -3077 this.addByString = function(s) { -3078 this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({'str': s, rule: this.sRule})); -3079 }; -3080 -3081 /** -3082 * add one AttributeTypeAndValue by multi-valued string<br/> -3083 * @name addByMultiValuedString -3084 * @memberOf KJUR.asn1.x509.RDN# -3085 * @function -3086 * @param {String} s string of multi-valued RDN -3087 * @return {Object} unspecified -3088 * @since jsrsasign 6.2.1 asn1x509 1.0.17 -3089 * @description -3090 * This method add multi-valued RDN to RDN object. -3091 * @example -3092 * rdn = new KJUR.asn1.x509.RDN(); -3093 * rdn.addByMultiValuedString("CN=john+O=test"); -3094 * rdn.addByMultiValuedString("O=a+O=b\+b\+b+O=c"); // multi-valued RDN with quoted plus -3095 * rdn.addByMultiValuedString("O=a+O=\"b+b+b\"+O=c"); // multi-valued RDN with quoted quotation -3096 */ -3097 this.addByMultiValuedString = function(s) { -3098 var a = KJUR.asn1.x509.RDN.parseString(s); -3099 for (var i = 0; i < a.length; i++) { -3100 this.addByString(a[i]); -3101 } -3102 }; -3103 -3104 this.getEncodedHex = function() { -3105 if (this.asn1Array.length == 0 && this.paramArray.length > 0) { -3106 for (var i = 0; i < this.paramArray.length; i++) { -3107 var param = this.paramArray[i]; -3108 if (param.rule !== undefined && -3109 this.sRule != "utf8") { -3110 param.rule = this.sRule; -3111 } -3112 //alert(JSON.stringify(param)); -3113 var asn1ATV = new _AttributeTypeAndValue(param); -3114 this.asn1Array.push(asn1ATV); -3115 } -3116 } -3117 var o = new KJUR.asn1.DERSet({"array": this.asn1Array}); -3118 this.TLV = o.getEncodedHex(); -3119 return this.TLV; -3120 }; -3121 -3122 if (params !== undefined) { -3123 this.setByParam(params); -3124 } -3125 }; -3126 YAHOO.lang.extend(KJUR.asn1.x509.RDN, KJUR.asn1.ASN1Object); -3127 -3128 /** -3129 * parse multi-valued RDN string and split into array of 'AttributeTypeAndValue'<br/> -3130 * @name parseString -3131 * @memberOf KJUR.asn1.x509.RDN -3132 * @function -3133 * @param {String} s multi-valued string of RDN -3134 * @return {Array} array of string of AttributeTypeAndValue -3135 * @since jsrsasign 6.2.1 asn1x509 1.0.17 -3136 * @description -3137 * This static method parses multi-valued RDN string and split into -3138 * array of AttributeTypeAndValue. -3139 * @example -3140 * KJUR.asn1.x509.RDN.parseString("CN=john") → ["CN=john"] -3141 * KJUR.asn1.x509.RDN.parseString("CN=john+OU=test") → ["CN=john", "OU=test"] -3142 * KJUR.asn1.x509.RDN.parseString('CN="jo+hn"+OU=test') → ["CN=jo+hn", "OU=test"] -3143 * KJUR.asn1.x509.RDN.parseString('CN=jo\+hn+OU=test') → ["CN=jo+hn", "OU=test"] -3144 * KJUR.asn1.x509.RDN.parseString("CN=john+OU=test+OU=t1") → ["CN=john", "OU=test", "OU=t1"] -3145 */ -3146 KJUR.asn1.x509.RDN.parseString = function(s) { -3147 var a = s.split(/\+/); -3148 -3149 // join \+ -3150 var isBSbefore = false; -3151 var a2 = []; -3152 for (var i = 0; a.length > 0; i++) { -3153 var item = a.shift(); -3154 //console.log("item=" + item); -3155 -3156 if (isBSbefore === true) { -3157 var a2last = a2.pop(); -3158 var newitem = (a2last + "+" + item).replace(/\\\+/g, "+"); -3159 a2.push(newitem); -3160 isBSbefore = false; -3161 } else { -3162 a2.push(item); -3163 } -3164 -3165 if (item.substr(-1, 1) === "\\") isBSbefore = true; -3166 } -3167 -3168 // join quote -3169 var beginQuote = false; -3170 var a3 = []; -3171 for (var i = 0; a2.length > 0; i++) { -3172 var item = a2.shift(); -3173 -3174 if (beginQuote === true) { -3175 var a3last = a3.pop(); -3176 if (item.match(/"$/)) { -3177 var newitem = (a3last + "+" + item).replace(/^([^=]+)="(.*)"$/, "$1=$2"); -3178 a3.push(newitem); -3179 beginQuote = false; -3180 } else { -3181 a3.push(a3last + "+" + item); -3182 } -3183 } else { -3184 a3.push(item); -3185 } -3186 -3187 if (item.match(/^[^=]+="/)) { -3188 //console.log(i + "=" + item); -3189 beginQuote = true; -3190 } -3191 } -3192 return a3; -3193 }; -3194 -3195 /** -3196 * AttributeTypeAndValue ASN.1 structure class -3197 * @name KJUR.asn1.x509.AttributeTypeAndValue -3198 * @class AttributeTypeAndValue ASN.1 structure class -3199 * @param {Array} params JSON object for parameters (ex. {str: 'C=US'}) -3200 * @extends KJUR.asn1.ASN1Object -3201 * @see KJUR.asn1.x509.X500Name -3202 * @see KJUR.asn1.x509.RDN -3203 * @see KJUR.asn1.x509.AttributeTypeAndValue -3204 * @see X509#getAttrTypeAndValue -3205 * @description -3206 * This class generates AttributeTypeAndValue defined in -3207 * <a href="https://tools.ietf.org/html/rfc5280#section-4.1.2.4"> -3208 * RFC 5280 4.1.2.4</a>. -3209 * <pre> -3210 * AttributeTypeAndValue ::= SEQUENCE { -3211 * type AttributeType, -3212 * value AttributeValue } -3213 * AttributeType ::= OBJECT IDENTIFIER -3214 * AttributeValue ::= ANY -- DEFINED BY AttributeType -3215 * </pre> -3216 * The constructor argument can have following parameters: -3217 * <ul> -3218 * <li>{String}type - AttributeType name or OID(ex. C,O,CN)</li> -3219 * <li>{String}value - raw string of ASN.1 value of AttributeValue</li> -3220 * <li>{String}ds - DirectoryString type of AttributeValue</li> -3221 * <li>{String}rule - DirectoryString type rule (ex. "prn" or "utf8") -3222 * set DirectoryString type automatically when "ds" not specified.</li> -3223 * <li>{String}str - AttributeTypeAndVale string (ex. "C=US"). -3224 * When type and value don't exists, -3225 * this "str" will be converted to "type" and "value". -3226 * </li> -3227 * </ul> -3228 * <br -3229 * NOTE: Parameters "type", "value,", "ds" and "rule" have -3230 * been supported since jsrsasign 9.0.0 asn1x509 2.0.0. -3231 * @example -3232 * new KJUR.asn1.x509.AttributeTypeAndValue({type:'C',value:'US',ds:'prn'}) -3233 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1'}) -3234 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1',rule='prn'}) -3235 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1',rule='utf8'}) -3236 */ -3237 KJUR.asn1.x509.AttributeTypeAndValue = function(params) { -3238 KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this); -3239 this.sRule = "utf8"; -3240 this.sType = null; -3241 this.sValue = null; -3242 this.dsType = null; -3243 var _KJUR = KJUR, -3244 _KJUR_asn1 = _KJUR.asn1, -3245 _DERSequence = _KJUR_asn1.DERSequence, -3246 _DERUTF8String = _KJUR_asn1.DERUTF8String, -3247 _DERPrintableString = _KJUR_asn1.DERPrintableString, -3248 _DERTeletexString = _KJUR_asn1.DERTeletexString, -3249 _DERIA5String = _KJUR_asn1.DERIA5String, -3250 _DERVisibleString = _KJUR_asn1.DERVisibleString, -3251 _DERBMPString = _KJUR_asn1.DERBMPString, -3252 _isMail = _KJUR.lang.String.isMail, -3253 _isPrintable = _KJUR.lang.String.isPrintable; -3254 -3255 this.setByParam = function(params) { -3256 if (params.rule !== undefined) this.sRule = params.rule; -3257 if (params.ds !== undefined) this.dsType = params.ds; -3258 -3259 if (params.value === undefined && -3260 params.str !== undefined) { -3261 var str = params.str; -3262 var matchResult = str.match(/^([^=]+)=(.+)$/); -3263 if (matchResult) { -3264 this.sType = matchResult[1]; -3265 this.sValue = matchResult[2]; -3266 } else { -3267 throw new Error("malformed attrTypeAndValueStr: " + -3268 attrTypeAndValueStr); -3269 } -3270 -3271 //this.setByString(params.str); -3272 } else { -3273 this.sType = params.type; -3274 this.sValue = params.value; -3275 } -3276 }; -3277 -3278 /* -3279 * @deprecated -3280 */ -3281 this.setByString = function(sTypeValue, sRule) { -3282 if (sRule !== undefined) this.sRule = sRule; -3283 var matchResult = sTypeValue.match(/^([^=]+)=(.+)$/); -3284 if (matchResult) { -3285 this.setByAttrTypeAndValueStr(matchResult[1], matchResult[2]); -3286 } else { -3287 throw new Error("malformed attrTypeAndValueStr: " + -3288 attrTypeAndValueStr); -3289 } -3290 }; -3291 -3292 this._getDsType = function() { -3293 var sType = this.sType; -3294 var sValue = this.sValue; -3295 var sRule = this.sRule; +2747 * new KJUR.asn1.x509.X500Name({str: "/C=US/ST=NY/L=Ballston Spa/STREET=915 Stillwater Ave"}); +2748 * new KJUR.asn1.x509.X500Name({str: "/CN=AAA/2.5.4.42=John/surname=Ray"}); +2749 * new KJUR.asn1.x509.X500Name({str: "/C=US/O=aaa+CN=contact@example.com"}); // multi valued +2750 * // 3. construct by LDAP string +2751 * new KJUR.asn1.x509.X500Name({ldapstr: "CN=foo@example.com,OU=bbb,C=US"}); +2752 * // 4. construct by ASN.1 hex string +2753 * new KJUR.asn1.x509.X500Name({hex: "304c3120..."}); +2754 * // 5. construct by issuer of PEM certificate +2755 * new KJUR.asn1.x509.X500Name({certsubject: "-----BEGIN CERT..."}); +2756 * // 6. construct by subject of PEM certificate +2757 * new KJUR.asn1.x509.X500Name({certissuer: "-----BEGIN CERT..."}); +2758 * // 7. construct by object (DEPRECATED) +2759 * new KJUR.asn1.x509.X500Name({C:"US",O:"aaa",CN:"http://example.com/"}); +2760 */ +2761 KJUR.asn1.x509.X500Name = function(params) { +2762 KJUR.asn1.x509.X500Name.superclass.constructor.call(this); +2763 this.asn1Array = []; +2764 this.paramArray = []; +2765 this.sRule = "utf8"; +2766 var _KJUR = KJUR, +2767 _KJUR_asn1 = _KJUR.asn1, +2768 _KJUR_asn1_x509 = _KJUR_asn1.x509, +2769 _RDN = _KJUR_asn1_x509.RDN, +2770 _pemtohex = pemtohex; +2771 +2772 /** +2773 * set DN by OpenSSL oneline distinguished name string<br/> +2774 * @name setByString +2775 * @memberOf KJUR.asn1.x509.X500Name# +2776 * @function +2777 * @param {String} dnStr distinguished name by string (ex. /C=US/O=aaa) +2778 * @description +2779 * Sets distinguished name by string. +2780 * dnStr must be formatted as +2781 * "/type0=value0/type1=value1/type2=value2...". +2782 * No need to escape a slash in an attribute value. +2783 * @example +2784 * name = new KJUR.asn1.x509.X500Name(); +2785 * name.setByString("/C=US/O=aaa/OU=bbb/CN=foo@example.com"); +2786 * // no need to escape slash in an attribute value +2787 * name.setByString("/C=US/O=aaa/CN=1980/12/31"); +2788 */ +2789 this.setByString = function(dnStr, sRule) { +2790 if (sRule !== undefined) this.sRule = sRule; +2791 var a = dnStr.split('/'); +2792 a.shift(); +2793 +2794 var a1 = []; +2795 for (var i = 0; i < a.length; i++) { +2796 if (a[i].match(/^[^=]+=.+$/)) { +2797 a1.push(a[i]); +2798 } else { +2799 var lastidx = a1.length - 1; +2800 a1[lastidx] = a1[lastidx] + "/" + a[i]; +2801 } +2802 } +2803 +2804 for (var i = 0; i < a1.length; i++) { +2805 this.asn1Array.push(new _RDN({'str':a1[i], rule:this.sRule})); +2806 } +2807 }; +2808 +2809 /** +2810 * set DN by LDAP(RFC 2253) distinguished name string<br/> +2811 * @name setByLdapString +2812 * @memberOf KJUR.asn1.x509.X500Name# +2813 * @function +2814 * @param {String} dnStr distinguished name by LDAP string (ex. O=aaa,C=US) +2815 * @since jsrsasign 6.2.2 asn1x509 1.0.18 +2816 * @see {@link KJUR.asn1.x509.X500Name.ldapToCompat} +2817 * @description +2818 * @example +2819 * name = new KJUR.asn1.x509.X500Name(); +2820 * name.setByLdapString("CN=foo@example.com,OU=bbb,O=aaa,C=US"); +2821 */ +2822 this.setByLdapString = function(dnStr, sRule) { +2823 if (sRule !== undefined) this.sRule = sRule; +2824 var compat = _KJUR_asn1_x509.X500Name.ldapToCompat(dnStr); +2825 this.setByString(compat, sRule); +2826 }; +2827 +2828 /** +2829 * set DN by associative array<br/> +2830 * @name setByObject +2831 * @memberOf KJUR.asn1.x509.X500Name# +2832 * @function +2833 * @param {Array} dnObj associative array of DN (ex. {C: "US", O: "aaa"}) +2834 * @since jsrsasign 4.9. asn1x509 1.0.13 +2835 * @description +2836 * @example +2837 * name = new KJUR.asn1.x509.X500Name(); +2838 * name.setByObject({C: "US", O: "aaa", CN="http://example.com/"1}); +2839 */ +2840 this.setByObject = function(dnObj, sRule) { +2841 if (sRule !== undefined) this.sRule = sRule; +2842 +2843 // Get all the dnObject attributes and stuff them in the ASN.1 array. +2844 for (var x in dnObj) { +2845 if (dnObj.hasOwnProperty(x)) { +2846 var newRDN = new _RDN({str: x + '=' + dnObj[x], rule: this.sRule}); +2847 // Initialize or push into the ANS1 array. +2848 this.asn1Array ? this.asn1Array.push(newRDN) +2849 : this.asn1Array = [newRDN]; +2850 } +2851 } +2852 }; +2853 +2854 this.setByParam = function(params) { +2855 if (params.rule !== undefined) this.sRule = params.rule; +2856 +2857 if (params.array !== undefined) { +2858 this.paramArray = params.array; +2859 } else { +2860 if (params.str !== undefined) { +2861 this.setByString(params.str); +2862 } else if (params.ldapstr !== undefined) { +2863 this.setByLdapString(params.ldapstr); +2864 } else if (params.hex !== undefined) { +2865 this.hTLV = params.hex; +2866 } else if (params.certissuer !== undefined) { +2867 var x = new X509(); +2868 x.readCertPEM(params.certissuer); +2869 this.hTLV = x.getIssuerHex(); +2870 } else if (params.certsubject !== undefined) { +2871 var x = new X509(); +2872 x.readCertPEM(params.certsubject); +2873 this.hTLV = x.getSubjectHex(); +2874 // If params is an object, then set the ASN1 array +2875 // just using the object attributes. +2876 // This is nice for fields that have lots of special +2877 // characters (i.e. CN: 'https://www.github.com/kjur//'). +2878 } else if (typeof params === "object" && +2879 params.certsubject === undefined && +2880 params.certissuer === undefined) { +2881 this.setByObject(params); +2882 } +2883 } +2884 } +2885 +2886 this.getEncodedHex = function() { +2887 if (typeof this.hTLV == "string") return this.hTLV; +2888 +2889 if (this.asn1Array.length == 0 && this.paramArray.length > 0) { +2890 for (var i = 0; i < this.paramArray.length; i++) { +2891 var param = {array: this.paramArray[i]}; +2892 if (this.sRule != "utf8") param.rule = this.sRule; +2893 var asn1RDN = new _RDN(param); +2894 this.asn1Array.push(asn1RDN); +2895 } +2896 } +2897 +2898 var o = new _KJUR_asn1.DERSequence({"array": this.asn1Array}); +2899 this.hTLV = o.getEncodedHex(); +2900 return this.hTLV; +2901 }; +2902 +2903 if (params !== undefined) this.setByParam(params); +2904 }; +2905 YAHOO.lang.extend(KJUR.asn1.x509.X500Name, KJUR.asn1.ASN1Object); +2906 +2907 /** +2908 * convert OpenSSL compat distinguished name format string to LDAP(RFC 2253) format<br/> +2909 * @name compatToLDAP +2910 * @memberOf KJUR.asn1.x509.X500Name +2911 * @function +2912 * @param {String} s distinguished name string in OpenSSL oneline compat (ex. /C=US/O=test) +2913 * @return {String} distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) +2914 * @since jsrsasign 8.0.19 asn1x509 1.1.20 +2915 * @description +2916 * This static method converts a distinguished name string in OpenSSL compat +2917 * format to LDAP(RFC 2253) format. +2918 * @see <a href="https://github.com/kjur/jsrsasign/wiki/NOTE-distinguished-name-representation-in-jsrsasign">jsrsasign wiki: distinguished name string difference between OpenSSL compat and LDAP(RFC 2253)</a> +2919 * @see <a href="https://www.openssl.org/docs/man1.0.2/man1/openssl-x509.html#NAME-OPTIONS">OpenSSL x509 command manual - NAME OPTIONS</a> +2920 * @example +2921 * KJUR.asn1.x509.X500Name.compatToLDAP("/C=US/O=test") → 'O=test,C=US' +2922 * KJUR.asn1.x509.X500Name.compatToLDAP("/C=US/O=a,a") → 'O=a\,a,C=US' +2923 */ +2924 KJUR.asn1.x509.X500Name.compatToLDAP = function(s) { +2925 if (s.substr(0, 1) !== "/") throw "malformed input"; +2926 +2927 var result = ""; +2928 s = s.substr(1); +2929 +2930 var a = s.split("/"); +2931 a.reverse(); +2932 a = a.map(function(s) {return s.replace(/,/, "\\,")}); +2933 +2934 return a.join(","); +2935 }; +2936 +2937 /** +2938 * convert OpenSSL compat distinguished name format string to LDAP(RFC 2253) format (DEPRECATED)<br/> +2939 * @name onelineToLDAP +2940 * @memberOf KJUR.asn1.x509.X500Name +2941 * @function +2942 * @param {String} s distinguished name string in OpenSSL compat format (ex. /C=US/O=test) +2943 * @return {String} distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) +2944 * @since jsrsasign 6.2.2 asn1x509 1.0.18 +2945 * @see KJUR.asn1.x509.X500Name.compatToLDAP +2946 * @description +2947 * This method is deprecated. Please use +2948 * {@link KJUR.asn1.x509.X500Name.compatToLDAP} instead. +2949 */ +2950 KJUR.asn1.x509.X500Name.onelineToLDAP = function(s) { +2951 return KJUR.asn1.x509.X500Name.compatToLDAP(s); +2952 } +2953 +2954 /** +2955 * convert LDAP(RFC 2253) distinguished name format string to OpenSSL compat format<br/> +2956 * @name ldapToCompat +2957 * @memberOf KJUR.asn1.x509.X500Name +2958 * @function +2959 * @param {String} s distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) +2960 * @return {String} distinguished name string in OpenSSL compat format (ex. /C=US/O=test) +2961 * @since jsrsasign 8.0.19 asn1x509 1.1.10 +2962 * @description +2963 * This static method converts a distinguished name string in +2964 * LDAP(RFC 2253) format to OpenSSL compat format. +2965 * @see <a href="https://github.com/kjur/jsrsasign/wiki/NOTE-distinguished-name-representation-in-jsrsasign">jsrsasign wiki: distinguished name string difference between OpenSSL compat and LDAP(RFC 2253)</a> +2966 * @example +2967 * KJUR.asn1.x509.X500Name.ldapToCompat('O=test,C=US') → '/C=US/O=test' +2968 * KJUR.asn1.x509.X500Name.ldapToCompat('O=a\,a,C=US') → '/C=US/O=a,a' +2969 * KJUR.asn1.x509.X500Name.ldapToCompat('O=a/a,C=US') → '/C=US/O=a\/a' +2970 */ +2971 KJUR.asn1.x509.X500Name.ldapToCompat = function(s) { +2972 var a = s.split(","); +2973 +2974 // join \, +2975 var isBSbefore = false; +2976 var a2 = []; +2977 for (var i = 0; a.length > 0; i++) { +2978 var item = a.shift(); +2979 //console.log("item=" + item); +2980 +2981 if (isBSbefore === true) { +2982 var a2last = a2.pop(); +2983 var newitem = (a2last + "," + item).replace(/\\,/g, ","); +2984 a2.push(newitem); +2985 isBSbefore = false; +2986 } else { +2987 a2.push(item); +2988 } +2989 +2990 if (item.substr(-1, 1) === "\\") isBSbefore = true; +2991 } +2992 +2993 a2 = a2.map(function(s) {return s.replace("/", "\\/")}); +2994 a2.reverse(); +2995 return "/" + a2.join("/"); +2996 }; +2997 +2998 /** +2999 * convert LDAP(RFC 2253) distinguished name format string to OpenSSL compat format (DEPRECATED)<br/> +3000 * @name ldapToOneline +3001 * @memberOf KJUR.asn1.x509.X500Name +3002 * @function +3003 * @param {String} s distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) +3004 * @return {String} distinguished name string in OpenSSL compat format (ex. /C=US/O=test) +3005 * @since jsrsasign 6.2.2 asn1x509 1.0.18 +3006 * @description +3007 * This method is deprecated. Please use +3008 * {@link KJUR.asn1.x509.X500Name.ldapToCompat} instead. +3009 */ +3010 KJUR.asn1.x509.X500Name.ldapToOneline = function(s) { +3011 return KJUR.asn1.x509.X500Name.ldapToCompat(s); +3012 }; +3013 +3014 /** +3015 * RDN (Relative Distinguished Name) ASN.1 structure class +3016 * @name KJUR.asn1.x509.RDN +3017 * @class RDN (Relative Distinguished Name) ASN.1 structure class +3018 * @param {Array} params associative array of parameters (ex. {'str': 'C=US'}) +3019 * @extends KJUR.asn1.ASN1Object +3020 * @see KJUR.asn1.x509.X500Name +3021 * @see KJUR.asn1.x509.RDN +3022 * @see KJUR.asn1.x509.AttributeTypeAndValue +3023 * @description +3024 * This class provides RelativeDistinguishedName ASN.1 class structure +3025 * defined in <a href="https://tools.ietf.org/html/rfc2253#section-2">RFC 2253 section 2</a>. +3026 * <blockquote><pre> +3027 * RelativeDistinguishedName ::= SET SIZE (1..MAX) OF +3028 * AttributeTypeAndValue +3029 * +3030 * AttributeTypeAndValue ::= SEQUENCE { +3031 * type AttributeType, +3032 * value AttributeValue } +3033 * </pre></blockquote> +3034 * <br/> +3035 * NOTE1: The "array" and "rule" parameters have been supported +3036 * since jsrsasign 9.0.0 asn1x509 2.0.0. +3037 * <br/> +3038 * NOTE2: Multi-valued RDN in "str" parameter have been +3039 * supported since jsrsasign 6.2.1 asn1x509 1.0.17. +3040 * @example +3041 * new KJUR.asn1.x509.RDN({array: [ // multi-valued +3042 * {type:"CN",value:"Bob",ds:"prn"}, +3043 * {type:"CN",value:"bob@example.com", ds:"ia5"} +3044 * ]}); +3045 * new KJUR.asn1.x509.RDN({str: "CN=test"}); +3046 * new KJUR.asn1.x509.RDN({str: "O=a+O=bb+O=c"}); // multi-valued +3047 * new KJUR.asn1.x509.RDN({str: "O=a+O=b\\+b+O=c"}); // plus escaped +3048 * new KJUR.asn1.x509.RDN({str: "O=a+O=\"b+b\"+O=c"}); // double quoted +3049 */ +3050 KJUR.asn1.x509.RDN = function(params) { +3051 KJUR.asn1.x509.RDN.superclass.constructor.call(this); +3052 this.asn1Array = []; +3053 this.paramArray = []; +3054 this.sRule = "utf8"; // DEFAULT "utf8" +3055 var _AttributeTypeAndValue = KJUR.asn1.x509.AttributeTypeAndValue; +3056 +3057 this.setByParam = function(params) { +3058 if (params.rule !== undefined) this.sRule = params.rule; +3059 if (params.str !== undefined) { +3060 this.addByMultiValuedString(params.str); +3061 } +3062 if (params.array !== undefined) this.paramArray = params.array; +3063 }; +3064 +3065 /** +3066 * add one AttributeTypeAndValue by string<br/> +3067 * @name addByString +3068 * @memberOf KJUR.asn1.x509.RDN# +3069 * @function +3070 * @param {String} s string of AttributeTypeAndValue +3071 * @return {Object} unspecified +3072 * @description +3073 * This method add one AttributeTypeAndValue to RDN object. +3074 * @example +3075 * rdn = new KJUR.asn1.x509.RDN(); +3076 * rdn.addByString("CN=john"); +3077 * rdn.addByString("serialNumber=1234"); // for multi-valued RDN +3078 */ +3079 this.addByString = function(s) { +3080 this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({'str': s, rule: this.sRule})); +3081 }; +3082 +3083 /** +3084 * add one AttributeTypeAndValue by multi-valued string<br/> +3085 * @name addByMultiValuedString +3086 * @memberOf KJUR.asn1.x509.RDN# +3087 * @function +3088 * @param {String} s string of multi-valued RDN +3089 * @return {Object} unspecified +3090 * @since jsrsasign 6.2.1 asn1x509 1.0.17 +3091 * @description +3092 * This method add multi-valued RDN to RDN object. +3093 * @example +3094 * rdn = new KJUR.asn1.x509.RDN(); +3095 * rdn.addByMultiValuedString("CN=john+O=test"); +3096 * rdn.addByMultiValuedString("O=a+O=b\+b\+b+O=c"); // multi-valued RDN with quoted plus +3097 * rdn.addByMultiValuedString("O=a+O=\"b+b+b\"+O=c"); // multi-valued RDN with quoted quotation +3098 */ +3099 this.addByMultiValuedString = function(s) { +3100 var a = KJUR.asn1.x509.RDN.parseString(s); +3101 for (var i = 0; i < a.length; i++) { +3102 this.addByString(a[i]); +3103 } +3104 }; +3105 +3106 this.getEncodedHex = function() { +3107 if (this.asn1Array.length == 0 && this.paramArray.length > 0) { +3108 for (var i = 0; i < this.paramArray.length; i++) { +3109 var param = this.paramArray[i]; +3110 if (param.rule !== undefined && +3111 this.sRule != "utf8") { +3112 param.rule = this.sRule; +3113 } +3114 //alert(JSON.stringify(param)); +3115 var asn1ATV = new _AttributeTypeAndValue(param); +3116 this.asn1Array.push(asn1ATV); +3117 } +3118 } +3119 var o = new KJUR.asn1.DERSet({"array": this.asn1Array}); +3120 this.TLV = o.getEncodedHex(); +3121 return this.TLV; +3122 }; +3123 +3124 if (params !== undefined) { +3125 this.setByParam(params); +3126 } +3127 }; +3128 YAHOO.lang.extend(KJUR.asn1.x509.RDN, KJUR.asn1.ASN1Object); +3129 +3130 /** +3131 * parse multi-valued RDN string and split into array of 'AttributeTypeAndValue'<br/> +3132 * @name parseString +3133 * @memberOf KJUR.asn1.x509.RDN +3134 * @function +3135 * @param {String} s multi-valued string of RDN +3136 * @return {Array} array of string of AttributeTypeAndValue +3137 * @since jsrsasign 6.2.1 asn1x509 1.0.17 +3138 * @description +3139 * This static method parses multi-valued RDN string and split into +3140 * array of AttributeTypeAndValue. +3141 * @example +3142 * KJUR.asn1.x509.RDN.parseString("CN=john") → ["CN=john"] +3143 * KJUR.asn1.x509.RDN.parseString("CN=john+OU=test") → ["CN=john", "OU=test"] +3144 * KJUR.asn1.x509.RDN.parseString('CN="jo+hn"+OU=test') → ["CN=jo+hn", "OU=test"] +3145 * KJUR.asn1.x509.RDN.parseString('CN=jo\+hn+OU=test') → ["CN=jo+hn", "OU=test"] +3146 * KJUR.asn1.x509.RDN.parseString("CN=john+OU=test+OU=t1") → ["CN=john", "OU=test", "OU=t1"] +3147 */ +3148 KJUR.asn1.x509.RDN.parseString = function(s) { +3149 var a = s.split(/\+/); +3150 +3151 // join \+ +3152 var isBSbefore = false; +3153 var a2 = []; +3154 for (var i = 0; a.length > 0; i++) { +3155 var item = a.shift(); +3156 //console.log("item=" + item); +3157 +3158 if (isBSbefore === true) { +3159 var a2last = a2.pop(); +3160 var newitem = (a2last + "+" + item).replace(/\\\+/g, "+"); +3161 a2.push(newitem); +3162 isBSbefore = false; +3163 } else { +3164 a2.push(item); +3165 } +3166 +3167 if (item.substr(-1, 1) === "\\") isBSbefore = true; +3168 } +3169 +3170 // join quote +3171 var beginQuote = false; +3172 var a3 = []; +3173 for (var i = 0; a2.length > 0; i++) { +3174 var item = a2.shift(); +3175 +3176 if (beginQuote === true) { +3177 var a3last = a3.pop(); +3178 if (item.match(/"$/)) { +3179 var newitem = (a3last + "+" + item).replace(/^([^=]+)="(.*)"$/, "$1=$2"); +3180 a3.push(newitem); +3181 beginQuote = false; +3182 } else { +3183 a3.push(a3last + "+" + item); +3184 } +3185 } else { +3186 a3.push(item); +3187 } +3188 +3189 if (item.match(/^[^=]+="/)) { +3190 //console.log(i + "=" + item); +3191 beginQuote = true; +3192 } +3193 } +3194 return a3; +3195 }; +3196 +3197 /** +3198 * AttributeTypeAndValue ASN.1 structure class +3199 * @name KJUR.asn1.x509.AttributeTypeAndValue +3200 * @class AttributeTypeAndValue ASN.1 structure class +3201 * @param {Array} params JSON object for parameters (ex. {str: 'C=US'}) +3202 * @extends KJUR.asn1.ASN1Object +3203 * @see KJUR.asn1.x509.X500Name +3204 * @see KJUR.asn1.x509.RDN +3205 * @see KJUR.asn1.x509.AttributeTypeAndValue +3206 * @see X509#getAttrTypeAndValue +3207 * @description +3208 * This class generates AttributeTypeAndValue defined in +3209 * <a href="https://tools.ietf.org/html/rfc5280#section-4.1.2.4"> +3210 * RFC 5280 4.1.2.4</a>. +3211 * <pre> +3212 * AttributeTypeAndValue ::= SEQUENCE { +3213 * type AttributeType, +3214 * value AttributeValue } +3215 * AttributeType ::= OBJECT IDENTIFIER +3216 * AttributeValue ::= ANY -- DEFINED BY AttributeType +3217 * </pre> +3218 * The constructor argument can have following parameters: +3219 * <ul> +3220 * <li>{String}type - AttributeType name or OID(ex. C,O,CN)</li> +3221 * <li>{String}value - raw string of ASN.1 value of AttributeValue</li> +3222 * <li>{String}ds - DirectoryString type of AttributeValue</li> +3223 * <li>{String}rule - DirectoryString type rule (ex. "prn" or "utf8") +3224 * set DirectoryString type automatically when "ds" not specified.</li> +3225 * <li>{String}str - AttributeTypeAndVale string (ex. "C=US"). +3226 * When type and value don't exists, +3227 * this "str" will be converted to "type" and "value". +3228 * </li> +3229 * </ul> +3230 * <br +3231 * NOTE: Parameters "type", "value,", "ds" and "rule" have +3232 * been supported since jsrsasign 9.0.0 asn1x509 2.0.0. +3233 * @example +3234 * new KJUR.asn1.x509.AttributeTypeAndValue({type:'C',value:'US',ds:'prn'}) +3235 * new KJUR.asn1.x509.AttributeTypeAndValue({type:'givenName',value:'John',ds:'prn'}) +3236 * new KJUR.asn1.x509.AttributeTypeAndValue({type:'2.5.4.9',value:'71 Bowman St',ds:'prn'}) +3237 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1'}) +3238 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'streetAddress=71 Bowman St'}) +3239 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1',rule='prn'}) +3240 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1',rule='utf8'}) +3241 */ +3242 KJUR.asn1.x509.AttributeTypeAndValue = function(params) { +3243 KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this); +3244 this.sRule = "utf8"; +3245 this.sType = null; +3246 this.sValue = null; +3247 this.dsType = null; +3248 var _KJUR = KJUR, +3249 _KJUR_asn1 = _KJUR.asn1, +3250 _DERSequence = _KJUR_asn1.DERSequence, +3251 _DERUTF8String = _KJUR_asn1.DERUTF8String, +3252 _DERPrintableString = _KJUR_asn1.DERPrintableString, +3253 _DERTeletexString = _KJUR_asn1.DERTeletexString, +3254 _DERIA5String = _KJUR_asn1.DERIA5String, +3255 _DERVisibleString = _KJUR_asn1.DERVisibleString, +3256 _DERBMPString = _KJUR_asn1.DERBMPString, +3257 _isMail = _KJUR.lang.String.isMail, +3258 _isPrintable = _KJUR.lang.String.isPrintable; +3259 +3260 this.setByParam = function(params) { +3261 if (params.rule !== undefined) this.sRule = params.rule; +3262 if (params.ds !== undefined) this.dsType = params.ds; +3263 +3264 if (params.value === undefined && +3265 params.str !== undefined) { +3266 var str = params.str; +3267 var matchResult = str.match(/^([^=]+)=(.+)$/); +3268 if (matchResult) { +3269 this.sType = matchResult[1]; +3270 this.sValue = matchResult[2]; +3271 } else { +3272 throw new Error("malformed attrTypeAndValueStr: " + +3273 attrTypeAndValueStr); +3274 } +3275 +3276 //this.setByString(params.str); +3277 } else { +3278 this.sType = params.type; +3279 this.sValue = params.value; +3280 } +3281 }; +3282 +3283 /* +3284 * @deprecated +3285 */ +3286 this.setByString = function(sTypeValue, sRule) { +3287 if (sRule !== undefined) this.sRule = sRule; +3288 var matchResult = sTypeValue.match(/^([^=]+)=(.+)$/); +3289 if (matchResult) { +3290 this.setByAttrTypeAndValueStr(matchResult[1], matchResult[2]); +3291 } else { +3292 throw new Error("malformed attrTypeAndValueStr: " + +3293 attrTypeAndValueStr); +3294 } +3295 }; 3296 -3297 if (sRule === "prn") { -3298 if (sType == "CN" && _isMail(sValue)) return "ia5"; -3299 if (_isPrintable(sValue)) return "prn"; -3300 return "utf8"; -3301 } else if (sRule === "utf8") { -3302 if (sType == "CN" && _isMail(sValue)) return "ia5"; -3303 if (sType == "C") return "prn"; -3304 return "utf8"; -3305 } -3306 return "utf8"; // default -3307 }; -3308 -3309 this.setByAttrTypeAndValueStr = function(sType, sValue, sRule) { -3310 if (sRule !== undefined) this.sRule = sRule; -3311 this.sType = sType; -3312 this.sValue = sValue; -3313 }; -3314 -3315 this.getValueObj = function(dsType, valueStr) { -3316 if (dsType == "utf8") return new _DERUTF8String({"str": valueStr}); -3317 if (dsType == "prn") return new _DERPrintableString({"str": valueStr}); -3318 if (dsType == "tel") return new _DERTeletexString({"str": valueStr}); -3319 if (dsType == "ia5") return new _DERIA5String({"str": valueStr}); -3320 if (dsType == "vis") return new _DERVisibleString({"str": valueStr}); -3321 if (dsType == "bmp") return new _DERBMPString({"str": valueStr}); -3322 throw new Error("unsupported directory string type: type=" + -3323 dsType + " value=" + valueStr); -3324 }; -3325 -3326 this.getEncodedHex = function() { -3327 if (this.dsType == null) this.dsType = this._getDsType(); -3328 var asn1Type = KJUR.asn1.x509.OID.atype2obj(this.sType); -3329 var asn1Value = this.getValueObj(this.dsType, this.sValue); -3330 var o = new _DERSequence({"array": [asn1Type, asn1Value]}); -3331 this.TLV = o.getEncodedHex(); -3332 return this.TLV; -3333 }; -3334 -3335 if (params !== undefined) { -3336 this.setByParam(params); -3337 } -3338 }; -3339 YAHOO.lang.extend(KJUR.asn1.x509.AttributeTypeAndValue, KJUR.asn1.ASN1Object); -3340 -3341 // === END X500Name Related ================================================= -3342 -3343 // === BEGIN Other ASN1 structure class ====================================== -3344 -3345 /** -3346 * SubjectPublicKeyInfo ASN.1 structure class -3347 * @name KJUR.asn1.x509.SubjectPublicKeyInfo -3348 * @class SubjectPublicKeyInfo ASN.1 structure class -3349 * @param {Object} params parameter for subject public key -3350 * @extends KJUR.asn1.ASN1Object -3351 * @description -3352 * <br/> -3353 * As for argument 'params' for constructor, you can specify one of -3354 * following properties: -3355 * <ul> -3356 * <li>{@link RSAKey} object</li> -3357 * <li>{@link KJUR.crypto.ECDSA} object</li> -3358 * <li>{@link KJUR.crypto.DSA} object</li> -3359 * </ul> -3360 * NOTE1: 'params' can be omitted.<br/> -3361 * NOTE2: DSA/ECDSA key object is also supported since asn1x509 1.0.6.<br/> -3362 * <h4>EXAMPLE</h4> -3363 * @example -3364 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(RSAKey_object); -3365 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(KJURcryptoECDSA_object); -3366 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(KJURcryptoDSA_object); -3367 */ -3368 KJUR.asn1.x509.SubjectPublicKeyInfo = function(params) { -3369 KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this); -3370 var asn1AlgId = null, -3371 asn1SubjPKey = null, -3372 _KJUR = KJUR, -3373 _KJUR_asn1 = _KJUR.asn1, -3374 _DERInteger = _KJUR_asn1.DERInteger, -3375 _DERBitString = _KJUR_asn1.DERBitString, -3376 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, -3377 _DERSequence = _KJUR_asn1.DERSequence, -3378 _newObject = _KJUR_asn1.ASN1Util.newObject, -3379 _KJUR_asn1_x509 = _KJUR_asn1.x509, -3380 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, -3381 _KJUR_crypto = _KJUR.crypto, -3382 _KJUR_crypto_ECDSA = _KJUR_crypto.ECDSA, -3383 _KJUR_crypto_DSA = _KJUR_crypto.DSA; -3384 -3385 /* -3386 * @since asn1x509 1.0.7 -3387 */ -3388 this.getASN1Object = function() { -3389 if (this.asn1AlgId == null || this.asn1SubjPKey == null) -3390 throw "algId and/or subjPubKey not set"; -3391 var o = new _DERSequence({'array': -3392 [this.asn1AlgId, this.asn1SubjPKey]}); -3393 return o; -3394 }; -3395 -3396 this.getEncodedHex = function() { -3397 var o = this.getASN1Object(); -3398 this.hTLV = o.getEncodedHex(); -3399 return this.hTLV; -3400 }; -3401 -3402 /** -3403 * @name setPubKey -3404 * @memberOf KJUR.asn1.x509.SubjectPublicKeyInfo# -3405 * @function -3406 * @param {Object} {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.DSA} object -3407 * @since jsrsasign 8.0.0 asn1x509 1.1.0 -3408 * @description -3409 * @example -3410 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(); -3411 * pubKey = KEYUTIL.getKey(PKCS8PUBKEYPEM); -3412 * spki.setPubKey(pubKey); -3413 */ -3414 this.setPubKey = function(key) { -3415 try { -3416 if (key instanceof RSAKey) { -3417 var asn1RsaPub = _newObject({ -3418 'seq': [{'int': {'bigint': key.n}}, {'int': {'int': key.e}}] -3419 }); -3420 var rsaKeyHex = asn1RsaPub.getEncodedHex(); -3421 this.asn1AlgId = new _AlgorithmIdentifier({'name':'rsaEncryption'}); -3422 this.asn1SubjPKey = new _DERBitString({'hex':'00'+rsaKeyHex}); -3423 } -3424 } catch(ex) {}; -3425 -3426 try { -3427 if (key instanceof KJUR.crypto.ECDSA) { -3428 var asn1Params = new _DERObjectIdentifier({'name': key.curveName}); -3429 this.asn1AlgId = -3430 new _AlgorithmIdentifier({'name': 'ecPublicKey', -3431 'asn1params': asn1Params}); -3432 this.asn1SubjPKey = new _DERBitString({'hex': '00' + key.pubKeyHex}); -3433 } -3434 } catch(ex) {}; -3435 -3436 try { -3437 if (key instanceof KJUR.crypto.DSA) { -3438 var asn1Params = new _newObject({ -3439 'seq': [{'int': {'bigint': key.p}}, -3440 {'int': {'bigint': key.q}}, -3441 {'int': {'bigint': key.g}}] -3442 }); -3443 this.asn1AlgId = -3444 new _AlgorithmIdentifier({'name': 'dsa', -3445 'asn1params': asn1Params}); -3446 var pubInt = new _DERInteger({'bigint': key.y}); -3447 this.asn1SubjPKey = -3448 new _DERBitString({'hex': '00' + pubInt.getEncodedHex()}); -3449 } -3450 } catch(ex) {}; -3451 }; -3452 -3453 if (params !== undefined) { -3454 this.setPubKey(params); -3455 } -3456 }; -3457 YAHOO.lang.extend(KJUR.asn1.x509.SubjectPublicKeyInfo, KJUR.asn1.ASN1Object); -3458 -3459 /** -3460 * Time ASN.1 structure class<br/> -3461 * @name KJUR.asn1.x509.Time -3462 * @class Time ASN.1 structure class -3463 * @param {Array} params associative array of parameters (ex. {'str': '130508235959Z'}) -3464 * @extends KJUR.asn1.ASN1Object -3465 * @see KJUR.asn1.DERUTCTime -3466 * @see KJUR.asn1.DERGeneralizedTime -3467 * @description -3468 * This class represents Time ASN.1 structure defined in -3469 * <a href="https://tools.ietf.org/html/rfc5280">RFC 5280</a> -3470 * <pre> -3471 * Time ::= CHOICE { -3472 * utcTime UTCTime, -3473 * generalTime GeneralizedTime } -3474 * </pre> -3475 * -3476 * @example -3477 * var t1 = new KJUR.asn1.x509.Time{'str': '130508235959Z'} // UTCTime by default -3478 * var t2 = new KJUR.asn1.x509.Time{'type': 'gen', 'str': '20130508235959Z'} // GeneralizedTime -3479 */ -3480 KJUR.asn1.x509.Time = function(params) { -3481 KJUR.asn1.x509.Time.superclass.constructor.call(this); -3482 var type = null, -3483 timeParams = null, -3484 _KJUR = KJUR, -3485 _KJUR_asn1 = _KJUR.asn1, -3486 _DERUTCTime = _KJUR_asn1.DERUTCTime, -3487 _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime; -3488 -3489 this.setTimeParams = function(timeParams) { -3490 this.timeParams = timeParams; -3491 } -3492 -3493 this.getEncodedHex = function() { -3494 var o = null; -3495 -3496 if (this.timeParams != null) { -3497 if (this.type == "utc") { -3498 o = new _DERUTCTime(this.timeParams); -3499 } else { -3500 o = new _DERGeneralizedTime(this.timeParams); -3501 } -3502 } else { -3503 if (this.type == "utc") { -3504 o = new _DERUTCTime(); -3505 } else { -3506 o = new _DERGeneralizedTime(); -3507 } -3508 } -3509 this.TLV = o.getEncodedHex(); -3510 return this.TLV; -3511 }; -3512 -3513 this.type = "utc"; -3514 if (params !== undefined) { -3515 if (params.type !== undefined) { -3516 this.type = params.type; -3517 } else { -3518 if (params.str !== undefined) { -3519 if (params.str.match(/^[0-9]{12}Z$/)) this.type = "utc"; -3520 if (params.str.match(/^[0-9]{14}Z$/)) this.type = "gen"; -3521 } -3522 } -3523 this.timeParams = params; -3524 } -3525 }; -3526 YAHOO.lang.extend(KJUR.asn1.x509.Time, KJUR.asn1.ASN1Object); -3527 -3528 /** -3529 * AlgorithmIdentifier ASN.1 structure class -3530 * @name KJUR.asn1.x509.AlgorithmIdentifier -3531 * @class AlgorithmIdentifier ASN.1 structure class -3532 * @param {Array} params associative array of parameters (ex. {'name': 'SHA1withRSA'}) -3533 * @extends KJUR.asn1.ASN1Object -3534 * @description -3535 * The 'params' argument is an associative array and has following parameters: -3536 * <ul> -3537 * <li>name: algorithm name (MANDATORY, ex. sha1, SHA256withRSA)</li> -3538 * <li>asn1params: explicitly specify ASN.1 object for algorithm. -3539 * (OPTION)</li> -3540 * <li>paramempty: set algorithm parameter to NULL by force. -3541 * If paramempty is false, algorithm parameter will be set automatically. -3542 * If paramempty is false and algorithm name is "*withDSA" or "withECDSA" parameter field of -3543 * AlgorithmIdentifier will be ommitted otherwise -3544 * it will be NULL by default. -3545 * (OPTION, DEFAULT = false)</li> -3546 * </ul> -3547 * RSA-PSS algorithm names such as SHA{,256,384,512}withRSAandMGF1 are -3548 * special names. They will set a suite of algorithm OID and multiple algorithm -3549 * parameters. Its ASN.1 schema is defined in -3550 * <a href="https://tools.ietf.org/html/rfc3447#appendix-A.2.3">RFC 3447 PKCS#1 2.1 -3551 * section A.2.3</a>. -3552 * <blockquote><pre> -3553 * id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 } -3554 * RSASSA-PSS-params ::= SEQUENCE { -3555 * hashAlgorithm [0] HashAlgorithm DEFAULT sha1, -3556 * maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1, -3557 * saltLength [2] INTEGER DEFAULT 20, -3558 * trailerField [3] TrailerField DEFAULT trailerFieldBC } -3559 * mgf1SHA1 MaskGenAlgorithm ::= { -3560 * algorithm id-mgf1, -3561 * parameters HashAlgorithm : sha1 } -3562 * id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 } -3563 * TrailerField ::= INTEGER { trailerFieldBC(1) } -3564 * </pre></blockquote> -3565 * Here is a table for PSS parameters: -3566 * <table> -3567 * <tr><th>Name</th><th>alg oid</th><th>pss hash</th><th>maskgen</th></th><th>pss saltlen</th><th>trailer</th></tr> -3568 * <tr><td>SHAwithRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>default(sha1)</td><td>default(mgf1sha1)</td><td>default(20)</td><td>default(1)</td></tr> -3569 * <tr><td>SHA256withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha256</td><td>mgf1sha256</td><td>32</td><td>default(1)</td></tr> -3570 * <tr><td>SHA384withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha384</td><td>mgf1sha384</td><td>48</td><td>default(1)</td></tr> -3571 * <tr><td>SHA512withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha512</td><td>mgf1sha512</td><td>64</td><td>default(1)</td></tr> -3572 * </table> -3573 * Default value is omitted as defined in ASN.1 schema. -3574 * These parameters are interoperable to OpenSSL or IAIK toolkit. -3575 * <br/> -3576 * NOTE: RSA-PSS algorihtm names are supported since jsrsasign 8.0.21. -3577 * @example -3578 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "sha1"}) -3579 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA"}) -3580 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA512withRSAandMGF1"}) // set parameters automatically -3581 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA", paramempty: true}) -3582 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "rsaEncryption"}) -3583 */ -3584 KJUR.asn1.x509.AlgorithmIdentifier = function(params) { -3585 KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this); -3586 this.nameAlg = null; -3587 this.asn1Alg = null; -3588 this.asn1Params = null; -3589 this.paramEmpty = false; -3590 -3591 var _KJUR = KJUR, -3592 _KJUR_asn1 = _KJUR.asn1, -3593 _PSSNAME2ASN1TLV = _KJUR_asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV; -3594 -3595 this.getEncodedHex = function() { -3596 if (this.nameAlg === null && this.asn1Alg === null) { -3597 throw new Error("algorithm not specified"); -3598 } +3297 this._getDsType = function() { +3298 var sType = this.sType; +3299 var sValue = this.sValue; +3300 var sRule = this.sRule; +3301 +3302 if (sRule === "prn") { +3303 if (sType == "CN" && _isMail(sValue)) return "ia5"; +3304 if (_isPrintable(sValue)) return "prn"; +3305 return "utf8"; +3306 } else if (sRule === "utf8") { +3307 if (sType == "CN" && _isMail(sValue)) return "ia5"; +3308 if (sType == "C") return "prn"; +3309 return "utf8"; +3310 } +3311 return "utf8"; // default +3312 }; +3313 +3314 this.setByAttrTypeAndValueStr = function(sType, sValue, sRule) { +3315 if (sRule !== undefined) this.sRule = sRule; +3316 this.sType = sType; +3317 this.sValue = sValue; +3318 }; +3319 +3320 this.getValueObj = function(dsType, valueStr) { +3321 if (dsType == "utf8") return new _DERUTF8String({"str": valueStr}); +3322 if (dsType == "prn") return new _DERPrintableString({"str": valueStr}); +3323 if (dsType == "tel") return new _DERTeletexString({"str": valueStr}); +3324 if (dsType == "ia5") return new _DERIA5String({"str": valueStr}); +3325 if (dsType == "vis") return new _DERVisibleString({"str": valueStr}); +3326 if (dsType == "bmp") return new _DERBMPString({"str": valueStr}); +3327 throw new Error("unsupported directory string type: type=" + +3328 dsType + " value=" + valueStr); +3329 }; +3330 +3331 this.getEncodedHex = function() { +3332 if (this.dsType == null) this.dsType = this._getDsType(); +3333 var asn1Type = KJUR.asn1.x509.OID.atype2obj(this.sType); +3334 var asn1Value = this.getValueObj(this.dsType, this.sValue); +3335 var o = new _DERSequence({"array": [asn1Type, asn1Value]}); +3336 this.TLV = o.getEncodedHex(); +3337 return this.TLV; +3338 }; +3339 +3340 if (params !== undefined) { +3341 this.setByParam(params); +3342 } +3343 }; +3344 YAHOO.lang.extend(KJUR.asn1.x509.AttributeTypeAndValue, KJUR.asn1.ASN1Object); +3345 +3346 // === END X500Name Related ================================================= +3347 +3348 // === BEGIN Other ASN1 structure class ====================================== +3349 +3350 /** +3351 * SubjectPublicKeyInfo ASN.1 structure class +3352 * @name KJUR.asn1.x509.SubjectPublicKeyInfo +3353 * @class SubjectPublicKeyInfo ASN.1 structure class +3354 * @param {Object} params parameter for subject public key +3355 * @extends KJUR.asn1.ASN1Object +3356 * @description +3357 * <br/> +3358 * As for argument 'params' for constructor, you can specify one of +3359 * following properties: +3360 * <ul> +3361 * <li>{@link RSAKey} object</li> +3362 * <li>{@link KJUR.crypto.ECDSA} object</li> +3363 * <li>{@link KJUR.crypto.DSA} object</li> +3364 * </ul> +3365 * NOTE1: 'params' can be omitted.<br/> +3366 * NOTE2: DSA/ECDSA key object is also supported since asn1x509 1.0.6.<br/> +3367 * <h4>EXAMPLE</h4> +3368 * @example +3369 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(RSAKey_object); +3370 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(KJURcryptoECDSA_object); +3371 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(KJURcryptoDSA_object); +3372 */ +3373 KJUR.asn1.x509.SubjectPublicKeyInfo = function(params) { +3374 KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this); +3375 var asn1AlgId = null, +3376 asn1SubjPKey = null, +3377 _KJUR = KJUR, +3378 _KJUR_asn1 = _KJUR.asn1, +3379 _DERInteger = _KJUR_asn1.DERInteger, +3380 _DERBitString = _KJUR_asn1.DERBitString, +3381 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, +3382 _DERSequence = _KJUR_asn1.DERSequence, +3383 _newObject = _KJUR_asn1.ASN1Util.newObject, +3384 _KJUR_asn1_x509 = _KJUR_asn1.x509, +3385 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, +3386 _KJUR_crypto = _KJUR.crypto, +3387 _KJUR_crypto_ECDSA = _KJUR_crypto.ECDSA, +3388 _KJUR_crypto_DSA = _KJUR_crypto.DSA; +3389 +3390 /* +3391 * @since asn1x509 1.0.7 +3392 */ +3393 this.getASN1Object = function() { +3394 if (this.asn1AlgId == null || this.asn1SubjPKey == null) +3395 throw "algId and/or subjPubKey not set"; +3396 var o = new _DERSequence({'array': +3397 [this.asn1AlgId, this.asn1SubjPKey]}); +3398 return o; +3399 }; +3400 +3401 this.getEncodedHex = function() { +3402 var o = this.getASN1Object(); +3403 this.hTLV = o.getEncodedHex(); +3404 return this.hTLV; +3405 }; +3406 +3407 /** +3408 * @name setPubKey +3409 * @memberOf KJUR.asn1.x509.SubjectPublicKeyInfo# +3410 * @function +3411 * @param {Object} {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.DSA} object +3412 * @since jsrsasign 8.0.0 asn1x509 1.1.0 +3413 * @description +3414 * @example +3415 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(); +3416 * pubKey = KEYUTIL.getKey(PKCS8PUBKEYPEM); +3417 * spki.setPubKey(pubKey); +3418 */ +3419 this.setPubKey = function(key) { +3420 try { +3421 if (key instanceof RSAKey) { +3422 var asn1RsaPub = _newObject({ +3423 'seq': [{'int': {'bigint': key.n}}, {'int': {'int': key.e}}] +3424 }); +3425 var rsaKeyHex = asn1RsaPub.getEncodedHex(); +3426 this.asn1AlgId = new _AlgorithmIdentifier({'name':'rsaEncryption'}); +3427 this.asn1SubjPKey = new _DERBitString({'hex':'00'+rsaKeyHex}); +3428 } +3429 } catch(ex) {}; +3430 +3431 try { +3432 if (key instanceof KJUR.crypto.ECDSA) { +3433 var asn1Params = new _DERObjectIdentifier({'name': key.curveName}); +3434 this.asn1AlgId = +3435 new _AlgorithmIdentifier({'name': 'ecPublicKey', +3436 'asn1params': asn1Params}); +3437 this.asn1SubjPKey = new _DERBitString({'hex': '00' + key.pubKeyHex}); +3438 } +3439 } catch(ex) {}; +3440 +3441 try { +3442 if (key instanceof KJUR.crypto.DSA) { +3443 var asn1Params = new _newObject({ +3444 'seq': [{'int': {'bigint': key.p}}, +3445 {'int': {'bigint': key.q}}, +3446 {'int': {'bigint': key.g}}] +3447 }); +3448 this.asn1AlgId = +3449 new _AlgorithmIdentifier({'name': 'dsa', +3450 'asn1params': asn1Params}); +3451 var pubInt = new _DERInteger({'bigint': key.y}); +3452 this.asn1SubjPKey = +3453 new _DERBitString({'hex': '00' + pubInt.getEncodedHex()}); +3454 } +3455 } catch(ex) {}; +3456 }; +3457 +3458 if (params !== undefined) { +3459 this.setPubKey(params); +3460 } +3461 }; +3462 YAHOO.lang.extend(KJUR.asn1.x509.SubjectPublicKeyInfo, KJUR.asn1.ASN1Object); +3463 +3464 /** +3465 * Time ASN.1 structure class<br/> +3466 * @name KJUR.asn1.x509.Time +3467 * @class Time ASN.1 structure class +3468 * @param {Array} params associative array of parameters (ex. {'str': '130508235959Z'}) +3469 * @extends KJUR.asn1.ASN1Object +3470 * @see KJUR.asn1.DERUTCTime +3471 * @see KJUR.asn1.DERGeneralizedTime +3472 * @description +3473 * This class represents Time ASN.1 structure defined in +3474 * <a href="https://tools.ietf.org/html/rfc5280">RFC 5280</a> +3475 * <pre> +3476 * Time ::= CHOICE { +3477 * utcTime UTCTime, +3478 * generalTime GeneralizedTime } +3479 * </pre> +3480 * +3481 * @example +3482 * var t1 = new KJUR.asn1.x509.Time{'str': '130508235959Z'} // UTCTime by default +3483 * var t2 = new KJUR.asn1.x509.Time{'type': 'gen', 'str': '20130508235959Z'} // GeneralizedTime +3484 */ +3485 KJUR.asn1.x509.Time = function(params) { +3486 KJUR.asn1.x509.Time.superclass.constructor.call(this); +3487 var type = null, +3488 timeParams = null, +3489 _KJUR = KJUR, +3490 _KJUR_asn1 = _KJUR.asn1, +3491 _DERUTCTime = _KJUR_asn1.DERUTCTime, +3492 _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime; +3493 +3494 this.setTimeParams = function(timeParams) { +3495 this.timeParams = timeParams; +3496 } +3497 +3498 this.getEncodedHex = function() { +3499 var o = null; +3500 +3501 if (this.timeParams != null) { +3502 if (this.type == "utc") { +3503 o = new _DERUTCTime(this.timeParams); +3504 } else { +3505 o = new _DERGeneralizedTime(this.timeParams); +3506 } +3507 } else { +3508 if (this.type == "utc") { +3509 o = new _DERUTCTime(); +3510 } else { +3511 o = new _DERGeneralizedTime(); +3512 } +3513 } +3514 this.TLV = o.getEncodedHex(); +3515 return this.TLV; +3516 }; +3517 +3518 this.type = "utc"; +3519 if (params !== undefined) { +3520 if (params.type !== undefined) { +3521 this.type = params.type; +3522 } else { +3523 if (params.str !== undefined) { +3524 if (params.str.match(/^[0-9]{12}Z$/)) this.type = "utc"; +3525 if (params.str.match(/^[0-9]{14}Z$/)) this.type = "gen"; +3526 } +3527 } +3528 this.timeParams = params; +3529 } +3530 }; +3531 YAHOO.lang.extend(KJUR.asn1.x509.Time, KJUR.asn1.ASN1Object); +3532 +3533 /** +3534 * AlgorithmIdentifier ASN.1 structure class +3535 * @name KJUR.asn1.x509.AlgorithmIdentifier +3536 * @class AlgorithmIdentifier ASN.1 structure class +3537 * @param {Array} params associative array of parameters (ex. {'name': 'SHA1withRSA'}) +3538 * @extends KJUR.asn1.ASN1Object +3539 * @description +3540 * The 'params' argument is an associative array and has following parameters: +3541 * <ul> +3542 * <li>name: algorithm name (MANDATORY, ex. sha1, SHA256withRSA)</li> +3543 * <li>asn1params: explicitly specify ASN.1 object for algorithm. +3544 * (OPTION)</li> +3545 * <li>paramempty: set algorithm parameter to NULL by force. +3546 * If paramempty is false, algorithm parameter will be set automatically. +3547 * If paramempty is false and algorithm name is "*withDSA" or "withECDSA" parameter field of +3548 * AlgorithmIdentifier will be ommitted otherwise +3549 * it will be NULL by default. +3550 * (OPTION, DEFAULT = false)</li> +3551 * </ul> +3552 * RSA-PSS algorithm names such as SHA{,256,384,512}withRSAandMGF1 are +3553 * special names. They will set a suite of algorithm OID and multiple algorithm +3554 * parameters. Its ASN.1 schema is defined in +3555 * <a href="https://tools.ietf.org/html/rfc3447#appendix-A.2.3">RFC 3447 PKCS#1 2.1 +3556 * section A.2.3</a>. +3557 * <blockquote><pre> +3558 * id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 } +3559 * RSASSA-PSS-params ::= SEQUENCE { +3560 * hashAlgorithm [0] HashAlgorithm DEFAULT sha1, +3561 * maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1, +3562 * saltLength [2] INTEGER DEFAULT 20, +3563 * trailerField [3] TrailerField DEFAULT trailerFieldBC } +3564 * mgf1SHA1 MaskGenAlgorithm ::= { +3565 * algorithm id-mgf1, +3566 * parameters HashAlgorithm : sha1 } +3567 * id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 } +3568 * TrailerField ::= INTEGER { trailerFieldBC(1) } +3569 * </pre></blockquote> +3570 * Here is a table for PSS parameters: +3571 * <table> +3572 * <tr><th>Name</th><th>alg oid</th><th>pss hash</th><th>maskgen</th></th><th>pss saltlen</th><th>trailer</th></tr> +3573 * <tr><td>SHAwithRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>default(sha1)</td><td>default(mgf1sha1)</td><td>default(20)</td><td>default(1)</td></tr> +3574 * <tr><td>SHA256withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha256</td><td>mgf1sha256</td><td>32</td><td>default(1)</td></tr> +3575 * <tr><td>SHA384withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha384</td><td>mgf1sha384</td><td>48</td><td>default(1)</td></tr> +3576 * <tr><td>SHA512withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha512</td><td>mgf1sha512</td><td>64</td><td>default(1)</td></tr> +3577 * </table> +3578 * Default value is omitted as defined in ASN.1 schema. +3579 * These parameters are interoperable to OpenSSL or IAIK toolkit. +3580 * <br/> +3581 * NOTE: RSA-PSS algorihtm names are supported since jsrsasign 8.0.21. +3582 * @example +3583 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "sha1"}) +3584 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA"}) +3585 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA512withRSAandMGF1"}) // set parameters automatically +3586 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA", paramempty: true}) +3587 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "rsaEncryption"}) +3588 */ +3589 KJUR.asn1.x509.AlgorithmIdentifier = function(params) { +3590 KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this); +3591 this.nameAlg = null; +3592 this.asn1Alg = null; +3593 this.asn1Params = null; +3594 this.paramEmpty = false; +3595 +3596 var _KJUR = KJUR, +3597 _KJUR_asn1 = _KJUR.asn1, +3598 _PSSNAME2ASN1TLV = _KJUR_asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV; 3599 -3600 // for RSAPSS algorithm name -3601 // && this.hTLV === null -3602 if (this.nameAlg !== null) { -3603 var hTLV = null; -3604 for (var key in _PSSNAME2ASN1TLV) { -3605 if (key === this.nameAlg) { -3606 hTLV = _PSSNAME2ASN1TLV[key]; -3607 } -3608 } -3609 if (hTLV !== null) { -3610 this.hTLV = hTLV; -3611 return this.hTLV; -3612 } -3613 } -3614 -3615 if (this.nameAlg !== null && this.asn1Alg === null) { -3616 this.asn1Alg = _KJUR_asn1.x509.OID.name2obj(this.nameAlg); -3617 } -3618 var a = [this.asn1Alg]; -3619 if (this.asn1Params !== null) a.push(this.asn1Params); -3620 -3621 var o = new _KJUR_asn1.DERSequence({'array': a}); -3622 this.hTLV = o.getEncodedHex(); -3623 return this.hTLV; -3624 }; +3600 this.getEncodedHex = function() { +3601 if (this.nameAlg === null && this.asn1Alg === null) { +3602 throw new Error("algorithm not specified"); +3603 } +3604 +3605 // for RSAPSS algorithm name +3606 // && this.hTLV === null +3607 if (this.nameAlg !== null) { +3608 var hTLV = null; +3609 for (var key in _PSSNAME2ASN1TLV) { +3610 if (key === this.nameAlg) { +3611 hTLV = _PSSNAME2ASN1TLV[key]; +3612 } +3613 } +3614 if (hTLV !== null) { +3615 this.hTLV = hTLV; +3616 return this.hTLV; +3617 } +3618 } +3619 +3620 if (this.nameAlg !== null && this.asn1Alg === null) { +3621 this.asn1Alg = _KJUR_asn1.x509.OID.name2obj(this.nameAlg); +3622 } +3623 var a = [this.asn1Alg]; +3624 if (this.asn1Params !== null) a.push(this.asn1Params); 3625 -3626 if (params !== undefined) { -3627 if (params.name !== undefined) { -3628 this.nameAlg = params.name; -3629 } -3630 if (params.asn1params !== undefined) { -3631 this.asn1Params = params.asn1params; -3632 } -3633 if (params.paramempty !== undefined) { -3634 this.paramEmpty = params.paramempty; -3635 } -3636 } -3637 -3638 // set algorithm parameters will be ommitted for -3639 // "*withDSA" or "*withECDSA" otherwise will be NULL. -3640 if (this.asn1Params === null && -3641 this.paramEmpty === false && -3642 this.nameAlg !== null) { -3643 -3644 if (this.nameAlg.name !== undefined) { -3645 this.nameAlg = this.nameAlg.name; -3646 } -3647 var lcNameAlg = this.nameAlg.toLowerCase(); +3626 var o = new _KJUR_asn1.DERSequence({'array': a}); +3627 this.hTLV = o.getEncodedHex(); +3628 return this.hTLV; +3629 }; +3630 +3631 if (params !== undefined) { +3632 if (params.name !== undefined) { +3633 this.nameAlg = params.name; +3634 } +3635 if (params.asn1params !== undefined) { +3636 this.asn1Params = params.asn1params; +3637 } +3638 if (params.paramempty !== undefined) { +3639 this.paramEmpty = params.paramempty; +3640 } +3641 } +3642 +3643 // set algorithm parameters will be ommitted for +3644 // "*withDSA" or "*withECDSA" otherwise will be NULL. +3645 if (this.asn1Params === null && +3646 this.paramEmpty === false && +3647 this.nameAlg !== null) { 3648 -3649 if (lcNameAlg.substr(-7, 7) !== "withdsa" && -3650 lcNameAlg.substr(-9, 9) !== "withecdsa") { -3651 this.asn1Params = new _KJUR_asn1.DERNull(); -3652 } -3653 } -3654 }; -3655 YAHOO.lang.extend(KJUR.asn1.x509.AlgorithmIdentifier, KJUR.asn1.ASN1Object); -3656 -3657 /** -3658 * AlgorithmIdentifier ASN.1 TLV string associative array for RSA-PSS algorithm names -3659 * @const -3660 */ -3661 KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV = { -3662 "SHAwithRSAandMGF1": -3663 "300d06092a864886f70d01010a3000", -3664 "SHA256withRSAandMGF1": -3665 "303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120", -3666 "SHA384withRSAandMGF1": -3667 "303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130", -3668 "SHA512withRSAandMGF1": -3669 "303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140" -3670 }; -3671 -3672 /** -3673 * GeneralName ASN.1 structure class<br/> -3674 * @name KJUR.asn1.x509.GeneralName -3675 * @class GeneralName ASN.1 structure class -3676 * @description -3677 * <br/> -3678 * As for argument 'params' for constructor, you can specify one of -3679 * following properties: -3680 * <ul> -3681 * <li>rfc822 - rfc822Name[1] (ex. user1@foo.com)</li> -3682 * <li>dns - dNSName[2] (ex. foo.com)</li> -3683 * <li>uri - uniformResourceIdentifier[6] (ex. http://foo.com/)</li> -3684 * <li>dn - directoryName[4] -3685 * distinguished name string or X500Name class parameters can be -3686 * specified (ex. "/C=US/O=Test", {hex: '301c...')</li> -3687 * <li>ldapdn - directoryName[4] (ex. O=Test,C=US)</li> -3688 * <li>certissuer - directoryName[4] (PEM or hex string of cert)</li> -3689 * <li>certsubj - directoryName[4] (PEM or hex string of cert)</li> -3690 * <li>ip - iPAddress[7] (ex. 192.168.1.1, 2001:db3::43, 3faa0101...)</li> -3691 * </ul> -3692 * NOTE1: certissuer and certsubj were supported since asn1x509 1.0.10.<br/> -3693 * NOTE2: dn and ldapdn were supported since jsrsasign 6.2.3 asn1x509 1.0.19.<br/> -3694 * NOTE3: ip were supported since jsrsasign 8.0.10 asn1x509 1.1.4.<br/> -3695 * NOTE4: X500Name parameters in dn were supported since jsrsasign 8.0.16.<br/> -3696 * -3697 * Here is definition of the ASN.1 syntax: -3698 * <pre> -3699 * -- NOTE: under the CHOICE, it will always be explicit. -3700 * GeneralName ::= CHOICE { -3701 * otherName [0] OtherName, -3702 * rfc822Name [1] IA5String, -3703 * dNSName [2] IA5String, -3704 * x400Address [3] ORAddress, -3705 * directoryName [4] Name, -3706 * ediPartyName [5] EDIPartyName, -3707 * uniformResourceIdentifier [6] IA5String, -3708 * iPAddress [7] OCTET STRING, -3709 * registeredID [8] OBJECT IDENTIFIER } -3710 * </pre> -3711 * -3712 * @example -3713 * gn = new KJUR.asn1.x509.GeneralName({dn: '/C=US/O=Test'}); -3714 * gn = new KJUR.asn1.x509.GeneralName({dn: X500NameObject); -3715 * gn = new KJUR.asn1.x509.GeneralName({dn: {str: /C=US/O=Test'}); -3716 * gn = new KJUR.asn1.x509.GeneralName({dn: {ldapstr: 'O=Test,C=US'}); -3717 * gn = new KJUR.asn1.x509.GeneralName({dn: {hex: '301c...'}); -3718 * gn = new KJUR.asn1.x509.GeneralName({dn: {certissuer: PEMCERTSTRING}); -3719 * gn = new KJUR.asn1.x509.GeneralName({dn: {certsubject: PEMCERTSTRING}); -3720 * gn = new KJUR.asn1.x509.GeneralName({ip: '192.168.1.1'}); -3721 * gn = new KJUR.asn1.x509.GeneralName({ip: '2001:db4::4:1'}); -3722 * gn = new KJUR.asn1.x509.GeneralName({ip: 'c0a80101'}); -3723 * gn = new KJUR.asn1.x509.GeneralName({rfc822: 'test@aaa.com'}); -3724 * gn = new KJUR.asn1.x509.GeneralName({dns: 'aaa.com'}); -3725 * gn = new KJUR.asn1.x509.GeneralName({uri: 'http://aaa.com/'}); -3726 * -3727 * gn = new KJUR.asn1.x509.GeneralName({ldapdn: 'O=Test,C=US'}); // DEPRECATED -3728 * gn = new KJUR.asn1.x509.GeneralName({certissuer: certPEM}); // DEPRECATED -3729 * gn = new KJUR.asn1.x509.GeneralName({certsubj: certPEM}); // DEPRECATED -3730 */ -3731 KJUR.asn1.x509.GeneralName = function(params) { -3732 KJUR.asn1.x509.GeneralName.superclass.constructor.call(this); -3733 var asn1Obj = null, -3734 type = null, -3735 pTag = {rfc822: '81', dns: '82', dn: 'a4', uri: '86', ip: '87'}, -3736 _KJUR = KJUR, -3737 _KJUR_asn1 = _KJUR.asn1, -3738 _DERSequence = _KJUR_asn1.DERSequence, -3739 _DEROctetString = _KJUR_asn1.DEROctetString, -3740 _DERIA5String = _KJUR_asn1.DERIA5String, -3741 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, -3742 _ASN1Object = _KJUR_asn1.ASN1Object, -3743 _X500Name = _KJUR_asn1.x509.X500Name, -3744 _pemtohex = pemtohex; -3745 -3746 this.explicit = false; -3747 -3748 this.setByParam = function(params) { -3749 var str = null; -3750 var v = null; -3751 -3752 if (params === undefined) return; -3753 -3754 if (params.rfc822 !== undefined) { -3755 this.type = 'rfc822'; -3756 v = new _DERIA5String({str: params[this.type]}); -3757 } +3649 if (this.nameAlg.name !== undefined) { +3650 this.nameAlg = this.nameAlg.name; +3651 } +3652 var lcNameAlg = this.nameAlg.toLowerCase(); +3653 +3654 if (lcNameAlg.substr(-7, 7) !== "withdsa" && +3655 lcNameAlg.substr(-9, 9) !== "withecdsa") { +3656 this.asn1Params = new _KJUR_asn1.DERNull(); +3657 } +3658 } +3659 }; +3660 YAHOO.lang.extend(KJUR.asn1.x509.AlgorithmIdentifier, KJUR.asn1.ASN1Object); +3661 +3662 /** +3663 * AlgorithmIdentifier ASN.1 TLV string associative array for RSA-PSS algorithm names +3664 * @const +3665 */ +3666 KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV = { +3667 "SHAwithRSAandMGF1": +3668 "300d06092a864886f70d01010a3000", +3669 "SHA256withRSAandMGF1": +3670 "303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120", +3671 "SHA384withRSAandMGF1": +3672 "303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130", +3673 "SHA512withRSAandMGF1": +3674 "303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140" +3675 }; +3676 +3677 /** +3678 * GeneralName ASN.1 structure class<br/> +3679 * @name KJUR.asn1.x509.GeneralName +3680 * @class GeneralName ASN.1 structure class +3681 * @description +3682 * <br/> +3683 * As for argument 'params' for constructor, you can specify one of +3684 * following properties: +3685 * <ul> +3686 * <li>rfc822 - rfc822Name[1] (ex. user1@foo.com)</li> +3687 * <li>dns - dNSName[2] (ex. foo.com)</li> +3688 * <li>uri - uniformResourceIdentifier[6] (ex. http://foo.com/)</li> +3689 * <li>dn - directoryName[4] +3690 * distinguished name string or X500Name class parameters can be +3691 * specified (ex. "/C=US/O=Test", {hex: '301c...')</li> +3692 * <li>ldapdn - directoryName[4] (ex. O=Test,C=US)</li> +3693 * <li>certissuer - directoryName[4] (PEM or hex string of cert)</li> +3694 * <li>certsubj - directoryName[4] (PEM or hex string of cert)</li> +3695 * <li>ip - iPAddress[7] (ex. 192.168.1.1, 2001:db3::43, 3faa0101...)</li> +3696 * </ul> +3697 * NOTE1: certissuer and certsubj were supported since asn1x509 1.0.10.<br/> +3698 * NOTE2: dn and ldapdn were supported since jsrsasign 6.2.3 asn1x509 1.0.19.<br/> +3699 * NOTE3: ip were supported since jsrsasign 8.0.10 asn1x509 1.1.4.<br/> +3700 * NOTE4: X500Name parameters in dn were supported since jsrsasign 8.0.16.<br/> +3701 * +3702 * Here is definition of the ASN.1 syntax: +3703 * <pre> +3704 * -- NOTE: under the CHOICE, it will always be explicit. +3705 * GeneralName ::= CHOICE { +3706 * otherName [0] OtherName, +3707 * rfc822Name [1] IA5String, +3708 * dNSName [2] IA5String, +3709 * x400Address [3] ORAddress, +3710 * directoryName [4] Name, +3711 * ediPartyName [5] EDIPartyName, +3712 * uniformResourceIdentifier [6] IA5String, +3713 * iPAddress [7] OCTET STRING, +3714 * registeredID [8] OBJECT IDENTIFIER } +3715 * </pre> +3716 * +3717 * @example +3718 * gn = new KJUR.asn1.x509.GeneralName({dn: '/C=US/O=Test'}); +3719 * gn = new KJUR.asn1.x509.GeneralName({dn: X500NameObject); +3720 * gn = new KJUR.asn1.x509.GeneralName({dn: {str: /C=US/O=Test'}); +3721 * gn = new KJUR.asn1.x509.GeneralName({dn: {ldapstr: 'O=Test,C=US'}); +3722 * gn = new KJUR.asn1.x509.GeneralName({dn: {hex: '301c...'}); +3723 * gn = new KJUR.asn1.x509.GeneralName({dn: {certissuer: PEMCERTSTRING}); +3724 * gn = new KJUR.asn1.x509.GeneralName({dn: {certsubject: PEMCERTSTRING}); +3725 * gn = new KJUR.asn1.x509.GeneralName({ip: '192.168.1.1'}); +3726 * gn = new KJUR.asn1.x509.GeneralName({ip: '2001:db4::4:1'}); +3727 * gn = new KJUR.asn1.x509.GeneralName({ip: 'c0a80101'}); +3728 * gn = new KJUR.asn1.x509.GeneralName({rfc822: 'test@aaa.com'}); +3729 * gn = new KJUR.asn1.x509.GeneralName({dns: 'aaa.com'}); +3730 * gn = new KJUR.asn1.x509.GeneralName({uri: 'http://aaa.com/'}); +3731 * +3732 * gn = new KJUR.asn1.x509.GeneralName({ldapdn: 'O=Test,C=US'}); // DEPRECATED +3733 * gn = new KJUR.asn1.x509.GeneralName({certissuer: certPEM}); // DEPRECATED +3734 * gn = new KJUR.asn1.x509.GeneralName({certsubj: certPEM}); // DEPRECATED +3735 */ +3736 KJUR.asn1.x509.GeneralName = function(params) { +3737 KJUR.asn1.x509.GeneralName.superclass.constructor.call(this); +3738 var asn1Obj = null, +3739 type = null, +3740 pTag = {rfc822: '81', dns: '82', dn: 'a4', uri: '86', ip: '87'}, +3741 _KJUR = KJUR, +3742 _KJUR_asn1 = _KJUR.asn1, +3743 _DERSequence = _KJUR_asn1.DERSequence, +3744 _DEROctetString = _KJUR_asn1.DEROctetString, +3745 _DERIA5String = _KJUR_asn1.DERIA5String, +3746 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, +3747 _ASN1Object = _KJUR_asn1.ASN1Object, +3748 _X500Name = _KJUR_asn1.x509.X500Name, +3749 _pemtohex = pemtohex; +3750 +3751 this.explicit = false; +3752 +3753 this.setByParam = function(params) { +3754 var str = null; +3755 var v = null; +3756 +3757 if (params === undefined) return; 3758 -3759 if (params.dns !== undefined) { -3760 this.type = 'dns'; +3759 if (params.rfc822 !== undefined) { +3760 this.type = 'rfc822'; 3761 v = new _DERIA5String({str: params[this.type]}); 3762 } 3763 -3764 if (params.uri !== undefined) { -3765 this.type = 'uri'; +3764 if (params.dns !== undefined) { +3765 this.type = 'dns'; 3766 v = new _DERIA5String({str: params[this.type]}); 3767 } 3768 -3769 if (params.dn !== undefined) { -3770 this.type = 'dn'; -3771 this.explicit = true; -3772 if (typeof params.dn === "string") { -3773 v = new _X500Name({str: params.dn}); -3774 } else if (params.dn instanceof KJUR.asn1.x509.X500Name) { -3775 v = params.dn; -3776 } else { -3777 v = new _X500Name(params.dn); -3778 } -3779 } -3780 -3781 if (params.ldapdn !== undefined) { -3782 this.type = 'dn'; -3783 this.explicit = true; -3784 v = new _X500Name({ldapstr: params.ldapdn}); -3785 } -3786 -3787 if (params.certissuer !== undefined) { -3788 this.type = 'dn'; -3789 this.explicit = true; -3790 var certStr = params.certissuer; -3791 var certHex = null; -3792 -3793 if (certStr.match(/^[0-9A-Fa-f]+$/)) { -3794 certHex == certStr; -3795 } -3796 -3797 if (certStr.indexOf("-----BEGIN ") != -1) { -3798 certHex = _pemtohex(certStr); -3799 } -3800 -3801 if (certHex == null) throw "certissuer param not cert"; -3802 var x = new X509(); -3803 x.hex = certHex; -3804 var dnHex = x.getIssuerHex(); -3805 v = new _ASN1Object(); -3806 v.hTLV = dnHex; -3807 } -3808 -3809 if (params.certsubj !== undefined) { -3810 this.type = 'dn'; -3811 this.explicit = true; -3812 var certStr = params.certsubj; -3813 var certHex = null; -3814 if (certStr.match(/^[0-9A-Fa-f]+$/)) { -3815 certHex == certStr; -3816 } -3817 if (certStr.indexOf("-----BEGIN ") != -1) { -3818 certHex = _pemtohex(certStr); -3819 } -3820 if (certHex == null) throw "certsubj param not cert"; -3821 var x = new X509(); -3822 x.hex = certHex; -3823 var dnHex = x.getSubjectHex(); -3824 v = new _ASN1Object(); -3825 v.hTLV = dnHex; -3826 } -3827 -3828 if (params.ip !== undefined) { -3829 this.type = 'ip'; -3830 this.explicit = false; -3831 var ip = params.ip; -3832 var hIP; -3833 var malformedIPMsg = "malformed IP address"; -3834 if (ip.match(/^[0-9.]+[.][0-9.]+$/)) { // ipv4 -3835 hIP = intarystrtohex("[" + ip.split(".").join(",") + "]"); -3836 if (hIP.length !== 8) throw malformedIPMsg; -3837 } else if (ip.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)) { // ipv6 -3838 hIP = ipv6tohex(ip); -3839 } else if (ip.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)) { // hex -3840 hIP = ip; -3841 } else { -3842 throw malformedIPMsg; -3843 } -3844 v = new _DEROctetString({hex: hIP}); -3845 } -3846 -3847 if (this.type == null) -3848 throw "unsupported type in params=" + params; -3849 this.asn1Obj = new _DERTaggedObject({'explicit': this.explicit, -3850 'tag': pTag[this.type], -3851 'obj': v}); -3852 }; -3853 -3854 this.getEncodedHex = function() { -3855 return this.asn1Obj.getEncodedHex(); -3856 } -3857 -3858 if (params !== undefined) { -3859 this.setByParam(params); -3860 } -3861 -3862 }; -3863 YAHOO.lang.extend(KJUR.asn1.x509.GeneralName, KJUR.asn1.ASN1Object); -3864 -3865 /** -3866 * GeneralNames ASN.1 structure class<br/> -3867 * @name KJUR.asn1.x509.GeneralNames -3868 * @class GeneralNames ASN.1 structure class -3869 * @description -3870 * <br/> -3871 * <h4>EXAMPLE AND ASN.1 SYNTAX</h4> -3872 * @example -3873 * gns = new KJUR.asn1.x509.GeneralNames([{'uri': 'http://aaa.com/'}, {'uri': 'http://bbb.com/'}]); -3874 * -3875 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName -3876 */ -3877 KJUR.asn1.x509.GeneralNames = function(paramsArray) { -3878 KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this); -3879 var asn1Array = null, -3880 _KJUR = KJUR, -3881 _KJUR_asn1 = _KJUR.asn1; -3882 -3883 /** -3884 * set a array of {@link KJUR.asn1.x509.GeneralName} parameters<br/> -3885 * @name setByParamArray -3886 * @memberOf KJUR.asn1.x509.GeneralNames# -3887 * @function -3888 * @param {Array} paramsArray Array of {@link KJUR.asn1.x509.GeneralNames} -3889 * @description -3890 * <br/> -3891 * <h4>EXAMPLES</h4> -3892 * @example -3893 * gns = new KJUR.asn1.x509.GeneralNames(); -3894 * gns.setByParamArray([{uri: 'http://aaa.com/'}, {uri: 'http://bbb.com/'}]); -3895 */ -3896 this.setByParamArray = function(paramsArray) { -3897 for (var i = 0; i < paramsArray.length; i++) { -3898 var o = new _KJUR_asn1.x509.GeneralName(paramsArray[i]); -3899 this.asn1Array.push(o); -3900 } -3901 }; -3902 -3903 this.getEncodedHex = function() { -3904 var o = new _KJUR_asn1.DERSequence({'array': this.asn1Array}); -3905 return o.getEncodedHex(); +3769 if (params.uri !== undefined) { +3770 this.type = 'uri'; +3771 v = new _DERIA5String({str: params[this.type]}); +3772 } +3773 +3774 if (params.dn !== undefined) { +3775 this.type = 'dn'; +3776 this.explicit = true; +3777 if (typeof params.dn === "string") { +3778 v = new _X500Name({str: params.dn}); +3779 } else if (params.dn instanceof KJUR.asn1.x509.X500Name) { +3780 v = params.dn; +3781 } else { +3782 v = new _X500Name(params.dn); +3783 } +3784 } +3785 +3786 if (params.ldapdn !== undefined) { +3787 this.type = 'dn'; +3788 this.explicit = true; +3789 v = new _X500Name({ldapstr: params.ldapdn}); +3790 } +3791 +3792 if (params.certissuer !== undefined) { +3793 this.type = 'dn'; +3794 this.explicit = true; +3795 var certStr = params.certissuer; +3796 var certHex = null; +3797 +3798 if (certStr.match(/^[0-9A-Fa-f]+$/)) { +3799 certHex == certStr; +3800 } +3801 +3802 if (certStr.indexOf("-----BEGIN ") != -1) { +3803 certHex = _pemtohex(certStr); +3804 } +3805 +3806 if (certHex == null) throw "certissuer param not cert"; +3807 var x = new X509(); +3808 x.hex = certHex; +3809 var dnHex = x.getIssuerHex(); +3810 v = new _ASN1Object(); +3811 v.hTLV = dnHex; +3812 } +3813 +3814 if (params.certsubj !== undefined) { +3815 this.type = 'dn'; +3816 this.explicit = true; +3817 var certStr = params.certsubj; +3818 var certHex = null; +3819 if (certStr.match(/^[0-9A-Fa-f]+$/)) { +3820 certHex == certStr; +3821 } +3822 if (certStr.indexOf("-----BEGIN ") != -1) { +3823 certHex = _pemtohex(certStr); +3824 } +3825 if (certHex == null) throw "certsubj param not cert"; +3826 var x = new X509(); +3827 x.hex = certHex; +3828 var dnHex = x.getSubjectHex(); +3829 v = new _ASN1Object(); +3830 v.hTLV = dnHex; +3831 } +3832 +3833 if (params.ip !== undefined) { +3834 this.type = 'ip'; +3835 this.explicit = false; +3836 var ip = params.ip; +3837 var hIP; +3838 var malformedIPMsg = "malformed IP address"; +3839 if (ip.match(/^[0-9.]+[.][0-9.]+$/)) { // ipv4 +3840 hIP = intarystrtohex("[" + ip.split(".").join(",") + "]"); +3841 if (hIP.length !== 8) throw malformedIPMsg; +3842 } else if (ip.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)) { // ipv6 +3843 hIP = ipv6tohex(ip); +3844 } else if (ip.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)) { // hex +3845 hIP = ip; +3846 } else { +3847 throw malformedIPMsg; +3848 } +3849 v = new _DEROctetString({hex: hIP}); +3850 } +3851 +3852 if (this.type == null) +3853 throw "unsupported type in params=" + params; +3854 this.asn1Obj = new _DERTaggedObject({'explicit': this.explicit, +3855 'tag': pTag[this.type], +3856 'obj': v}); +3857 }; +3858 +3859 this.getEncodedHex = function() { +3860 return this.asn1Obj.getEncodedHex(); +3861 } +3862 +3863 if (params !== undefined) { +3864 this.setByParam(params); +3865 } +3866 +3867 }; +3868 YAHOO.lang.extend(KJUR.asn1.x509.GeneralName, KJUR.asn1.ASN1Object); +3869 +3870 /** +3871 * GeneralNames ASN.1 structure class<br/> +3872 * @name KJUR.asn1.x509.GeneralNames +3873 * @class GeneralNames ASN.1 structure class +3874 * @description +3875 * <br/> +3876 * <h4>EXAMPLE AND ASN.1 SYNTAX</h4> +3877 * @example +3878 * gns = new KJUR.asn1.x509.GeneralNames([{'uri': 'http://aaa.com/'}, {'uri': 'http://bbb.com/'}]); +3879 * +3880 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName +3881 */ +3882 KJUR.asn1.x509.GeneralNames = function(paramsArray) { +3883 KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this); +3884 var asn1Array = null, +3885 _KJUR = KJUR, +3886 _KJUR_asn1 = _KJUR.asn1; +3887 +3888 /** +3889 * set a array of {@link KJUR.asn1.x509.GeneralName} parameters<br/> +3890 * @name setByParamArray +3891 * @memberOf KJUR.asn1.x509.GeneralNames# +3892 * @function +3893 * @param {Array} paramsArray Array of {@link KJUR.asn1.x509.GeneralNames} +3894 * @description +3895 * <br/> +3896 * <h4>EXAMPLES</h4> +3897 * @example +3898 * gns = new KJUR.asn1.x509.GeneralNames(); +3899 * gns.setByParamArray([{uri: 'http://aaa.com/'}, {uri: 'http://bbb.com/'}]); +3900 */ +3901 this.setByParamArray = function(paramsArray) { +3902 for (var i = 0; i < paramsArray.length; i++) { +3903 var o = new _KJUR_asn1.x509.GeneralName(paramsArray[i]); +3904 this.asn1Array.push(o); +3905 } 3906 }; 3907 -3908 this.asn1Array = new Array(); -3909 if (typeof paramsArray != "undefined") { -3910 this.setByParamArray(paramsArray); -3911 } -3912 }; -3913 YAHOO.lang.extend(KJUR.asn1.x509.GeneralNames, KJUR.asn1.ASN1Object); -3914 -3915 /** -3916 * static object for OID -3917 * @name KJUR.asn1.x509.OID -3918 * @class static object for OID -3919 * @property {Assoc Array} atype2oidList for short attribute type name and oid (ex. 'C' and '2.5.4.6') -3920 * @property {Assoc Array} name2oidList for oid name and oid (ex. 'keyUsage' and '2.5.29.15') -3921 * @property {Assoc Array} objCache for caching name and DERObjectIdentifier object -3922 * @description -3923 * This class defines OID name and values. -3924 * AttributeType names registered in OID.atype2oidList are following: -3925 * <table style="border-width: thin; border-style: solid; witdh: 100%"> -3926 * <tr><th>short</th><th>long</th><th>OID</th></tr> -3927 * <tr><td>CN</td>commonName<td></td><td>2.5.4.3</td></tr> -3928 * <tr><td>L</td><td>localityName</td><td>2.5.4.7</td></tr> -3929 * <tr><td>ST</td><td>stateOrProvinceName</td><td>2.5.4.8</td></tr> -3930 * <tr><td>O</td><td>organizationName</td><td>2.5.4.10</td></tr> -3931 * <tr><td>OU</td><td>organizationalUnitName</td><td>2.5.4.11</td></tr> -3932 * <tr><td>C</td><td></td>countryName<td>2.5.4.6</td></tr> -3933 * <tr><td>STREET</td>streetAddress<td></td><td>2.5.4.6</td></tr> -3934 * <tr><td>DC</td><td>domainComponent</td><td>0.9.2342.19200300.100.1.25</td></tr> -3935 * <tr><td>UID</td><td>userId</td><td>0.9.2342.19200300.100.1.1</td></tr> -3936 * <tr><td>SN</td><td>surname</td><td>2.5.4.4</td></tr> -3937 * <tr><td>DN</td><td>distinguishedName</td><td>2.5.4.49</td></tr> -3938 * <tr><td>E</td><td>emailAddress</td><td>1.2.840.113549.1.9.1</td></tr> -3939 * <tr><td></td><td>businessCategory</td><td>2.5.4.15</td></tr> -3940 * <tr><td></td><td>postalCode</td><td>2.5.4.17</td></tr> -3941 * <tr><td></td><td>jurisdictionOfIncorporationL</td><td>1.3.6.1.4.1.311.60.2.1.1</td></tr> -3942 * <tr><td></td><td>jurisdictionOfIncorporationSP</td><td>1.3.6.1.4.1.311.60.2.1.2</td></tr> -3943 * <tr><td></td><td>jurisdictionOfIncorporationC</td><td>1.3.6.1.4.1.311.60.2.1.3</td></tr> -3944 * </table> -3945 * -3946 * @example -3947 */ -3948 KJUR.asn1.x509.OID = new function(params) { -3949 this.atype2oidList = { -3950 // RFC 4514 AttributeType name string (MUST recognized) -3951 'CN': '2.5.4.3', -3952 'L': '2.5.4.7', -3953 'ST': '2.5.4.8', -3954 'O': '2.5.4.10', -3955 'OU': '2.5.4.11', -3956 'C': '2.5.4.6', -3957 'STREET': '2.5.4.9', -3958 'DC': '0.9.2342.19200300.100.1.25', -3959 'UID': '0.9.2342.19200300.100.1.1', -3960 // other AttributeType name string -3961 // http://blog.livedoor.jp/k_urushima/archives/656114.html -3962 'SN': '2.5.4.4', // surname -3963 'T': '2.5.4.12', // title -3964 'DN': '2.5.4.49', // distinguishedName -3965 'E': '1.2.840.113549.1.9.1', // emailAddress in MS.NET or Bouncy -3966 // other AttributeType name string (no short name) -3967 'description': '2.5.4.13', -3968 'businessCategory': '2.5.4.15', -3969 'postalCode': '2.5.4.17', -3970 'serialNumber': '2.5.4.5', -3971 'uniqueIdentifier': '2.5.4.45', -3972 'organizationIdentifier': '2.5.4.97', -3973 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', -3974 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', -3975 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3' -3976 }; -3977 this.name2oidList = { -3978 'sha1': '1.3.14.3.2.26', -3979 'sha256': '2.16.840.1.101.3.4.2.1', -3980 'sha384': '2.16.840.1.101.3.4.2.2', -3981 'sha512': '2.16.840.1.101.3.4.2.3', -3982 'sha224': '2.16.840.1.101.3.4.2.4', -3983 'md5': '1.2.840.113549.2.5', -3984 'md2': '1.3.14.7.2.2.1', -3985 'ripemd160': '1.3.36.3.2.1', -3986 -3987 'MD2withRSA': '1.2.840.113549.1.1.2', -3988 'MD4withRSA': '1.2.840.113549.1.1.3', -3989 'MD5withRSA': '1.2.840.113549.1.1.4', -3990 'SHA1withRSA': '1.2.840.113549.1.1.5', -3991 'pkcs1-MGF': '1.2.840.113549.1.1.8', -3992 'rsaPSS': '1.2.840.113549.1.1.10', -3993 'SHA224withRSA': '1.2.840.113549.1.1.14', -3994 'SHA256withRSA': '1.2.840.113549.1.1.11', -3995 'SHA384withRSA': '1.2.840.113549.1.1.12', -3996 'SHA512withRSA': '1.2.840.113549.1.1.13', -3997 -3998 'SHA1withECDSA': '1.2.840.10045.4.1', -3999 'SHA224withECDSA': '1.2.840.10045.4.3.1', -4000 'SHA256withECDSA': '1.2.840.10045.4.3.2', -4001 'SHA384withECDSA': '1.2.840.10045.4.3.3', -4002 'SHA512withECDSA': '1.2.840.10045.4.3.4', -4003 -4004 'dsa': '1.2.840.10040.4.1', -4005 'SHA1withDSA': '1.2.840.10040.4.3', -4006 'SHA224withDSA': '2.16.840.1.101.3.4.3.1', -4007 'SHA256withDSA': '2.16.840.1.101.3.4.3.2', +3908 this.getEncodedHex = function() { +3909 var o = new _KJUR_asn1.DERSequence({'array': this.asn1Array}); +3910 return o.getEncodedHex(); +3911 }; +3912 +3913 this.asn1Array = new Array(); +3914 if (typeof paramsArray != "undefined") { +3915 this.setByParamArray(paramsArray); +3916 } +3917 }; +3918 YAHOO.lang.extend(KJUR.asn1.x509.GeneralNames, KJUR.asn1.ASN1Object); +3919 +3920 /** +3921 * static object for OID +3922 * @name KJUR.asn1.x509.OID +3923 * @class static object for OID +3924 * @property {Assoc Array} atype2oidList for short attribute type name and oid (ex. 'C' and '2.5.4.6') +3925 * @property {Assoc Array} name2oidList for oid name and oid (ex. 'keyUsage' and '2.5.29.15') +3926 * @property {Assoc Array} objCache for caching name and DERObjectIdentifier object +3927 * @description +3928 * This class defines OID name and values. +3929 * AttributeType names registered in OID.atype2oidList are following: +3930 * <table style="border-width: thin; border-style: solid; witdh: 100%"> +3931 * <tr><th>short</th><th>long</th><th>OID</th></tr> +3932 * <tr><td>CN</td>commonName<td></td><td>2.5.4.3</td></tr> +3933 * <tr><td>L</td><td>localityName</td><td>2.5.4.7</td></tr> +3934 * <tr><td>ST</td><td>stateOrProvinceName</td><td>2.5.4.8</td></tr> +3935 * <tr><td>O</td><td>organizationName</td><td>2.5.4.10</td></tr> +3936 * <tr><td>OU</td><td>organizationalUnitName</td><td>2.5.4.11</td></tr> +3937 * <tr><td>C</td><td></td>countryName<td>2.5.4.6</td></tr> +3938 * <tr><td>STREET</td>streetAddress<td></td><td>2.5.4.6</td></tr> +3939 * <tr><td>DC</td><td>domainComponent</td><td>0.9.2342.19200300.100.1.25</td></tr> +3940 * <tr><td>UID</td><td>userId</td><td>0.9.2342.19200300.100.1.1</td></tr> +3941 * <tr><td>SN</td><td>surname</td><td>2.5.4.4</td></tr> +3942 * <tr><td>DN</td><td>distinguishedName</td><td>2.5.4.49</td></tr> +3943 * <tr><td>E</td><td>emailAddress</td><td>1.2.840.113549.1.9.1</td></tr> +3944 * <tr><td></td><td>businessCategory</td><td>2.5.4.15</td></tr> +3945 * <tr><td></td><td>postalCode</td><td>2.5.4.17</td></tr> +3946 * <tr><td></td><td>jurisdictionOfIncorporationL</td><td>1.3.6.1.4.1.311.60.2.1.1</td></tr> +3947 * <tr><td></td><td>jurisdictionOfIncorporationSP</td><td>1.3.6.1.4.1.311.60.2.1.2</td></tr> +3948 * <tr><td></td><td>jurisdictionOfIncorporationC</td><td>1.3.6.1.4.1.311.60.2.1.3</td></tr> +3949 * </table> +3950 * +3951 * @example +3952 */ +3953 KJUR.asn1.x509.OID = new function(params) { +3954 this.atype2oidList = { +3955 // RFC 4514 AttributeType name string (MUST recognized) +3956 'CN': '2.5.4.3', +3957 'L': '2.5.4.7', +3958 'ST': '2.5.4.8', +3959 'O': '2.5.4.10', +3960 'OU': '2.5.4.11', +3961 'C': '2.5.4.6', +3962 'STREET': '2.5.4.9', +3963 'DC': '0.9.2342.19200300.100.1.25', +3964 'UID': '0.9.2342.19200300.100.1.1', +3965 // other AttributeType name string +3966 // http://blog.livedoor.jp/k_urushima/archives/656114.html +3967 'SN': '2.5.4.4', // surname +3968 'T': '2.5.4.12', // title +3969 'DN': '2.5.4.49', // distinguishedName +3970 'E': '1.2.840.113549.1.9.1', // emailAddress in MS.NET or Bouncy +3971 // other AttributeType name string (no short name) +3972 'description': '2.5.4.13', +3973 'businessCategory': '2.5.4.15', +3974 'postalCode': '2.5.4.17', +3975 'serialNumber': '2.5.4.5', +3976 'uniqueIdentifier': '2.5.4.45', +3977 'organizationIdentifier': '2.5.4.97', +3978 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', +3979 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', +3980 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3' +3981 }; +3982 this.name2oidList = { +3983 'sha1': '1.3.14.3.2.26', +3984 'sha256': '2.16.840.1.101.3.4.2.1', +3985 'sha384': '2.16.840.1.101.3.4.2.2', +3986 'sha512': '2.16.840.1.101.3.4.2.3', +3987 'sha224': '2.16.840.1.101.3.4.2.4', +3988 'md5': '1.2.840.113549.2.5', +3989 'md2': '1.3.14.7.2.2.1', +3990 'ripemd160': '1.3.36.3.2.1', +3991 +3992 'MD2withRSA': '1.2.840.113549.1.1.2', +3993 'MD4withRSA': '1.2.840.113549.1.1.3', +3994 'MD5withRSA': '1.2.840.113549.1.1.4', +3995 'SHA1withRSA': '1.2.840.113549.1.1.5', +3996 'pkcs1-MGF': '1.2.840.113549.1.1.8', +3997 'rsaPSS': '1.2.840.113549.1.1.10', +3998 'SHA224withRSA': '1.2.840.113549.1.1.14', +3999 'SHA256withRSA': '1.2.840.113549.1.1.11', +4000 'SHA384withRSA': '1.2.840.113549.1.1.12', +4001 'SHA512withRSA': '1.2.840.113549.1.1.13', +4002 +4003 'SHA1withECDSA': '1.2.840.10045.4.1', +4004 'SHA224withECDSA': '1.2.840.10045.4.3.1', +4005 'SHA256withECDSA': '1.2.840.10045.4.3.2', +4006 'SHA384withECDSA': '1.2.840.10045.4.3.3', +4007 'SHA512withECDSA': '1.2.840.10045.4.3.4', 4008 -4009 'rsaEncryption': '1.2.840.113549.1.1.1', -4010 -4011 // X.500 AttributeType defined in RFC 4514 -4012 'commonName': '2.5.4.3', -4013 'countryName': '2.5.4.6', -4014 'localityName': '2.5.4.7', -4015 'stateOrProvinceName': '2.5.4.8', -4016 'streetAddress': '2.5.4.9', -4017 'organizationName': '2.5.4.10', -4018 'organizationalUnitName': '2.5.4.11', -4019 'domainComponent': '0.9.2342.19200300.100.1.25', -4020 'userId': '0.9.2342.19200300.100.1.1', -4021 // other AttributeType name string -4022 'surname': '2.5.4.4', -4023 'title': '2.5.4.12', -4024 'distinguishedName': '2.5.4.49', -4025 'emailAddress': '1.2.840.113549.1.9.1', -4026 // other AttributeType name string (no short name) -4027 'description': '2.5.4.13', -4028 'businessCategory': '2.5.4.15', -4029 'postalCode': '2.5.4.17', -4030 'uniqueIdentifier': '2.5.4.45', -4031 'organizationIdentifier': '2.5.4.97', -4032 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', -4033 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', -4034 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3', -4035 -4036 'subjectDirectoryAttributes': '2.5.29.9', -4037 'subjectKeyIdentifier': '2.5.29.14', -4038 'keyUsage': '2.5.29.15', -4039 'subjectAltName': '2.5.29.17', -4040 'issuerAltName': '2.5.29.18', -4041 'basicConstraints': '2.5.29.19', -4042 'cRLNumber': '2.5.29.20', -4043 'cRLReason': '2.5.29.21', -4044 'nameConstraints': '2.5.29.30', -4045 'cRLDistributionPoints':'2.5.29.31', -4046 'certificatePolicies': '2.5.29.32', -4047 'anyPolicy': '2.5.29.32.0', -4048 'authorityKeyIdentifier':'2.5.29.35', -4049 'policyConstraints': '2.5.29.36', -4050 'extKeyUsage': '2.5.29.37', -4051 'authorityInfoAccess': '1.3.6.1.5.5.7.1.1', -4052 'ocsp': '1.3.6.1.5.5.7.48.1', -4053 'ocspBasic': '1.3.6.1.5.5.7.48.1.1', -4054 'ocspNonce': '1.3.6.1.5.5.7.48.1.2', -4055 'ocspNoCheck': '1.3.6.1.5.5.7.48.1.5', -4056 'caIssuers': '1.3.6.1.5.5.7.48.2', -4057 -4058 'anyExtendedKeyUsage': '2.5.29.37.0', -4059 'serverAuth': '1.3.6.1.5.5.7.3.1', -4060 'clientAuth': '1.3.6.1.5.5.7.3.2', -4061 'codeSigning': '1.3.6.1.5.5.7.3.3', -4062 'emailProtection': '1.3.6.1.5.5.7.3.4', -4063 'timeStamping': '1.3.6.1.5.5.7.3.8', -4064 'ocspSigning': '1.3.6.1.5.5.7.3.9', -4065 -4066 'dateOfBirth': '1.3.6.1.5.5.7.9.1', -4067 'placeOfBirth': '1.3.6.1.5.5.7.9.2', -4068 'gender': '1.3.6.1.5.5.7.9.3', -4069 'countryOfCitizenship': '1.3.6.1.5.5.7.9.4', -4070 'countryOfResidence': '1.3.6.1.5.5.7.9.5', +4009 'dsa': '1.2.840.10040.4.1', +4010 'SHA1withDSA': '1.2.840.10040.4.3', +4011 'SHA224withDSA': '2.16.840.1.101.3.4.3.1', +4012 'SHA256withDSA': '2.16.840.1.101.3.4.3.2', +4013 +4014 'rsaEncryption': '1.2.840.113549.1.1.1', +4015 +4016 // X.500 AttributeType defined in RFC 4514 +4017 'commonName': '2.5.4.3', +4018 'countryName': '2.5.4.6', +4019 'localityName': '2.5.4.7', +4020 'stateOrProvinceName': '2.5.4.8', +4021 'streetAddress': '2.5.4.9', +4022 'organizationName': '2.5.4.10', +4023 'organizationalUnitName': '2.5.4.11', +4024 'domainComponent': '0.9.2342.19200300.100.1.25', +4025 'userId': '0.9.2342.19200300.100.1.1', +4026 // other AttributeType name string +4027 'surname': '2.5.4.4', +4028 'givenName': '2.5.4.42', +4029 'title': '2.5.4.12', +4030 'distinguishedName': '2.5.4.49', +4031 'emailAddress': '1.2.840.113549.1.9.1', +4032 // other AttributeType name string (no short name) +4033 'description': '2.5.4.13', +4034 'businessCategory': '2.5.4.15', +4035 'postalCode': '2.5.4.17', +4036 'uniqueIdentifier': '2.5.4.45', +4037 'organizationIdentifier': '2.5.4.97', +4038 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', +4039 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', +4040 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3', +4041 +4042 'subjectDirectoryAttributes': '2.5.29.9', +4043 'subjectKeyIdentifier': '2.5.29.14', +4044 'keyUsage': '2.5.29.15', +4045 'subjectAltName': '2.5.29.17', +4046 'issuerAltName': '2.5.29.18', +4047 'basicConstraints': '2.5.29.19', +4048 'cRLNumber': '2.5.29.20', +4049 'cRLReason': '2.5.29.21', +4050 'nameConstraints': '2.5.29.30', +4051 'cRLDistributionPoints':'2.5.29.31', +4052 'certificatePolicies': '2.5.29.32', +4053 'anyPolicy': '2.5.29.32.0', +4054 'authorityKeyIdentifier':'2.5.29.35', +4055 'policyConstraints': '2.5.29.36', +4056 'extKeyUsage': '2.5.29.37', +4057 'authorityInfoAccess': '1.3.6.1.5.5.7.1.1', +4058 'ocsp': '1.3.6.1.5.5.7.48.1', +4059 'ocspBasic': '1.3.6.1.5.5.7.48.1.1', +4060 'ocspNonce': '1.3.6.1.5.5.7.48.1.2', +4061 'ocspNoCheck': '1.3.6.1.5.5.7.48.1.5', +4062 'caIssuers': '1.3.6.1.5.5.7.48.2', +4063 +4064 'anyExtendedKeyUsage': '2.5.29.37.0', +4065 'serverAuth': '1.3.6.1.5.5.7.3.1', +4066 'clientAuth': '1.3.6.1.5.5.7.3.2', +4067 'codeSigning': '1.3.6.1.5.5.7.3.3', +4068 'emailProtection': '1.3.6.1.5.5.7.3.4', +4069 'timeStamping': '1.3.6.1.5.5.7.3.8', +4070 'ocspSigning': '1.3.6.1.5.5.7.3.9', 4071 -4072 'ecPublicKey': '1.2.840.10045.2.1', -4073 'P-256': '1.2.840.10045.3.1.7', -4074 'secp256r1': '1.2.840.10045.3.1.7', -4075 'secp256k1': '1.3.132.0.10', -4076 'secp384r1': '1.3.132.0.34', +4072 'dateOfBirth': '1.3.6.1.5.5.7.9.1', +4073 'placeOfBirth': '1.3.6.1.5.5.7.9.2', +4074 'gender': '1.3.6.1.5.5.7.9.3', +4075 'countryOfCitizenship': '1.3.6.1.5.5.7.9.4', +4076 'countryOfResidence': '1.3.6.1.5.5.7.9.5', 4077 -4078 'pkcs5PBES2': '1.2.840.113549.1.5.13', -4079 'pkcs5PBKDF2': '1.2.840.113549.1.5.12', -4080 -4081 'des-EDE3-CBC': '1.2.840.113549.3.7', -4082 -4083 'data': '1.2.840.113549.1.7.1', // CMS data -4084 'signed-data': '1.2.840.113549.1.7.2', // CMS signed-data -4085 'enveloped-data': '1.2.840.113549.1.7.3', // CMS enveloped-data -4086 'digested-data': '1.2.840.113549.1.7.5', // CMS digested-data -4087 'encrypted-data': '1.2.840.113549.1.7.6', // CMS encrypted-data -4088 'authenticated-data': '1.2.840.113549.1.9.16.1.2', // CMS authenticated-data -4089 'tstinfo': '1.2.840.113549.1.9.16.1.4', // RFC3161 TSTInfo -4090 'signingCertificate': '1.2.840.113549.1.9.16.2.12',// SMIME -4091 'timeStampToken': '1.2.840.113549.1.9.16.2.14',// sigTS -4092 'signaturePolicyIdentifier': '1.2.840.113549.1.9.16.2.15',// cades -4093 'etsArchiveTimeStamp': '1.2.840.113549.1.9.16.2.27',// SMIME -4094 'signingCertificateV2': '1.2.840.113549.1.9.16.2.47',// SMIME -4095 'etsArchiveTimeStampV2':'1.2.840.113549.1.9.16.2.48',// SMIME -4096 'extensionRequest': '1.2.840.113549.1.9.14',// CSR extensionRequest -4097 'contentType': '1.2.840.113549.1.9.3',//PKCS#9 -4098 'messageDigest': '1.2.840.113549.1.9.4',//PKCS#9 -4099 'signingTime': '1.2.840.113549.1.9.5',//PKCS#9 -4100 'counterSignature': '1.2.840.113549.1.9.6',//PKCS#9 -4101 'archiveTimeStampV3': '0.4.0.1733.2.4',//ETSI EN29319122/TS101733 -4102 'pdfRevocationInfoArchival':'1.2.840.113583.1.1.8', //Adobe -4103 'adobeTimeStamp': '1.2.840.113583.1.1.9.1' // Adobe -4104 }; -4105 -4106 this.objCache = {}; -4107 -4108 /** -4109 * get DERObjectIdentifier by registered OID name -4110 * @name name2obj -4111 * @memberOf KJUR.asn1.x509.OID -4112 * @function -4113 * @param {String} name OID -4114 * @description -4115 * @example -4116 * var asn1ObjOID = OID.name2obj('SHA1withRSA'); -4117 */ -4118 this.name2obj = function(name) { -4119 if (typeof this.objCache[name] != "undefined") -4120 return this.objCache[name]; -4121 if (typeof this.name2oidList[name] == "undefined") -4122 throw "Name of ObjectIdentifier not defined: " + name; -4123 var oid = this.name2oidList[name]; -4124 var obj = new KJUR.asn1.DERObjectIdentifier({'oid': oid}); -4125 this.objCache[name] = obj; -4126 return obj; -4127 }; -4128 -4129 /** -4130 * get DERObjectIdentifier by registered attribute type name such like 'C' or 'CN'<br/> -4131 * @name atype2obj -4132 * @memberOf KJUR.asn1.x509.OID -4133 * @function -4134 * @param {String} atype short attribute type name such like 'C' or 'CN' -4135 * @description -4136 * @example -4137 * KJUR.asn1.x509.OID.atype2obj('CN') → 2.5.4.3 -4138 * KJUR.asn1.x509.OID.atype2obj('OU') → 2.5.4.11 -4139 */ -4140 this.atype2obj = function(atype) { -4141 if (typeof this.objCache[atype] != "undefined") -4142 return this.objCache[atype]; -4143 if (typeof this.atype2oidList[atype] == "undefined") -4144 throw "AttributeType name undefined: " + atype; -4145 var oid = this.atype2oidList[atype]; -4146 var obj = new KJUR.asn1.DERObjectIdentifier({'oid': oid}); -4147 this.objCache[atype] = obj; -4148 return obj; -4149 }; -4150 }; -4151 -4152 /** -4153 * convert OID to name<br/> -4154 * @name oid2name -4155 * @memberOf KJUR.asn1.x509.OID -4156 * @function -4157 * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4) -4158 * @return {String} OID name if registered otherwise empty string -4159 * @since asn1x509 1.0.9 -4160 * @description -4161 * This static method converts OID string to its name. -4162 * If OID is undefined then it returns empty string (i.e. ''). -4163 * @example -4164 * KJUR.asn1.x509.OID.oid2name("1.3.6.1.5.5.7.1.1") → 'authorityInfoAccess' -4165 */ -4166 KJUR.asn1.x509.OID.oid2name = function(oid) { -4167 var list = KJUR.asn1.x509.OID.name2oidList; -4168 for (var name in list) { -4169 if (list[name] == oid) return name; -4170 } -4171 return ''; -4172 }; -4173 -4174 /** -4175 * convert OID to AttributeType name<br/> -4176 * @name oid2atype -4177 * @memberOf KJUR.asn1.x509.OID -4178 * @function -4179 * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4) -4180 * @return {String} OID AttributeType name if registered otherwise oid -4181 * @since jsrsasign 6.2.2 asn1x509 1.0.18 -4182 * @description -4183 * This static method converts OID string to its AttributeType name. -4184 * If OID is not defined in OID.atype2oidList associative array then it returns OID -4185 * specified as argument. -4186 * @example -4187 * KJUR.asn1.x509.OID.oid2atype("2.5.4.3") → CN -4188 * KJUR.asn1.x509.OID.oid2atype("1.3.6.1.4.1.311.60.2.1.3") → jurisdictionOfIncorporationC -4189 * KJUR.asn1.x509.OID.oid2atype("0.1.2.3.4") → 0.1.2.3.4 // unregistered OID -4190 */ -4191 KJUR.asn1.x509.OID.oid2atype = function(oid) { -4192 var list = KJUR.asn1.x509.OID.atype2oidList; -4193 for (var atype in list) { -4194 if (list[atype] == oid) return atype; -4195 } -4196 return oid; -4197 }; -4198 -4199 /** -4200 * convert OID name to OID value<br/> -4201 * @name name2oid -4202 * @memberOf KJUR.asn1.x509.OID -4203 * @function -4204 * @param {String} name OID name or OID (ex. "sha1" or "1.2.3.4") -4205 * @return {String} dot noted Object Identifer string (ex. 1.2.3.4) -4206 * @since asn1x509 1.0.11 -4207 * @description -4208 * This static method converts from OID name to OID string. -4209 * If OID is undefined then it returns empty string (i.e. ''). -4210 * @example -4211 * KJUR.asn1.x509.OID.name2oid("authorityInfoAccess") → "1.3.6.1.5.5.7.1.1" -4212 * KJUR.asn1.x509.OID.name2oid("1.2.3.4") → "1.2.3.4" -4213 * KJUR.asn1.x509.OID.name2oid("UNKNOWN NAME") → "" -4214 */ -4215 KJUR.asn1.x509.OID.name2oid = function(name) { -4216 if (name.match(/^[0-9.]+$/)) return name; -4217 var list = KJUR.asn1.x509.OID.name2oidList; -4218 if (list[name] === undefined) return ''; -4219 return list[name]; -4220 }; -4221 -4222 /** -4223 * X.509 certificate and CRL utilities class<br/> -4224 * @name KJUR.asn1.x509.X509Util -4225 * @class X.509 certificate and CRL utilities class -4226 */ -4227 KJUR.asn1.x509.X509Util = {}; -4228 -4229 /** -4230 * issue a certificate in PEM format (DEPRECATED) -4231 * @name newCertPEM -4232 * @memberOf KJUR.asn1.x509.X509Util -4233 * @function -4234 * @param {Array} param JSON object of parameter to issue a certificate -4235 * @since asn1x509 1.0.6 -4236 * @deprecated since jsrsasign 9.0.0 asn1x509 2.0.0. please move to {@link KJUR.asn1.x509.Certificate} constructor -4237 * @description -4238 * This method can issue a certificate by a simple -4239 * JSON object. -4240 * Signature value will be provided by signing with -4241 * private key using 'cakey' parameter or -4242 * hexadecimal signature value by 'sighex' parameter. -4243 * <br/> -4244 * NOTE: Algorithm parameter of AlgorithmIdentifier will -4245 * be set automatically by default. -4246 * (see {@link KJUR.asn1.x509.AlgorithmIdentifier}) -4247 * from jsrsasign 7.1.1 asn1x509 1.0.20. -4248 * <br/> -4249 * NOTE2: -4250 * RSA-PSS algorithm has been supported from jsrsasign 8.0.21. -4251 * As for RSA-PSS signature algorithm names and signing parameters -4252 * such as MGF function and salt length, please see -4253 * {@link KJUR.asn1.x509.AlgorithmIdentifier} class. -4254 * -4255 * @example -4256 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4257 * serial: {int: 4}, -4258 * sigalg: {name: 'SHA1withECDSA'}, -4259 * issuer: {str: '/C=US/O=a'}, -4260 * notbefore: {'str': '130504235959Z'}, -4261 * notafter: {'str': '140504235959Z'}, -4262 * subject: {str: '/C=US/O=b'}, -4263 * sbjpubkey: pubKeyObj, -4264 * ext: [ -4265 * {basicConstraints: {cA: true, critical: true}}, -4266 * {keyUsage: {bin: '11'}}, -4267 * ], -4268 * cakey: prvKeyObj -4269 * }); -4270 * // -- or -- -4271 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4272 * serial: {int: 4}, -4273 * sigalg: {name: 'SHA1withECDSA'}, -4274 * issuer: {str: '/C=US/O=a'}, -4275 * notbefore: {'str': '130504235959Z'}, -4276 * notafter: {'str': '140504235959Z'}, -4277 * subject: {str: '/C=US/O=b'}, -4278 * sbjpubkey: pubKeyPEM, -4279 * ext: [ -4280 * {basicConstraints: {cA: true, critical: true}}, -4281 * {keyUsage: {bin: '11'}}, -4282 * ], -4283 * cakey: [prvkey, pass]} -4284 * ); -4285 * // -- or -- -4286 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4287 * serial: {int: 1}, -4288 * sigalg: {name: 'SHA1withRSA'}, -4289 * issuer: {str: '/C=US/O=T1'}, -4290 * notbefore: {'str': '130504235959Z'}, -4291 * notafter: {'str': '140504235959Z'}, -4292 * subject: {str: '/C=US/O=T1'}, -4293 * sbjpubkey: pubKeyObj, -4294 * sighex: '0102030405..' -4295 * }); -4296 * // for the issuer and subject field, another -4297 * // representation is also available -4298 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4299 * serial: {int: 1}, -4300 * sigalg: {name: 'SHA256withRSA'}, -4301 * issuer: {C: "US", O: "T1"}, -4302 * notbefore: {'str': '130504235959Z'}, -4303 * notafter: {'str': '140504235959Z'}, -4304 * subject: {C: "US", O: "T1", CN: "http://example.com/"}, -4305 * sbjpubkey: pubKeyObj, -4306 * sighex: '0102030405..' -4307 * }); -4308 */ -4309 KJUR.asn1.x509.X509Util.newCertPEM = function(param) { -4310 var _KJUR_asn1_x509 = KJUR.asn1.x509, -4311 _TBSCertificate = _KJUR_asn1_x509.TBSCertificate, -4312 _Certificate = _KJUR_asn1_x509.Certificate; -4313 var cert = new _Certificate(param); -4314 return cert.getPEM(); -4315 }; -4316 -4317