diff --git a/ChangeLog.txt b/ChangeLog.txt index c1a5d400..43359bba 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,23 @@ ChangeLog for jsrsasign +more SubjectDirectoryExtension support +* Changes from 10.8.3 to 10.8.4 (2023-Apr-26) + - src/asn1x509.js + - SubjectDirectoryAttributes class + - add array of array support for arbitrary attribute value + - src/x509.js + - add X509.getExtSubjectDirectoryAttributes method for + ExtSubjectDirectoryAttributes extension + - update X509.getExtParam method + - support SubjectDirectoryAttributes + - parse unknown extension as ASN.1 + - src/base64x.js + - bugfix foldnl function: when length of s is multiple of n, + result has unnecessary new line in the end of string. + - qunit-do-{asn1x509,x509-ext,base64x,x500-param}.html + - update and add some test cases for above + CABF SMIMEBR OID support * Changes from 10.8.2 to 10.8.3 (2023-Apr-20) - src/asn1x509.js diff --git a/README.md b/README.md index f4d8c6ae..700f91ab 100755 --- a/README.md +++ b/README.md @@ -53,7 +53,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 [1M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2023-04-05) +- very popular crypto library with [1M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2023-04-20) - supports "Add-on" architecture INSTALL diff --git a/api/files.html b/api/files.html index d065bc70..21039485 100644 --- a/api/files.html +++ b/api/files.html @@ -668,7 +668,7 @@
+SubjectDirectoryAttributes ::= Attributes +Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute +Attribute ::= SEQUENCE { + type AttributeType + values SET OF AttributeValue } +AttributeType ::= OBJECT IDENTIFIER +AttributeValue ::= ANY DEFINED BY AttributeType ++
x.getExtSubjectDirectoryAttributes(<+ + + + +>) → +{ "extname": "SubjectDirectoryAttributes", + "array": [ + { "attr": "gender", "array": [{"prnstr": {"str": "female"}}] }, + { "attr": "1.2.3.4.5", "array": [{"prnstr": {"str": "aaa"}}, {"utf8str": {"str": "bbb"}}] } + ] }
1 /* asn1x509-2.1.18.js (c) 2013-2022 Kenji Urushima | kjur.github.io/jsrsasign/license +1 /* asn1x509-2.1.20.js (c) 2013-2022 Kenji Urushima | kjur.github.io/jsrsasign/license 2 */ 3 /* 4 * asn1x509.js - ASN.1 DER encoder classes for X.509 certificate 5 * - 6 * Copyright (c) 2013-2022 Kenji Urushima (kenji.urushima@gmail.com) + 6 * Copyright (c) 2013-2023 Kenji Urushima (kenji.urushima@gmail.com) 7 * 8 * This software is licensed under the terms of the MIT License. 9 * https://kjur.github.io/jsrsasign/license @@ -23,7 +23,7 @@ 16 * @fileOverview 17 * @name asn1x509-1.0.js 18 * @author Kenji Urushima kenji.urushima@gmail.com - 19 * @version jsrsasign 10.6.1 asn1x509 2.1.18 (2022-Nov-20) + 19 * @version jsrsasign 10.8.4 asn1x509 2.1.20 (2023-Apr-26) 20 * @since jsrsasign 2.1 21 * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a> 22 */ @@ -2276,2674 +2276,2702 @@ 2269 * @param {Array} params associative array of parameters 2270 * @extends KJUR.asn1.x509.Extension 2271 * @since jsrsasign 10.1.9 asn1x509 2.1.7 -2272 * @description -2273 * This class provides X.509v3 SubjectDirectoryAttributes extension -2274 * defined in <a href="https://tools.ietf.org/html/rfc3739#section-3.3.2"> -2275 * RFC 3739 Qualified Certificate Profile section 3.3.2</a>. -2276 * <pre> -2277 * SubjectDirectoryAttributes ::= Attributes -2278 * Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute -2279 * Attribute ::= SEQUENCE { -2280 * type AttributeType -2281 * values SET OF AttributeValue } -2282 * AttributeType ::= OBJECT IDENTIFIER -2283 * AttributeValue ::= ANY DEFINED BY AttributeType -2284 * </pre> -2285 * @example -2286 * e1 = new KJUR.asn1.x509.SubjectDirectoryAttributes({ -2287 * extname: "subjectDirectoryAttributes", -2288 * array: [ -2289 * { attr: "dateOfBirth", str: "19701231230000Z" }, -2290 * { attr: "placeOfBirth", str: "Tokyo" }, -2291 * { attr: "gender", str: "F" }, -2292 * { attr: "countryOfCitizenship", str: "JP" }, -2293 * { attr: "countryOfResidence", str: "JP" } -2294 * ] -2295 * }); -2296 */ -2297 KJUR.asn1.x509.SubjectDirectoryAttributes = function(params) { -2298 KJUR.asn1.x509.SubjectDirectoryAttributes.superclass.constructor.call(this, params); -2299 var _KJUR_asn1 = KJUR.asn1, -2300 _DERSequence = _KJUR_asn1.DERSequence, -2301 _newObject = _KJUR_asn1.ASN1Util.newObject, -2302 _name2oid = _KJUR_asn1.x509.OID.name2oid; -2303 -2304 this.params = null; -2305 -2306 this.getExtnValueHex = function() { -2307 var a = []; -2308 for (var i = 0; i < this.params.array.length; i++) { -2309 var pAttr = this.params.array[i]; -2310 -2311 var newparam = { -2312 "seq": [ -2313 {"oid": "1.2.3.4"}, -2314 {"set": [{"utf8str": "DE"}]} -2315 ] -2316 }; -2317 -2318 if (pAttr.attr == "dateOfBirth") { -2319 newparam.seq[0].oid = _name2oid(pAttr.attr); -2320 newparam.seq[1].set[0] = {"gentime": pAttr.str}; -2321 } else if (pAttr.attr == "placeOfBirth") { -2322 newparam.seq[0].oid = _name2oid(pAttr.attr); -2323 newparam.seq[1].set[0] = {"utf8str": pAttr.str}; -2324 } else if (pAttr.attr == "gender") { -2325 newparam.seq[0].oid = _name2oid(pAttr.attr); -2326 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; -2327 } else if (pAttr.attr == "countryOfCitizenship") { -2328 newparam.seq[0].oid = _name2oid(pAttr.attr); -2329 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; -2330 } else if (pAttr.attr == "countryOfResidence") { -2331 newparam.seq[0].oid = _name2oid(pAttr.attr); -2332 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; -2333 } else { -2334 throw new Error("unsupported attribute: " + pAttr.attr); -2335 } -2336 a.push(new _newObject(newparam)); -2337 } -2338 var seq = new _DERSequence({array: a}); -2339 this.asn1ExtnValue = seq; -2340 return this.asn1ExtnValue.tohex(); -2341 }; -2342 -2343 this.oid = "2.5.29.9"; -2344 if (params !== undefined) { -2345 this.params = params; -2346 } -2347 }; -2348 extendClass(KJUR.asn1.x509.SubjectDirectoryAttributes, KJUR.asn1.x509.Extension); -2349 -2350 -2351 /** -2352 * priavte extension ASN.1 structure class<br/> -2353 * @name KJUR.asn1.x509.PrivateExtension -2354 * @class private extension ASN.1 structure class -2355 * @param {Array} params JSON object of private extension -2356 * @extends KJUR.asn1.x509.Extension -2357 * @since jsrsasign 9.1.1 asn1x509 -2358 * @see KJUR.asn1.ASN1Util.newObject -2359 * -2360 * @description -2361 * This class is to represent private extension or -2362 * unsupported extension. -2363 * <pre> -2364 * Extension ::= SEQUENCE { -2365 * extnID OBJECT IDENTIFIER, -2366 * critical BOOLEAN DEFAULT FALSE, -2367 * extnValue OCTET STRING } -2368 * </pre> -2369 * Following properties can be set for JSON parameter: -2370 * <ul> -2371 * <li>{String}extname - string of OID or predefined extension name</li> -2372 * <li>{Boolean}critical - critical flag</li> -2373 * <li>{Object}extn - hexadecimal string or -2374 * of {@link KJUR.asn1.ASN1Util.newObject} -2375 * JSON parameter for extnValue field</li> -2376 * </li> -2377 * </ul> -2378 * -2379 * @example -2380 * // extn by hexadecimal -2381 * new KJUR.asn1.x509.PrivateExtension({ -2382 * extname: "1.2.3.4", -2383 * critical: true, -2384 * extn: "13026161" // means PrintableString "aa" -2385 * }); -2386 * -2387 * // extn by JSON parameter -2388 * new KJUR.asn1.x509.PrivateExtension({ -2389 * extname: "1.2.3.5", -2390 * extn: {seq: [{prnstr:"abc"},{utf8str:"def"}]} -2391 * }); -2392 */ -2393 KJUR.asn1.x509.PrivateExtension = function(params) { -2394 KJUR.asn1.x509.PrivateExtension.superclass.constructor.call(this, params) -2395 -2396 var _KJUR = KJUR, -2397 _isHex = _KJUR.lang.String.isHex, -2398 _KJUR_asn1 = _KJUR.asn1, -2399 _name2oid = _KJUR_asn1.x509.OID.name2oid, -2400 _newObject = _KJUR_asn1.ASN1Util.newObject; -2401 -2402 this.params = null; -2403 -2404 this.setByParam = function(params) { -2405 this.oid = _name2oid(params.extname); -2406 this.params = params; -2407 }; -2408 -2409 this.getExtnValueHex = function() { -2410 if (this.params.extname == undefined || -2411 this.params.extn == undefined) { -2412 throw new Error("extname or extnhex not specified"); -2413 } -2414 -2415 var extn = this.params.extn; -2416 if (typeof extn == "string" && _isHex(extn)) { -2417 return extn; -2418 } else if (typeof extn == "object") { -2419 try { -2420 return _newObject(extn).tohex(); -2421 } catch(ex) {} -2422 } -2423 throw new Error("unsupported extn value"); -2424 }; -2425 -2426 if (params != undefined) { -2427 this.setByParam(params); -2428 } -2429 }; -2430 extendClass(KJUR.asn1.x509.PrivateExtension, KJUR.asn1.x509.Extension); -2431 -2432 // === END X.509v3 Extensions Related ======================================= -2433 -2434 // === BEGIN CRL Related =================================================== -2435 /** -2436 * X.509 CRL class to sign and generate hex encoded CRL<br/> -2437 * @name KJUR.asn1.x509.CRL -2438 * @class X.509 CRL class to sign and generate hex encoded certificate -2439 * @property {Array} params JSON object of parameters -2440 * @param {Array} params JSON object of CRL parameters -2441 * @extends KJUR.asn1.ASN1Object -2442 * @since 1.0.3 -2443 * @see KJUR.asn1.x509.TBSCertList -2444 * -2445 * @description -2446 * This class represents CertificateList ASN.1 structur of X.509 CRL -2447 * defined in <a href="https://tools.ietf.org/html/rfc5280#section-5.1"> -2448 * RFC 5280 5.1</a> -2449 * <pre> -2450 * CertificateList ::= SEQUENCE { -2451 * tbsCertList TBSCertList, -2452 * signatureAlgorithm AlgorithmIdentifier, -2453 * signatureValue BIT STRING } -2454 * </pre> -2455 * NOTE: CRL class is updated without backward -2456 * compatibility from jsrsasign 9.1.0 asn1x509 2.1.0. -2457 * Most of methods are removed and parameters can be set -2458 * by JSON object. -2459 * <br/> -2460 * Constructor of this class can accept all -2461 * parameters of {@link KJUR.asn1.x509.TBSCertList}. -2462 * It also accept following parameters additionally: -2463 * <ul> -2464 * <li>{TBSCertList}tbsobj (OPTION) - -2465 * specifies {@link KJUR.asn1.x509.TBSCertList} -2466 * object to be signed if needed. -2467 * When this isn't specified, -2468 * this will be set from other parametes of TBSCertList.</li> -2469 * <li>{Object}cakey (OPTION) - specifies CRL signing private key. -2470 * Parameter "cakey" or "sighex" shall be specified. Following -2471 * values can be specified: -2472 * <ul> -2473 * <li>PKCS#1/5 or PKCS#8 PEM string of private key</li> -2474 * <li>RSAKey/DSA/ECDSA key object. {@link KEYUTIL.getKey} is useful -2475 * to generate a key object.</li> -2476 * </ul> -2477 * </li> -2478 * <li>{String}sighex (OPTION) - hexadecimal string of signature value -2479 * (i.e. ASN.1 value(V) of signatureValue BIT STRING without -2480 * unused bits)</li> -2481 * </ul> -2482 * -2483 * @example -2484 * var crl = new KJUR.asn1.x509.CRL({ -2485 * sigalg: "SHA256withRSA", -2486 * issuer: {str:'/C=JP/O=Test1'}, -2487 * thisupdate: "200821235959Z", -2488 * nextupdate: "200828235959Z", // OPTION -2489 * revcert: [{sn: {hex: "12ab"}, date: "200401235959Z"}], -2490 * ext: [ -2491 * {extname: "cRLNumber", num: {'int': 8}}, -2492 * {extname: "authorityKeyIdentifier", "kid": {hex: "12ab"}} -2493 * ], -2494 * cakey: prvkey -2495 * }); -2496 * crl.gettohex() → "30..." -2497 * crl.getPEM() → "-----BEGIN X509 CRL..." -2498 */ -2499 KJUR.asn1.x509.CRL = function(params) { -2500 KJUR.asn1.x509.CRL.superclass.constructor.call(this); -2501 var _KJUR = KJUR, -2502 _KJUR_asn1 = _KJUR.asn1, -2503 _DERSequence = _KJUR_asn1.DERSequence, -2504 _DERBitString = _KJUR_asn1.DERBitString, -2505 _KJUR_asn1_x509 = _KJUR_asn1.x509, -2506 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, -2507 _TBSCertList = _KJUR_asn1_x509.TBSCertList; -2508 -2509 this.params = undefined; -2510 -2511 this.setByParam = function(params) { -2512 this.params = params; -2513 }; -2514 -2515 /** -2516 * sign CRL<br/> -2517 * @name sign -2518 * @memberOf KJUR.asn1.x509.CRL# -2519 * @function -2520 * @description -2521 * This method signs TBSCertList with a specified -2522 * private key and algorithm by -2523 * this.params.cakey and this.params.sigalg parameter. -2524 * @example -2525 * crl = new KJUR.asn1.x509.CRL({..., cakey:prvkey}); -2526 * crl.sign() -2527 */ -2528 this.sign = function() { -2529 var hTBSCL = (new _TBSCertList(this.params)).tohex(); -2530 var sig = new KJUR.crypto.Signature({alg: this.params.sigalg}); -2531 sig.init(this.params.cakey); -2532 sig.updateHex(hTBSCL); -2533 var sighex = sig.sign(); -2534 this.params.sighex = sighex; -2535 }; -2536 -2537 /** -2538 * get PEM formatted CRL string after signed<br/> -2539 * @name getPEM -2540 * @memberOf KJUR.asn1.x509.CRL# -2541 * @function -2542 * @return PEM formatted string of CRL -2543 * @since jsrsasign 9.1.0 asn1hex 2.1.0 -2544 * @description -2545 * This method returns a string of PEM formatted -2546 * CRL. -2547 * @example -2548 * crl = new KJUR.asn1.x509.CRL({...}); -2549 * crl.getPEM() → -2550 * "-----BEGIN X509 CRL-----\r\n..." -2551 */ -2552 this.getPEM = function() { -2553 return hextopem(this.tohex(), "X509 CRL"); -2554 }; -2555 -2556 this.tohex = function() { -2557 var params = this.params; -2558 -2559 if (params.tbsobj == undefined) { -2560 params.tbsobj = new _TBSCertList(params); -2561 } -2562 -2563 if (params.sighex == undefined && params.cakey != undefined) { -2564 this.sign(); -2565 } -2566 -2567 if (params.sighex == undefined) { -2568 throw new Error("sighex or cakey parameter not defined"); -2569 } -2570 -2571 var a = []; -2572 a.push(params.tbsobj); -2573 a.push(new _AlgorithmIdentifier({name: params.sigalg})); -2574 a.push(new _DERBitString({hex: "00" + params.sighex})); -2575 var seq = new _DERSequence({array: a}); -2576 return seq.tohex(); -2577 }; -2578 this.getEncodedHex = function() { return this.tohex(); }; -2579 -2580 if (params != undefined) this.params = params; -2581 }; -2582 extendClass(KJUR.asn1.x509.CRL, KJUR.asn1.ASN1Object); -2583 -2584 /** -2585 * ASN.1 TBSCertList ASN.1 structure class for CRL<br/> -2586 * @name KJUR.asn1.x509.TBSCertList -2587 * @class TBSCertList ASN.1 structure class for CRL -2588 * @property {Array} params JSON object of parameters -2589 * @param {Array} params JSON object of TBSCertList parameters -2590 * @extends KJUR.asn1.ASN1Object -2591 * @since 1.0.3 -2592 * -2593 * @description -2594 * This class represents TBSCertList of CRL defined in -2595 * <a href="https://tools.ietf.org/html/rfc5280#section-5.1"> -2596 * RFC 5280 5.1</a>. -2597 * <pre> -2598 * TBSCertList ::= SEQUENCE { -2599 * version Version OPTIONAL, -2600 * -- if present, MUST be v2 -2601 * signature AlgorithmIdentifier, -2602 * issuer Name, -2603 * thisUpdate Time, -2604 * nextUpdate Time OPTIONAL, -2605 * revokedCertificates SEQUENCE OF SEQUENCE { -2606 * userCertificate CertificateSerialNumber, -2607 * revocationDate Time, -2608 * crlEntryExtensions Extensions OPTIONAL -2609 * -- if present, version MUST be v2 -2610 * } OPTIONAL, -2611 * crlExtensions [0] EXPLICIT Extensions OPTIONAL -2612 * } -2613 * </pre> -2614 * NOTE: TBSCertList class is updated without backward -2615 * compatibility from jsrsasign 9.1.0 asn1x509 2.1.0. -2616 * Most of methods are removed and parameters can be set -2617 * by JSON object. -2618 * <br/> -2619 * Constructor of this class may have following parameters: -2620 * <ul> -2621 * <li>{Integer}version (OPTION) - version number. Omitted by default.</li> -2622 * <li>{String}sigalg - signature algorithm name</li> -2623 * <li>{Array}issuer - issuer parameter of {@link KJUR.asn1.x509.X500Name}</li> -2624 * <li>{String}thisupdate - thisUpdate field value</li> -2625 * <li>{String}nextupdate (OPTION) - thisUpdate field value</li> -2626 * <li>{Array}revcert (OPTION) - revokedCertificates field value as array -2627 * Its element may have following property: -2628 * <ul> -2629 * <li>{Array}sn - serialNumber of userCertificate field specified -2630 * by {@link KJUR.asn1.DERInteger}</li> -2631 * <li>{String}date - revocationDate field specified by -2632 * a string of {@link KJUR.asn1.x509.Time} parameter</li> -2633 * <li>{Array}ext (OPTION) - array of CRL entry extension parameter</li> -2634 * </ul> -2635 * </li> -2636 * </ul> -2637 * -2638 * @example -2639 * var o = new KJUR.asn1.x509.TBSCertList({ -2640 * sigalg: "SHA256withRSA", -2641 * issuer: {array: [[{type:'C',value:'JP',ds:'prn'}], -2642 * [{type:'O',value:'T1',ds:'prn'}]]}, -2643 * thisupdate: "200821235959Z", -2644 * nextupdate: "200828235959Z", // OPTION -2645 * revcert: [ -2646 * {sn: {hex: "12ab"}, date: "200401235959Z", ext: [{extname: "cRLReason", code:1}]}, -2647 * {sn: {hex: "12bc"}, date: "200405235959Z", ext: [{extname: "cRLReason", code:2}]} -2648 * ], -2649 * ext: [ -2650 * {extname: "cRLNumber", num: {'int': 8}}, -2651 * {extname: "authorityKeyIdentifier", "kid": {hex: "12ab"}} -2652 * ] -2653 * }); -2654 * o.tohex() → "30..." -2655 */ -2656 KJUR.asn1.x509.TBSCertList = function(params) { -2657 KJUR.asn1.x509.TBSCertList.superclass.constructor.call(this); -2658 var _KJUR = KJUR, -2659 _KJUR_asn1 = _KJUR.asn1, -2660 _DERInteger = _KJUR_asn1.DERInteger, -2661 _DERSequence = _KJUR_asn1.DERSequence, -2662 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, -2663 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, -2664 _KJUR_asn1_x509 = _KJUR_asn1.x509, -2665 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, -2666 _Time = _KJUR_asn1_x509.Time, -2667 _Extensions = _KJUR_asn1_x509.Extensions, -2668 _X500Name = _KJUR_asn1_x509.X500Name; -2669 this.params = null; -2670 -2671 /** -2672 * get array of ASN.1 object for extensions<br/> -2673 * @name setByParam -2674 * @memberOf KJUR.asn1.x509.TBSCertList# -2675 * @function -2676 * @param {Array} JSON object of TBSCertList parameters -2677 * @example -2678 * tbsc = new KJUR.asn1.x509.TBSCertificate(); -2679 * tbsc.setByParam({version:3, serial:{hex:'1234...'},...}); -2680 */ -2681 this.setByParam = function(params) { -2682 this.params = params; -2683 }; +2272 * @see +2273 * +2274 * @description +2275 * This class provides X.509v3 SubjectDirectoryAttributes extension +2276 * defined in <a href="https://tools.ietf.org/html/rfc3739#section-3.3.2"> +2277 * RFC 3739 Qualified Certificate Profile section 3.3.2</a>. +2278 * <pre> +2279 * SubjectDirectoryAttributes ::= Attributes +2280 * Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute +2281 * Attribute ::= SEQUENCE { +2282 * type AttributeType +2283 * values SET OF AttributeValue } +2284 * AttributeType ::= OBJECT IDENTIFIER +2285 * AttributeValue ::= ANY DEFINED BY AttributeType +2286 * </pre> +2287 * Value of member "array" is an array which as following associative arrays as elements: +2288 * <ul> +2289 * <li>attr: OID name or value of attribute type (ex. "gender" or "1.2.3.4")</li> +2290 * <li>str: attribute value of pre defined types (See example for registered attribute types)</li> +2291 * <li>array: array of ASN.1 parameters as attribute value (See {@link KJUR.asn1.ASN1Util#newObject})</li> +2292 * </ul> +2293 * <br/> +2294 * NOTE: From jsrsasign 10.8.4, member "array in array" supported for an arbitrary +2295 * attribute value. +2296 * +2297 * @example +2298 * e1 = new KJUR.asn1.x509.SubjectDirectoryAttributes({ +2299 * extname: "subjectDirectoryAttributes", +2300 * array: [ +2301 * { attr: "dateOfBirth", str: "19701231230000Z" }, +2302 * { attr: "placeOfBirth", str: "Tokyo" }, +2303 * { attr: "gender", str: "F" }, +2304 * { attr: "countryOfCitizenship", str: "JP" }, +2305 * { attr: "countryOfResidence", str: "JP" }, +2306 * { attr: "1.2.3.4.5", array: [{prnstr: {str: "aaa"}}] } +2307 * ] +2308 * }); +2309 */ +2310 KJUR.asn1.x509.SubjectDirectoryAttributes = function(params) { +2311 KJUR.asn1.x509.SubjectDirectoryAttributes.superclass.constructor.call(this, params); +2312 var _KJUR_asn1 = KJUR.asn1, +2313 _DERSequence = _KJUR_asn1.DERSequence, +2314 _newObject = _KJUR_asn1.ASN1Util.newObject, +2315 _name2oid = _KJUR_asn1.x509.OID.name2oid; +2316 +2317 this.params = null; +2318 +2319 this.getExtnValueHex = function() { +2320 var a = []; +2321 for (var i = 0; i < this.params.array.length; i++) { +2322 var pAttr = this.params.array[i]; +2323 +2324 if (pAttr.attr != undefined && pAttr.array != undefined) { +2325 var pObj = {"seq": [{"oid": pAttr.attr}, {"set": pAttr.array}]}; +2326 a.push(_newObject(pObj)); +2327 continue; +2328 } +2329 +2330 var newparam = {"seq": [{"oid": "1.2.3.4"}, {"set": [{"utf8str": "DE"}]}]}; +2331 +2332 if (pAttr.attr == "dateOfBirth") { +2333 newparam.seq[0].oid = _name2oid(pAttr.attr); +2334 newparam.seq[1].set[0] = {"gentime": pAttr.str}; +2335 } else if (pAttr.attr == "placeOfBirth") { +2336 newparam.seq[0].oid = _name2oid(pAttr.attr); +2337 newparam.seq[1].set[0] = {"utf8str": pAttr.str}; +2338 } else if (pAttr.attr == "gender") { +2339 newparam.seq[0].oid = _name2oid(pAttr.attr); +2340 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; +2341 } else if (pAttr.attr == "countryOfCitizenship") { +2342 newparam.seq[0].oid = _name2oid(pAttr.attr); +2343 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; +2344 } else if (pAttr.attr == "countryOfResidence") { +2345 newparam.seq[0].oid = _name2oid(pAttr.attr); +2346 newparam.seq[1].set[0] = {"prnstr": pAttr.str}; +2347 } else { +2348 throw new Error("unsupported attribute: " + pAttr.attr); +2349 } +2350 a.push(new _newObject(newparam)); +2351 } +2352 var seq = new _DERSequence({array: a}); +2353 this.asn1ExtnValue = seq; +2354 return this.asn1ExtnValue.tohex(); +2355 }; +2356 +2357 this.oid = "2.5.29.9"; +2358 if (params !== undefined) { +2359 this.params = params; +2360 } +2361 }; +2362 extendClass(KJUR.asn1.x509.SubjectDirectoryAttributes, KJUR.asn1.x509.Extension); +2363 +2364 +2365 /** +2366 * priavte extension ASN.1 structure class<br/> +2367 * @name KJUR.asn1.x509.PrivateExtension +2368 * @class private extension ASN.1 structure class +2369 * @param {Array} params JSON object of private extension +2370 * @extends KJUR.asn1.x509.Extension +2371 * @since jsrsasign 9.1.1 asn1x509 +2372 * @see KJUR.asn1.ASN1Util.newObject +2373 * +2374 * @description +2375 * This class is to represent private extension or +2376 * unsupported extension. +2377 * <pre> +2378 * Extension ::= SEQUENCE { +2379 * extnID OBJECT IDENTIFIER, +2380 * critical BOOLEAN DEFAULT FALSE, +2381 * extnValue OCTET STRING } +2382 * </pre> +2383 * Following properties can be set for JSON parameter: +2384 * <ul> +2385 * <li>{String}extname - string of OID or predefined extension name</li> +2386 * <li>{Boolean}critical - critical flag</li> +2387 * <li>{Object}extn - hexadecimal string or +2388 * of {@link KJUR.asn1.ASN1Util.newObject} +2389 * JSON parameter for extnValue field</li> +2390 * </li> +2391 * </ul> +2392 * +2393 * @example +2394 * // extn by hexadecimal +2395 * new KJUR.asn1.x509.PrivateExtension({ +2396 * extname: "1.2.3.4", +2397 * critical: true, +2398 * extn: "13026161" // means PrintableString "aa" +2399 * }); +2400 * +2401 * // extn by JSON parameter +2402 * new KJUR.asn1.x509.PrivateExtension({ +2403 * extname: "1.2.3.5", +2404 * extn: {seq: [{prnstr:"abc"},{utf8str:"def"}]} +2405 * }); +2406 */ +2407 KJUR.asn1.x509.PrivateExtension = function(params) { +2408 KJUR.asn1.x509.PrivateExtension.superclass.constructor.call(this, params) +2409 +2410 var _KJUR = KJUR, +2411 _isHex = _KJUR.lang.String.isHex, +2412 _KJUR_asn1 = _KJUR.asn1, +2413 _name2oid = _KJUR_asn1.x509.OID.name2oid, +2414 _newObject = _KJUR_asn1.ASN1Util.newObject; +2415 +2416 this.params = null; +2417 +2418 this.setByParam = function(params) { +2419 this.oid = _name2oid(params.extname); +2420 this.params = params; +2421 }; +2422 +2423 this.getExtnValueHex = function() { +2424 if (this.params.extname == undefined || +2425 this.params.extn == undefined) { +2426 throw new Error("extname or extnhex not specified"); +2427 } +2428 +2429 var extn = this.params.extn; +2430 if (typeof extn == "string" && _isHex(extn)) { +2431 return extn; +2432 } else if (typeof extn == "object") { +2433 try { +2434 return _newObject(extn).tohex(); +2435 } catch(ex) {} +2436 } +2437 throw new Error("unsupported extn value"); +2438 }; +2439 +2440 if (params != undefined) { +2441 this.setByParam(params); +2442 } +2443 }; +2444 extendClass(KJUR.asn1.x509.PrivateExtension, KJUR.asn1.x509.Extension); +2445 +2446 // === END X.509v3 Extensions Related ======================================= +2447 +2448 // === BEGIN CRL Related =================================================== +2449 /** +2450 * X.509 CRL class to sign and generate hex encoded CRL<br/> +2451 * @name KJUR.asn1.x509.CRL +2452 * @class X.509 CRL class to sign and generate hex encoded certificate +2453 * @property {Array} params JSON object of parameters +2454 * @param {Array} params JSON object of CRL parameters +2455 * @extends KJUR.asn1.ASN1Object +2456 * @since 1.0.3 +2457 * @see KJUR.asn1.x509.TBSCertList +2458 * +2459 * @description +2460 * This class represents CertificateList ASN.1 structur of X.509 CRL +2461 * defined in <a href="https://tools.ietf.org/html/rfc5280#section-5.1"> +2462 * RFC 5280 5.1</a> +2463 * <pre> +2464 * CertificateList ::= SEQUENCE { +2465 * tbsCertList TBSCertList, +2466 * signatureAlgorithm AlgorithmIdentifier, +2467 * signatureValue BIT STRING } +2468 * </pre> +2469 * NOTE: CRL class is updated without backward +2470 * compatibility from jsrsasign 9.1.0 asn1x509 2.1.0. +2471 * Most of methods are removed and parameters can be set +2472 * by JSON object. +2473 * <br/> +2474 * Constructor of this class can accept all +2475 * parameters of {@link KJUR.asn1.x509.TBSCertList}. +2476 * It also accept following parameters additionally: +2477 * <ul> +2478 * <li>{TBSCertList}tbsobj (OPTION) - +2479 * specifies {@link KJUR.asn1.x509.TBSCertList} +2480 * object to be signed if needed. +2481 * When this isn't specified, +2482 * this will be set from other parametes of TBSCertList.</li> +2483 * <li>{Object}cakey (OPTION) - specifies CRL signing private key. +2484 * Parameter "cakey" or "sighex" shall be specified. Following +2485 * values can be specified: +2486 * <ul> +2487 * <li>PKCS#1/5 or PKCS#8 PEM string of private key</li> +2488 * <li>RSAKey/DSA/ECDSA key object. {@link KEYUTIL.getKey} is useful +2489 * to generate a key object.</li> +2490 * </ul> +2491 * </li> +2492 * <li>{String}sighex (OPTION) - hexadecimal string of signature value +2493 * (i.e. ASN.1 value(V) of signatureValue BIT STRING without +2494 * unused bits)</li> +2495 * </ul> +2496 * +2497 * @example +2498 * var crl = new KJUR.asn1.x509.CRL({ +2499 * sigalg: "SHA256withRSA", +2500 * issuer: {str:'/C=JP/O=Test1'}, +2501 * thisupdate: "200821235959Z", +2502 * nextupdate: "200828235959Z", // OPTION +2503 * revcert: [{sn: {hex: "12ab"}, date: "200401235959Z"}], +2504 * ext: [ +2505 * {extname: "cRLNumber", num: {'int': 8}}, +2506 * {extname: "authorityKeyIdentifier", "kid": {hex: "12ab"}} +2507 * ], +2508 * cakey: prvkey +2509 * }); +2510 * crl.gettohex() → "30..." +2511 * crl.getPEM() → "-----BEGIN X509 CRL..." +2512 */ +2513 KJUR.asn1.x509.CRL = function(params) { +2514 KJUR.asn1.x509.CRL.superclass.constructor.call(this); +2515 var _KJUR = KJUR, +2516 _KJUR_asn1 = _KJUR.asn1, +2517 _DERSequence = _KJUR_asn1.DERSequence, +2518 _DERBitString = _KJUR_asn1.DERBitString, +2519 _KJUR_asn1_x509 = _KJUR_asn1.x509, +2520 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, +2521 _TBSCertList = _KJUR_asn1_x509.TBSCertList; +2522 +2523 this.params = undefined; +2524 +2525 this.setByParam = function(params) { +2526 this.params = params; +2527 }; +2528 +2529 /** +2530 * sign CRL<br/> +2531 * @name sign +2532 * @memberOf KJUR.asn1.x509.CRL# +2533 * @function +2534 * @description +2535 * This method signs TBSCertList with a specified +2536 * private key and algorithm by +2537 * this.params.cakey and this.params.sigalg parameter. +2538 * @example +2539 * crl = new KJUR.asn1.x509.CRL({..., cakey:prvkey}); +2540 * crl.sign() +2541 */ +2542 this.sign = function() { +2543 var hTBSCL = (new _TBSCertList(this.params)).tohex(); +2544 var sig = new KJUR.crypto.Signature({alg: this.params.sigalg}); +2545 sig.init(this.params.cakey); +2546 sig.updateHex(hTBSCL); +2547 var sighex = sig.sign(); +2548 this.params.sighex = sighex; +2549 }; +2550 +2551 /** +2552 * get PEM formatted CRL string after signed<br/> +2553 * @name getPEM +2554 * @memberOf KJUR.asn1.x509.CRL# +2555 * @function +2556 * @return PEM formatted string of CRL +2557 * @since jsrsasign 9.1.0 asn1hex 2.1.0 +2558 * @description +2559 * This method returns a string of PEM formatted +2560 * CRL. +2561 * @example +2562 * crl = new KJUR.asn1.x509.CRL({...}); +2563 * crl.getPEM() → +2564 * "-----BEGIN X509 CRL-----\r\n..." +2565 */ +2566 this.getPEM = function() { +2567 return hextopem(this.tohex(), "X509 CRL"); +2568 }; +2569 +2570 this.tohex = function() { +2571 var params = this.params; +2572 +2573 if (params.tbsobj == undefined) { +2574 params.tbsobj = new _TBSCertList(params); +2575 } +2576 +2577 if (params.sighex == undefined && params.cakey != undefined) { +2578 this.sign(); +2579 } +2580 +2581 if (params.sighex == undefined) { +2582 throw new Error("sighex or cakey parameter not defined"); +2583 } +2584 +2585 var a = []; +2586 a.push(params.tbsobj); +2587 a.push(new _AlgorithmIdentifier({name: params.sigalg})); +2588 a.push(new _DERBitString({hex: "00" + params.sighex})); +2589 var seq = new _DERSequence({array: a}); +2590 return seq.tohex(); +2591 }; +2592 this.getEncodedHex = function() { return this.tohex(); }; +2593 +2594 if (params != undefined) this.params = params; +2595 }; +2596 extendClass(KJUR.asn1.x509.CRL, KJUR.asn1.ASN1Object); +2597 +2598 /** +2599 * ASN.1 TBSCertList ASN.1 structure class for CRL<br/> +2600 * @name KJUR.asn1.x509.TBSCertList +2601 * @class TBSCertList ASN.1 structure class for CRL +2602 * @property {Array} params JSON object of parameters +2603 * @param {Array} params JSON object of TBSCertList parameters +2604 * @extends KJUR.asn1.ASN1Object +2605 * @since 1.0.3 +2606 * +2607 * @description +2608 * This class represents TBSCertList of CRL defined in +2609 * <a href="https://tools.ietf.org/html/rfc5280#section-5.1"> +2610 * RFC 5280 5.1</a>. +2611 * <pre> +2612 * TBSCertList ::= SEQUENCE { +2613 * version Version OPTIONAL, +2614 * -- if present, MUST be v2 +2615 * signature AlgorithmIdentifier, +2616 * issuer Name, +2617 * thisUpdate Time, +2618 * nextUpdate Time OPTIONAL, +2619 * revokedCertificates SEQUENCE OF SEQUENCE { +2620 * userCertificate CertificateSerialNumber, +2621 * revocationDate Time, +2622 * crlEntryExtensions Extensions OPTIONAL +2623 * -- if present, version MUST be v2 +2624 * } OPTIONAL, +2625 * crlExtensions [0] EXPLICIT Extensions OPTIONAL +2626 * } +2627 * </pre> +2628 * NOTE: TBSCertList class is updated without backward +2629 * compatibility from jsrsasign 9.1.0 asn1x509 2.1.0. +2630 * Most of methods are removed and parameters can be set +2631 * by JSON object. +2632 * <br/> +2633 * Constructor of this class may have following parameters: +2634 * <ul> +2635 * <li>{Integer}version (OPTION) - version number. Omitted by default.</li> +2636 * <li>{String}sigalg - signature algorithm name</li> +2637 * <li>{Array}issuer - issuer parameter of {@link KJUR.asn1.x509.X500Name}</li> +2638 * <li>{String}thisupdate - thisUpdate field value</li> +2639 * <li>{String}nextupdate (OPTION) - thisUpdate field value</li> +2640 * <li>{Array}revcert (OPTION) - revokedCertificates field value as array +2641 * Its element may have following property: +2642 * <ul> +2643 * <li>{Array}sn - serialNumber of userCertificate field specified +2644 * by {@link KJUR.asn1.DERInteger}</li> +2645 * <li>{String}date - revocationDate field specified by +2646 * a string of {@link KJUR.asn1.x509.Time} parameter</li> +2647 * <li>{Array}ext (OPTION) - array of CRL entry extension parameter</li> +2648 * </ul> +2649 * </li> +2650 * </ul> +2651 * +2652 * @example +2653 * var o = new KJUR.asn1.x509.TBSCertList({ +2654 * sigalg: "SHA256withRSA", +2655 * issuer: {array: [[{type:'C',value:'JP',ds:'prn'}], +2656 * [{type:'O',value:'T1',ds:'prn'}]]}, +2657 * thisupdate: "200821235959Z", +2658 * nextupdate: "200828235959Z", // OPTION +2659 * revcert: [ +2660 * {sn: {hex: "12ab"}, date: "200401235959Z", ext: [{extname: "cRLReason", code:1}]}, +2661 * {sn: {hex: "12bc"}, date: "200405235959Z", ext: [{extname: "cRLReason", code:2}]} +2662 * ], +2663 * ext: [ +2664 * {extname: "cRLNumber", num: {'int': 8}}, +2665 * {extname: "authorityKeyIdentifier", "kid": {hex: "12ab"}} +2666 * ] +2667 * }); +2668 * o.tohex() → "30..." +2669 */ +2670 KJUR.asn1.x509.TBSCertList = function(params) { +2671 KJUR.asn1.x509.TBSCertList.superclass.constructor.call(this); +2672 var _KJUR = KJUR, +2673 _KJUR_asn1 = _KJUR.asn1, +2674 _DERInteger = _KJUR_asn1.DERInteger, +2675 _DERSequence = _KJUR_asn1.DERSequence, +2676 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, +2677 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, +2678 _KJUR_asn1_x509 = _KJUR_asn1.x509, +2679 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, +2680 _Time = _KJUR_asn1_x509.Time, +2681 _Extensions = _KJUR_asn1_x509.Extensions, +2682 _X500Name = _KJUR_asn1_x509.X500Name; +2683 this.params = null; 2684 2685 /** -2686 * get DERSequence for revokedCertificates<br/> -2687 * @name getRevCertSequence +2686 * get array of ASN.1 object for extensions<br/> +2687 * @name setByParam 2688 * @memberOf KJUR.asn1.x509.TBSCertList# 2689 * @function -2690 * @return {@link KJUR.asn1.DERSequence} of revokedCertificates -2691 */ -2692 this.getRevCertSequence = function() { -2693 var a = []; -2694 var aRevCert = this.params.revcert; -2695 for (var i = 0; i < aRevCert.length; i++) { -2696 var aEntry = [ -2697 new _DERInteger(aRevCert[i].sn), -2698 new _Time(aRevCert[i].date) -2699 ]; -2700 if (aRevCert[i].ext != undefined) { -2701 aEntry.push(new _Extensions(aRevCert[i].ext)); -2702 } -2703 a.push(new _DERSequence({array: aEntry})); -2704 } -2705 return new _DERSequence({array: a}); -2706 }; -2707 -2708 this.tohex = function() { -2709 var a = []; -2710 var params = this.params; -2711 -2712 if (params.version != undefined) { -2713 var version = params.version - 1; -2714 var obj = new _DERInteger({'int': version}); -2715 a.push(obj); -2716 } -2717 -2718 a.push(new _AlgorithmIdentifier({name: params.sigalg})); -2719 a.push(new _X500Name(params.issuer)); -2720 a.push(new _Time(params.thisupdate)); -2721 if (params.nextupdate != undefined) -2722 a.push(new _Time(params.nextupdate)) -2723 if (params.revcert != undefined) { -2724 a.push(this.getRevCertSequence()); -2725 } -2726 if (params.ext != undefined) { -2727 var dExt = new _Extensions(params.ext); -2728 a.push(new _DERTaggedObject({tag:'a0', -2729 explicit:true, -2730 obj:dExt})); -2731 } -2732 -2733 var seq = new _DERSequence({array: a}); -2734 return seq.tohex(); -2735 }; -2736 this.getEncodedHex = function() { return this.tohex(); }; -2737 -2738 if (params !== undefined) this.setByParam(params); -2739 }; -2740 extendClass(KJUR.asn1.x509.TBSCertList, KJUR.asn1.ASN1Object); -2741 -2742 /** -2743 * ASN.1 CRLEntry structure class for CRL (DEPRECATED)<br/> -2744 * @name KJUR.asn1.x509.CRLEntry -2745 * @class ASN.1 CRLEntry structure class for CRL -2746 * @param {Array} params JSON object for CRL entry parameter -2747 * @extends KJUR.asn1.ASN1Object -2748 * @since 1.0.3 -2749 * @see KJUR.asn1.x509.TBSCertList -2750 * @deprecated since jsrsasign 9.1.0 asn1x509 2.1.0 -2751 * @description -2752 * This class is to represent revokedCertificate in TBSCertList. -2753 * However this is no more used by TBSCertList since -2754 * jsrsasign 9.1.0. So this class have been deprecated in -2755 * jsrsasign 9.1.0. -2756 * <pre> -2757 * revokedCertificates SEQUENCE OF SEQUENCE { -2758 * userCertificate CertificateSerialNumber, -2759 * revocationDate Time, -2760 * crlEntryExtensions Extensions OPTIONAL -2761 * -- if present, version MUST be v2 } -2762 * </pre> -2763 * @example -2764 * var e = new KJUR.asn1.x509.CRLEntry({'time': {'str': '130514235959Z'}, 'sn': {'int': 234}}); -2765 */ -2766 KJUR.asn1.x509.CRLEntry = function(params) { -2767 KJUR.asn1.x509.CRLEntry.superclass.constructor.call(this); -2768 var sn = null, -2769 time = null, -2770 _KJUR = KJUR, -2771 _KJUR_asn1 = _KJUR.asn1; -2772 -2773 /** -2774 * set DERInteger parameter for serial number of revoked certificate -2775 * @name setCertSerial -2776 * @memberOf KJUR.asn1.x509.CRLEntry -2777 * @function -2778 * @param {Array} intParam DERInteger parameter for certificate serial number -2779 * @description -2780 * @example -2781 * entry.setCertSerial({'int': 3}); -2782 */ -2783 this.setCertSerial = function(intParam) { -2784 this.sn = new _KJUR_asn1.DERInteger(intParam); -2785 }; +2690 * @param {Array} JSON object of TBSCertList parameters +2691 * @example +2692 * tbsc = new KJUR.asn1.x509.TBSCertificate(); +2693 * tbsc.setByParam({version:3, serial:{hex:'1234...'},...}); +2694 */ +2695 this.setByParam = function(params) { +2696 this.params = params; +2697 }; +2698 +2699 /** +2700 * get DERSequence for revokedCertificates<br/> +2701 * @name getRevCertSequence +2702 * @memberOf KJUR.asn1.x509.TBSCertList# +2703 * @function +2704 * @return {@link KJUR.asn1.DERSequence} of revokedCertificates +2705 */ +2706 this.getRevCertSequence = function() { +2707 var a = []; +2708 var aRevCert = this.params.revcert; +2709 for (var i = 0; i < aRevCert.length; i++) { +2710 var aEntry = [ +2711 new _DERInteger(aRevCert[i].sn), +2712 new _Time(aRevCert[i].date) +2713 ]; +2714 if (aRevCert[i].ext != undefined) { +2715 aEntry.push(new _Extensions(aRevCert[i].ext)); +2716 } +2717 a.push(new _DERSequence({array: aEntry})); +2718 } +2719 return new _DERSequence({array: a}); +2720 }; +2721 +2722 this.tohex = function() { +2723 var a = []; +2724 var params = this.params; +2725 +2726 if (params.version != undefined) { +2727 var version = params.version - 1; +2728 var obj = new _DERInteger({'int': version}); +2729 a.push(obj); +2730 } +2731 +2732 a.push(new _AlgorithmIdentifier({name: params.sigalg})); +2733 a.push(new _X500Name(params.issuer)); +2734 a.push(new _Time(params.thisupdate)); +2735 if (params.nextupdate != undefined) +2736 a.push(new _Time(params.nextupdate)) +2737 if (params.revcert != undefined) { +2738 a.push(this.getRevCertSequence()); +2739 } +2740 if (params.ext != undefined) { +2741 var dExt = new _Extensions(params.ext); +2742 a.push(new _DERTaggedObject({tag:'a0', +2743 explicit:true, +2744 obj:dExt})); +2745 } +2746 +2747 var seq = new _DERSequence({array: a}); +2748 return seq.tohex(); +2749 }; +2750 this.getEncodedHex = function() { return this.tohex(); }; +2751 +2752 if (params !== undefined) this.setByParam(params); +2753 }; +2754 extendClass(KJUR.asn1.x509.TBSCertList, KJUR.asn1.ASN1Object); +2755 +2756 /** +2757 * ASN.1 CRLEntry structure class for CRL (DEPRECATED)<br/> +2758 * @name KJUR.asn1.x509.CRLEntry +2759 * @class ASN.1 CRLEntry structure class for CRL +2760 * @param {Array} params JSON object for CRL entry parameter +2761 * @extends KJUR.asn1.ASN1Object +2762 * @since 1.0.3 +2763 * @see KJUR.asn1.x509.TBSCertList +2764 * @deprecated since jsrsasign 9.1.0 asn1x509 2.1.0 +2765 * @description +2766 * This class is to represent revokedCertificate in TBSCertList. +2767 * However this is no more used by TBSCertList since +2768 * jsrsasign 9.1.0. So this class have been deprecated in +2769 * jsrsasign 9.1.0. +2770 * <pre> +2771 * revokedCertificates SEQUENCE OF SEQUENCE { +2772 * userCertificate CertificateSerialNumber, +2773 * revocationDate Time, +2774 * crlEntryExtensions Extensions OPTIONAL +2775 * -- if present, version MUST be v2 } +2776 * </pre> +2777 * @example +2778 * var e = new KJUR.asn1.x509.CRLEntry({'time': {'str': '130514235959Z'}, 'sn': {'int': 234}}); +2779 */ +2780 KJUR.asn1.x509.CRLEntry = function(params) { +2781 KJUR.asn1.x509.CRLEntry.superclass.constructor.call(this); +2782 var sn = null, +2783 time = null, +2784 _KJUR = KJUR, +2785 _KJUR_asn1 = _KJUR.asn1; 2786 2787 /** -2788 * set Time parameter for revocation date -2789 * @name setRevocationDate +2788 * set DERInteger parameter for serial number of revoked certificate +2789 * @name setCertSerial 2790 * @memberOf KJUR.asn1.x509.CRLEntry 2791 * @function -2792 * @param {Array} timeParam Time parameter for revocation date +2792 * @param {Array} intParam DERInteger parameter for certificate serial number 2793 * @description 2794 * @example -2795 * entry.setRevocationDate({'str': '130508235959Z'}); +2795 * entry.setCertSerial({'int': 3}); 2796 */ -2797 this.setRevocationDate = function(timeParam) { -2798 this.time = new _KJUR_asn1.x509.Time(timeParam); +2797 this.setCertSerial = function(intParam) { +2798 this.sn = new _KJUR_asn1.DERInteger(intParam); 2799 }; 2800 -2801 this.tohex = function() { -2802 var o = new _KJUR_asn1.DERSequence({"array": [this.sn, this.time]}); -2803 this.TLV = o.tohex(); -2804 return this.TLV; -2805 }; -2806 this.getEncodedHex = function() { return this.tohex(); }; -2807 -2808 if (params !== undefined) { -2809 if (params.time !== undefined) { -2810 this.setRevocationDate(params.time); -2811 } -2812 if (params.sn !== undefined) { -2813 this.setCertSerial(params.sn); -2814 } -2815 } -2816 }; -2817 extendClass(KJUR.asn1.x509.CRLEntry, KJUR.asn1.ASN1Object); -2818 -2819 /** -2820 * CRLNumber CRL extension ASN.1 structure class<br/> -2821 * @name KJUR.asn1.x509.CRLNumber -2822 * @class CRLNumber CRL extension ASN.1 structure class -2823 * @extends KJUR.asn1.x509.Extension -2824 * @since jsrsasign 9.1.0 asn1x509 2.1.0 -2825 * @see KJUR.asn1.x509.TBSCertList -2826 * @see KJUR.asn1.x509.Extensions -2827 * @description -2828 * This class represents ASN.1 structure for -2829 * CRLNumber CRL extension defined in -2830 * <a href="https://tools.ietf.org/html/rfc5280#section-5.2.3"> -2831 * RFC 5280 5.2.3</a>. -2832 * <pre> -2833 * id-ce-cRLNumber OBJECT IDENTIFIER ::= { id-ce 20 } -2834 * CRLNumber ::= INTEGER (0..MAX) -2835 * </pre> -2836 * Constructor of this class may have following parameters: -2837 * <ul> -2838 * <li>{String}extname - name "cRLNumber". It is ignored in this class but -2839 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> -2840 * <li>{Object}num - CRLNumber value to specify -2841 * {@link KJUR.asn1.DERInteger} parameter.</li> -2842 * <li>{Boolean}critical - critical flag. Generally false and not specified -2843 * in this class.(OPTION)</li> -2844 * </ul> -2845 * -2846 * @example -2847 * new KJUR.asn1.x509.CRLNumber({extname:'cRLNumber', -2848 * num:{'int':147}}) -2849 */ -2850 KJUR.asn1.x509.CRLNumber = function(params) { -2851 KJUR.asn1.x509.CRLNumber.superclass.constructor.call(this, params); -2852 this.params = undefined; -2853 -2854 this.getExtnValueHex = function() { -2855 this.asn1ExtnValue = new KJUR.asn1.DERInteger(this.params.num); -2856 return this.asn1ExtnValue.tohex(); -2857 }; -2858 -2859 this.oid = "2.5.29.20"; -2860 if (params != undefined) this.params = params; -2861 }; -2862 extendClass(KJUR.asn1.x509.CRLNumber, KJUR.asn1.x509.Extension); -2863 -2864 /** -2865 * CRLReason CRL entry extension ASN.1 structure class<br/> -2866 * @name KJUR.asn1.x509.CRLReason -2867 * @class CRLReason CRL entry extension ASN.1 structure class -2868 * @extends KJUR.asn1.x509.Extension -2869 * @since jsrsasign 9.1.0 asn1x509 2.1.0 -2870 * @see KJUR.asn1.x509.TBSCertList -2871 * @see KJUR.asn1.x509.Extensions -2872 * @description -2873 * This class represents ASN.1 structure for -2874 * CRLReason CRL entry extension defined in -2875 * <a href="https://tools.ietf.org/html/rfc5280#section-5.3.1"> -2876 * RFC 5280 5.3.1</a> -2877 * <pre> -2878 * id-ce-cRLReasons OBJECT IDENTIFIER ::= { id-ce 21 } -2879 * -- reasonCode ::= { CRLReason } -2880 * CRLReason ::= ENUMERATED { -2881 * unspecified (0), -2882 * keyCompromise (1), -2883 * cACompromise (2), -2884 * affiliationChanged (3), -2885 * superseded (4), -2886 * cessationOfOperation (5), -2887 * certificateHold (6), -2888 * removeFromCRL (8), -2889 * privilegeWithdrawn (9), -2890 * aACompromise (10) } -2891 * </pre> -2892 * Constructor of this class may have following parameters: -2893 * <ul> -2894 * <li>{String}extname - name "cRLReason". It is ignored in this class but -2895 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> -2896 * <li>{Integer}code - reasonCode value</li> -2897 * <li>{Boolean}critical - critical flag. Generally false and not specified -2898 * in this class.(OPTION)</li> -2899 * </ul> -2900 * -2901 * @example -2902 * new KJUR.asn1.x509.CRLReason({extname:'cRLReason',code:4}) -2903 */ -2904 KJUR.asn1.x509.CRLReason = function(params) { -2905 KJUR.asn1.x509.CRLReason.superclass.constructor.call(this, params); -2906 this.params = undefined; -2907 -2908 this.getExtnValueHex = function() { -2909 this.asn1ExtnValue = new KJUR.asn1.DEREnumerated(this.params.code); -2910 return this.asn1ExtnValue.tohex(); -2911 }; -2912 -2913 this.oid = "2.5.29.21"; -2914 if (params != undefined) this.params = params; -2915 }; -2916 extendClass(KJUR.asn1.x509.CRLReason, KJUR.asn1.x509.Extension); -2917 -2918 // === END CRL Related =================================================== -2919 -2920 // === BEGIN OCSP Related =================================================== -2921 /** -2922 * Nonce OCSP extension ASN.1 structure class<br/> -2923 * @name KJUR.asn1.x509.OCSPNonce -2924 * @class Nonce OCSP extension ASN.1 structure class -2925 * @extends KJUR.asn1.x509.Extension -2926 * @since jsrsasign 9.1.6 asn1x509 2.1.2 -2927 * @param {Array} params JSON object for Nonce extension -2928 * @see KJUR.asn1.ocsp.ResponseData -2929 * @see KJUR.asn1.x509.Extensions -2930 * @see X509#getExtOCSPNonce -2931 * @description -2932 * This class represents -2933 * Nonce OCSP extension value defined in -2934 * <a href="https://tools.ietf.org/html/rfc6960#section-4.4.1"> -2935 * RFC 6960 4.4.1</a> as JSON object. -2936 * <pre> -2937 * id-pkix-ocsp OBJECT IDENTIFIER ::= { id-ad-ocsp } -2938 * id-pkix-ocsp-nonce OBJECT IDENTIFIER ::= { id-pkix-ocsp 2 } -2939 * Nonce ::= OCTET STRING -2940 * </pre> -2941 * Constructor of this class may have following parameters: -2942 * <ul> -2943 * <li>{String}extname - name "ocspNonce". It is ignored in this class but -2944 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> -2945 * <li>{String}hex - hexadecimal string of nonce value</li> -2946 * <li>{Number}int - integer of nonce value. "hex" or "int" needs to be -2947 * specified.</li> -2948 * <li>{Boolean}critical - critical flag. Generally false and not specified -2949 * in this class.(OPTION)</li> -2950 * </ul> -2951 * -2952 * @example -2953 * new KJUR.asn1.x509.OCSPNonce({extname:'ocspNonce', -2954 * hex: '12ab...'}) -2955 */ -2956 KJUR.asn1.x509.OCSPNonce = function(params) { -2957 KJUR.asn1.x509.OCSPNonce.superclass.constructor.call(this, params); -2958 this.params = undefined; -2959 -2960 this.getExtnValueHex = function() { -2961 this.asn1ExtnValue = new KJUR.asn1.DEROctetString(this.params); -2962 return this.asn1ExtnValue.tohex(); -2963 }; -2964 -2965 this.oid = "1.3.6.1.5.5.7.48.1.2"; -2966 if (params != undefined) this.params = params; -2967 }; -2968 extendClass(KJUR.asn1.x509.OCSPNonce, KJUR.asn1.x509.Extension); -2969 -2970 /** -2971 * OCSPNoCheck certificate ASN.1 structure class<br/> -2972 * @name KJUR.asn1.x509.OCSPNoCheck -2973 * @class OCSPNoCheck extension ASN.1 structure class -2974 * @extends KJUR.asn1.x509.Extension -2975 * @since jsrsasign 9.1.6 asn1x509 2.1.2 -2976 * @param {Array} params JSON object for OCSPNoCheck extension -2977 * @see KJUR.asn1.x509.Extensions -2978 * @see X509#getExtOCSPNoCheck -2979 * @description -2980 * This class represents -2981 * OCSPNoCheck extension value defined in -2982 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.2.2.1"> -2983 * RFC 6960 4.2.2.2.1</a> as JSON object. -2984 * <pre> -2985 * id-pkix-ocsp-nocheck OBJECT IDENTIFIER ::= { id-pkix-ocsp 5 } -2986 * </pre> -2987 * Constructor of this class may have following parameters: -2988 * <ul> -2989 * <li>{String}extname - name "ocspNoCheck". It is ignored in this class but -2990 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> -2991 * <li>{Boolean}critical - critical flag. Generally false and not specified -2992 * in this class.(OPTION)</li> -2993 * </ul> -2994 * -2995 * @example -2996 * new KJUR.asn1.x509.OCSPNonce({extname:'ocspNoCheck'}) -2997 */ -2998 KJUR.asn1.x509.OCSPNoCheck = function(params) { -2999 KJUR.asn1.x509.OCSPNoCheck.superclass.constructor.call(this, params); -3000 this.params = undefined; -3001 -3002 this.getExtnValueHex = function() { -3003 this.asn1ExtnValue = new KJUR.asn1.DERNull(); -3004 return this.asn1ExtnValue.tohex(); -3005 }; -3006 -3007 this.oid = "1.3.6.1.5.5.7.48.1.5"; -3008 if (params != undefined) this.params = params; -3009 }; -3010 extendClass(KJUR.asn1.x509.OCSPNoCheck, KJUR.asn1.x509.Extension); -3011 -3012 // === END OCSP Related =================================================== -3013 -3014 // === BEGIN Other X.509v3 Extensions======================================== +2801 /** +2802 * set Time parameter for revocation date +2803 * @name setRevocationDate +2804 * @memberOf KJUR.asn1.x509.CRLEntry +2805 * @function +2806 * @param {Array} timeParam Time parameter for revocation date +2807 * @description +2808 * @example +2809 * entry.setRevocationDate({'str': '130508235959Z'}); +2810 */ +2811 this.setRevocationDate = function(timeParam) { +2812 this.time = new _KJUR_asn1.x509.Time(timeParam); +2813 }; +2814 +2815 this.tohex = function() { +2816 var o = new _KJUR_asn1.DERSequence({"array": [this.sn, this.time]}); +2817 this.TLV = o.tohex(); +2818 return this.TLV; +2819 }; +2820 this.getEncodedHex = function() { return this.tohex(); }; +2821 +2822 if (params !== undefined) { +2823 if (params.time !== undefined) { +2824 this.setRevocationDate(params.time); +2825 } +2826 if (params.sn !== undefined) { +2827 this.setCertSerial(params.sn); +2828 } +2829 } +2830 }; +2831 extendClass(KJUR.asn1.x509.CRLEntry, KJUR.asn1.ASN1Object); +2832 +2833 /** +2834 * CRLNumber CRL extension ASN.1 structure class<br/> +2835 * @name KJUR.asn1.x509.CRLNumber +2836 * @class CRLNumber CRL extension ASN.1 structure class +2837 * @extends KJUR.asn1.x509.Extension +2838 * @since jsrsasign 9.1.0 asn1x509 2.1.0 +2839 * @see KJUR.asn1.x509.TBSCertList +2840 * @see KJUR.asn1.x509.Extensions +2841 * @description +2842 * This class represents ASN.1 structure for +2843 * CRLNumber CRL extension defined in +2844 * <a href="https://tools.ietf.org/html/rfc5280#section-5.2.3"> +2845 * RFC 5280 5.2.3</a>. +2846 * <pre> +2847 * id-ce-cRLNumber OBJECT IDENTIFIER ::= { id-ce 20 } +2848 * CRLNumber ::= INTEGER (0..MAX) +2849 * </pre> +2850 * Constructor of this class may have following parameters: +2851 * <ul> +2852 * <li>{String}extname - name "cRLNumber". It is ignored in this class but +2853 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> +2854 * <li>{Object}num - CRLNumber value to specify +2855 * {@link KJUR.asn1.DERInteger} parameter.</li> +2856 * <li>{Boolean}critical - critical flag. Generally false and not specified +2857 * in this class.(OPTION)</li> +2858 * </ul> +2859 * +2860 * @example +2861 * new KJUR.asn1.x509.CRLNumber({extname:'cRLNumber', +2862 * num:{'int':147}}) +2863 */ +2864 KJUR.asn1.x509.CRLNumber = function(params) { +2865 KJUR.asn1.x509.CRLNumber.superclass.constructor.call(this, params); +2866 this.params = undefined; +2867 +2868 this.getExtnValueHex = function() { +2869 this.asn1ExtnValue = new KJUR.asn1.DERInteger(this.params.num); +2870 return this.asn1ExtnValue.tohex(); +2871 }; +2872 +2873 this.oid = "2.5.29.20"; +2874 if (params != undefined) this.params = params; +2875 }; +2876 extendClass(KJUR.asn1.x509.CRLNumber, KJUR.asn1.x509.Extension); +2877 +2878 /** +2879 * CRLReason CRL entry extension ASN.1 structure class<br/> +2880 * @name KJUR.asn1.x509.CRLReason +2881 * @class CRLReason CRL entry extension ASN.1 structure class +2882 * @extends KJUR.asn1.x509.Extension +2883 * @since jsrsasign 9.1.0 asn1x509 2.1.0 +2884 * @see KJUR.asn1.x509.TBSCertList +2885 * @see KJUR.asn1.x509.Extensions +2886 * @description +2887 * This class represents ASN.1 structure for +2888 * CRLReason CRL entry extension defined in +2889 * <a href="https://tools.ietf.org/html/rfc5280#section-5.3.1"> +2890 * RFC 5280 5.3.1</a> +2891 * <pre> +2892 * id-ce-cRLReasons OBJECT IDENTIFIER ::= { id-ce 21 } +2893 * -- reasonCode ::= { CRLReason } +2894 * CRLReason ::= ENUMERATED { +2895 * unspecified (0), +2896 * keyCompromise (1), +2897 * cACompromise (2), +2898 * affiliationChanged (3), +2899 * superseded (4), +2900 * cessationOfOperation (5), +2901 * certificateHold (6), +2902 * removeFromCRL (8), +2903 * privilegeWithdrawn (9), +2904 * aACompromise (10) } +2905 * </pre> +2906 * Constructor of this class may have following parameters: +2907 * <ul> +2908 * <li>{String}extname - name "cRLReason". It is ignored in this class but +2909 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> +2910 * <li>{Integer}code - reasonCode value</li> +2911 * <li>{Boolean}critical - critical flag. Generally false and not specified +2912 * in this class.(OPTION)</li> +2913 * </ul> +2914 * +2915 * @example +2916 * new KJUR.asn1.x509.CRLReason({extname:'cRLReason',code:4}) +2917 */ +2918 KJUR.asn1.x509.CRLReason = function(params) { +2919 KJUR.asn1.x509.CRLReason.superclass.constructor.call(this, params); +2920 this.params = undefined; +2921 +2922 this.getExtnValueHex = function() { +2923 this.asn1ExtnValue = new KJUR.asn1.DEREnumerated(this.params.code); +2924 return this.asn1ExtnValue.tohex(); +2925 }; +2926 +2927 this.oid = "2.5.29.21"; +2928 if (params != undefined) this.params = params; +2929 }; +2930 extendClass(KJUR.asn1.x509.CRLReason, KJUR.asn1.x509.Extension); +2931 +2932 // === END CRL Related =================================================== +2933 +2934 // === BEGIN OCSP Related =================================================== +2935 /** +2936 * Nonce OCSP extension ASN.1 structure class<br/> +2937 * @name KJUR.asn1.x509.OCSPNonce +2938 * @class Nonce OCSP extension ASN.1 structure class +2939 * @extends KJUR.asn1.x509.Extension +2940 * @since jsrsasign 9.1.6 asn1x509 2.1.2 +2941 * @param {Array} params JSON object for Nonce extension +2942 * @see KJUR.asn1.ocsp.ResponseData +2943 * @see KJUR.asn1.x509.Extensions +2944 * @see X509#getExtOCSPNonce +2945 * @description +2946 * This class represents +2947 * Nonce OCSP extension value defined in +2948 * <a href="https://tools.ietf.org/html/rfc6960#section-4.4.1"> +2949 * RFC 6960 4.4.1</a> as JSON object. +2950 * <pre> +2951 * id-pkix-ocsp OBJECT IDENTIFIER ::= { id-ad-ocsp } +2952 * id-pkix-ocsp-nonce OBJECT IDENTIFIER ::= { id-pkix-ocsp 2 } +2953 * Nonce ::= OCTET STRING +2954 * </pre> +2955 * Constructor of this class may have following parameters: +2956 * <ul> +2957 * <li>{String}extname - name "ocspNonce". It is ignored in this class but +2958 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> +2959 * <li>{String}hex - hexadecimal string of nonce value</li> +2960 * <li>{Number}int - integer of nonce value. "hex" or "int" needs to be +2961 * specified.</li> +2962 * <li>{Boolean}critical - critical flag. Generally false and not specified +2963 * in this class.(OPTION)</li> +2964 * </ul> +2965 * +2966 * @example +2967 * new KJUR.asn1.x509.OCSPNonce({extname:'ocspNonce', +2968 * hex: '12ab...'}) +2969 */ +2970 KJUR.asn1.x509.OCSPNonce = function(params) { +2971 KJUR.asn1.x509.OCSPNonce.superclass.constructor.call(this, params); +2972 this.params = undefined; +2973 +2974 this.getExtnValueHex = function() { +2975 this.asn1ExtnValue = new KJUR.asn1.DEROctetString(this.params); +2976 return this.asn1ExtnValue.tohex(); +2977 }; +2978 +2979 this.oid = "1.3.6.1.5.5.7.48.1.2"; +2980 if (params != undefined) this.params = params; +2981 }; +2982 extendClass(KJUR.asn1.x509.OCSPNonce, KJUR.asn1.x509.Extension); +2983 +2984 /** +2985 * OCSPNoCheck certificate ASN.1 structure class<br/> +2986 * @name KJUR.asn1.x509.OCSPNoCheck +2987 * @class OCSPNoCheck extension ASN.1 structure class +2988 * @extends KJUR.asn1.x509.Extension +2989 * @since jsrsasign 9.1.6 asn1x509 2.1.2 +2990 * @param {Array} params JSON object for OCSPNoCheck extension +2991 * @see KJUR.asn1.x509.Extensions +2992 * @see X509#getExtOCSPNoCheck +2993 * @description +2994 * This class represents +2995 * OCSPNoCheck extension value defined in +2996 * <a href="https://tools.ietf.org/html/rfc6960#section-4.2.2.2.1"> +2997 * RFC 6960 4.2.2.2.1</a> as JSON object. +2998 * <pre> +2999 * id-pkix-ocsp-nocheck OBJECT IDENTIFIER ::= { id-pkix-ocsp 5 } +3000 * </pre> +3001 * Constructor of this class may have following parameters: +3002 * <ul> +3003 * <li>{String}extname - name "ocspNoCheck". It is ignored in this class but +3004 * required to use with {@link KJUR.asn1.x509.Extensions} class. (OPTION)</li> +3005 * <li>{Boolean}critical - critical flag. Generally false and not specified +3006 * in this class.(OPTION)</li> +3007 * </ul> +3008 * +3009 * @example +3010 * new KJUR.asn1.x509.OCSPNonce({extname:'ocspNoCheck'}) +3011 */ +3012 KJUR.asn1.x509.OCSPNoCheck = function(params) { +3013 KJUR.asn1.x509.OCSPNoCheck.superclass.constructor.call(this, params); +3014 this.params = undefined; 3015 -3016 /** -3017 * AdobeTimeStamp X.509v3 extension ASN.1 encoder class<br/> -3018 * @name KJUR.asn1.x509.AdobeTimeStamp -3019 * @class AdobeTimeStamp X.509v3 extension ASN.1 encoder class -3020 * @extends KJUR.asn1.x509.Extension -3021 * @since jsrsasign 10.0.1 asn1x509 2.1.4 -3022 * @param {Array} params JSON object for AdobeTimeStamp extension parameter -3023 * @see KJUR.asn1.x509.Extensions -3024 * @see X509#getExtAdobeTimeStamp -3025 * @description -3026 * This class represents -3027 * AdobeTimeStamp X.509v3 extension value defined in -3028 * <a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/DigSigDC/oids.html"> -3029 * Adobe site</a> as JSON object. -3030 * <pre> -3031 * adbe- OBJECT IDENTIFIER ::= { adbe(1.2.840.113583) acrobat(1) security(1) x509Ext(9) 1 } -3032 * ::= SEQUENCE { -3033 * version INTEGER { v1(1) }, -- extension version -3034 * location GeneralName (In v1 GeneralName can be only uniformResourceIdentifier) -3035 * requiresAuth boolean (default false), OPTIONAL } -3036 * </pre> -3037 * Constructor of this class may have following parameters: -3038 * <ul> -3039 * <li>{String}uri - RFC 3161 time stamp service URL</li> -3040 * <li>{Boolean}reqauth - authentication required or not</li> -3041 * </ul> -3042 * </pre> -3043 * <br/> -3044 * NOTE: This extesion doesn't seem to have official name. This may be called as "pdfTimeStamp". -3045 * @example -3046 * new KJUR.asn1.x509.AdobeTimesStamp({ -3047 * uri: "http://tsa.example.com/", -3048 * reqauth: true -3049 * } -3050 */ -3051 KJUR.asn1.x509.AdobeTimeStamp = function(params) { -3052 KJUR.asn1.x509.AdobeTimeStamp.superclass.constructor.call(this, params); -3053 -3054 var _KJUR = KJUR, -3055 _KJUR_asn1 = _KJUR.asn1, -3056 _DERInteger = _KJUR_asn1.DERInteger, -3057 _DERBoolean = _KJUR_asn1.DERBoolean, -3058 _DERSequence = _KJUR_asn1.DERSequence, -3059 _GeneralName = _KJUR_asn1.x509.GeneralName; -3060 -3061 this.params = null; -3062 -3063 this.getExtnValueHex = function() { -3064 var params = this.params; -3065 var a = [new _DERInteger(1)]; -3066 a.push(new _GeneralName({uri: params.uri})); -3067 if (params.reqauth != undefined) { -3068 a.push(new _DERBoolean(params.reqauth)); -3069 } -3070 -3071 this.asn1ExtnValue = new _DERSequence({array: a}); -3072 return this.asn1ExtnValue.tohex(); -3073 }; +3016 this.getExtnValueHex = function() { +3017 this.asn1ExtnValue = new KJUR.asn1.DERNull(); +3018 return this.asn1ExtnValue.tohex(); +3019 }; +3020 +3021 this.oid = "1.3.6.1.5.5.7.48.1.5"; +3022 if (params != undefined) this.params = params; +3023 }; +3024 extendClass(KJUR.asn1.x509.OCSPNoCheck, KJUR.asn1.x509.Extension); +3025 +3026 // === END OCSP Related =================================================== +3027 +3028 // === BEGIN Other X.509v3 Extensions======================================== +3029 +3030 /** +3031 * AdobeTimeStamp X.509v3 extension ASN.1 encoder class<br/> +3032 * @name KJUR.asn1.x509.AdobeTimeStamp +3033 * @class AdobeTimeStamp X.509v3 extension ASN.1 encoder class +3034 * @extends KJUR.asn1.x509.Extension +3035 * @since jsrsasign 10.0.1 asn1x509 2.1.4 +3036 * @param {Array} params JSON object for AdobeTimeStamp extension parameter +3037 * @see KJUR.asn1.x509.Extensions +3038 * @see X509#getExtAdobeTimeStamp +3039 * @description +3040 * This class represents +3041 * AdobeTimeStamp X.509v3 extension value defined in +3042 * <a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/DigSigDC/oids.html"> +3043 * Adobe site</a> as JSON object. +3044 * <pre> +3045 * adbe- OBJECT IDENTIFIER ::= { adbe(1.2.840.113583) acrobat(1) security(1) x509Ext(9) 1 } +3046 * ::= SEQUENCE { +3047 * version INTEGER { v1(1) }, -- extension version +3048 * location GeneralName (In v1 GeneralName can be only uniformResourceIdentifier) +3049 * requiresAuth boolean (default false), OPTIONAL } +3050 * </pre> +3051 * Constructor of this class may have following parameters: +3052 * <ul> +3053 * <li>{String}uri - RFC 3161 time stamp service URL</li> +3054 * <li>{Boolean}reqauth - authentication required or not</li> +3055 * </ul> +3056 * </pre> +3057 * <br/> +3058 * NOTE: This extesion doesn't seem to have official name. This may be called as "pdfTimeStamp". +3059 * @example +3060 * new KJUR.asn1.x509.AdobeTimesStamp({ +3061 * uri: "http://tsa.example.com/", +3062 * reqauth: true +3063 * } +3064 */ +3065 KJUR.asn1.x509.AdobeTimeStamp = function(params) { +3066 KJUR.asn1.x509.AdobeTimeStamp.superclass.constructor.call(this, params); +3067 +3068 var _KJUR = KJUR, +3069 _KJUR_asn1 = _KJUR.asn1, +3070 _DERInteger = _KJUR_asn1.DERInteger, +3071 _DERBoolean = _KJUR_asn1.DERBoolean, +3072 _DERSequence = _KJUR_asn1.DERSequence, +3073 _GeneralName = _KJUR_asn1.x509.GeneralName; 3074 -3075 this.oid = "1.2.840.113583.1.1.9.1"; -3076 if (params !== undefined) this.setByParam(params); -3077 }; -3078 extendClass(KJUR.asn1.x509.AdobeTimeStamp, KJUR.asn1.x509.Extension); -3079 -3080 // === END Other X.509v3 Extensions======================================== -3081 -3082 -3083 // === BEGIN X500Name Related ================================================= -3084 /** -3085 * X500Name ASN.1 structure class -3086 * @name KJUR.asn1.x509.X500Name -3087 * @class X500Name ASN.1 structure class -3088 * @param {Array} params associative array of parameters (ex. {'str': '/C=US/O=a'}) -3089 * @extends KJUR.asn1.ASN1Object -3090 * @see KJUR.asn1.x509.X500Name -3091 * @see KJUR.asn1.x509.RDN -3092 * @see KJUR.asn1.x509.AttributeTypeAndValue -3093 * @see X509#getX500Name -3094 * @description -3095 * This class provides DistinguishedName ASN.1 class structure -3096 * defined in <a href="https://tools.ietf.org/html/rfc2253#section-2">RFC 2253 section 2</a>. -3097 * <blockquote><pre> -3098 * DistinguishedName ::= RDNSequence -3099 * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName -3100 * RelativeDistinguishedName ::= SET SIZE (1..MAX) OF -3101 * AttributeTypeAndValue -3102 * AttributeTypeAndValue ::= SEQUENCE { -3103 * type AttributeType, -3104 * value AttributeValue } -3105 * </pre></blockquote> -3106 * <br/> -3107 * Argument for the constructor can be one of following parameters: -3108 * <ul> -3109 * <li>{Array}array - array of {@link KJUR.asn1.x509.RDN} parameter</li> -3110 * <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> -3111 * <li>{String}ldapstr - string for distinguish name in LDAP format (ex: CN=test,O=test,C=US)</li> -3112 * <li>{String}hex - hexadecimal string for ASN.1 distinguish name structure</li> -3113 * <li>{String}certissuer - issuer name in the specified PEM certificate</li> -3114 * <li>{String}certsubject - subject name in the specified PEM certificate</li> -3115 * <li>{String}rule - DirectoryString rule (ex. "prn" or "utf8")</li> -3116 * </ul> -3117 * <br/> -3118 * NOTE1: The "array" and "rule" parameters have been supported -3119 * since jsrsasign 9.0.0 asn1x509 2.0.0. +3075 this.params = null; +3076 +3077 this.getExtnValueHex = function() { +3078 var params = this.params; +3079 var a = [new _DERInteger(1)]; +3080 a.push(new _GeneralName({uri: params.uri})); +3081 if (params.reqauth != undefined) { +3082 a.push(new _DERBoolean(params.reqauth)); +3083 } +3084 +3085 this.asn1ExtnValue = new _DERSequence({array: a}); +3086 return this.asn1ExtnValue.tohex(); +3087 }; +3088 +3089 this.oid = "1.2.840.113583.1.1.9.1"; +3090 if (params !== undefined) this.setByParam(params); +3091 }; +3092 extendClass(KJUR.asn1.x509.AdobeTimeStamp, KJUR.asn1.x509.Extension); +3093 +3094 // === END Other X.509v3 Extensions======================================== +3095 +3096 +3097 // === BEGIN X500Name Related ================================================= +3098 /** +3099 * X500Name ASN.1 structure class +3100 * @name KJUR.asn1.x509.X500Name +3101 * @class X500Name ASN.1 structure class +3102 * @param {Array} params associative array of parameters (ex. {'str': '/C=US/O=a'}) +3103 * @extends KJUR.asn1.ASN1Object +3104 * @see KJUR.asn1.x509.X500Name +3105 * @see KJUR.asn1.x509.RDN +3106 * @see KJUR.asn1.x509.AttributeTypeAndValue +3107 * @see X509#getX500Name +3108 * @description +3109 * This class provides DistinguishedName ASN.1 class structure +3110 * defined in <a href="https://tools.ietf.org/html/rfc2253#section-2">RFC 2253 section 2</a>. +3111 * <blockquote><pre> +3112 * DistinguishedName ::= RDNSequence +3113 * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName +3114 * RelativeDistinguishedName ::= SET SIZE (1..MAX) OF +3115 * AttributeTypeAndValue +3116 * AttributeTypeAndValue ::= SEQUENCE { +3117 * type AttributeType, +3118 * value AttributeValue } +3119 * </pre></blockquote> 3120 * <br/> -3121 * NOTE2: Multi-valued RDN in "str" parameter have been -3122 * supported since jsrsasign 6.2.1 asn1x509 1.0.17. -3123 * @example -3124 * // 1. construct with array -3125 * new KJUR.asn1.x509.X500Name({array:[ -3126 * [{type:'C',value:'JP',ds:'prn'}], -3127 * [{type:'O',value:'aaa',ds:'utf8'}, // multi-valued RDN -3128 * {type:'CN',value:'bob@example.com',ds:'ia5'}] -3129 * ]}) -3130 * // 2. construct with string -3131 * new KJUR.asn1.x509.X500Name({str: "/C=US/ST=NY/L=Ballston Spa/STREET=915 Stillwater Ave"}); -3132 * new KJUR.asn1.x509.X500Name({str: "/CN=AAA/2.5.4.42=John/surname=Ray"}); -3133 * new KJUR.asn1.x509.X500Name({str: "/C=US/O=aaa+CN=contact@example.com"}); // multi valued -3134 * // 3. construct by LDAP string -3135 * new KJUR.asn1.x509.X500Name({ldapstr: "CN=foo@example.com,OU=bbb,C=US"}); -3136 * // 4. construct by ASN.1 hex string -3137 * new KJUR.asn1.x509.X500Name({hex: "304c3120..."}); -3138 * // 5. construct by issuer of PEM certificate -3139 * new KJUR.asn1.x509.X500Name({certsubject: "-----BEGIN CERT..."}); -3140 * // 6. construct by subject of PEM certificate -3141 * new KJUR.asn1.x509.X500Name({certissuer: "-----BEGIN CERT..."}); -3142 * // 7. construct by object (DEPRECATED) -3143 * new KJUR.asn1.x509.X500Name({C:"US",O:"aaa",CN:"http://example.com/"}); -3144 */ -3145 KJUR.asn1.x509.X500Name = function(params) { -3146 KJUR.asn1.x509.X500Name.superclass.constructor.call(this); -3147 this.asn1Array = []; -3148 this.paramArray = []; -3149 this.sRule = "utf8"; -3150 var _KJUR = KJUR, -3151 _KJUR_asn1 = _KJUR.asn1, -3152 _KJUR_asn1_x509 = _KJUR_asn1.x509, -3153 _RDN = _KJUR_asn1_x509.RDN, -3154 _pemtohex = pemtohex; -3155 -3156 /** -3157 * set DN by OpenSSL oneline distinguished name string<br/> -3158 * @name setByString -3159 * @memberOf KJUR.asn1.x509.X500Name# -3160 * @function -3161 * @param {String} dnStr distinguished name by string (ex. /C=US/O=aaa) -3162 * @description -3163 * Sets distinguished name by string. -3164 * dnStr must be formatted as -3165 * "/type0=value0/type1=value1/type2=value2...". -3166 * No need to escape a slash in an attribute value. -3167 * @example -3168 * name = new KJUR.asn1.x509.X500Name(); -3169 * name.setByString("/C=US/O=aaa/OU=bbb/CN=foo@example.com"); -3170 * // no need to escape slash in an attribute value -3171 * name.setByString("/C=US/O=aaa/CN=1980/12/31"); -3172 */ -3173 this.setByString = function(dnStr, sRule) { -3174 if (sRule !== undefined) this.sRule = sRule; -3175 var a = dnStr.split('/'); -3176 a.shift(); -3177 -3178 var a1 = []; -3179 for (var i = 0; i < a.length; i++) { -3180 if (a[i].match(/^[^=]+=.+$/)) { -3181 a1.push(a[i]); -3182 } else { -3183 var lastidx = a1.length - 1; -3184 a1[lastidx] = a1[lastidx] + "/" + a[i]; -3185 } -3186 } -3187 -3188 for (var i = 0; i < a1.length; i++) { -3189 this.asn1Array.push(new _RDN({'str':a1[i], rule:this.sRule})); -3190 } -3191 }; -3192 -3193 /** -3194 * set DN by LDAP(RFC 2253) distinguished name string<br/> -3195 * @name setByLdapString -3196 * @memberOf KJUR.asn1.x509.X500Name# -3197 * @function -3198 * @param {String} dnStr distinguished name by LDAP string (ex. O=aaa,C=US) -3199 * @since jsrsasign 6.2.2 asn1x509 1.0.18 -3200 * @see {@link KJUR.asn1.x509.X500Name.ldapToCompat} -3201 * @description -3202 * @example -3203 * name = new KJUR.asn1.x509.X500Name(); -3204 * name.setByLdapString("CN=foo@example.com,OU=bbb,O=aaa,C=US"); -3205 */ -3206 this.setByLdapString = function(dnStr, sRule) { -3207 if (sRule !== undefined) this.sRule = sRule; -3208 var compat = _KJUR_asn1_x509.X500Name.ldapToCompat(dnStr); -3209 this.setByString(compat, sRule); -3210 }; -3211 -3212 /** -3213 * set DN by associative array<br/> -3214 * @name setByObject -3215 * @memberOf KJUR.asn1.x509.X500Name# -3216 * @function -3217 * @param {Array} dnObj associative array of DN (ex. {C: "US", O: "aaa"}) -3218 * @since jsrsasign 4.9. asn1x509 1.0.13 -3219 * @description -3220 * @example -3221 * name = new KJUR.asn1.x509.X500Name(); -3222 * name.setByObject({C: "US", O: "aaa", CN="http://example.com/"1}); -3223 */ -3224 this.setByObject = function(dnObj, sRule) { -3225 if (sRule !== undefined) this.sRule = sRule; -3226 -3227 // Get all the dnObject attributes and stuff them in the ASN.1 array. -3228 for (var x in dnObj) { -3229 if (dnObj.hasOwnProperty(x)) { -3230 var newRDN = new _RDN({str: x + '=' + dnObj[x], rule: this.sRule}); -3231 // Initialize or push into the ANS1 array. -3232 this.asn1Array ? this.asn1Array.push(newRDN) -3233 : this.asn1Array = [newRDN]; -3234 } -3235 } -3236 }; -3237 -3238 this.setByParam = function(params) { -3239 if (params.rule !== undefined) this.sRule = params.rule; +3121 * Argument for the constructor can be one of following parameters: +3122 * <ul> +3123 * <li>{Array}array - array of {@link KJUR.asn1.x509.RDN} parameter</li> +3124 * <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> +3125 * <li>{String}ldapstr - string for distinguish name in LDAP format (ex: CN=test,O=test,C=US)</li> +3126 * <li>{String}hex - hexadecimal string for ASN.1 distinguish name structure</li> +3127 * <li>{String}certissuer - issuer name in the specified PEM certificate</li> +3128 * <li>{String}certsubject - subject name in the specified PEM certificate</li> +3129 * <li>{String}rule - DirectoryString rule (ex. "prn" or "utf8")</li> +3130 * </ul> +3131 * <br/> +3132 * NOTE1: The "array" and "rule" parameters have been supported +3133 * since jsrsasign 9.0.0 asn1x509 2.0.0. +3134 * <br/> +3135 * NOTE2: Multi-valued RDN in "str" parameter have been +3136 * supported since jsrsasign 6.2.1 asn1x509 1.0.17. +3137 * @example +3138 * // 1. construct with array +3139 * new KJUR.asn1.x509.X500Name({array:[ +3140 * [{type:'C',value:'JP',ds:'prn'}], +3141 * [{type:'O',value:'aaa',ds:'utf8'}, // multi-valued RDN +3142 * {type:'CN',value:'bob@example.com',ds:'ia5'}] +3143 * ]}) +3144 * // 2. construct with string +3145 * new KJUR.asn1.x509.X500Name({str: "/C=US/ST=NY/L=Ballston Spa/STREET=915 Stillwater Ave"}); +3146 * new KJUR.asn1.x509.X500Name({str: "/CN=AAA/2.5.4.42=John/surname=Ray"}); +3147 * new KJUR.asn1.x509.X500Name({str: "/C=US/O=aaa+CN=contact@example.com"}); // multi valued +3148 * // 3. construct by LDAP string +3149 * new KJUR.asn1.x509.X500Name({ldapstr: "CN=foo@example.com,OU=bbb,C=US"}); +3150 * // 4. construct by ASN.1 hex string +3151 * new KJUR.asn1.x509.X500Name({hex: "304c3120..."}); +3152 * // 5. construct by issuer of PEM certificate +3153 * new KJUR.asn1.x509.X500Name({certsubject: "-----BEGIN CERT..."}); +3154 * // 6. construct by subject of PEM certificate +3155 * new KJUR.asn1.x509.X500Name({certissuer: "-----BEGIN CERT..."}); +3156 * // 7. construct by object (DEPRECATED) +3157 * new KJUR.asn1.x509.X500Name({C:"US",O:"aaa",CN:"http://example.com/"}); +3158 */ +3159 KJUR.asn1.x509.X500Name = function(params) { +3160 KJUR.asn1.x509.X500Name.superclass.constructor.call(this); +3161 this.asn1Array = []; +3162 this.paramArray = []; +3163 this.sRule = "utf8"; +3164 var _KJUR = KJUR, +3165 _KJUR_asn1 = _KJUR.asn1, +3166 _KJUR_asn1_x509 = _KJUR_asn1.x509, +3167 _RDN = _KJUR_asn1_x509.RDN, +3168 _pemtohex = pemtohex; +3169 +3170 /** +3171 * set DN by OpenSSL oneline distinguished name string<br/> +3172 * @name setByString +3173 * @memberOf KJUR.asn1.x509.X500Name# +3174 * @function +3175 * @param {String} dnStr distinguished name by string (ex. /C=US/O=aaa) +3176 * @description +3177 * Sets distinguished name by string. +3178 * dnStr must be formatted as +3179 * "/type0=value0/type1=value1/type2=value2...". +3180 * No need to escape a slash in an attribute value. +3181 * @example +3182 * name = new KJUR.asn1.x509.X500Name(); +3183 * name.setByString("/C=US/O=aaa/OU=bbb/CN=foo@example.com"); +3184 * // no need to escape slash in an attribute value +3185 * name.setByString("/C=US/O=aaa/CN=1980/12/31"); +3186 */ +3187 this.setByString = function(dnStr, sRule) { +3188 if (sRule !== undefined) this.sRule = sRule; +3189 var a = dnStr.split('/'); +3190 a.shift(); +3191 +3192 var a1 = []; +3193 for (var i = 0; i < a.length; i++) { +3194 if (a[i].match(/^[^=]+=.+$/)) { +3195 a1.push(a[i]); +3196 } else { +3197 var lastidx = a1.length - 1; +3198 a1[lastidx] = a1[lastidx] + "/" + a[i]; +3199 } +3200 } +3201 +3202 for (var i = 0; i < a1.length; i++) { +3203 this.asn1Array.push(new _RDN({'str':a1[i], rule:this.sRule})); +3204 } +3205 }; +3206 +3207 /** +3208 * set DN by LDAP(RFC 2253) distinguished name string<br/> +3209 * @name setByLdapString +3210 * @memberOf KJUR.asn1.x509.X500Name# +3211 * @function +3212 * @param {String} dnStr distinguished name by LDAP string (ex. O=aaa,C=US) +3213 * @since jsrsasign 6.2.2 asn1x509 1.0.18 +3214 * @see {@link KJUR.asn1.x509.X500Name.ldapToCompat} +3215 * @description +3216 * @example +3217 * name = new KJUR.asn1.x509.X500Name(); +3218 * name.setByLdapString("CN=foo@example.com,OU=bbb,O=aaa,C=US"); +3219 */ +3220 this.setByLdapString = function(dnStr, sRule) { +3221 if (sRule !== undefined) this.sRule = sRule; +3222 var compat = _KJUR_asn1_x509.X500Name.ldapToCompat(dnStr); +3223 this.setByString(compat, sRule); +3224 }; +3225 +3226 /** +3227 * set DN by associative array<br/> +3228 * @name setByObject +3229 * @memberOf KJUR.asn1.x509.X500Name# +3230 * @function +3231 * @param {Array} dnObj associative array of DN (ex. {C: "US", O: "aaa"}) +3232 * @since jsrsasign 4.9. asn1x509 1.0.13 +3233 * @description +3234 * @example +3235 * name = new KJUR.asn1.x509.X500Name(); +3236 * name.setByObject({C: "US", O: "aaa", CN="http://example.com/"1}); +3237 */ +3238 this.setByObject = function(dnObj, sRule) { +3239 if (sRule !== undefined) this.sRule = sRule; 3240 -3241 if (params.array !== undefined) { -3242 this.paramArray = params.array; -3243 } else { -3244 if (params.str !== undefined) { -3245 this.setByString(params.str); -3246 } else if (params.ldapstr !== undefined) { -3247 this.setByLdapString(params.ldapstr); -3248 } else if (params.hex !== undefined) { -3249 this.hTLV = params.hex; -3250 } else if (params.certissuer !== undefined) { -3251 var x = new X509(); -3252 x.readCertPEM(params.certissuer); -3253 this.hTLV = x.getIssuerHex(); -3254 } else if (params.certsubject !== undefined) { -3255 var x = new X509(); -3256 x.readCertPEM(params.certsubject); -3257 this.hTLV = x.getSubjectHex(); -3258 // If params is an object, then set the ASN1 array -3259 // just using the object attributes. -3260 // This is nice for fields that have lots of special -3261 // characters (i.e. CN: 'https://www.github.com/kjur//'). -3262 } else if (typeof params === "object" && -3263 params.certsubject === undefined && -3264 params.certissuer === undefined) { -3265 this.setByObject(params); -3266 } -3267 } -3268 } -3269 -3270 this.tohex = function() { -3271 if (typeof this.hTLV == "string") return this.hTLV; -3272 -3273 if (this.asn1Array.length == 0 && this.paramArray.length > 0) { -3274 for (var i = 0; i < this.paramArray.length; i++) { -3275 var param = {array: this.paramArray[i]}; -3276 if (this.sRule != "utf8") param.rule = this.sRule; -3277 var asn1RDN = new _RDN(param); -3278 this.asn1Array.push(asn1RDN); -3279 } -3280 } -3281 -3282 var o = new _KJUR_asn1.DERSequence({"array": this.asn1Array}); -3283 this.hTLV = o.tohex(); -3284 return this.hTLV; -3285 }; -3286 this.getEncodedHex = function() { return this.tohex(); }; -3287 -3288 if (params !== undefined) this.setByParam(params); -3289 }; -3290 extendClass(KJUR.asn1.x509.X500Name, KJUR.asn1.ASN1Object); -3291 -3292 /** -3293 * convert OpenSSL compat distinguished name format string to LDAP(RFC 2253) format<br/> -3294 * @name compatToLDAP -3295 * @memberOf KJUR.asn1.x509.X500Name -3296 * @function -3297 * @param {String} s distinguished name string in OpenSSL oneline compat (ex. /C=US/O=test) -3298 * @return {String} distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) -3299 * @since jsrsasign 8.0.19 asn1x509 1.1.20 -3300 * @description -3301 * This static method converts a distinguished name string in OpenSSL compat -3302 * format to LDAP(RFC 2253) format. -3303 * @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> -3304 * @see <a href="https://www.openssl.org/docs/man1.0.2/man1/openssl-x509.html#NAME-OPTIONS">OpenSSL x509 command manual - NAME OPTIONS</a> -3305 * @example -3306 * KJUR.asn1.x509.X500Name.compatToLDAP("/C=US/O=test") → 'O=test,C=US' -3307 * KJUR.asn1.x509.X500Name.compatToLDAP("/C=US/O=a,a") → 'O=a\,a,C=US' -3308 */ -3309 KJUR.asn1.x509.X500Name.compatToLDAP = function(s) { -3310 if (s.substr(0, 1) !== "/") throw "malformed input"; -3311 -3312 var result = ""; -3313 s = s.substr(1); -3314 -3315 var a = s.split("/"); -3316 a.reverse(); -3317 a = a.map(function(s) {return s.replace(/,/, "\\,")}); -3318 -3319 return a.join(","); -3320 }; -3321 -3322 /** -3323 * convert OpenSSL compat distinguished name format string to LDAP(RFC 2253) format (DEPRECATED)<br/> -3324 * @name onelineToLDAP -3325 * @memberOf KJUR.asn1.x509.X500Name -3326 * @function -3327 * @param {String} s distinguished name string in OpenSSL compat format (ex. /C=US/O=test) -3328 * @return {String} distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) -3329 * @since jsrsasign 6.2.2 asn1x509 1.0.18 -3330 * @see KJUR.asn1.x509.X500Name.compatToLDAP -3331 * @description -3332 * This method is deprecated. Please use -3333 * {@link KJUR.asn1.x509.X500Name.compatToLDAP} instead. -3334 */ -3335 KJUR.asn1.x509.X500Name.onelineToLDAP = function(s) { -3336 return KJUR.asn1.x509.X500Name.compatToLDAP(s); -3337 } -3338 -3339 /** -3340 * convert LDAP(RFC 2253) distinguished name format string to OpenSSL compat format<br/> -3341 * @name ldapToCompat -3342 * @memberOf KJUR.asn1.x509.X500Name -3343 * @function -3344 * @param {String} s distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) -3345 * @return {String} distinguished name string in OpenSSL compat format (ex. /C=US/O=test) -3346 * @since jsrsasign 8.0.19 asn1x509 1.1.10 -3347 * @description -3348 * This static method converts a distinguished name string in -3349 * LDAP(RFC 2253) format to OpenSSL compat format. -3350 * @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> -3351 * @example -3352 * KJUR.asn1.x509.X500Name.ldapToCompat('O=test,C=US') → '/C=US/O=test' -3353 * KJUR.asn1.x509.X500Name.ldapToCompat('O=a\,a,C=US') → '/C=US/O=a,a' -3354 * KJUR.asn1.x509.X500Name.ldapToCompat('O=a/a,C=US') → '/C=US/O=a\/a' -3355 */ -3356 KJUR.asn1.x509.X500Name.ldapToCompat = function(s) { -3357 var a = s.split(","); -3358 -3359 // join \, -3360 var isBSbefore = false; -3361 var a2 = []; -3362 for (var i = 0; a.length > 0; i++) { -3363 var item = a.shift(); -3364 //console.log("item=" + item); -3365 -3366 if (isBSbefore === true) { -3367 var a2last = a2.pop(); -3368 var newitem = (a2last + "," + item).replace(/\\,/g, ","); -3369 a2.push(newitem); -3370 isBSbefore = false; -3371 } else { -3372 a2.push(item); -3373 } -3374 -3375 if (item.substr(-1, 1) === "\\") isBSbefore = true; -3376 } -3377 -3378 a2 = a2.map(function(s) {return s.replace("/", "\\/")}); -3379 a2.reverse(); -3380 return "/" + a2.join("/"); -3381 }; -3382 -3383 /** -3384 * convert LDAP(RFC 2253) distinguished name format string to OpenSSL compat format (DEPRECATED)<br/> -3385 * @name ldapToOneline -3386 * @memberOf KJUR.asn1.x509.X500Name -3387 * @function -3388 * @param {String} s distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) -3389 * @return {String} distinguished name string in OpenSSL compat format (ex. /C=US/O=test) -3390 * @since jsrsasign 6.2.2 asn1x509 1.0.18 -3391 * @description -3392 * This method is deprecated. Please use -3393 * {@link KJUR.asn1.x509.X500Name.ldapToCompat} instead. -3394 */ -3395 KJUR.asn1.x509.X500Name.ldapToOneline = function(s) { -3396 return KJUR.asn1.x509.X500Name.ldapToCompat(s); -3397 }; -3398 -3399 /** -3400 * RDN (Relative Distinguished Name) ASN.1 structure class -3401 * @name KJUR.asn1.x509.RDN -3402 * @class RDN (Relative Distinguished Name) ASN.1 structure class -3403 * @param {Array} params associative array of parameters (ex. {'str': 'C=US'}) -3404 * @extends KJUR.asn1.ASN1Object -3405 * @see KJUR.asn1.x509.X500Name -3406 * @see KJUR.asn1.x509.RDN -3407 * @see KJUR.asn1.x509.AttributeTypeAndValue -3408 * @description -3409 * This class provides RelativeDistinguishedName ASN.1 class structure -3410 * defined in <a href="https://tools.ietf.org/html/rfc2253#section-2">RFC 2253 section 2</a>. -3411 * <blockquote><pre> -3412 * RelativeDistinguishedName ::= SET SIZE (1..MAX) OF -3413 * AttributeTypeAndValue -3414 * -3415 * AttributeTypeAndValue ::= SEQUENCE { -3416 * type AttributeType, -3417 * value AttributeValue } -3418 * </pre></blockquote> -3419 * <br/> -3420 * NOTE1: The "array" and "rule" parameters have been supported -3421 * since jsrsasign 9.0.0 asn1x509 2.0.0. -3422 * <br/> -3423 * NOTE2: Multi-valued RDN in "str" parameter have been -3424 * supported since jsrsasign 6.2.1 asn1x509 1.0.17. -3425 * @example -3426 * new KJUR.asn1.x509.RDN({array: [ // multi-valued -3427 * {type:"CN",value:"Bob",ds:"prn"}, -3428 * {type:"CN",value:"bob@example.com", ds:"ia5"} -3429 * ]}); -3430 * new KJUR.asn1.x509.RDN({str: "CN=test"}); -3431 * new KJUR.asn1.x509.RDN({str: "O=a+O=bb+O=c"}); // multi-valued -3432 * new KJUR.asn1.x509.RDN({str: "O=a+O=b\\+b+O=c"}); // plus escaped -3433 * new KJUR.asn1.x509.RDN({str: "O=a+O=\"b+b\"+O=c"}); // double quoted -3434 */ -3435 KJUR.asn1.x509.RDN = function(params) { -3436 KJUR.asn1.x509.RDN.superclass.constructor.call(this); -3437 this.asn1Array = []; -3438 this.paramArray = []; -3439 this.sRule = "utf8"; // DEFAULT "utf8" -3440 var _AttributeTypeAndValue = KJUR.asn1.x509.AttributeTypeAndValue; -3441 -3442 this.setByParam = function(params) { -3443 if (params.rule !== undefined) this.sRule = params.rule; -3444 if (params.str !== undefined) { -3445 this.addByMultiValuedString(params.str); -3446 } -3447 if (params.array !== undefined) this.paramArray = params.array; -3448 }; -3449 -3450 /** -3451 * add one AttributeTypeAndValue by string<br/> -3452 * @name addByString -3453 * @memberOf KJUR.asn1.x509.RDN# -3454 * @function -3455 * @param {String} s string of AttributeTypeAndValue -3456 * @return {Object} unspecified -3457 * @description -3458 * This method add one AttributeTypeAndValue to RDN object. -3459 * @example -3460 * rdn = new KJUR.asn1.x509.RDN(); -3461 * rdn.addByString("CN=john"); -3462 * rdn.addByString("serialNumber=1234"); // for multi-valued RDN -3463 */ -3464 this.addByString = function(s) { -3465 this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({'str': s, rule: this.sRule})); -3466 }; -3467 -3468 /** -3469 * add one AttributeTypeAndValue by multi-valued string<br/> -3470 * @name addByMultiValuedString -3471 * @memberOf KJUR.asn1.x509.RDN# -3472 * @function -3473 * @param {String} s string of multi-valued RDN -3474 * @return {Object} unspecified -3475 * @since jsrsasign 6.2.1 asn1x509 1.0.17 -3476 * @description -3477 * This method add multi-valued RDN to RDN object. -3478 * @example -3479 * rdn = new KJUR.asn1.x509.RDN(); -3480 * rdn.addByMultiValuedString("CN=john+O=test"); -3481 * rdn.addByMultiValuedString("O=a+O=b\+b\+b+O=c"); // multi-valued RDN with quoted plus -3482 * rdn.addByMultiValuedString("O=a+O=\"b+b+b\"+O=c"); // multi-valued RDN with quoted quotation -3483 */ -3484 this.addByMultiValuedString = function(s) { -3485 var a = KJUR.asn1.x509.RDN.parseString(s); -3486 for (var i = 0; i < a.length; i++) { -3487 this.addByString(a[i]); -3488 } -3489 }; -3490 -3491 this.tohex = function() { -3492 if (this.asn1Array.length == 0 && this.paramArray.length > 0) { -3493 for (var i = 0; i < this.paramArray.length; i++) { -3494 var param = this.paramArray[i]; -3495 if (param.rule !== undefined && -3496 this.sRule != "utf8") { -3497 param.rule = this.sRule; -3498 } -3499 //alert(JSON.stringify(param)); -3500 var asn1ATV = new _AttributeTypeAndValue(param); -3501 this.asn1Array.push(asn1ATV); -3502 } -3503 } -3504 var o = new KJUR.asn1.DERSet({"array": this.asn1Array}); -3505 this.TLV = o.tohex(); -3506 return this.TLV; -3507 }; -3508 this.getEncodedHex = function() { return this.tohex(); }; -3509 -3510 if (params !== undefined) { -3511 this.setByParam(params); -3512 } -3513 }; -3514 extendClass(KJUR.asn1.x509.RDN, KJUR.asn1.ASN1Object); -3515 -3516 /** -3517 * parse multi-valued RDN string and split into array of 'AttributeTypeAndValue'<br/> -3518 * @name parseString -3519 * @memberOf KJUR.asn1.x509.RDN -3520 * @function -3521 * @param {String} s multi-valued string of RDN -3522 * @return {Array} array of string of AttributeTypeAndValue -3523 * @since jsrsasign 6.2.1 asn1x509 1.0.17 -3524 * @description -3525 * This static method parses multi-valued RDN string and split into -3526 * array of AttributeTypeAndValue. -3527 * @example -3528 * KJUR.asn1.x509.RDN.parseString("CN=john") → ["CN=john"] -3529 * KJUR.asn1.x509.RDN.parseString("CN=john+OU=test") → ["CN=john", "OU=test"] -3530 * KJUR.asn1.x509.RDN.parseString('CN="jo+hn"+OU=test') → ["CN=jo+hn", "OU=test"] -3531 * KJUR.asn1.x509.RDN.parseString('CN=jo\+hn+OU=test') → ["CN=jo+hn", "OU=test"] -3532 * KJUR.asn1.x509.RDN.parseString("CN=john+OU=test+OU=t1") → ["CN=john", "OU=test", "OU=t1"] -3533 */ -3534 KJUR.asn1.x509.RDN.parseString = function(s) { -3535 var a = s.split(/\+/); -3536 -3537 // join \+ -3538 var isBSbefore = false; -3539 var a2 = []; -3540 for (var i = 0; a.length > 0; i++) { -3541 var item = a.shift(); -3542 //console.log("item=" + item); -3543 -3544 if (isBSbefore === true) { -3545 var a2last = a2.pop(); -3546 var newitem = (a2last + "+" + item).replace(/\\\+/g, "+"); -3547 a2.push(newitem); -3548 isBSbefore = false; -3549 } else { -3550 a2.push(item); -3551 } -3552 -3553 if (item.substr(-1, 1) === "\\") isBSbefore = true; -3554 } -3555 -3556 // join quote -3557 var beginQuote = false; -3558 var a3 = []; -3559 for (var i = 0; a2.length > 0; i++) { -3560 var item = a2.shift(); -3561 -3562 if (beginQuote === true) { -3563 var a3last = a3.pop(); -3564 if (item.match(/"$/)) { -3565 var newitem = (a3last + "+" + item).replace(/^([^=]+)="(.*)"$/, "$1=$2"); -3566 a3.push(newitem); -3567 beginQuote = false; -3568 } else { -3569 a3.push(a3last + "+" + item); -3570 } -3571 } else { -3572 a3.push(item); -3573 } -3574 -3575 if (item.match(/^[^=]+="/)) { -3576 //console.log(i + "=" + item); -3577 beginQuote = true; -3578 } -3579 } -3580 return a3; -3581 }; -3582 -3583 /** -3584 * AttributeTypeAndValue ASN.1 structure class -3585 * @name KJUR.asn1.x509.AttributeTypeAndValue -3586 * @class AttributeTypeAndValue ASN.1 structure class -3587 * @param {Array} params JSON object for parameters (ex. {str: 'C=US'}) -3588 * @extends KJUR.asn1.ASN1Object -3589 * @see KJUR.asn1.x509.X500Name -3590 * @see KJUR.asn1.x509.RDN -3591 * @see KJUR.asn1.x509.AttributeTypeAndValue -3592 * @see X509#getAttrTypeAndValue -3593 * @description -3594 * This class generates AttributeTypeAndValue defined in -3595 * <a href="https://tools.ietf.org/html/rfc5280#section-4.1.2.4"> -3596 * RFC 5280 4.1.2.4</a>. -3597 * <pre> -3598 * AttributeTypeAndValue ::= SEQUENCE { -3599 * type AttributeType, -3600 * value AttributeValue } -3601 * AttributeType ::= OBJECT IDENTIFIER -3602 * AttributeValue ::= ANY -- DEFINED BY AttributeType -3603 * </pre> -3604 * The constructor argument can have following parameters: -3605 * <ul> -3606 * <li>{String}type - AttributeType name or OID(ex. C,O,CN)</li> -3607 * <li>{String}value - raw string of ASN.1 value of AttributeValue</li> -3608 * <li>{String}ds - DirectoryString type of AttributeValue</li> -3609 * <li>{String}rule - DirectoryString type rule (ex. "prn" or "utf8") -3610 * set DirectoryString type automatically when "ds" not specified.</li> -3611 * <li>{String}str - AttributeTypeAndVale string (ex. "C=US"). -3612 * When type and value don't exists, -3613 * this "str" will be converted to "type" and "value". -3614 * </li> -3615 * </ul> -3616 * <br -3617 * NOTE: Parameters "type", "value,", "ds" and "rule" have -3618 * been supported since jsrsasign 9.0.0 asn1x509 2.0.0. -3619 * @example -3620 * new KJUR.asn1.x509.AttributeTypeAndValue({type:'C',value:'US',ds:'prn'}) -3621 * new KJUR.asn1.x509.AttributeTypeAndValue({type:'givenName',value:'John',ds:'prn'}) -3622 * new KJUR.asn1.x509.AttributeTypeAndValue({type:'2.5.4.9',value:'71 Bowman St',ds:'prn'}) -3623 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1'}) -3624 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'streetAddress=71 Bowman St'}) -3625 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1',rule='prn'}) -3626 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1',rule='utf8'}) -3627 */ -3628 KJUR.asn1.x509.AttributeTypeAndValue = function(params) { -3629 KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this); -3630 this.sRule = "utf8"; -3631 this.sType = null; -3632 this.sValue = null; -3633 this.dsType = null; -3634 var _KJUR = KJUR, -3635 _KJUR_asn1 = _KJUR.asn1, -3636 _DERSequence = _KJUR_asn1.DERSequence, -3637 _DERUTF8String = _KJUR_asn1.DERUTF8String, -3638 _DERPrintableString = _KJUR_asn1.DERPrintableString, -3639 _DERTeletexString = _KJUR_asn1.DERTeletexString, -3640 _DERIA5String = _KJUR_asn1.DERIA5String, -3641 _DERVisibleString = _KJUR_asn1.DERVisibleString, -3642 _DERBMPString = _KJUR_asn1.DERBMPString, -3643 _isMail = _KJUR.lang.String.isMail, -3644 _isPrintable = _KJUR.lang.String.isPrintable; -3645 -3646 this.setByParam = function(params) { -3647 if (params.rule !== undefined) this.sRule = params.rule; -3648 if (params.ds !== undefined) this.dsType = params.ds; -3649 -3650 if (params.value === undefined && -3651 params.str !== undefined) { -3652 var str = params.str; -3653 var matchResult = str.match(/^([^=]+)=(.+)$/); -3654 if (matchResult) { -3655 this.sType = matchResult[1]; -3656 this.sValue = matchResult[2]; -3657 } else { -3658 throw new Error("malformed attrTypeAndValueStr: " + -3659 attrTypeAndValueStr); -3660 } -3661 -3662 //this.setByString(params.str); -3663 } else { -3664 this.sType = params.type; -3665 this.sValue = params.value; -3666 } -3667 }; -3668 -3669 /* -3670 * @deprecated -3671 */ -3672 this.setByString = function(sTypeValue, sRule) { -3673 if (sRule !== undefined) this.sRule = sRule; -3674 var matchResult = sTypeValue.match(/^([^=]+)=(.+)$/); -3675 if (matchResult) { -3676 this.setByAttrTypeAndValueStr(matchResult[1], matchResult[2]); +3241 // Get all the dnObject attributes and stuff them in the ASN.1 array. +3242 for (var x in dnObj) { +3243 if (dnObj.hasOwnProperty(x)) { +3244 var newRDN = new _RDN({str: x + '=' + dnObj[x], rule: this.sRule}); +3245 // Initialize or push into the ANS1 array. +3246 this.asn1Array ? this.asn1Array.push(newRDN) +3247 : this.asn1Array = [newRDN]; +3248 } +3249 } +3250 }; +3251 +3252 this.setByParam = function(params) { +3253 if (params.rule !== undefined) this.sRule = params.rule; +3254 +3255 if (params.array !== undefined) { +3256 this.paramArray = params.array; +3257 } else { +3258 if (params.str !== undefined) { +3259 this.setByString(params.str); +3260 } else if (params.ldapstr !== undefined) { +3261 this.setByLdapString(params.ldapstr); +3262 } else if (params.hex !== undefined) { +3263 this.hTLV = params.hex; +3264 } else if (params.certissuer !== undefined) { +3265 var x = new X509(); +3266 x.readCertPEM(params.certissuer); +3267 this.hTLV = x.getIssuerHex(); +3268 } else if (params.certsubject !== undefined) { +3269 var x = new X509(); +3270 x.readCertPEM(params.certsubject); +3271 this.hTLV = x.getSubjectHex(); +3272 // If params is an object, then set the ASN1 array +3273 // just using the object attributes. +3274 // This is nice for fields that have lots of special +3275 // characters (i.e. CN: 'https://www.github.com/kjur//'). +3276 } else if (typeof params === "object" && +3277 params.certsubject === undefined && +3278 params.certissuer === undefined) { +3279 this.setByObject(params); +3280 } +3281 } +3282 } +3283 +3284 this.tohex = function() { +3285 if (typeof this.hTLV == "string") return this.hTLV; +3286 +3287 if (this.asn1Array.length == 0 && this.paramArray.length > 0) { +3288 for (var i = 0; i < this.paramArray.length; i++) { +3289 var param = {array: this.paramArray[i]}; +3290 if (this.sRule != "utf8") param.rule = this.sRule; +3291 var asn1RDN = new _RDN(param); +3292 this.asn1Array.push(asn1RDN); +3293 } +3294 } +3295 +3296 var o = new _KJUR_asn1.DERSequence({"array": this.asn1Array}); +3297 this.hTLV = o.tohex(); +3298 return this.hTLV; +3299 }; +3300 this.getEncodedHex = function() { return this.tohex(); }; +3301 +3302 if (params !== undefined) this.setByParam(params); +3303 }; +3304 extendClass(KJUR.asn1.x509.X500Name, KJUR.asn1.ASN1Object); +3305 +3306 /** +3307 * convert OpenSSL compat distinguished name format string to LDAP(RFC 2253) format<br/> +3308 * @name compatToLDAP +3309 * @memberOf KJUR.asn1.x509.X500Name +3310 * @function +3311 * @param {String} s distinguished name string in OpenSSL oneline compat (ex. /C=US/O=test) +3312 * @return {String} distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) +3313 * @since jsrsasign 8.0.19 asn1x509 1.1.20 +3314 * @description +3315 * This static method converts a distinguished name string in OpenSSL compat +3316 * format to LDAP(RFC 2253) format. +3317 * @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> +3318 * @see <a href="https://www.openssl.org/docs/man1.0.2/man1/openssl-x509.html#NAME-OPTIONS">OpenSSL x509 command manual - NAME OPTIONS</a> +3319 * @example +3320 * KJUR.asn1.x509.X500Name.compatToLDAP("/C=US/O=test") → 'O=test,C=US' +3321 * KJUR.asn1.x509.X500Name.compatToLDAP("/C=US/O=a,a") → 'O=a\,a,C=US' +3322 */ +3323 KJUR.asn1.x509.X500Name.compatToLDAP = function(s) { +3324 if (s.substr(0, 1) !== "/") throw "malformed input"; +3325 +3326 var result = ""; +3327 s = s.substr(1); +3328 +3329 var a = s.split("/"); +3330 a.reverse(); +3331 a = a.map(function(s) {return s.replace(/,/, "\\,")}); +3332 +3333 return a.join(","); +3334 }; +3335 +3336 /** +3337 * convert OpenSSL compat distinguished name format string to LDAP(RFC 2253) format (DEPRECATED)<br/> +3338 * @name onelineToLDAP +3339 * @memberOf KJUR.asn1.x509.X500Name +3340 * @function +3341 * @param {String} s distinguished name string in OpenSSL compat format (ex. /C=US/O=test) +3342 * @return {String} distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) +3343 * @since jsrsasign 6.2.2 asn1x509 1.0.18 +3344 * @see KJUR.asn1.x509.X500Name.compatToLDAP +3345 * @description +3346 * This method is deprecated. Please use +3347 * {@link KJUR.asn1.x509.X500Name.compatToLDAP} instead. +3348 */ +3349 KJUR.asn1.x509.X500Name.onelineToLDAP = function(s) { +3350 return KJUR.asn1.x509.X500Name.compatToLDAP(s); +3351 } +3352 +3353 /** +3354 * convert LDAP(RFC 2253) distinguished name format string to OpenSSL compat format<br/> +3355 * @name ldapToCompat +3356 * @memberOf KJUR.asn1.x509.X500Name +3357 * @function +3358 * @param {String} s distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) +3359 * @return {String} distinguished name string in OpenSSL compat format (ex. /C=US/O=test) +3360 * @since jsrsasign 8.0.19 asn1x509 1.1.10 +3361 * @description +3362 * This static method converts a distinguished name string in +3363 * LDAP(RFC 2253) format to OpenSSL compat format. +3364 * @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> +3365 * @example +3366 * KJUR.asn1.x509.X500Name.ldapToCompat('O=test,C=US') → '/C=US/O=test' +3367 * KJUR.asn1.x509.X500Name.ldapToCompat('O=a\,a,C=US') → '/C=US/O=a,a' +3368 * KJUR.asn1.x509.X500Name.ldapToCompat('O=a/a,C=US') → '/C=US/O=a\/a' +3369 */ +3370 KJUR.asn1.x509.X500Name.ldapToCompat = function(s) { +3371 var a = s.split(","); +3372 +3373 // join \, +3374 var isBSbefore = false; +3375 var a2 = []; +3376 for (var i = 0; a.length > 0; i++) { +3377 var item = a.shift(); +3378 //console.log("item=" + item); +3379 +3380 if (isBSbefore === true) { +3381 var a2last = a2.pop(); +3382 var newitem = (a2last + "," + item).replace(/\\,/g, ","); +3383 a2.push(newitem); +3384 isBSbefore = false; +3385 } else { +3386 a2.push(item); +3387 } +3388 +3389 if (item.substr(-1, 1) === "\\") isBSbefore = true; +3390 } +3391 +3392 a2 = a2.map(function(s) {return s.replace("/", "\\/")}); +3393 a2.reverse(); +3394 return "/" + a2.join("/"); +3395 }; +3396 +3397 /** +3398 * convert LDAP(RFC 2253) distinguished name format string to OpenSSL compat format (DEPRECATED)<br/> +3399 * @name ldapToOneline +3400 * @memberOf KJUR.asn1.x509.X500Name +3401 * @function +3402 * @param {String} s distinguished name string in LDAP(RFC 2253) format (ex. O=test,C=US) +3403 * @return {String} distinguished name string in OpenSSL compat format (ex. /C=US/O=test) +3404 * @since jsrsasign 6.2.2 asn1x509 1.0.18 +3405 * @description +3406 * This method is deprecated. Please use +3407 * {@link KJUR.asn1.x509.X500Name.ldapToCompat} instead. +3408 */ +3409 KJUR.asn1.x509.X500Name.ldapToOneline = function(s) { +3410 return KJUR.asn1.x509.X500Name.ldapToCompat(s); +3411 }; +3412 +3413 /** +3414 * RDN (Relative Distinguished Name) ASN.1 structure class +3415 * @name KJUR.asn1.x509.RDN +3416 * @class RDN (Relative Distinguished Name) ASN.1 structure class +3417 * @param {Array} params associative array of parameters (ex. {'str': 'C=US'}) +3418 * @extends KJUR.asn1.ASN1Object +3419 * @see KJUR.asn1.x509.X500Name +3420 * @see KJUR.asn1.x509.RDN +3421 * @see KJUR.asn1.x509.AttributeTypeAndValue +3422 * @description +3423 * This class provides RelativeDistinguishedName ASN.1 class structure +3424 * defined in <a href="https://tools.ietf.org/html/rfc2253#section-2">RFC 2253 section 2</a>. +3425 * <blockquote><pre> +3426 * RelativeDistinguishedName ::= SET SIZE (1..MAX) OF +3427 * AttributeTypeAndValue +3428 * +3429 * AttributeTypeAndValue ::= SEQUENCE { +3430 * type AttributeType, +3431 * value AttributeValue } +3432 * </pre></blockquote> +3433 * <br/> +3434 * NOTE1: The "array" and "rule" parameters have been supported +3435 * since jsrsasign 9.0.0 asn1x509 2.0.0. +3436 * <br/> +3437 * NOTE2: Multi-valued RDN in "str" parameter have been +3438 * supported since jsrsasign 6.2.1 asn1x509 1.0.17. +3439 * @example +3440 * new KJUR.asn1.x509.RDN({array: [ // multi-valued +3441 * {type:"CN",value:"Bob",ds:"prn"}, +3442 * {type:"CN",value:"bob@example.com", ds:"ia5"} +3443 * ]}); +3444 * new KJUR.asn1.x509.RDN({str: "CN=test"}); +3445 * new KJUR.asn1.x509.RDN({str: "O=a+O=bb+O=c"}); // multi-valued +3446 * new KJUR.asn1.x509.RDN({str: "O=a+O=b\\+b+O=c"}); // plus escaped +3447 * new KJUR.asn1.x509.RDN({str: "O=a+O=\"b+b\"+O=c"}); // double quoted +3448 */ +3449 KJUR.asn1.x509.RDN = function(params) { +3450 KJUR.asn1.x509.RDN.superclass.constructor.call(this); +3451 this.asn1Array = []; +3452 this.paramArray = []; +3453 this.sRule = "utf8"; // DEFAULT "utf8" +3454 var _AttributeTypeAndValue = KJUR.asn1.x509.AttributeTypeAndValue; +3455 +3456 this.setByParam = function(params) { +3457 if (params.rule !== undefined) this.sRule = params.rule; +3458 if (params.str !== undefined) { +3459 this.addByMultiValuedString(params.str); +3460 } +3461 if (params.array !== undefined) this.paramArray = params.array; +3462 }; +3463 +3464 /** +3465 * add one AttributeTypeAndValue by string<br/> +3466 * @name addByString +3467 * @memberOf KJUR.asn1.x509.RDN# +3468 * @function +3469 * @param {String} s string of AttributeTypeAndValue +3470 * @return {Object} unspecified +3471 * @description +3472 * This method add one AttributeTypeAndValue to RDN object. +3473 * @example +3474 * rdn = new KJUR.asn1.x509.RDN(); +3475 * rdn.addByString("CN=john"); +3476 * rdn.addByString("serialNumber=1234"); // for multi-valued RDN +3477 */ +3478 this.addByString = function(s) { +3479 this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({'str': s, rule: this.sRule})); +3480 }; +3481 +3482 /** +3483 * add one AttributeTypeAndValue by multi-valued string<br/> +3484 * @name addByMultiValuedString +3485 * @memberOf KJUR.asn1.x509.RDN# +3486 * @function +3487 * @param {String} s string of multi-valued RDN +3488 * @return {Object} unspecified +3489 * @since jsrsasign 6.2.1 asn1x509 1.0.17 +3490 * @description +3491 * This method add multi-valued RDN to RDN object. +3492 * @example +3493 * rdn = new KJUR.asn1.x509.RDN(); +3494 * rdn.addByMultiValuedString("CN=john+O=test"); +3495 * rdn.addByMultiValuedString("O=a+O=b\+b\+b+O=c"); // multi-valued RDN with quoted plus +3496 * rdn.addByMultiValuedString("O=a+O=\"b+b+b\"+O=c"); // multi-valued RDN with quoted quotation +3497 */ +3498 this.addByMultiValuedString = function(s) { +3499 var a = KJUR.asn1.x509.RDN.parseString(s); +3500 for (var i = 0; i < a.length; i++) { +3501 this.addByString(a[i]); +3502 } +3503 }; +3504 +3505 this.tohex = function() { +3506 if (this.asn1Array.length == 0 && this.paramArray.length > 0) { +3507 for (var i = 0; i < this.paramArray.length; i++) { +3508 var param = this.paramArray[i]; +3509 if (param.rule !== undefined && +3510 this.sRule != "utf8") { +3511 param.rule = this.sRule; +3512 } +3513 //alert(JSON.stringify(param)); +3514 var asn1ATV = new _AttributeTypeAndValue(param); +3515 this.asn1Array.push(asn1ATV); +3516 } +3517 } +3518 var o = new KJUR.asn1.DERSet({"array": this.asn1Array}); +3519 this.TLV = o.tohex(); +3520 return this.TLV; +3521 }; +3522 this.getEncodedHex = function() { return this.tohex(); }; +3523 +3524 if (params !== undefined) { +3525 this.setByParam(params); +3526 } +3527 }; +3528 extendClass(KJUR.asn1.x509.RDN, KJUR.asn1.ASN1Object); +3529 +3530 /** +3531 * parse multi-valued RDN string and split into array of 'AttributeTypeAndValue'<br/> +3532 * @name parseString +3533 * @memberOf KJUR.asn1.x509.RDN +3534 * @function +3535 * @param {String} s multi-valued string of RDN +3536 * @return {Array} array of string of AttributeTypeAndValue +3537 * @since jsrsasign 6.2.1 asn1x509 1.0.17 +3538 * @description +3539 * This static method parses multi-valued RDN string and split into +3540 * array of AttributeTypeAndValue. +3541 * @example +3542 * KJUR.asn1.x509.RDN.parseString("CN=john") → ["CN=john"] +3543 * KJUR.asn1.x509.RDN.parseString("CN=john+OU=test") → ["CN=john", "OU=test"] +3544 * KJUR.asn1.x509.RDN.parseString('CN="jo+hn"+OU=test') → ["CN=jo+hn", "OU=test"] +3545 * KJUR.asn1.x509.RDN.parseString('CN=jo\+hn+OU=test') → ["CN=jo+hn", "OU=test"] +3546 * KJUR.asn1.x509.RDN.parseString("CN=john+OU=test+OU=t1") → ["CN=john", "OU=test", "OU=t1"] +3547 */ +3548 KJUR.asn1.x509.RDN.parseString = function(s) { +3549 var a = s.split(/\+/); +3550 +3551 // join \+ +3552 var isBSbefore = false; +3553 var a2 = []; +3554 for (var i = 0; a.length > 0; i++) { +3555 var item = a.shift(); +3556 //console.log("item=" + item); +3557 +3558 if (isBSbefore === true) { +3559 var a2last = a2.pop(); +3560 var newitem = (a2last + "+" + item).replace(/\\\+/g, "+"); +3561 a2.push(newitem); +3562 isBSbefore = false; +3563 } else { +3564 a2.push(item); +3565 } +3566 +3567 if (item.substr(-1, 1) === "\\") isBSbefore = true; +3568 } +3569 +3570 // join quote +3571 var beginQuote = false; +3572 var a3 = []; +3573 for (var i = 0; a2.length > 0; i++) { +3574 var item = a2.shift(); +3575 +3576 if (beginQuote === true) { +3577 var a3last = a3.pop(); +3578 if (item.match(/"$/)) { +3579 var newitem = (a3last + "+" + item).replace(/^([^=]+)="(.*)"$/, "$1=$2"); +3580 a3.push(newitem); +3581 beginQuote = false; +3582 } else { +3583 a3.push(a3last + "+" + item); +3584 } +3585 } else { +3586 a3.push(item); +3587 } +3588 +3589 if (item.match(/^[^=]+="/)) { +3590 //console.log(i + "=" + item); +3591 beginQuote = true; +3592 } +3593 } +3594 return a3; +3595 }; +3596 +3597 /** +3598 * AttributeTypeAndValue ASN.1 structure class +3599 * @name KJUR.asn1.x509.AttributeTypeAndValue +3600 * @class AttributeTypeAndValue ASN.1 structure class +3601 * @param {Array} params JSON object for parameters (ex. {str: 'C=US'}) +3602 * @extends KJUR.asn1.ASN1Object +3603 * @see KJUR.asn1.x509.X500Name +3604 * @see KJUR.asn1.x509.RDN +3605 * @see KJUR.asn1.x509.AttributeTypeAndValue +3606 * @see X509#getAttrTypeAndValue +3607 * @description +3608 * This class generates AttributeTypeAndValue defined in +3609 * <a href="https://tools.ietf.org/html/rfc5280#section-4.1.2.4"> +3610 * RFC 5280 4.1.2.4</a>. +3611 * <pre> +3612 * AttributeTypeAndValue ::= SEQUENCE { +3613 * type AttributeType, +3614 * value AttributeValue } +3615 * AttributeType ::= OBJECT IDENTIFIER +3616 * AttributeValue ::= ANY -- DEFINED BY AttributeType +3617 * </pre> +3618 * The constructor argument can have following parameters: +3619 * <ul> +3620 * <li>{String}type - AttributeType name or OID(ex. C,O,CN)</li> +3621 * <li>{String}value - raw string of ASN.1 value of AttributeValue</li> +3622 * <li>{String}ds - DirectoryString type of AttributeValue</li> +3623 * <li>{String}rule - DirectoryString type rule (ex. "prn" or "utf8") +3624 * set DirectoryString type automatically when "ds" not specified.</li> +3625 * <li>{String}str - AttributeTypeAndVale string (ex. "C=US"). +3626 * When type and value don't exists, +3627 * this "str" will be converted to "type" and "value". +3628 * </li> +3629 * </ul> +3630 * <br +3631 * NOTE: Parameters "type", "value,", "ds" and "rule" have +3632 * been supported since jsrsasign 9.0.0 asn1x509 2.0.0. +3633 * @example +3634 * new KJUR.asn1.x509.AttributeTypeAndValue({type:'C',value:'US',ds:'prn'}) +3635 * new KJUR.asn1.x509.AttributeTypeAndValue({type:'givenName',value:'John',ds:'prn'}) +3636 * new KJUR.asn1.x509.AttributeTypeAndValue({type:'2.5.4.9',value:'71 Bowman St',ds:'prn'}) +3637 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1'}) +3638 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'streetAddress=71 Bowman St'}) +3639 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1',rule='prn'}) +3640 * new KJUR.asn1.x509.AttributeTypeAndValue({str:'O=T1',rule='utf8'}) +3641 */ +3642 KJUR.asn1.x509.AttributeTypeAndValue = function(params) { +3643 KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this); +3644 this.sRule = "utf8"; +3645 this.sType = null; +3646 this.sValue = null; +3647 this.dsType = null; +3648 var _KJUR = KJUR, +3649 _KJUR_asn1 = _KJUR.asn1, +3650 _DERSequence = _KJUR_asn1.DERSequence, +3651 _DERUTF8String = _KJUR_asn1.DERUTF8String, +3652 _DERPrintableString = _KJUR_asn1.DERPrintableString, +3653 _DERTeletexString = _KJUR_asn1.DERTeletexString, +3654 _DERIA5String = _KJUR_asn1.DERIA5String, +3655 _DERVisibleString = _KJUR_asn1.DERVisibleString, +3656 _DERBMPString = _KJUR_asn1.DERBMPString, +3657 _isMail = _KJUR.lang.String.isMail, +3658 _isPrintable = _KJUR.lang.String.isPrintable; +3659 +3660 this.setByParam = function(params) { +3661 if (params.rule !== undefined) this.sRule = params.rule; +3662 if (params.ds !== undefined) this.dsType = params.ds; +3663 +3664 if (params.value === undefined && +3665 params.str !== undefined) { +3666 var str = params.str; +3667 var matchResult = str.match(/^([^=]+)=(.+)$/); +3668 if (matchResult) { +3669 this.sType = matchResult[1]; +3670 this.sValue = matchResult[2]; +3671 } else { +3672 throw new Error("malformed attrTypeAndValueStr: " + +3673 attrTypeAndValueStr); +3674 } +3675 +3676 //this.setByString(params.str); 3677 } else { -3678 throw new Error("malformed attrTypeAndValueStr: " + -3679 attrTypeAndValueStr); -3680 } +3678 this.sType = params.type; +3679 this.sValue = params.value; +3680 } 3681 }; 3682 -3683 this._getDsType = function() { -3684 var sType = this.sType; -3685 var sValue = this.sValue; -3686 var sRule = this.sRule; -3687 -3688 if (sRule === "prn") { -3689 if (sType == "CN" && _isMail(sValue)) return "ia5"; -3690 if (_isPrintable(sValue)) return "prn"; -3691 return "utf8"; -3692 } else if (sRule === "utf8") { -3693 if (sType == "CN" && _isMail(sValue)) return "ia5"; -3694 if (sType == "C") return "prn"; -3695 return "utf8"; -3696 } -3697 return "utf8"; // default -3698 }; -3699 -3700 this.setByAttrTypeAndValueStr = function(sType, sValue, sRule) { -3701 if (sRule !== undefined) this.sRule = sRule; -3702 this.sType = sType; -3703 this.sValue = sValue; -3704 }; -3705 -3706 this.getValueObj = function(dsType, valueStr) { -3707 if (dsType == "utf8") return new _DERUTF8String({"str": valueStr}); -3708 if (dsType == "prn") return new _DERPrintableString({"str": valueStr}); -3709 if (dsType == "tel") return new _DERTeletexString({"str": valueStr}); -3710 if (dsType == "ia5") return new _DERIA5String({"str": valueStr}); -3711 if (dsType == "vis") return new _DERVisibleString({"str": valueStr}); -3712 if (dsType == "bmp") return new _DERBMPString({"str": valueStr}); -3713 throw new Error("unsupported directory string type: type=" + -3714 dsType + " value=" + valueStr); -3715 }; -3716 -3717 this.tohex = function() { -3718 if (this.dsType == null) this.dsType = this._getDsType(); -3719 var asn1Type = KJUR.asn1.x509.OID.atype2obj(this.sType); -3720 var asn1Value = this.getValueObj(this.dsType, this.sValue); -3721 var o = new _DERSequence({"array": [asn1Type, asn1Value]}); -3722 this.TLV = o.tohex(); -3723 return this.TLV; -3724 } -3725 -3726 this.getEncodedHex = function() { return this.tohex(); }; -3727 -3728 if (params !== undefined) { -3729 this.setByParam(params); -3730 } -3731 }; -3732 extendClass(KJUR.asn1.x509.AttributeTypeAndValue, KJUR.asn1.ASN1Object); -3733 -3734 // === END X500Name Related ================================================= -3735 -3736 // === BEGIN Other ASN1 structure class ====================================== -3737 -3738 /** -3739 * SubjectPublicKeyInfo ASN.1 structure class -3740 * @name KJUR.asn1.x509.SubjectPublicKeyInfo -3741 * @class SubjectPublicKeyInfo ASN.1 structure class -3742 * @param {Object} params parameter for subject public key -3743 * @extends KJUR.asn1.ASN1Object -3744 * @description -3745 * <br/> -3746 * As for argument 'params' for constructor, you can specify one of -3747 * following properties: -3748 * <ul> -3749 * <li>{@link RSAKey} object</li> -3750 * <li>{@link KJUR.crypto.ECDSA} object</li> -3751 * <li>{@link KJUR.crypto.DSA} object</li> -3752 * </ul> -3753 * NOTE1: 'params' can be omitted.<br/> -3754 * NOTE2: DSA/ECDSA key object is also supported since asn1x509 1.0.6.<br/> -3755 * <h4>EXAMPLE</h4> -3756 * @example -3757 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(RSAKey_object); -3758 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(KJURcryptoECDSA_object); -3759 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(KJURcryptoDSA_object); -3760 */ -3761 KJUR.asn1.x509.SubjectPublicKeyInfo = function(params) { -3762 KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this); -3763 var asn1AlgId = null, -3764 asn1SubjPKey = null, -3765 _KJUR = KJUR, -3766 _KJUR_asn1 = _KJUR.asn1, -3767 _DERInteger = _KJUR_asn1.DERInteger, -3768 _DERBitString = _KJUR_asn1.DERBitString, -3769 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, -3770 _DERSequence = _KJUR_asn1.DERSequence, -3771 _newObject = _KJUR_asn1.ASN1Util.newObject, -3772 _KJUR_asn1_x509 = _KJUR_asn1.x509, -3773 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, -3774 _KJUR_crypto = _KJUR.crypto, -3775 _KJUR_crypto_ECDSA = _KJUR_crypto.ECDSA, -3776 _KJUR_crypto_DSA = _KJUR_crypto.DSA; -3777 -3778 /* -3779 * @since asn1x509 1.0.7 -3780 */ -3781 this.getASN1Object = function() { -3782 if (this.asn1AlgId == null || this.asn1SubjPKey == null) -3783 throw "algId and/or subjPubKey not set"; -3784 var o = new _DERSequence({'array': -3785 [this.asn1AlgId, this.asn1SubjPKey]}); -3786 return o; -3787 }; -3788 -3789 this.tohex = function() { -3790 var o = this.getASN1Object(); -3791 this.hTLV = o.tohex(); -3792 return this.hTLV; -3793 }; -3794 this.getEncodedHex = function() { return this.tohex(); }; -3795 -3796 /** -3797 * @name setPubKey -3798 * @memberOf KJUR.asn1.x509.SubjectPublicKeyInfo# -3799 * @function -3800 * @param {Object} {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.DSA} object -3801 * @since jsrsasign 8.0.0 asn1x509 1.1.0 -3802 * @description -3803 * @example -3804 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(); -3805 * pubKey = KEYUTIL.getKey(PKCS8PUBKEYPEM); -3806 * spki.setPubKey(pubKey); -3807 */ -3808 this.setPubKey = function(key) { -3809 try { -3810 if (key instanceof RSAKey) { -3811 var asn1RsaPub = _newObject({ -3812 'seq': [{'int': {'bigint': key.n}}, {'int': {'int': key.e}}] -3813 }); -3814 var rsaKeyHex = asn1RsaPub.tohex(); -3815 this.asn1AlgId = new _AlgorithmIdentifier({'name':'rsaEncryption'}); -3816 this.asn1SubjPKey = new _DERBitString({'hex':'00'+rsaKeyHex}); -3817 } -3818 } catch(ex) {}; -3819 -3820 try { -3821 if (key instanceof KJUR.crypto.ECDSA) { -3822 var asn1Params = new _DERObjectIdentifier({'name': key.curveName}); -3823 this.asn1AlgId = -3824 new _AlgorithmIdentifier({'name': 'ecPublicKey', -3825 'asn1params': asn1Params}); -3826 this.asn1SubjPKey = new _DERBitString({'hex': '00' + key.pubKeyHex}); -3827 } -3828 } catch(ex) {}; -3829 -3830 try { -3831 if (key instanceof KJUR.crypto.DSA) { -3832 var asn1Params = new _newObject({ -3833 'seq': [{'int': {'bigint': key.p}}, -3834 {'int': {'bigint': key.q}}, -3835 {'int': {'bigint': key.g}}] -3836 }); +3683 /* +3684 * @deprecated +3685 */ +3686 this.setByString = function(sTypeValue, sRule) { +3687 if (sRule !== undefined) this.sRule = sRule; +3688 var matchResult = sTypeValue.match(/^([^=]+)=(.+)$/); +3689 if (matchResult) { +3690 this.setByAttrTypeAndValueStr(matchResult[1], matchResult[2]); +3691 } else { +3692 throw new Error("malformed attrTypeAndValueStr: " + +3693 attrTypeAndValueStr); +3694 } +3695 }; +3696 +3697 this._getDsType = function() { +3698 var sType = this.sType; +3699 var sValue = this.sValue; +3700 var sRule = this.sRule; +3701 +3702 if (sRule === "prn") { +3703 if (sType == "CN" && _isMail(sValue)) return "ia5"; +3704 if (_isPrintable(sValue)) return "prn"; +3705 return "utf8"; +3706 } else if (sRule === "utf8") { +3707 if (sType == "CN" && _isMail(sValue)) return "ia5"; +3708 if (sType == "C") return "prn"; +3709 return "utf8"; +3710 } +3711 return "utf8"; // default +3712 }; +3713 +3714 this.setByAttrTypeAndValueStr = function(sType, sValue, sRule) { +3715 if (sRule !== undefined) this.sRule = sRule; +3716 this.sType = sType; +3717 this.sValue = sValue; +3718 }; +3719 +3720 this.getValueObj = function(dsType, valueStr) { +3721 if (dsType == "utf8") return new _DERUTF8String({"str": valueStr}); +3722 if (dsType == "prn") return new _DERPrintableString({"str": valueStr}); +3723 if (dsType == "tel") return new _DERTeletexString({"str": valueStr}); +3724 if (dsType == "ia5") return new _DERIA5String({"str": valueStr}); +3725 if (dsType == "vis") return new _DERVisibleString({"str": valueStr}); +3726 if (dsType == "bmp") return new _DERBMPString({"str": valueStr}); +3727 throw new Error("unsupported directory string type: type=" + +3728 dsType + " value=" + valueStr); +3729 }; +3730 +3731 this.tohex = function() { +3732 if (this.dsType == null) this.dsType = this._getDsType(); +3733 var asn1Type = KJUR.asn1.x509.OID.atype2obj(this.sType); +3734 var asn1Value = this.getValueObj(this.dsType, this.sValue); +3735 var o = new _DERSequence({"array": [asn1Type, asn1Value]}); +3736 this.TLV = o.tohex(); +3737 return this.TLV; +3738 } +3739 +3740 this.getEncodedHex = function() { return this.tohex(); }; +3741 +3742 if (params !== undefined) { +3743 this.setByParam(params); +3744 } +3745 }; +3746 extendClass(KJUR.asn1.x509.AttributeTypeAndValue, KJUR.asn1.ASN1Object); +3747 +3748 // === END X500Name Related ================================================= +3749 +3750 // === BEGIN Other ASN1 structure class ====================================== +3751 +3752 /** +3753 * SubjectPublicKeyInfo ASN.1 structure class +3754 * @name KJUR.asn1.x509.SubjectPublicKeyInfo +3755 * @class SubjectPublicKeyInfo ASN.1 structure class +3756 * @param {Object} params parameter for subject public key +3757 * @extends KJUR.asn1.ASN1Object +3758 * @description +3759 * <br/> +3760 * As for argument 'params' for constructor, you can specify one of +3761 * following properties: +3762 * <ul> +3763 * <li>{@link RSAKey} object</li> +3764 * <li>{@link KJUR.crypto.ECDSA} object</li> +3765 * <li>{@link KJUR.crypto.DSA} object</li> +3766 * </ul> +3767 * NOTE1: 'params' can be omitted.<br/> +3768 * NOTE2: DSA/ECDSA key object is also supported since asn1x509 1.0.6.<br/> +3769 * <h4>EXAMPLE</h4> +3770 * @example +3771 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(RSAKey_object); +3772 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(KJURcryptoECDSA_object); +3773 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(KJURcryptoDSA_object); +3774 */ +3775 KJUR.asn1.x509.SubjectPublicKeyInfo = function(params) { +3776 KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this); +3777 var asn1AlgId = null, +3778 asn1SubjPKey = null, +3779 _KJUR = KJUR, +3780 _KJUR_asn1 = _KJUR.asn1, +3781 _DERInteger = _KJUR_asn1.DERInteger, +3782 _DERBitString = _KJUR_asn1.DERBitString, +3783 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, +3784 _DERSequence = _KJUR_asn1.DERSequence, +3785 _newObject = _KJUR_asn1.ASN1Util.newObject, +3786 _KJUR_asn1_x509 = _KJUR_asn1.x509, +3787 _AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier, +3788 _KJUR_crypto = _KJUR.crypto, +3789 _KJUR_crypto_ECDSA = _KJUR_crypto.ECDSA, +3790 _KJUR_crypto_DSA = _KJUR_crypto.DSA; +3791 +3792 /* +3793 * @since asn1x509 1.0.7 +3794 */ +3795 this.getASN1Object = function() { +3796 if (this.asn1AlgId == null || this.asn1SubjPKey == null) +3797 throw "algId and/or subjPubKey not set"; +3798 var o = new _DERSequence({'array': +3799 [this.asn1AlgId, this.asn1SubjPKey]}); +3800 return o; +3801 }; +3802 +3803 this.tohex = function() { +3804 var o = this.getASN1Object(); +3805 this.hTLV = o.tohex(); +3806 return this.hTLV; +3807 }; +3808 this.getEncodedHex = function() { return this.tohex(); }; +3809 +3810 /** +3811 * @name setPubKey +3812 * @memberOf KJUR.asn1.x509.SubjectPublicKeyInfo# +3813 * @function +3814 * @param {Object} {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.DSA} object +3815 * @since jsrsasign 8.0.0 asn1x509 1.1.0 +3816 * @description +3817 * @example +3818 * spki = new KJUR.asn1.x509.SubjectPublicKeyInfo(); +3819 * pubKey = KEYUTIL.getKey(PKCS8PUBKEYPEM); +3820 * spki.setPubKey(pubKey); +3821 */ +3822 this.setPubKey = function(key) { +3823 try { +3824 if (key instanceof RSAKey) { +3825 var asn1RsaPub = _newObject({ +3826 'seq': [{'int': {'bigint': key.n}}, {'int': {'int': key.e}}] +3827 }); +3828 var rsaKeyHex = asn1RsaPub.tohex(); +3829 this.asn1AlgId = new _AlgorithmIdentifier({'name':'rsaEncryption'}); +3830 this.asn1SubjPKey = new _DERBitString({'hex':'00'+rsaKeyHex}); +3831 } +3832 } catch(ex) {}; +3833 +3834 try { +3835 if (key instanceof KJUR.crypto.ECDSA) { +3836 var asn1Params = new _DERObjectIdentifier({'name': key.curveName}); 3837 this.asn1AlgId = -3838 new _AlgorithmIdentifier({'name': 'dsa', +3838 new _AlgorithmIdentifier({'name': 'ecPublicKey', 3839 'asn1params': asn1Params}); -3840 var pubInt = new _DERInteger({'bigint': key.y}); -3841 this.asn1SubjPKey = -3842 new _DERBitString({'hex': '00' + pubInt.tohex()}); -3843 } -3844 } catch(ex) {}; -3845 }; -3846 -3847 if (params !== undefined) { -3848 this.setPubKey(params); -3849 } -3850 }; -3851 extendClass(KJUR.asn1.x509.SubjectPublicKeyInfo, KJUR.asn1.ASN1Object); -3852 -3853 /** -3854 * Time ASN.1 structure class<br/> -3855 * @name KJUR.asn1.x509.Time -3856 * @class Time ASN.1 structure class -3857 * @param {Array} params associative array of parameters (ex. {'str': '130508235959Z'}) -3858 * @extends KJUR.asn1.ASN1Object -3859 * @see KJUR.asn1.DERUTCTime -3860 * @see KJUR.asn1.DERGeneralizedTime -3861 * @description -3862 * This class represents Time ASN.1 structure defined in -3863 * <a href="https://tools.ietf.org/html/rfc5280">RFC 5280</a> -3864 * <pre> -3865 * Time ::= CHOICE { -3866 * utcTime UTCTime, -3867 * generalTime GeneralizedTime } -3868 * </pre> -3869 * -3870 * @example -3871 * var t1 = new KJUR.asn1.x509.Time{'str': '130508235959Z'} // UTCTime by default -3872 * var t2 = new KJUR.asn1.x509.Time{'type': 'gen', 'str': '20130508235959Z'} // GeneralizedTime -3873 */ -3874 KJUR.asn1.x509.Time = function(params) { -3875 KJUR.asn1.x509.Time.superclass.constructor.call(this); -3876 var type = null, -3877 timeParams = null, -3878 _KJUR = KJUR, -3879 _KJUR_asn1 = _KJUR.asn1, -3880 _DERUTCTime = _KJUR_asn1.DERUTCTime, -3881 _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime; -3882 this.params = null; -3883 this.type = null; -3884 -3885 // deprecated -3886 this.setTimeParams = function(timeParams) { -3887 this.timeParams = timeParams; -3888 } -3889 -3890 this.setByParam = function(params) { -3891 this.params = params; -3892 }; -3893 -3894 this.getType = function(s) { -3895 if (s.match(/^[0-9]{12}Z$/)) return "utc"; -3896 if (s.match(/^[0-9]{14}Z$/)) return "gen"; -3897 if (s.match(/^[0-9]{12}\.[0-9]+Z$/)) return "utc"; -3898 if (s.match(/^[0-9]{14}\.[0-9]+Z$/)) return "gen"; -3899 return null; -3900 }; -3901 -3902 this.tohex = function() { -3903 var params = this.params; -3904 var o = null; -3905 -3906 if (typeof params == "string") params = {str: params}; -3907 if (params != null && -3908 params.str && -3909 (params.type == null || params.type == undefined)) { -3910 params.type = this.getType(params.str); -3911 } -3912 -3913 if (params != null && params.str) { -3914 if (params.type == "utc") o = new _DERUTCTime(params.str); -3915 if (params.type == "gen") o = new _DERGeneralizedTime(params.str); -3916 } else { -3917 if (this.type == "gen") { -3918 o = new _DERGeneralizedTime(); -3919 } else { -3920 o = new _DERUTCTime(); -3921 } -3922 } -3923 -3924 if (o == null) throw new Error("wrong setting for Time"); -3925 this.TLV = o.tohex(); -3926 return this.TLV; -3927 }; -3928 this.getEncodedHex = function() { return this.tohex(); }; -3929 -3930 if (params != undefined) this.setByParam(params); -3931 }; -3932 -3933 KJUR.asn1.x509.Time_bak = function(params) { -3934 KJUR.asn1.x509.Time_bak.superclass.constructor.call(this); -3935 var type = null, -3936 timeParams = null, -3937 _KJUR = KJUR, -3938 _KJUR_asn1 = _KJUR.asn1, -3939 _DERUTCTime = _KJUR_asn1.DERUTCTime, -3940 _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime; -3941 -3942 this.setTimeParams = function(timeParams) { -3943 this.timeParams = timeParams; -3944 } -3945 -3946 this.tohex = function() { -3947 var o = null; -3948 -3949 if (this.timeParams != null) { -3950 if (this.type == "utc") { -3951 o = new _DERUTCTime(this.timeParams); -3952 } else { -3953 o = new _DERGeneralizedTime(this.timeParams); -3954 } -3955 } else { -3956 if (this.type == "utc") { -3957 o = new _DERUTCTime(); -3958 } else { -3959 o = new _DERGeneralizedTime(); -3960 } -3961 } -3962 this.TLV = o.tohex(); -3963 return this.TLV; -3964 }; -3965 this.getEncodedHex = function() { return this.tohex(); }; -3966 -3967 this.type = "utc"; -3968 if (params !== undefined) { -3969 if (params.type !== undefined) { -3970 this.type = params.type; -3971 } else { -3972 if (params.str !== undefined) { -3973 if (params.str.match(/^[0-9]{12}Z$/)) this.type = "utc"; -3974 if (params.str.match(/^[0-9]{14}Z$/)) this.type = "gen"; -3975 } -3976 } -3977 this.timeParams = params; -3978 } -3979 }; -3980 extendClass(KJUR.asn1.x509.Time, KJUR.asn1.ASN1Object); -3981 -3982 /** -3983 * AlgorithmIdentifier ASN.1 structure class -3984 * @name KJUR.asn1.x509.AlgorithmIdentifier -3985 * @class AlgorithmIdentifier ASN.1 structure class -3986 * @param {Array} params associative array of parameters (ex. {'name': 'SHA1withRSA'}) -3987 * @extends KJUR.asn1.ASN1Object -3988 * @description -3989 * The 'params' argument is an associative array and has following parameters: -3990 * <ul> -3991 * <li>name: algorithm name (MANDATORY, ex. sha1, SHA256withRSA)</li> -3992 * <li>asn1params: explicitly specify ASN.1 object for algorithm. -3993 * (OPTION)</li> -3994 * <li>paramempty: set algorithm parameter to NULL by force. -3995 * If paramempty is false, algorithm parameter will be set automatically. -3996 * If paramempty is false and algorithm name is "*withDSA" or "withECDSA" parameter field of -3997 * AlgorithmIdentifier will be ommitted otherwise -3998 * it will be NULL by default. -3999 * (OPTION, DEFAULT = false)</li> -4000 * </ul> -4001 * RSA-PSS algorithm names such as SHA{,256,384,512}withRSAandMGF1 are -4002 * special names. They will set a suite of algorithm OID and multiple algorithm -4003 * parameters. Its ASN.1 schema is defined in -4004 * <a href="https://tools.ietf.org/html/rfc3447#appendix-A.2.3">RFC 3447 PKCS#1 2.1 -4005 * section A.2.3</a>. -4006 * <blockquote><pre> -4007 * id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 } -4008 * RSASSA-PSS-params ::= SEQUENCE { -4009 * hashAlgorithm [0] HashAlgorithm DEFAULT sha1, -4010 * maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1, -4011 * saltLength [2] INTEGER DEFAULT 20, -4012 * trailerField [3] TrailerField DEFAULT trailerFieldBC } -4013 * mgf1SHA1 MaskGenAlgorithm ::= { -4014 * algorithm id-mgf1, -4015 * parameters HashAlgorithm : sha1 } -4016 * id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 } -4017 * TrailerField ::= INTEGER { trailerFieldBC(1) } -4018 * </pre></blockquote> -4019 * Here is a table for PSS parameters: -4020 * <table> -4021 * <tr><th>Name</th><th>alg oid</th><th>pss hash</th><th>maskgen</th></th><th>pss saltlen</th><th>trailer</th></tr> -4022 * <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> -4023 * <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> -4024 * <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> -4025 * <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> -4026 * </table> -4027 * Default value is omitted as defined in ASN.1 schema. -4028 * These parameters are interoperable to OpenSSL or IAIK toolkit. -4029 * <br/> -4030 * NOTE: RSA-PSS algorihtm names are supported since jsrsasign 8.0.21. -4031 * @example -4032 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "sha1"}) -4033 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA"}) -4034 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA512withRSAandMGF1"}) // set parameters automatically -4035 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA", paramempty: true}) -4036 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "rsaEncryption"}) -4037 */ -4038 KJUR.asn1.x509.AlgorithmIdentifier = function(params) { -4039 KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this); -4040 this.nameAlg = null; -4041 this.asn1Alg = null; -4042 this.asn1Params = null; -4043 this.paramEmpty = false; -4044 -4045 var _KJUR = KJUR, -4046 _KJUR_asn1 = _KJUR.asn1, -4047 _PSSNAME2ASN1TLV = _KJUR_asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV; -4048 -4049 this.tohex = function() { -4050 if (this.nameAlg === null && this.asn1Alg === null) { -4051 throw new Error("algorithm not specified"); -4052 } -4053 -4054 // for RSAPSS algorithm name -4055 // && this.hTLV === null -4056 if (this.nameAlg !== null) { -4057 var hTLV = null; -4058 for (var key in _PSSNAME2ASN1TLV) { -4059 if (key === this.nameAlg) { -4060 hTLV = _PSSNAME2ASN1TLV[key]; -4061 } -4062 } -4063 if (hTLV !== null) { -4064 this.hTLV = hTLV; -4065 return this.hTLV; -4066 } -4067 } -4068 -4069 if (this.nameAlg !== null && this.asn1Alg === null) { -4070 this.asn1Alg = _KJUR_asn1.x509.OID.name2obj(this.nameAlg); -4071 } -4072 var a = [this.asn1Alg]; -4073 if (this.asn1Params !== null) a.push(this.asn1Params); -4074 -4075 var o = new _KJUR_asn1.DERSequence({'array': a}); -4076 this.hTLV = o.tohex(); -4077 return this.hTLV; -4078 }; -4079 this.getEncodedHex = function() { return this.tohex(); }; -4080 -4081 if (params !== undefined) { -4082 if (params.name !== undefined) { -4083 this.nameAlg = params.name; -4084 } -4085 if (params.asn1params !== undefined) { -4086 this.asn1Params = params.asn1params; -4087 } -4088 if (params.paramempty !== undefined) { -4089 this.paramEmpty = params.paramempty; -4090 } -4091 } -4092 -4093 // set algorithm parameters will be ommitted for -4094 // "*withDSA" or "*withECDSA" otherwise will be NULL. -4095 if (this.asn1Params === null && -4096 this.paramEmpty === false && -4097 this.nameAlg !== null) { -4098 -4099 if (this.nameAlg.name !== undefined) { -4100 this.nameAlg = this.nameAlg.name; -4101 } -4102 var lcNameAlg = this.nameAlg.toLowerCase(); -4103 -4104 if (lcNameAlg.substr(-7, 7) !== "withdsa" && -4105 lcNameAlg.substr(-9, 9) !== "withecdsa") { -4106 this.asn1Params = new _KJUR_asn1.DERNull(); -4107 } -4108 } -4109 }; -4110 extendClass(KJUR.asn1.x509.AlgorithmIdentifier, KJUR.asn1.ASN1Object); -4111 -4112 /** -4113 * AlgorithmIdentifier ASN.1 TLV string associative array for RSA-PSS algorithm names -4114 * @const -4115 */ -4116 KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV = { -4117 "SHAwithRSAandMGF1": -4118 "300d06092a864886f70d01010a3000", -4119 "SHA256withRSAandMGF1": -4120 "303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120", -4121 "SHA384withRSAandMGF1": -4122 "303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130", -4123 "SHA512withRSAandMGF1": -4124 "303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140" -4125 }; -4126 -4127 /** -4128 * GeneralName ASN.1 structure class<br/> -4129 * @name KJUR.asn1.x509.GeneralName -4130 * @class GeneralName ASN.1 structure class -4131 * @see KJUR.asn1.x509.OtherName -4132 * @see KJUR.asn1.x509.X500Name -4133 * -4134 * @description -4135 * <br/> -4136 * As for argument 'params' for constructor, you can specify one of -4137 * following properties: -4138 * <ul> -4139 * <li>rfc822 - rfc822Name[1] (ex. user1@foo.com)</li> -4140 * <li>dns - dNSName[2] (ex. foo.com)</li> -4141 * <li>uri - uniformResourceIdentifier[6] (ex. http://foo.com/)</li> -4142 * <li>dn - directoryName[4] -4143 * distinguished name string or X500Name class parameters can be -4144 * specified (ex. "/C=US/O=Test", {hex: '301c...')</li> -4145 * <li>ldapdn - directoryName[4] (ex. O=Test,C=US)</li> -4146 * <li>certissuer - directoryName[4] (PEM or hex string of cert)</li> -4147 * <li>certsubj - directoryName[4] (PEM or hex string of cert)</li> -4148 * <li>ip - iPAddress[7] (ex. 192.168.1.1, 2001:db3::43, 3faa0101...)</li> -4149 * </ul> -4150 * NOTE1: certissuer and certsubj were supported since asn1x509 1.0.10.<br/> -4151 * NOTE2: dn and ldapdn were supported since jsrsasign 6.2.3 asn1x509 1.0.19.<br/> -4152 * NOTE3: ip were supported since jsrsasign 8.0.10 asn1x509 1.1.4.<br/> -4153 * NOTE4: X500Name parameters in dn were supported since jsrsasign 8.0.16.<br/> -4154 * NOTE5: otherName is supported since jsrsasign 10.5.3.<br/> -4155 * -4156 * Here is definition of the ASN.1 syntax: -4157 * <pre> -4158 * -- NOTE: under the CHOICE, it will always be explicit. -4159 * GeneralName ::= CHOICE { -4160 * otherName [0] OtherName, -4161 * rfc822Name [1] IA5String, -4162 * dNSName [2] IA5String, -4163 * x400Address [3] ORAddress, -4164 * directoryName [4] Name, -4165 * ediPartyName [5] EDIPartyName, -4166 * uniformResourceIdentifier [6] IA5String, -4167 * iPAddress [7] OCTET STRING, -4168 * registeredID [8] OBJECT IDENTIFIER } +3840 this.asn1SubjPKey = new _DERBitString({'hex': '00' + key.pubKeyHex}); +3841 } +3842 } catch(ex) {}; +3843 +3844 try { +3845 if (key instanceof KJUR.crypto.DSA) { +3846 var asn1Params = new _newObject({ +3847 'seq': [{'int': {'bigint': key.p}}, +3848 {'int': {'bigint': key.q}}, +3849 {'int': {'bigint': key.g}}] +3850 }); +3851 this.asn1AlgId = +3852 new _AlgorithmIdentifier({'name': 'dsa', +3853 'asn1params': asn1Params}); +3854 var pubInt = new _DERInteger({'bigint': key.y}); +3855 this.asn1SubjPKey = +3856 new _DERBitString({'hex': '00' + pubInt.tohex()}); +3857 } +3858 } catch(ex) {}; +3859 }; +3860 +3861 if (params !== undefined) { +3862 this.setPubKey(params); +3863 } +3864 }; +3865 extendClass(KJUR.asn1.x509.SubjectPublicKeyInfo, KJUR.asn1.ASN1Object); +3866 +3867 /** +3868 * Time ASN.1 structure class<br/> +3869 * @name KJUR.asn1.x509.Time +3870 * @class Time ASN.1 structure class +3871 * @param {Array} params associative array of parameters (ex. {'str': '130508235959Z'}) +3872 * @extends KJUR.asn1.ASN1Object +3873 * @see KJUR.asn1.DERUTCTime +3874 * @see KJUR.asn1.DERGeneralizedTime +3875 * @description +3876 * This class represents Time ASN.1 structure defined in +3877 * <a href="https://tools.ietf.org/html/rfc5280">RFC 5280</a> +3878 * <pre> +3879 * Time ::= CHOICE { +3880 * utcTime UTCTime, +3881 * generalTime GeneralizedTime } +3882 * </pre> +3883 * +3884 * @example +3885 * var t1 = new KJUR.asn1.x509.Time{'str': '130508235959Z'} // UTCTime by default +3886 * var t2 = new KJUR.asn1.x509.Time{'type': 'gen', 'str': '20130508235959Z'} // GeneralizedTime +3887 */ +3888 KJUR.asn1.x509.Time = function(params) { +3889 KJUR.asn1.x509.Time.superclass.constructor.call(this); +3890 var type = null, +3891 timeParams = null, +3892 _KJUR = KJUR, +3893 _KJUR_asn1 = _KJUR.asn1, +3894 _DERUTCTime = _KJUR_asn1.DERUTCTime, +3895 _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime; +3896 this.params = null; +3897 this.type = null; +3898 +3899 // deprecated +3900 this.setTimeParams = function(timeParams) { +3901 this.timeParams = timeParams; +3902 } +3903 +3904 this.setByParam = function(params) { +3905 this.params = params; +3906 }; +3907 +3908 this.getType = function(s) { +3909 if (s.match(/^[0-9]{12}Z$/)) return "utc"; +3910 if (s.match(/^[0-9]{14}Z$/)) return "gen"; +3911 if (s.match(/^[0-9]{12}\.[0-9]+Z$/)) return "utc"; +3912 if (s.match(/^[0-9]{14}\.[0-9]+Z$/)) return "gen"; +3913 return null; +3914 }; +3915 +3916 this.tohex = function() { +3917 var params = this.params; +3918 var o = null; +3919 +3920 if (typeof params == "string") params = {str: params}; +3921 if (params != null && +3922 params.str && +3923 (params.type == null || params.type == undefined)) { +3924 params.type = this.getType(params.str); +3925 } +3926 +3927 if (params != null && params.str) { +3928 if (params.type == "utc") o = new _DERUTCTime(params.str); +3929 if (params.type == "gen") o = new _DERGeneralizedTime(params.str); +3930 } else { +3931 if (this.type == "gen") { +3932 o = new _DERGeneralizedTime(); +3933 } else { +3934 o = new _DERUTCTime(); +3935 } +3936 } +3937 +3938 if (o == null) throw new Error("wrong setting for Time"); +3939 this.TLV = o.tohex(); +3940 return this.TLV; +3941 }; +3942 this.getEncodedHex = function() { return this.tohex(); }; +3943 +3944 if (params != undefined) this.setByParam(params); +3945 }; +3946 +3947 KJUR.asn1.x509.Time_bak = function(params) { +3948 KJUR.asn1.x509.Time_bak.superclass.constructor.call(this); +3949 var type = null, +3950 timeParams = null, +3951 _KJUR = KJUR, +3952 _KJUR_asn1 = _KJUR.asn1, +3953 _DERUTCTime = _KJUR_asn1.DERUTCTime, +3954 _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime; +3955 +3956 this.setTimeParams = function(timeParams) { +3957 this.timeParams = timeParams; +3958 } +3959 +3960 this.tohex = function() { +3961 var o = null; +3962 +3963 if (this.timeParams != null) { +3964 if (this.type == "utc") { +3965 o = new _DERUTCTime(this.timeParams); +3966 } else { +3967 o = new _DERGeneralizedTime(this.timeParams); +3968 } +3969 } else { +3970 if (this.type == "utc") { +3971 o = new _DERUTCTime(); +3972 } else { +3973 o = new _DERGeneralizedTime(); +3974 } +3975 } +3976 this.TLV = o.tohex(); +3977 return this.TLV; +3978 }; +3979 this.getEncodedHex = function() { return this.tohex(); }; +3980 +3981 this.type = "utc"; +3982 if (params !== undefined) { +3983 if (params.type !== undefined) { +3984 this.type = params.type; +3985 } else { +3986 if (params.str !== undefined) { +3987 if (params.str.match(/^[0-9]{12}Z$/)) this.type = "utc"; +3988 if (params.str.match(/^[0-9]{14}Z$/)) this.type = "gen"; +3989 } +3990 } +3991 this.timeParams = params; +3992 } +3993 }; +3994 extendClass(KJUR.asn1.x509.Time, KJUR.asn1.ASN1Object); +3995 +3996 /** +3997 * AlgorithmIdentifier ASN.1 structure class +3998 * @name KJUR.asn1.x509.AlgorithmIdentifier +3999 * @class AlgorithmIdentifier ASN.1 structure class +4000 * @param {Array} params associative array of parameters (ex. {'name': 'SHA1withRSA'}) +4001 * @extends KJUR.asn1.ASN1Object +4002 * @description +4003 * The 'params' argument is an associative array and has following parameters: +4004 * <ul> +4005 * <li>name: algorithm name (MANDATORY, ex. sha1, SHA256withRSA)</li> +4006 * <li>asn1params: explicitly specify ASN.1 object for algorithm. +4007 * (OPTION)</li> +4008 * <li>paramempty: set algorithm parameter to NULL by force. +4009 * If paramempty is false, algorithm parameter will be set automatically. +4010 * If paramempty is false and algorithm name is "*withDSA" or "withECDSA" parameter field of +4011 * AlgorithmIdentifier will be ommitted otherwise +4012 * it will be NULL by default. +4013 * (OPTION, DEFAULT = false)</li> +4014 * </ul> +4015 * RSA-PSS algorithm names such as SHA{,256,384,512}withRSAandMGF1 are +4016 * special names. They will set a suite of algorithm OID and multiple algorithm +4017 * parameters. Its ASN.1 schema is defined in +4018 * <a href="https://tools.ietf.org/html/rfc3447#appendix-A.2.3">RFC 3447 PKCS#1 2.1 +4019 * section A.2.3</a>. +4020 * <blockquote><pre> +4021 * id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 } +4022 * RSASSA-PSS-params ::= SEQUENCE { +4023 * hashAlgorithm [0] HashAlgorithm DEFAULT sha1, +4024 * maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1, +4025 * saltLength [2] INTEGER DEFAULT 20, +4026 * trailerField [3] TrailerField DEFAULT trailerFieldBC } +4027 * mgf1SHA1 MaskGenAlgorithm ::= { +4028 * algorithm id-mgf1, +4029 * parameters HashAlgorithm : sha1 } +4030 * id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 } +4031 * TrailerField ::= INTEGER { trailerFieldBC(1) } +4032 * </pre></blockquote> +4033 * Here is a table for PSS parameters: +4034 * <table> +4035 * <tr><th>Name</th><th>alg oid</th><th>pss hash</th><th>maskgen</th></th><th>pss saltlen</th><th>trailer</th></tr> +4036 * <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> +4037 * <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> +4038 * <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> +4039 * <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> +4040 * </table> +4041 * Default value is omitted as defined in ASN.1 schema. +4042 * These parameters are interoperable to OpenSSL or IAIK toolkit. +4043 * <br/> +4044 * NOTE: RSA-PSS algorihtm names are supported since jsrsasign 8.0.21. +4045 * @example +4046 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "sha1"}) +4047 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA"}) +4048 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA512withRSAandMGF1"}) // set parameters automatically +4049 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA", paramempty: true}) +4050 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "rsaEncryption"}) +4051 */ +4052 KJUR.asn1.x509.AlgorithmIdentifier = function(params) { +4053 KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this); +4054 this.nameAlg = null; +4055 this.asn1Alg = null; +4056 this.asn1Params = null; +4057 this.paramEmpty = false; +4058 +4059 var _KJUR = KJUR, +4060 _KJUR_asn1 = _KJUR.asn1, +4061 _PSSNAME2ASN1TLV = _KJUR_asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV; +4062 +4063 this.tohex = function() { +4064 if (this.nameAlg === null && this.asn1Alg === null) { +4065 throw new Error("algorithm not specified"); +4066 } +4067 +4068 // for RSAPSS algorithm name +4069 // && this.hTLV === null +4070 if (this.nameAlg !== null) { +4071 var hTLV = null; +4072 for (var key in _PSSNAME2ASN1TLV) { +4073 if (key === this.nameAlg) { +4074 hTLV = _PSSNAME2ASN1TLV[key]; +4075 } +4076 } +4077 if (hTLV !== null) { +4078 this.hTLV = hTLV; +4079 return this.hTLV; +4080 } +4081 } +4082 +4083 if (this.nameAlg !== null && this.asn1Alg === null) { +4084 this.asn1Alg = _KJUR_asn1.x509.OID.name2obj(this.nameAlg); +4085 } +4086 var a = [this.asn1Alg]; +4087 if (this.asn1Params !== null) a.push(this.asn1Params); +4088 +4089 var o = new _KJUR_asn1.DERSequence({'array': a}); +4090 this.hTLV = o.tohex(); +4091 return this.hTLV; +4092 }; +4093 this.getEncodedHex = function() { return this.tohex(); }; +4094 +4095 if (params !== undefined) { +4096 if (params.name !== undefined) { +4097 this.nameAlg = params.name; +4098 } +4099 if (params.asn1params !== undefined) { +4100 this.asn1Params = params.asn1params; +4101 } +4102 if (params.paramempty !== undefined) { +4103 this.paramEmpty = params.paramempty; +4104 } +4105 } +4106 +4107 // set algorithm parameters will be ommitted for +4108 // "*withDSA" or "*withECDSA" otherwise will be NULL. +4109 if (this.asn1Params === null && +4110 this.paramEmpty === false && +4111 this.nameAlg !== null) { +4112 +4113 if (this.nameAlg.name !== undefined) { +4114 this.nameAlg = this.nameAlg.name; +4115 } +4116 var lcNameAlg = this.nameAlg.toLowerCase(); +4117 +4118 if (lcNameAlg.substr(-7, 7) !== "withdsa" && +4119 lcNameAlg.substr(-9, 9) !== "withecdsa") { +4120 this.asn1Params = new _KJUR_asn1.DERNull(); +4121 } +4122 } +4123 }; +4124 extendClass(KJUR.asn1.x509.AlgorithmIdentifier, KJUR.asn1.ASN1Object); +4125 +4126 /** +4127 * AlgorithmIdentifier ASN.1 TLV string associative array for RSA-PSS algorithm names +4128 * @const +4129 */ +4130 KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV = { +4131 "SHAwithRSAandMGF1": +4132 "300d06092a864886f70d01010a3000", +4133 "SHA256withRSAandMGF1": +4134 "303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120", +4135 "SHA384withRSAandMGF1": +4136 "303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130", +4137 "SHA512withRSAandMGF1": +4138 "303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140" +4139 }; +4140 +4141 /** +4142 * GeneralName ASN.1 structure class<br/> +4143 * @name KJUR.asn1.x509.GeneralName +4144 * @class GeneralName ASN.1 structure class +4145 * @see KJUR.asn1.x509.OtherName +4146 * @see KJUR.asn1.x509.X500Name +4147 * +4148 * @description +4149 * <br/> +4150 * As for argument 'params' for constructor, you can specify one of +4151 * following properties: +4152 * <ul> +4153 * <li>rfc822 - rfc822Name[1] (ex. user1@foo.com)</li> +4154 * <li>dns - dNSName[2] (ex. foo.com)</li> +4155 * <li>uri - uniformResourceIdentifier[6] (ex. http://foo.com/)</li> +4156 * <li>dn - directoryName[4] +4157 * distinguished name string or X500Name class parameters can be +4158 * specified (ex. "/C=US/O=Test", {hex: '301c...')</li> +4159 * <li>ldapdn - directoryName[4] (ex. O=Test,C=US)</li> +4160 * <li>certissuer - directoryName[4] (PEM or hex string of cert)</li> +4161 * <li>certsubj - directoryName[4] (PEM or hex string of cert)</li> +4162 * <li>ip - iPAddress[7] (ex. 192.168.1.1, 2001:db3::43, 3faa0101...)</li> +4163 * </ul> +4164 * NOTE1: certissuer and certsubj were supported since asn1x509 1.0.10.<br/> +4165 * NOTE2: dn and ldapdn were supported since jsrsasign 6.2.3 asn1x509 1.0.19.<br/> +4166 * NOTE3: ip were supported since jsrsasign 8.0.10 asn1x509 1.1.4.<br/> +4167 * NOTE4: X500Name parameters in dn were supported since jsrsasign 8.0.16.<br/> +4168 * NOTE5: otherName is supported since jsrsasign 10.5.3.<br/> 4169 * -4170 * OtherName ::= SEQUENCE { -4171 * type-id OBJECT IDENTIFIER, -4172 * value [0] EXPLICIT ANY DEFINED BY type-id } -4173 * </pre> -4174 * -4175 * @example -4176 * gn = new KJUR.asn1.x509.GeneralName({dn: '/C=US/O=Test'}); -4177 * gn = new KJUR.asn1.x509.GeneralName({dn: X500NameObject); -4178 * gn = new KJUR.asn1.x509.GeneralName({dn: {str: /C=US/O=Test'}); -4179 * gn = new KJUR.asn1.x509.GeneralName({dn: {ldapstr: 'O=Test,C=US'}); -4180 * gn = new KJUR.asn1.x509.GeneralName({dn: {hex: '301c...'}); -4181 * gn = new KJUR.asn1.x509.GeneralName({dn: {certissuer: PEMCERTSTRING}); -4182 * gn = new KJUR.asn1.x509.GeneralName({dn: {certsubject: PEMCERTSTRING}); -4183 * gn = new KJUR.asn1.x509.GeneralName({ip: '192.168.1.1'}); -4184 * gn = new KJUR.asn1.x509.GeneralName({ip: '2001:db4::4:1'}); -4185 * gn = new KJUR.asn1.x509.GeneralName({ip: 'c0a80101'}); -4186 * gn = new KJUR.asn1.x509.GeneralName({rfc822: 'test@aaa.com'}); -4187 * gn = new KJUR.asn1.x509.GeneralName({dns: 'aaa.com'}); -4188 * gn = new KJUR.asn1.x509.GeneralName({uri: 'http://aaa.com/'}); -4189 * gn = new KJUR.asn1.x509.GeneralName({other: { -4190 * oid: "1.2.3.4", -4191 * value: {utf8str: "example"} // any ASN.1 which passed to ASN1Util.newObject -4192 * }}); -4193 * -4194 * gn = new KJUR.asn1.x509.GeneralName({ldapdn: 'O=Test,C=US'}); // DEPRECATED -4195 * gn = new KJUR.asn1.x509.GeneralName({certissuer: certPEM}); // DEPRECATED -4196 * gn = new KJUR.asn1.x509.GeneralName({certsubj: certPEM}); // DEPRECATED -4197 */ -4198 KJUR.asn1.x509.GeneralName = function(params) { -4199 KJUR.asn1.x509.GeneralName.superclass.constructor.call(this); -4200 -4201 var pTag = { rfc822: '81', dns: '82', dn: 'a4', -4202 uri: '86', ip: '87', otherName: 'a0'}, -4203 _KJUR = KJUR, -4204 _KJUR_asn1 = _KJUR.asn1, -4205 _KJUR_asn1_x509 = _KJUR_asn1.x509, -4206 _X500Name = _KJUR_asn1_x509.X500Name, -4207 _OtherName = _KJUR_asn1_x509.OtherName, -4208 _DERIA5String = _KJUR_asn1.DERIA5String, -4209 _DERPrintableString = _KJUR_asn1.DERPrintableString, -4210 _DEROctetString = _KJUR_asn1.DEROctetString, -4211 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, -4212 _ASN1Object = _KJUR_asn1.ASN1Object, -4213 _Error = Error; +4170 * Here is definition of the ASN.1 syntax: +4171 * <pre> +4172 * -- NOTE: under the CHOICE, it will always be explicit. +4173 * GeneralName ::= CHOICE { +4174 * otherName [0] OtherName, +4175 * rfc822Name [1] IA5String, +4176 * dNSName [2] IA5String, +4177 * x400Address [3] ORAddress, +4178 * directoryName [4] Name, +4179 * ediPartyName [5] EDIPartyName, +4180 * uniformResourceIdentifier [6] IA5String, +4181 * iPAddress [7] OCTET STRING, +4182 * registeredID [8] OBJECT IDENTIFIER } +4183 * +4184 * OtherName ::= SEQUENCE { +4185 * type-id OBJECT IDENTIFIER, +4186 * value [0] EXPLICIT ANY DEFINED BY type-id } +4187 * </pre> +4188 * +4189 * @example +4190 * gn = new KJUR.asn1.x509.GeneralName({dn: '/C=US/O=Test'}); +4191 * gn = new KJUR.asn1.x509.GeneralName({dn: X500NameObject); +4192 * gn = new KJUR.asn1.x509.GeneralName({dn: {str: /C=US/O=Test'}); +4193 * gn = new KJUR.asn1.x509.GeneralName({dn: {ldapstr: 'O=Test,C=US'}); +4194 * gn = new KJUR.asn1.x509.GeneralName({dn: {hex: '301c...'}); +4195 * gn = new KJUR.asn1.x509.GeneralName({dn: {certissuer: PEMCERTSTRING}); +4196 * gn = new KJUR.asn1.x509.GeneralName({dn: {certsubject: PEMCERTSTRING}); +4197 * gn = new KJUR.asn1.x509.GeneralName({ip: '192.168.1.1'}); +4198 * gn = new KJUR.asn1.x509.GeneralName({ip: '2001:db4::4:1'}); +4199 * gn = new KJUR.asn1.x509.GeneralName({ip: 'c0a80101'}); +4200 * gn = new KJUR.asn1.x509.GeneralName({rfc822: 'test@aaa.com'}); +4201 * gn = new KJUR.asn1.x509.GeneralName({dns: 'aaa.com'}); +4202 * gn = new KJUR.asn1.x509.GeneralName({uri: 'http://aaa.com/'}); +4203 * gn = new KJUR.asn1.x509.GeneralName({other: { +4204 * oid: "1.2.3.4", +4205 * value: {utf8str: "example"} // any ASN.1 which passed to ASN1Util.newObject +4206 * }}); +4207 * +4208 * gn = new KJUR.asn1.x509.GeneralName({ldapdn: 'O=Test,C=US'}); // DEPRECATED +4209 * gn = new KJUR.asn1.x509.GeneralName({certissuer: certPEM}); // DEPRECATED +4210 * gn = new KJUR.asn1.x509.GeneralName({certsubj: certPEM}); // DEPRECATED +4211 */ +4212 KJUR.asn1.x509.GeneralName = function(params) { +4213 KJUR.asn1.x509.GeneralName.superclass.constructor.call(this); 4214 -4215 this.params = null; -4216 -4217 this.setByParam = function(params) { -4218 this.params = params; -4219 }; -4220 -4221 this.tohex = function() { -4222 var params = this.params; -4223 var hTag, explicitFlag, dObj; -4224 var explicitFlag = false; -4225 if (params.other !== undefined) { -4226 hTag = "a0", -4227 dObj = new _OtherName(params.other); -4228 } else if (params.rfc822 !== undefined) { -4229 hTag = "81"; -4230 dObj = new _DERIA5String({str: params.rfc822}); -4231 } else if (params.dns !== undefined) { -4232 hTag = "82"; -4233 dObj = new _DERIA5String({str: params.dns}); -4234 } else if (params.dn !== undefined) { -4235 hTag = "a4"; -4236 explicitFlag = true; -4237 if (typeof params.dn === "string") { -4238 dObj = new _X500Name({str: params.dn}); -4239 } else if (params.dn instanceof KJUR.asn1.x509.X500Name) { -4240 dObj = params.dn; -4241 } else { -4242 dObj = new _X500Name(params.dn); -4243 } -4244 } else if (params.ldapdn !== undefined) { -4245 hTag = "a4"; -4246 explicitFlag = true; -4247 dObj = new _X500Name({ldapstr: params.ldapdn}); -4248 } else if (params.certissuer !== undefined || -4249 params.certsubj !== undefined) { -4250 hTag = "a4"; -4251 explicitFlag = true; -4252 var isIssuer, certStr; -4253 var certHex = null; -4254 if (params.certsubj !== undefined) { -4255 isIssuer = false; -4256 certStr = params.certsubj; -4257 } else { -4258 isIssuer = true; -4259 certStr = params.certissuer; -4260 } -4261 -4262 if (certStr.match(/^[0-9A-Fa-f]+$/)) { -4263 certHex == certStr; -4264 } -4265 if (certStr.indexOf("-----BEGIN ") != -1) { -4266 certHex = pemtohex(certStr); -4267 } -4268 if (certHex == null) -4269 throw new Error("certsubj/certissuer not cert"); -4270 -4271 var x = new X509(); -4272 x.hex = certHex; -4273 -4274 var hDN; -4275 if (isIssuer) { -4276 hDN = x.getIssuerHex(); -4277 } else { -4278 hDN = x.getSubjectHex(); -4279 } -4280 dObj = new _ASN1Object(); -4281 dObj.hTLV = hDN; -4282 } else if (params.uri !== undefined) { -4283 hTag = "86"; -4284 dObj = new _DERIA5String({str: params.uri}); -4285 } else if (params.ip !== undefined) { -4286 hTag = "87"; -4287 var hIP; -4288 var ip = params.ip; -4289 try { -4290 if (ip.match(/^[0-9a-f]+$/)) { -4291 var len = ip.length; -4292 if (len == 8 || len == 16 || len == 32 || len == 64) { -4293 hIP = ip; -4294 } else { -4295 throw "err"; -4296 } -4297 } else { -4298 hIP = iptohex(ip); -4299 } -4300 } catch(ex) { -4301 throw new _Error("malformed IP address: " + params.ip + ":" + ex.message); -4302 } -4303 dObj = new _DEROctetString({hex: hIP}); -4304 } else { -4305 throw new _Error("improper params"); -4306 } -4307 -4308 var dTag = new _DERTaggedObject({tag: hTag, -4309 explicit: explicitFlag, -4310 obj: dObj}); -4311 return dTag.tohex(); -4312 }; -4313 this.getEncodedHex = function() { return this.tohex(); }; -4314 -4315 if (params !== undefined) this.setByParam(params); -4316 }; -4317 extendClass(KJUR.asn1.x509.GeneralName, KJUR.asn1.ASN1Object); -4318 -4319 /** -4320 * GeneralNames ASN.1 structure class<br/> -4321 * @name KJUR.asn1.x509.GeneralNames -4322 * @class GeneralNames ASN.1 structure class -4323 * @description -4324 * <br/> -4325 * <h4>EXAMPLE AND ASN.1 SYNTAX</h4> -4326 * @example -4327 * gns = new KJUR.asn1.x509.GeneralNames([{'uri': 'http://aaa.com/'}, {'uri': 'http://bbb.com/'}]); -4328 * -4329 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName -4330 */ -4331 KJUR.asn1.x509.GeneralNames = function(paramsArray) { -4332 KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this); -4333 var asn1Array = null, -4334 _KJUR = KJUR, -4335 _KJUR_asn1 = _KJUR.asn1; -4336 -4337 /** -4338 * set a array of {@link KJUR.asn1.x509.GeneralName} parameters<br/> -4339 * @name setByParamArray -4340 * @memberOf KJUR.asn1.x509.GeneralNames# -4341 * @function -4342 * @param {Array} paramsArray Array of {@link KJUR.asn1.x509.GeneralNames} -4343 * @description -4344 * <br/> -4345 * <h4>EXAMPLES</h4> -4346 * @example -4347 * gns = new KJUR.asn1.x509.GeneralNames(); -4348 * gns.setByParamArray([{uri: 'http://aaa.com/'}, {uri: 'http://bbb.com/'}]); -4349 */ -4350 this.setByParamArray = function(paramsArray) { -4351 for (var i = 0; i < paramsArray.length; i++) { -4352 var o = new _KJUR_asn1.x509.GeneralName(paramsArray[i]); -4353 this.asn1Array.push(o); -4354 } -4355 }; -4356 -4357 this.tohex = function() { -4358 var o = new _KJUR_asn1.DERSequence({'array': this.asn1Array}); -4359 return o.tohex(); -4360 }; -4361 this.getEncodedHex = function() { return this.tohex(); }; -4362 -4363 this.asn1Array = new Array(); -4364 if (typeof paramsArray != "undefined") { -4365 this.setByParamArray(paramsArray); -4366 } -4367 }; -4368 extendClass(KJUR.asn1.x509.GeneralNames, KJUR.asn1.ASN1Object); -4369 -4370 /** -4371 * OtherName of GeneralName ASN.1 structure class<br/> -4372 * @name KJUR.asn1.x509.OtherName -4373 * @class OtherName ASN.1 structure class -4374 * @since jsrsasign 10.5.3 asn1x509 2.1.12 -4375 * @see KJUR.asn1.x509.GeneralName -4376 * @see KJUR.asn1.ASN1Util.newObject -4377 * -4378 * @description -4379 * This class is for OtherName of GeneralName ASN.1 structure. -4380 * Constructor has two members: -4381 * <ul> -4382 * <li>oid - oid string (ex. "1.2.3.4")</li> -4383 * <li>value - JSON object passed to ASN1Util.newObject or ASN1Object object</li> -4384 * </ul> -4385 * -4386 * <pre> -4387 * OtherName ::= SEQUENCE { -4388 * type-id OBJECT IDENTIFIER, -4389 * value [0] EXPLICIT ANY DEFINED BY type-id } -4390 * </pre> +4215 var pTag = { rfc822: '81', dns: '82', dn: 'a4', +4216 uri: '86', ip: '87', otherName: 'a0'}, +4217 _KJUR = KJUR, +4218 _KJUR_asn1 = _KJUR.asn1, +4219 _KJUR_asn1_x509 = _KJUR_asn1.x509, +4220 _X500Name = _KJUR_asn1_x509.X500Name, +4221 _OtherName = _KJUR_asn1_x509.OtherName, +4222 _DERIA5String = _KJUR_asn1.DERIA5String, +4223 _DERPrintableString = _KJUR_asn1.DERPrintableString, +4224 _DEROctetString = _KJUR_asn1.DEROctetString, +4225 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, +4226 _ASN1Object = _KJUR_asn1.ASN1Object, +4227 _Error = Error; +4228 +4229 this.params = null; +4230 +4231 this.setByParam = function(params) { +4232 this.params = params; +4233 }; +4234 +4235 this.tohex = function() { +4236 var params = this.params; +4237 var hTag, explicitFlag, dObj; +4238 var explicitFlag = false; +4239 if (params.other !== undefined) { +4240 hTag = "a0", +4241 dObj = new _OtherName(params.other); +4242 } else if (params.rfc822 !== undefined) { +4243 hTag = "81"; +4244 dObj = new _DERIA5String({str: params.rfc822}); +4245 } else if (params.dns !== undefined) { +4246 hTag = "82"; +4247 dObj = new _DERIA5String({str: params.dns}); +4248 } else if (params.dn !== undefined) { +4249 hTag = "a4"; +4250 explicitFlag = true; +4251 if (typeof params.dn === "string") { +4252 dObj = new _X500Name({str: params.dn}); +4253 } else if (params.dn instanceof KJUR.asn1.x509.X500Name) { +4254 dObj = params.dn; +4255 } else { +4256 dObj = new _X500Name(params.dn); +4257 } +4258 } else if (params.ldapdn !== undefined) { +4259 hTag = "a4"; +4260 explicitFlag = true; +4261 dObj = new _X500Name({ldapstr: params.ldapdn}); +4262 } else if (params.certissuer !== undefined || +4263 params.certsubj !== undefined) { +4264 hTag = "a4"; +4265 explicitFlag = true; +4266 var isIssuer, certStr; +4267 var certHex = null; +4268 if (params.certsubj !== undefined) { +4269 isIssuer = false; +4270 certStr = params.certsubj; +4271 } else { +4272 isIssuer = true; +4273 certStr = params.certissuer; +4274 } +4275 +4276 if (certStr.match(/^[0-9A-Fa-f]+$/)) { +4277 certHex == certStr; +4278 } +4279 if (certStr.indexOf("-----BEGIN ") != -1) { +4280 certHex = pemtohex(certStr); +4281 } +4282 if (certHex == null) +4283 throw new Error("certsubj/certissuer not cert"); +4284 +4285 var x = new X509(); +4286 x.hex = certHex; +4287 +4288 var hDN; +4289 if (isIssuer) { +4290 hDN = x.getIssuerHex(); +4291 } else { +4292 hDN = x.getSubjectHex(); +4293 } +4294 dObj = new _ASN1Object(); +4295 dObj.hTLV = hDN; +4296 } else if (params.uri !== undefined) { +4297 hTag = "86"; +4298 dObj = new _DERIA5String({str: params.uri}); +4299 } else if (params.ip !== undefined) { +4300 hTag = "87"; +4301 var hIP; +4302 var ip = params.ip; +4303 try { +4304 if (ip.match(/^[0-9a-f]+$/)) { +4305 var len = ip.length; +4306 if (len == 8 || len == 16 || len == 32 || len == 64) { +4307 hIP = ip; +4308 } else { +4309 throw "err"; +4310 } +4311 } else { +4312 hIP = iptohex(ip); +4313 } +4314 } catch(ex) { +4315 throw new _Error("malformed IP address: " + params.ip + ":" + ex.message); +4316 } +4317 dObj = new _DEROctetString({hex: hIP}); +4318 } else { +4319 throw new _Error("improper params"); +4320 } +4321 +4322 var dTag = new _DERTaggedObject({tag: hTag, +4323 explicit: explicitFlag, +4324 obj: dObj}); +4325 return dTag.tohex(); +4326 }; +4327 this.getEncodedHex = function() { return this.tohex(); }; +4328 +4329 if (params !== undefined) this.setByParam(params); +4330 }; +4331 extendClass(KJUR.asn1.x509.GeneralName, KJUR.asn1.ASN1Object); +4332 +4333 /** +4334 * GeneralNames ASN.1 structure class<br/> +4335 * @name KJUR.asn1.x509.GeneralNames +4336 * @class GeneralNames ASN.1 structure class +4337 * @description +4338 * <br/> +4339 * <h4>EXAMPLE AND ASN.1 SYNTAX</h4> +4340 * @example +4341 * gns = new KJUR.asn1.x509.GeneralNames([{'uri': 'http://aaa.com/'}, {'uri': 'http://bbb.com/'}]); +4342 * +4343 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName +4344 */ +4345 KJUR.asn1.x509.GeneralNames = function(paramsArray) { +4346 KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this); +4347 var asn1Array = null, +4348 _KJUR = KJUR, +4349 _KJUR_asn1 = _KJUR.asn1; +4350 +4351 /** +4352 * set a array of {@link KJUR.asn1.x509.GeneralName} parameters<br/> +4353 * @name setByParamArray +4354 * @memberOf KJUR.asn1.x509.GeneralNames# +4355 * @function +4356 * @param {Array} paramsArray Array of {@link KJUR.asn1.x509.GeneralNames} +4357 * @description +4358 * <br/> +4359 * <h4>EXAMPLES</h4> +4360 * @example +4361 * gns = new KJUR.asn1.x509.GeneralNames(); +4362 * gns.setByParamArray([{uri: 'http://aaa.com/'}, {uri: 'http://bbb.com/'}]); +4363 */ +4364 this.setByParamArray = function(paramsArray) { +4365 for (var i = 0; i < paramsArray.length; i++) { +4366 var o = new _KJUR_asn1.x509.GeneralName(paramsArray[i]); +4367 this.asn1Array.push(o); +4368 } +4369 }; +4370 +4371 this.tohex = function() { +4372 var o = new _KJUR_asn1.DERSequence({'array': this.asn1Array}); +4373 return o.tohex(); +4374 }; +4375 this.getEncodedHex = function() { return this.tohex(); }; +4376 +4377 this.asn1Array = new Array(); +4378 if (typeof paramsArray != "undefined") { +4379 this.setByParamArray(paramsArray); +4380 } +4381 }; +4382 extendClass(KJUR.asn1.x509.GeneralNames, KJUR.asn1.ASN1Object); +4383 +4384 /** +4385 * OtherName of GeneralName ASN.1 structure class<br/> +4386 * @name KJUR.asn1.x509.OtherName +4387 * @class OtherName ASN.1 structure class +4388 * @since jsrsasign 10.5.3 asn1x509 2.1.12 +4389 * @see KJUR.asn1.x509.GeneralName +4390 * @see KJUR.asn1.ASN1Util.newObject 4391 * -4392 * @example -4393 * new KJUR.asn1.x509.OtherName({ -4394 * oid: "1.2.3.4", -4395 * value: {prnstr: {str: "abc"}} -4396 * }) -4397 */ -4398 KJUR.asn1.x509.OtherName = function(params) { -4399 KJUR.asn1.x509.OtherName.superclass.constructor.call(this); -4400 -4401 var asn1Obj = null, -4402 type = null, -4403 _KJUR = KJUR, -4404 _KJUR_asn1 = _KJUR.asn1, -4405 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, -4406 _DERSequence = _KJUR_asn1.DERSequence, -4407 _newObject = _KJUR_asn1.ASN1Util.newObject; -4408 -4409 this.params = null; -4410 -4411 this.setByParam = function(params) { -4412 this.params = params; -4413 }; +4392 * @description +4393 * This class is for OtherName of GeneralName ASN.1 structure. +4394 * Constructor has two members: +4395 * <ul> +4396 * <li>oid - oid string (ex. "1.2.3.4")</li> +4397 * <li>value - JSON object passed to ASN1Util.newObject or ASN1Object object</li> +4398 * </ul> +4399 * +4400 * <pre> +4401 * OtherName ::= SEQUENCE { +4402 * type-id OBJECT IDENTIFIER, +4403 * value [0] EXPLICIT ANY DEFINED BY type-id } +4404 * </pre> +4405 * +4406 * @example +4407 * new KJUR.asn1.x509.OtherName({ +4408 * oid: "1.2.3.4", +4409 * value: {prnstr: {str: "abc"}} +4410 * }) +4411 */ +4412 KJUR.asn1.x509.OtherName = function(params) { +4413 KJUR.asn1.x509.OtherName.superclass.constructor.call(this); 4414 -4415 this.tohex = function() { -4416 var params = this.params; -4417 -4418 if (params.oid == undefined || params.value == undefined) -4419 throw new Error("oid or value not specified"); -4420 -4421 var dOid = new _DERObjectIdentifier({oid: params.oid}); -4422 var dValue = _newObject({tag: {tag: "a0", -4423 explicit: true, -4424 obj: params.value}}); -4425 var dSeq = new _DERSequence({array: [dOid, dValue]}); -4426 -4427 return dSeq.tohex(); -4428 }; -4429 this.getEncodedHex = function() { return this.tohex(); }; -4430 -4431 if (params !== undefined) this.setByParam(params); -4432 }; -4433 extendClass(KJUR.asn1.x509.OtherName, KJUR.asn1.ASN1Object); +4415 var asn1Obj = null, +4416 type = null, +4417 _KJUR = KJUR, +4418 _KJUR_asn1 = _KJUR.asn1, +4419 _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, +4420 _DERSequence = _KJUR_asn1.DERSequence, +4421 _newObject = _KJUR_asn1.ASN1Util.newObject; +4422 +4423 this.params = null; +4424 +4425 this.setByParam = function(params) { +4426 this.params = params; +4427 }; +4428 +4429 this.tohex = function() { +4430 var params = this.params; +4431 +4432 if (params.oid == undefined || params.value == undefined) +4433 throw new Error("oid or value not specified"); 4434 -4435 /** -4436 * static object for OID -4437 * @name KJUR.asn1.x509.OID -4438 * @class static object for OID -4439 * @property {Assoc Array} atype2oidList for short attribute type name and oid (ex. 'C' and '2.5.4.6') -4440 * @property {Assoc Array} name2oidList for oid name and oid (ex. 'keyUsage' and '2.5.29.15') -4441 * @property {Assoc Array} objCache for caching name and DERObjectIdentifier object -4442 * -4443 * @description -4444 * This class defines OID name and values. -4445 * AttributeType names registered in OID.atype2oidList are following: -4446 * <table style="border-width: thin; border-style: solid; witdh: 100%"> -4447 * <tr><th>short</th><th>long</th><th>OID</th></tr> -4448 * <tr><td>CN</td>commonName<td></td><td>2.5.4.3</td></tr> -4449 * <tr><td>L</td><td>localityName</td><td>2.5.4.7</td></tr> -4450 * <tr><td>ST</td><td>stateOrProvinceName</td><td>2.5.4.8</td></tr> -4451 * <tr><td>O</td><td>organizationName</td><td>2.5.4.10</td></tr> -4452 * <tr><td>OU</td><td>organizationalUnitName</td><td>2.5.4.11</td></tr> -4453 * <tr><td>C</td><td></td>countryName<td>2.5.4.6</td></tr> -4454 * <tr><td>STREET</td>streetAddress<td></td><td>2.5.4.6</td></tr> -4455 * <tr><td>DC</td><td>domainComponent</td><td>0.9.2342.19200300.100.1.25</td></tr> -4456 * <tr><td>UID</td><td>userId</td><td>0.9.2342.19200300.100.1.1</td></tr> -4457 * <tr><td>SN</td><td>surname</td><td>2.5.4.4</td></tr> -4458 * <tr><td>DN</td><td>distinguishedName</td><td>2.5.4.49</td></tr> -4459 * <tr><td>E</td><td>emailAddress</td><td>1.2.840.113549.1.9.1</td></tr> -4460 * <tr><td></td><td>businessCategory</td><td>2.5.4.15</td></tr> -4461 * <tr><td></td><td>postalCode</td><td>2.5.4.17</td></tr> -4462 * <tr><td></td><td>jurisdictionOfIncorporationL</td><td>1.3.6.1.4.1.311.60.2.1.1</td></tr> -4463 * <tr><td></td><td>jurisdictionOfIncorporationSP</td><td>1.3.6.1.4.1.311.60.2.1.2</td></tr> -4464 * <tr><td></td><td>jurisdictionOfIncorporationC</td><td>1.3.6.1.4.1.311.60.2.1.3</td></tr> -4465 * </table> -4466 * -4467 * @example -4468 */ -4469 KJUR.asn1.x509.OID = new function() { -4470 var _DERObjectIdentifier = KJUR.asn1.DERObjectIdentifier; -4471 -4472 this.name2oidList = { -4473 'sha1': '1.3.14.3.2.26', -4474 'sha256': '2.16.840.1.101.3.4.2.1', -4475 'sha384': '2.16.840.1.101.3.4.2.2', -4476 'sha512': '2.16.840.1.101.3.4.2.3', -4477 'sha224': '2.16.840.1.101.3.4.2.4', -4478 'md5': '1.2.840.113549.2.5', -4479 'md2': '1.3.14.7.2.2.1', -4480 'ripemd160': '1.3.36.3.2.1', -4481 -4482 'MD2withRSA': '1.2.840.113549.1.1.2', -4483 'MD4withRSA': '1.2.840.113549.1.1.3', -4484 'MD5withRSA': '1.2.840.113549.1.1.4', -4485 'SHA1withRSA': '1.2.840.113549.1.1.5', -4486 'pkcs1-MGF': '1.2.840.113549.1.1.8', -4487 'rsaPSS': '1.2.840.113549.1.1.10', -4488 'SHA224withRSA': '1.2.840.113549.1.1.14', -4489 'SHA256withRSA': '1.2.840.113549.1.1.11', -4490 'SHA384withRSA': '1.2.840.113549.1.1.12', -4491 'SHA512withRSA': '1.2.840.113549.1.1.13', -4492 -4493 'SHA1withECDSA': '1.2.840.10045.4.1', -4494 'SHA224withECDSA': '1.2.840.10045.4.3.1', -4495 'SHA256withECDSA': '1.2.840.10045.4.3.2', -4496 'SHA384withECDSA': '1.2.840.10045.4.3.3', -4497 'SHA512withECDSA': '1.2.840.10045.4.3.4', -4498 -4499 'dsa': '1.2.840.10040.4.1', -4500 'SHA1withDSA': '1.2.840.10040.4.3', -4501 'SHA224withDSA': '2.16.840.1.101.3.4.3.1', -4502 'SHA256withDSA': '2.16.840.1.101.3.4.3.2', -4503 -4504 'rsaEncryption': '1.2.840.113549.1.1.1', -4505 -4506 // X.500 AttributeType defined in RFC 4514 -4507 'commonName': '2.5.4.3', -4508 'countryName': '2.5.4.6', -4509 'localityName': '2.5.4.7', -4510 'stateOrProvinceName': '2.5.4.8', -4511 'streetAddress': '2.5.4.9', -4512 'organizationName': '2.5.4.10', -4513 'organizationalUnitName': '2.5.4.11', -4514 'domainComponent': '0.9.2342.19200300.100.1.25', -4515 'userId': '0.9.2342.19200300.100.1.1', -4516 // other AttributeType name string -4517 'surname': '2.5.4.4', -4518 'givenName': '2.5.4.42', -4519 'title': '2.5.4.12', -4520 'distinguishedName': '2.5.4.49', -4521 'emailAddress': '1.2.840.113549.1.9.1', -4522 // other AttributeType name string (no short name) -4523 'description': '2.5.4.13', -4524 'businessCategory': '2.5.4.15', -4525 'postalCode': '2.5.4.17', -4526 'uniqueIdentifier': '2.5.4.45', -4527 'organizationIdentifier': '2.5.4.97', -4528 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', -4529 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', -4530 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3', -4531 -4532 'subjectDirectoryAttributes': '2.5.29.9', -4533 'subjectKeyIdentifier': '2.5.29.14', -4534 'keyUsage': '2.5.29.15', -4535 'subjectAltName': '2.5.29.17', -4536 'issuerAltName': '2.5.29.18', -4537 'basicConstraints': '2.5.29.19', -4538 'cRLNumber': '2.5.29.20', -4539 'cRLReason': '2.5.29.21', -4540 'nameConstraints': '2.5.29.30', -4541 'cRLDistributionPoints':'2.5.29.31', -4542 'certificatePolicies': '2.5.29.32', -4543 'anyPolicy': '2.5.29.32.0', -4544 'policyMappings': '2.5.29.33', -4545 'authorityKeyIdentifier':'2.5.29.35', -4546 'policyConstraints': '2.5.29.36', -4547 'extKeyUsage': '2.5.29.37', -4548 'inhibitAnyPolicy': '2.5.29.54', -4549 'authorityInfoAccess': '1.3.6.1.5.5.7.1.1', -4550 'ocsp': '1.3.6.1.5.5.7.48.1', -4551 'ocspBasic': '1.3.6.1.5.5.7.48.1.1', -4552 'ocspNonce': '1.3.6.1.5.5.7.48.1.2', -4553 'ocspNoCheck': '1.3.6.1.5.5.7.48.1.5', -4554 'caIssuers': '1.3.6.1.5.5.7.48.2', -4555 -4556 'anyExtendedKeyUsage': '2.5.29.37.0', -4557 'serverAuth': '1.3.6.1.5.5.7.3.1', -4558 'clientAuth': '1.3.6.1.5.5.7.3.2', -4559 'codeSigning': '1.3.6.1.5.5.7.3.3', -4560 'emailProtection': '1.3.6.1.5.5.7.3.4', -4561 'timeStamping': '1.3.6.1.5.5.7.3.8', -4562 'ocspSigning': '1.3.6.1.5.5.7.3.9', -4563 -4564 // 'otherNameForms': '1.3.6.1.5.5.7.8', -4565 'smtpUTF8Mailbox': '1.3.6.1.5.5.7.8.9', -4566 -4567 'dateOfBirth': '1.3.6.1.5.5.7.9.1', -4568 'placeOfBirth': '1.3.6.1.5.5.7.9.2', -4569 'gender': '1.3.6.1.5.5.7.9.3', -4570 'countryOfCitizenship': '1.3.6.1.5.5.7.9.4', -4571 'countryOfResidence': '1.3.6.1.5.5.7.9.5', -4572 -4573 'ecPublicKey': '1.2.840.10045.2.1', -4574 'P-256': '1.2.840.10045.3.1.7', -4575 'secp256r1': '1.2.840.10045.3.1.7', -4576 'secp256k1': '1.3.132.0.10', -4577 'secp384r1': '1.3.132.0.34', -4578 'secp521r1': '1.3.132.0.35', -4579 -4580 'pkcs5PBES2': '1.2.840.113549.1.5.13', -4581 'pkcs5PBKDF2': '1.2.840.113549.1.5.12', -4582 -4583 'des-EDE3-CBC': '1.2.840.113549.3.7', -4584 -4585 'data': '1.2.840.113549.1.7.1', // CMS data -4586 'signed-data': '1.2.840.113549.1.7.2', // CMS signed-data -4587 'enveloped-data': '1.2.840.113549.1.7.3', // CMS enveloped-data -4588 'digested-data': '1.2.840.113549.1.7.5', // CMS digested-data -4589 'encrypted-data': '1.2.840.113549.1.7.6', // CMS encrypted-data -4590 'authenticated-data': '1.2.840.113549.1.9.16.1.2', // CMS authenticated-data -4591 'tstinfo': '1.2.840.113549.1.9.16.1.4', // RFC3161 TSTInfo -4592 'signingCertificate': '1.2.840.113549.1.9.16.2.12',// SMIME -4593 'timeStampToken': '1.2.840.113549.1.9.16.2.14',// sigTS -4594 'signaturePolicyIdentifier': '1.2.840.113549.1.9.16.2.15',// cades -4595 'etsArchiveTimeStamp': '1.2.840.113549.1.9.16.2.27',// SMIME -4596 'signingCertificateV2': '1.2.840.113549.1.9.16.2.47',// SMIME -4597 'etsArchiveTimeStampV2':'1.2.840.113549.1.9.16.2.48',// SMIME -4598 'extensionRequest': '1.2.840.113549.1.9.14',// CSR extensionRequest -4599 'contentType': '1.2.840.113549.1.9.3',//PKCS#9 -4600 'messageDigest': '1.2.840.113549.1.9.4',//PKCS#9 -4601 'signingTime': '1.2.840.113549.1.9.5',//PKCS#9 -4602 'counterSignature': '1.2.840.113549.1.9.6',//PKCS#9 -4603 'archiveTimeStampV3': '0.4.0.1733.2.4',//ETSI EN29319122/TS101733 -4604 'pdfRevocationInfoArchival':'1.2.840.113583.1.1.8', //Adobe -4605 'adobeTimeStamp': '1.2.840.113583.1.1.9.1', // Adobe -4606 }; -4607 -4608 this.atype2oidList = { -4609 // RFC 4514 AttributeType name string (MUST recognized) -4610 'CN': '2.5.4.3', -4611 'L': '2.5.4.7', -4612 'ST': '2.5.4.8', -4613 'O': '2.5.4.10', -4614 'OU': '2.5.4.11', -4615 'C': '2.5.4.6', -4616 'STREET': '2.5.4.9', -4617 'DC': '0.9.2342.19200300.100.1.25', -4618 'UID': '0.9.2342.19200300.100.1.1', -4619 // other AttributeType name string -4620 // http://blog.livedoor.jp/k_urushima/archives/656114.html -4621 'SN': '2.5.4.4', // surname -4622 'T': '2.5.4.12', // title -4623 'DN': '2.5.4.49', // distinguishedName -4624 'E': '1.2.840.113549.1.9.1', // emailAddress in MS.NET or Bouncy -4625 // other AttributeType name string (no short name) -4626 'description': '2.5.4.13', -4627 'businessCategory': '2.5.4.15', -4628 'postalCode': '2.5.4.17', -4629 'serialNumber': '2.5.4.5', -4630 'uniqueIdentifier': '2.5.4.45', -4631 'organizationIdentifier': '2.5.4.97', -4632 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', -4633 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', -4634 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3' -4635 }; -4636 -4637 this.objCache = {}; -4638 -4639 /** -4640 * get DERObjectIdentifier by registered OID name -4641 * @name name2obj -4642 * @memberOf KJUR.asn1.x509.OID -4643 * @function -4644 * @param {String} name OID -4645 * @return {Object} DERObjectIdentifier instance -4646 * @see KJUR.asn1.DERObjectIdentifier -4647 * -4648 * @description -4649 * This static method returns DERObjectIdentifier object -4650 * for the specified OID. -4651 * -4652 * @example -4653 * var asn1ObjOID = KJUR.asn1.x509.OID.name2obj('SHA1withRSA'); -4654 */ -4655 this.name2obj = function(name) { -4656 if (typeof this.objCache[name] != "undefined") -4657 return this.objCache[name]; -4658 if (typeof this.name2oidList[name] == "undefined") -4659 throw "Name of ObjectIdentifier not defined: " + name; -4660 var oid = this.name2oidList[name]; -4661 var obj = new _DERObjectIdentifier({'oid': oid}); -4662 this.objCache[name] = obj; -4663 return obj; -4664 }; -4665 -4666 /** -4667 * get DERObjectIdentifier by registered attribute type name such like 'C' or 'CN'<br/> -4668 * @name atype2obj -4669 * @memberOf KJUR.asn1.x509.OID -4670 * @function -4671 * @param {String} atype short attribute type name such like 'C', 'CN' or OID -4672 * @return KJUR.asn1.DERObjectIdentifier instance -4673 * @description -4674 * @example -4675 * KJUR.asn1.x509.OID.atype2obj('CN') → DERObjectIdentifier of 2.5.4.3 -4676 * KJUR.asn1.x509.OID.atype2obj('OU') → DERObjectIdentifier of 2.5.4.11 -4677 * KJUR.asn1.x509.OID.atype2obj('streetAddress') → DERObjectIdentifier of 2.5.4.9 -4678 * KJUR.asn1.x509.OID.atype2obj('2.5.4.9') → DERObjectIdentifier of 2.5.4.9 -4679 */ -4680 this.atype2obj = function(atype) { -4681 if (this.objCache[atype] !== undefined) -4682 return this.objCache[atype]; -4683 -4684 var oid; -4685 -4686 if (atype.match(/^\d+\.\d+\.[0-9.]+$/)) { -4687 oid = atype; -4688 } else if (this.atype2oidList[atype] !== undefined) { -4689 oid = this.atype2oidList[atype]; -4690 } else if (this.name2oidList[atype] !== undefined) { -4691 oid = this.name2oidList[atype]; -4692 } else { -4693 throw new Error("AttributeType name undefined: " + atype); -4694 } -4695 var obj = new _DERObjectIdentifier({'oid': oid}); -4696 this.objCache[atype] = obj; -4697 return obj; -4698 }; -4699 -4700 /** -4701 * register OID list<br/> -4702 * @name registerOIDs -4703 * @memberOf KJUR.asn1.x509.OID -4704 * @function -4705 * @param {object} oids associative array of names and oids -4706 * @since jsrsasign 10.5.2 asn1x509 2.1.11 -4707 * @see KJUR.asn1.x509.OID.checkOIDs -4708 * -4709 * @description -4710 * This static method to register an oids to existing list -4711 * additionally. -4712 * -4713 * @example -4714 * KJUR.asn1.x509.OID.checkOIDs({ -4715 * "test1": "4.5.7.8" -4716 * }) // do nothing for invalid list -4717 * -4718 * KJUR.asn1.x509.OID.registerOIDs({ -4719 * "test1": "1.2.3", -4720 * "test2": "0.2.3.4.23", -4721 * }) // successfully registered -4722 * -4723 * KJUR.asn1.x509.OID.name2oid("test1") → "1.2.3" -4724 */ -4725 this.registerOIDs = function(oids) { -4726 if (! this.checkOIDs(oids)) return; -4727 for (var name in oids) { -4728 this.name2oidList[name] = oids[name]; -4729 } -4730 }; -4731 -4732 /** -4733 * check validity for OID list<br/> -4734 * @name checkOIDs -4735 * @memberOf KJUR.asn1.x509.OID -4736 * @function -4737 * @param {object} oids associative array of names and oids -4738 * @return {boolean} return true when valid OID list otherwise false -4739 * @since jsrsasign 10.5.2 asn1x509 2.1.11 -4740 * @see KJUR.asn1.x509.OID.registOIDs -4741 * -4742 * @description -4743 * This static method validates an associative array -4744 * as oid list. +4435 var dOid = new _DERObjectIdentifier({oid: params.oid}); +4436 var dValue = _newObject({tag: {tag: "a0", +4437 explicit: true, +4438 obj: params.value}}); +4439 var dSeq = new _DERSequence({array: [dOid, dValue]}); +4440 +4441 return dSeq.tohex(); +4442 }; +4443 this.getEncodedHex = function() { return this.tohex(); }; +4444 +4445 if (params !== undefined) this.setByParam(params); +4446 }; +4447 extendClass(KJUR.asn1.x509.OtherName, KJUR.asn1.ASN1Object); +4448 +4449 /** +4450 * static object for OID +4451 * @name KJUR.asn1.x509.OID +4452 * @class static object for OID +4453 * @property {Assoc Array} atype2oidList for short attribute type name and oid (ex. 'C' and '2.5.4.6') +4454 * @property {Assoc Array} name2oidList for oid name and oid (ex. 'keyUsage' and '2.5.29.15') +4455 * @property {Assoc Array} objCache for caching name and DERObjectIdentifier object +4456 * +4457 * @description +4458 * This class defines OID name and values. +4459 * AttributeType names registered in OID.atype2oidList are following: +4460 * <table style="border-width: thin; border-style: solid; witdh: 100%"> +4461 * <tr><th>short</th><th>long</th><th>OID</th></tr> +4462 * <tr><td>CN</td>commonName<td></td><td>2.5.4.3</td></tr> +4463 * <tr><td>L</td><td>localityName</td><td>2.5.4.7</td></tr> +4464 * <tr><td>ST</td><td>stateOrProvinceName</td><td>2.5.4.8</td></tr> +4465 * <tr><td>O</td><td>organizationName</td><td>2.5.4.10</td></tr> +4466 * <tr><td>OU</td><td>organizationalUnitName</td><td>2.5.4.11</td></tr> +4467 * <tr><td>C</td><td></td>countryName<td>2.5.4.6</td></tr> +4468 * <tr><td>STREET</td>streetAddress<td></td><td>2.5.4.6</td></tr> +4469 * <tr><td>DC</td><td>domainComponent</td><td>0.9.2342.19200300.100.1.25</td></tr> +4470 * <tr><td>UID</td><td>userId</td><td>0.9.2342.19200300.100.1.1</td></tr> +4471 * <tr><td>SN</td><td>surname</td><td>2.5.4.4</td></tr> +4472 * <tr><td>DN</td><td>distinguishedName</td><td>2.5.4.49</td></tr> +4473 * <tr><td>E</td><td>emailAddress</td><td>1.2.840.113549.1.9.1</td></tr> +4474 * <tr><td></td><td>businessCategory</td><td>2.5.4.15</td></tr> +4475 * <tr><td></td><td>postalCode</td><td>2.5.4.17</td></tr> +4476 * <tr><td></td><td>jurisdictionOfIncorporationL</td><td>1.3.6.1.4.1.311.60.2.1.1</td></tr> +4477 * <tr><td></td><td>jurisdictionOfIncorporationSP</td><td>1.3.6.1.4.1.311.60.2.1.2</td></tr> +4478 * <tr><td></td><td>jurisdictionOfIncorporationC</td><td>1.3.6.1.4.1.311.60.2.1.3</td></tr> +4479 * </table> +4480 * +4481 * @example +4482 */ +4483 KJUR.asn1.x509.OID = new function() { +4484 var _DERObjectIdentifier = KJUR.asn1.DERObjectIdentifier; +4485 +4486 this.name2oidList = { +4487 'sha1': '1.3.14.3.2.26', +4488 'sha256': '2.16.840.1.101.3.4.2.1', +4489 'sha384': '2.16.840.1.101.3.4.2.2', +4490 'sha512': '2.16.840.1.101.3.4.2.3', +4491 'sha224': '2.16.840.1.101.3.4.2.4', +4492 'md5': '1.2.840.113549.2.5', +4493 'md2': '1.3.14.7.2.2.1', +4494 'ripemd160': '1.3.36.3.2.1', +4495 +4496 'MD2withRSA': '1.2.840.113549.1.1.2', +4497 'MD4withRSA': '1.2.840.113549.1.1.3', +4498 'MD5withRSA': '1.2.840.113549.1.1.4', +4499 'SHA1withRSA': '1.2.840.113549.1.1.5', +4500 'pkcs1-MGF': '1.2.840.113549.1.1.8', +4501 'rsaPSS': '1.2.840.113549.1.1.10', +4502 'SHA224withRSA': '1.2.840.113549.1.1.14', +4503 'SHA256withRSA': '1.2.840.113549.1.1.11', +4504 'SHA384withRSA': '1.2.840.113549.1.1.12', +4505 'SHA512withRSA': '1.2.840.113549.1.1.13', +4506 +4507 'SHA1withECDSA': '1.2.840.10045.4.1', +4508 'SHA224withECDSA': '1.2.840.10045.4.3.1', +4509 'SHA256withECDSA': '1.2.840.10045.4.3.2', +4510 'SHA384withECDSA': '1.2.840.10045.4.3.3', +4511 'SHA512withECDSA': '1.2.840.10045.4.3.4', +4512 +4513 'dsa': '1.2.840.10040.4.1', +4514 'SHA1withDSA': '1.2.840.10040.4.3', +4515 'SHA224withDSA': '2.16.840.1.101.3.4.3.1', +4516 'SHA256withDSA': '2.16.840.1.101.3.4.3.2', +4517 +4518 'rsaEncryption': '1.2.840.113549.1.1.1', +4519 +4520 // X.500 AttributeType defined in RFC 4514 +4521 'commonName': '2.5.4.3', +4522 'countryName': '2.5.4.6', +4523 'localityName': '2.5.4.7', +4524 'stateOrProvinceName': '2.5.4.8', +4525 'streetAddress': '2.5.4.9', +4526 'organizationName': '2.5.4.10', +4527 'organizationalUnitName': '2.5.4.11', +4528 'domainComponent': '0.9.2342.19200300.100.1.25', +4529 'userId': '0.9.2342.19200300.100.1.1', +4530 // other AttributeType name string +4531 'surname': '2.5.4.4', +4532 'givenName': '2.5.4.42', +4533 'title': '2.5.4.12', +4534 'distinguishedName': '2.5.4.49', +4535 'emailAddress': '1.2.840.113549.1.9.1', +4536 // other AttributeType name string (no short name) +4537 'description': '2.5.4.13', +4538 'businessCategory': '2.5.4.15', +4539 'postalCode': '2.5.4.17', +4540 'uniqueIdentifier': '2.5.4.45', +4541 'organizationIdentifier': '2.5.4.97', +4542 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', +4543 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', +4544 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3', +4545 +4546 'subjectDirectoryAttributes': '2.5.29.9', +4547 'subjectKeyIdentifier': '2.5.29.14', +4548 'keyUsage': '2.5.29.15', +4549 'subjectAltName': '2.5.29.17', +4550 'issuerAltName': '2.5.29.18', +4551 'basicConstraints': '2.5.29.19', +4552 'cRLNumber': '2.5.29.20', +4553 'cRLReason': '2.5.29.21', +4554 'nameConstraints': '2.5.29.30', +4555 'cRLDistributionPoints':'2.5.29.31', +4556 'certificatePolicies': '2.5.29.32', +4557 'anyPolicy': '2.5.29.32.0', +4558 'policyMappings': '2.5.29.33', +4559 'authorityKeyIdentifier':'2.5.29.35', +4560 'policyConstraints': '2.5.29.36', +4561 'extKeyUsage': '2.5.29.37', +4562 'inhibitAnyPolicy': '2.5.29.54', +4563 'authorityInfoAccess': '1.3.6.1.5.5.7.1.1', +4564 'ocsp': '1.3.6.1.5.5.7.48.1', +4565 'ocspBasic': '1.3.6.1.5.5.7.48.1.1', +4566 'ocspNonce': '1.3.6.1.5.5.7.48.1.2', +4567 'ocspNoCheck': '1.3.6.1.5.5.7.48.1.5', +4568 'caIssuers': '1.3.6.1.5.5.7.48.2', +4569 +4570 'anyExtendedKeyUsage': '2.5.29.37.0', +4571 'serverAuth': '1.3.6.1.5.5.7.3.1', +4572 'clientAuth': '1.3.6.1.5.5.7.3.2', +4573 'codeSigning': '1.3.6.1.5.5.7.3.3', +4574 'emailProtection': '1.3.6.1.5.5.7.3.4', +4575 'timeStamping': '1.3.6.1.5.5.7.3.8', +4576 'ocspSigning': '1.3.6.1.5.5.7.3.9', +4577 +4578 // 'otherNameForms': '1.3.6.1.5.5.7.8', +4579 'smtpUTF8Mailbox': '1.3.6.1.5.5.7.8.9', +4580 +4581 'dateOfBirth': '1.3.6.1.5.5.7.9.1', +4582 'placeOfBirth': '1.3.6.1.5.5.7.9.2', +4583 'gender': '1.3.6.1.5.5.7.9.3', +4584 'countryOfCitizenship': '1.3.6.1.5.5.7.9.4', +4585 'countryOfResidence': '1.3.6.1.5.5.7.9.5', +4586 +4587 'ecPublicKey': '1.2.840.10045.2.1', +4588 'P-256': '1.2.840.10045.3.1.7', +4589 'secp256r1': '1.2.840.10045.3.1.7', +4590 'secp256k1': '1.3.132.0.10', +4591 'secp384r1': '1.3.132.0.34', +4592 'secp521r1': '1.3.132.0.35', +4593 +4594 'pkcs5PBES2': '1.2.840.113549.1.5.13', +4595 'pkcs5PBKDF2': '1.2.840.113549.1.5.12', +4596 +4597 'des-EDE3-CBC': '1.2.840.113549.3.7', +4598 +4599 'data': '1.2.840.113549.1.7.1', // CMS data +4600 'signed-data': '1.2.840.113549.1.7.2', // CMS signed-data +4601 'enveloped-data': '1.2.840.113549.1.7.3', // CMS enveloped-data +4602 'digested-data': '1.2.840.113549.1.7.5', // CMS digested-data +4603 'encrypted-data': '1.2.840.113549.1.7.6', // CMS encrypted-data +4604 'authenticated-data': '1.2.840.113549.1.9.16.1.2', // CMS authenticated-data +4605 'tstinfo': '1.2.840.113549.1.9.16.1.4', // RFC3161 TSTInfo +4606 'signingCertificate': '1.2.840.113549.1.9.16.2.12',// SMIME +4607 'timeStampToken': '1.2.840.113549.1.9.16.2.14',// sigTS +4608 'signaturePolicyIdentifier': '1.2.840.113549.1.9.16.2.15',// cades +4609 'etsArchiveTimeStamp': '1.2.840.113549.1.9.16.2.27',// SMIME +4610 'signingCertificateV2': '1.2.840.113549.1.9.16.2.47',// SMIME +4611 'etsArchiveTimeStampV2':'1.2.840.113549.1.9.16.2.48',// SMIME +4612 'extensionRequest': '1.2.840.113549.1.9.14',// CSR extensionRequest +4613 'contentType': '1.2.840.113549.1.9.3',//PKCS#9 +4614 'messageDigest': '1.2.840.113549.1.9.4',//PKCS#9 +4615 'signingTime': '1.2.840.113549.1.9.5',//PKCS#9 +4616 'counterSignature': '1.2.840.113549.1.9.6',//PKCS#9 +4617 'archiveTimeStampV3': '0.4.0.1733.2.4',//ETSI EN29319122/TS101733 +4618 'pdfRevocationInfoArchival':'1.2.840.113583.1.1.8', //Adobe +4619 'adobeTimeStamp': '1.2.840.113583.1.1.9.1', // Adobe +4620 // CABF S/MIME BR +4621 'smimeMailboxLegacy': '2.23.140.1.5.1.1', +4622 'smimeMailboxMulti': '2.23.140.1.5.1.2', +4623 'smimeMailboxStrict': '2.23.140.1.5.1.3', +4624 'smimeOrganizationLegacy': '2.23.140.1.5.2.1', +4625 'smimeOrganizationMulti': '2.23.140.1.5.2.2', +4626 'smimeOrganizationStrict': '2.23.140.1.5.2.3', +4627 'smimeSponsorLegacy': '2.23.140.1.5.3.1', +4628 'smimeSponsorMulti': '2.23.140.1.5.3.2', +4629 'smimeSponsorStrict': '2.23.140.1.5.3.3', +4630 'smimeIndividualLegacy': '2.23.140.1.5.4.1', +4631 'smimeIndividualMulti': '2.23.140.1.5.4.2', +4632 'smimeIndividualStrict': '2.23.140.1.5.4.3', +4633 }; +4634 +4635 this.atype2oidList = { +4636 // RFC 4514 AttributeType name string (MUST recognized) +4637 'CN': '2.5.4.3', +4638 'L': '2.5.4.7', +4639 'ST': '2.5.4.8', +4640 'O': '2.5.4.10', +4641 'OU': '2.5.4.11', +4642 'C': '2.5.4.6', +4643 'STREET': '2.5.4.9', +4644 'DC': '0.9.2342.19200300.100.1.25', +4645 'UID': '0.9.2342.19200300.100.1.1', +4646 // other AttributeType name string +4647 // http://blog.livedoor.jp/k_urushima/archives/656114.html +4648 'SN': '2.5.4.4', // surname +4649 'T': '2.5.4.12', // title +4650 'GN': '2.5.4.42', // givenName +4651 'DN': '2.5.4.49', // distinguishedName +4652 'E': '1.2.840.113549.1.9.1', // emailAddress in MS.NET or Bouncy +4653 // other AttributeType name string (no short name) +4654 'description': '2.5.4.13', +4655 'businessCategory': '2.5.4.15', +4656 'postalCode': '2.5.4.17', +4657 'serialNumber': '2.5.4.5', +4658 'uniqueIdentifier': '2.5.4.45', +4659 'organizationIdentifier': '2.5.4.97', +4660 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', +4661 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', +4662 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3' +4663 }; +4664 +4665 this.objCache = {}; +4666 +4667 /** +4668 * get DERObjectIdentifier by registered OID name +4669 * @name name2obj +4670 * @memberOf KJUR.asn1.x509.OID +4671 * @function +4672 * @param {String} name OID +4673 * @return {Object} DERObjectIdentifier instance +4674 * @see KJUR.asn1.DERObjectIdentifier +4675 * +4676 * @description +4677 * This static method returns DERObjectIdentifier object +4678 * for the specified OID. +4679 * +4680 * @example +4681 * var asn1ObjOID = KJUR.asn1.x509.OID.name2obj('SHA1withRSA'); +4682 */ +4683 this.name2obj = function(name) { +4684 if (typeof this.objCache[name] != "undefined") +4685 return this.objCache[name]; +4686 if (typeof this.name2oidList[name] == "undefined") +4687 throw "Name of ObjectIdentifier not defined: " + name; +4688 var oid = this.name2oidList[name]; +4689 var obj = new _DERObjectIdentifier({'oid': oid}); +4690 this.objCache[name] = obj; +4691 return obj; +4692 }; +4693 +4694 /** +4695 * get DERObjectIdentifier by registered attribute type name such like 'C' or 'CN'<br/> +4696 * @name atype2obj +4697 * @memberOf KJUR.asn1.x509.OID +4698 * @function +4699 * @param {String} atype short attribute type name such like 'C', 'CN' or OID +4700 * @return KJUR.asn1.DERObjectIdentifier instance +4701 * @description +4702 * @example +4703 * KJUR.asn1.x509.OID.atype2obj('CN') → DERObjectIdentifier of 2.5.4.3 +4704 * KJUR.asn1.x509.OID.atype2obj('OU') → DERObjectIdentifier of 2.5.4.11 +4705 * KJUR.asn1.x509.OID.atype2obj('streetAddress') → DERObjectIdentifier of 2.5.4.9 +4706 * KJUR.asn1.x509.OID.atype2obj('2.5.4.9') → DERObjectIdentifier of 2.5.4.9 +4707 */ +4708 this.atype2obj = function(atype) { +4709 if (this.objCache[atype] !== undefined) +4710 return this.objCache[atype]; +4711 +4712 var oid; +4713 +4714 if (atype.match(/^\d+\.\d+\.[0-9.]+$/)) { +4715 oid = atype; +4716 } else if (this.atype2oidList[atype] !== undefined) { +4717 oid = this.atype2oidList[atype]; +4718 } else if (this.name2oidList[atype] !== undefined) { +4719 oid = this.name2oidList[atype]; +4720 } else { +4721 throw new Error("AttributeType name undefined: " + atype); +4722 } +4723 var obj = new _DERObjectIdentifier({'oid': oid}); +4724 this.objCache[atype] = obj; +4725 return obj; +4726 }; +4727 +4728 /** +4729 * register OID list<br/> +4730 * @name registerOIDs +4731 * @memberOf KJUR.asn1.x509.OID +4732 * @function +4733 * @param {object} oids associative array of names and oids +4734 * @since jsrsasign 10.5.2 asn1x509 2.1.11 +4735 * @see KJUR.asn1.x509.OID.checkOIDs +4736 * +4737 * @description +4738 * This static method to register an oids to existing list +4739 * additionally. +4740 * +4741 * @example +4742 * KJUR.asn1.x509.OID.checkOIDs({ +4743 * "test1": "4.5.7.8" +4744 * }) // do nothing for invalid list 4745 * -4746 * @example -4747 * KJUR.asn1.x509.OID.checkOIDs(*non-assoc-array*) → false -4748 * KJUR.asn1.x509.OID.checkOIDs({}) → false -4749 * KJUR.asn1.x509.OID.checkOIDs({"test1": "apple"}) → false -4750 * KJUR.asn1.x509.OID.checkOIDs({ -4751 * "test1": "1.2.3", -4752 * "test2": "0.2.3.4.23", -4753 * }) → true // valid oids -4754 * KJUR.asn1.x509.OID.checkOIDs({ -4755 * "test1": "4.5.7.8" -4756 * }) → false // invalid oid -4757 */ -4758 this.checkOIDs = function(oids) { -4759 try { -4760 var nameList = Object.keys(oids); -4761 if (nameList.length == 0) -4762 return false; -4763 nameList.map(function(value, index, array) { -4764 var oid = this[value]; -4765 if (! oid.match(/^[0-2]\.[0-9.]+$/)) -4766 throw new Error("value is not OID"); -4767 }, oids); -4768 return true; -4769 } catch(ex) { -4770 return false; -4771 } -4772 }; -4773 -4774 -4775 }; -4776 -4777 /** -4778 * convert OID to name<br/> -4779 * @name oid2name -4780 * @memberOf KJUR.asn1.x509.OID -4781 * @function -4782 * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4) -4783 * @return {String} OID name if registered otherwise empty string -4784 * @since asn1x509 1.0.9 -4785 * @description -4786 * This static method converts OID string to its name. -4787 * If OID is undefined then it returns empty string (i.e. ''). -4788 * @example -4789 * KJUR.asn1.x509.OID.oid2name("1.3.6.1.5.5.7.1.1") → 'authorityInfoAccess' -4790 */ -4791 KJUR.asn1.x509.OID.oid2name = function(oid) { -4792 var list = KJUR.asn1.x509.OID.name2oidList; -4793 for (var name in list) { -4794 if (list[name] == oid) return name; -4795 } -4796 return ''; -4797 }; -4798 -4799 /** -4800 * convert OID to AttributeType name<br/> -4801 * @name oid2atype -4802 * @memberOf KJUR.asn1.x509.OID -4803 * @function -4804 * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4) -4805 * @return {String} OID AttributeType name if registered otherwise oid -4806 * @since jsrsasign 6.2.2 asn1x509 1.0.18 -4807 * @description -4808 * This static method converts OID string to its AttributeType name. -4809 * If OID is not defined in OID.atype2oidList associative array then it returns OID -4810 * specified as argument. -4811 * @example -4812 * KJUR.asn1.x509.OID.oid2atype("2.5.4.3") → CN -4813 * KJUR.asn1.x509.OID.oid2atype("1.3.6.1.4.1.311.60.2.1.3") → jurisdictionOfIncorporationC -4814 * KJUR.asn1.x509.OID.oid2atype("0.1.2.3.4") → 0.1.2.3.4 // unregistered OID -4815 */ -4816 KJUR.asn1.x509.OID.oid2atype = function(oid) { -4817 var list = KJUR.asn1.x509.OID.atype2oidList; -4818 for (var atype in list) { -4819 if (list[atype] == oid) return atype; -4820 } -4821 return oid; -4822 }; -4823 -4824 /** -4825 * convert OID name to OID value<br/> -4826 * @name name2oid -4827 * @memberOf KJUR.asn1.x509.OID -4828 * @function -4829 * @param {String} name OID name or OID (ex. "sha1" or "1.2.3.4") -4830 * @return {String} dot noted Object Identifer string (ex. 1.2.3.4) -4831 * @since asn1x509 1.0.11 -4832 * @description -4833 * This static method converts from OID name to OID string. -4834 * If OID is undefined then it returns empty string (i.e. ''). -4835 * @example -4836 * KJUR.asn1.x509.OID.name2oid("authorityInfoAccess") → "1.3.6.1.5.5.7.1.1" -4837 * KJUR.asn1.x509.OID.name2oid("1.2.3.4") → "1.2.3.4" -4838 * KJUR.asn1.x509.OID.name2oid("UNKNOWN NAME") → "" -4839 */ -4840 KJUR.asn1.x509.OID.name2oid = function(name) { -4841 if (name.match(/^[0-9.]+$/)) return name; -4842 var list = KJUR.asn1.x509.OID.name2oidList; -4843 if (list[name] === undefined) return ''; -4844 return list[name]; -4845 }; -4846 -4847 /** -4848 * X.509 certificate and CRL utilities class<br/> -4849 * @name KJUR.asn1.x509.X509Util -4850 * @class X.509 certificate and CRL utilities class -4851 */ -4852 KJUR.asn1.x509.X509Util = {}; -4853 -4854 /** -4855 * issue a certificate in PEM format (DEPRECATED) -4856 * @name newCertPEM -4857 * @memberOf KJUR.asn1.x509.X509Util -4858 * @function -4859 * @param {Array} param JSON object of parameter to issue a certificate -4860 * @since asn1x509 1.0.6 -4861 * @deprecated since jsrsasign 9.0.0 asn1x509 2.0.0. please move to {@link KJUR.asn1.x509.Certificate} constructor -4862 * @description -4863 * This method can issue a certificate by a simple -4864 * JSON object. -4865 * Signature value will be provided by signing with -4866 * private key using 'cakey' parameter or -4867 * hexadecimal signature value by 'sighex' parameter. -4868 * <br/> -4869 * NOTE: Algorithm parameter of AlgorithmIdentifier will -4870 * be set automatically by default. -4871 * (see {@link KJUR.asn1.x509.AlgorithmIdentifier}) -4872 * from jsrsasign 7.1.1 asn1x509 1.0.20. -4873 * <br/> -4874 * NOTE2: -4875 * RSA-PSS algorithm has been supported from jsrsasign 8.0.21. -4876 * As for RSA-PSS signature algorithm names and signing parameters -4877 * such as MGF function and salt length, please see -4878 * {@link KJUR.asn1.x509.AlgorithmIdentifier} class. -4879 * -4880 * @example -4881 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4882 * serial: {int: 4}, -4883 * sigalg: {name: 'SHA1withECDSA'}, -4884 * issuer: {str: '/C=US/O=a'}, -4885 * notbefore: {'str': '130504235959Z'}, -4886 * notafter: {'str': '140504235959Z'}, -4887 * subject: {str: '/C=US/O=b'}, -4888 * sbjpubkey: pubKeyObj, -4889 * ext: [ -4890 * {basicConstraints: {cA: true, critical: true}}, -4891 * {keyUsage: {bin: '11'}}, -4892 * ], -4893 * cakey: prvKeyObj -4894 * }); -4895 * // -- or -- -4896 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4897 * serial: {int: 4}, -4898 * sigalg: {name: 'SHA1withECDSA'}, -4899 * issuer: {str: '/C=US/O=a'}, -4900 * notbefore: {'str': '130504235959Z'}, -4901 * notafter: {'str': '140504235959Z'}, -4902 * subject: {str: '/C=US/O=b'}, -4903 * sbjpubkey: pubKeyPEM, -4904 * ext: [ -4905 * {basicConstraints: {cA: true, critical: true}}, -4906 * {keyUsage: {bin: '11'}}, -4907 * ], -4908 * cakey: [prvkey, pass]} -4909 * ); -4910 * // -- or -- -4911 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4912 * serial: {int: 1}, -4913 * sigalg: {name: 'SHA1withRSA'}, -4914 * issuer: {str: '/C=US/O=T1'}, -4915 * notbefore: {'str': '130504235959Z'}, -4916 * notafter: {'str': '140504235959Z'}, -4917 * subject: {str: '/C=US/O=T1'}, -4918 * sbjpubkey: pubKeyObj, -4919 * sighex: '0102030405..' -4920 * }); -4921 * // for the issuer and subject field, another -4922 * // representation is also available -4923 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4924 * serial: {int: 1}, -4925 * sigalg: {name: 'SHA256withRSA'}, -4926 * issuer: {C: "US", O: "T1"}, -4927 * notbefore: {'str': '130504235959Z'}, -4928 * notafter: {'str': '140504235959Z'}, -4929 * subject: {C: "US", O: "T1", CN: "http://example.com/"}, -4930 * sbjpubkey: pubKeyObj, -4931 * sighex: '0102030405..' -4932 * }); -4933 */ -4934 KJUR.asn1.x509.X509Util.newCertPEM = function(param) { -4935 var _KJUR_asn1_x509 = KJUR.asn1.x509, -4936 _TBSCertificate = _KJUR_asn1_x509.TBSCertificate, -4937 _Certificate = _KJUR_asn1_x509.Certificate; -4938 var cert = new _Certificate(param); -4939 return cert.getPEM(); -4940 }; -4941 -4942