node-forge 0.9.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -1
- package/README.md +11 -41
- package/dist/forge.all.min.js +1 -1
- package/dist/forge.all.min.js.map +1 -1
- package/dist/forge.min.js +1 -1
- package/dist/forge.min.js.map +1 -1
- package/dist/prime.worker.min.js +1 -1
- package/lib/http.js +16 -34
- package/lib/index.js +0 -2
- package/lib/log.js +10 -5
- package/lib/oids.js +6 -1
- package/lib/pem.js +8 -1
- package/lib/pkcs7.js +6 -3
- package/lib/pkcs7asn1.js +2 -1
- package/lib/prng.js +1 -1
- package/lib/util.js +0 -351
- package/lib/x509.js +128 -219
- package/lib/xhr.js +8 -6
- package/package.json +20 -17
- package/lib/debug.js +0 -78
- package/lib/task.js +0 -725
package/lib/util.js
CHANGED
|
@@ -2258,357 +2258,6 @@ util.clearItems = function(api, id, location) {
|
|
|
2258
2258
|
_callStorageFunction(_clearItems, arguments, location);
|
|
2259
2259
|
};
|
|
2260
2260
|
|
|
2261
|
-
/**
|
|
2262
|
-
* Parses the scheme, host, and port from an http(s) url.
|
|
2263
|
-
*
|
|
2264
|
-
* @param str the url string.
|
|
2265
|
-
*
|
|
2266
|
-
* @return the parsed url object or null if the url is invalid.
|
|
2267
|
-
*/
|
|
2268
|
-
util.parseUrl = function(str) {
|
|
2269
|
-
// FIXME: this regex looks a bit broken
|
|
2270
|
-
var regex = /^(https?):\/\/([^:&^\/]*):?(\d*)(.*)$/g;
|
|
2271
|
-
regex.lastIndex = 0;
|
|
2272
|
-
var m = regex.exec(str);
|
|
2273
|
-
var url = (m === null) ? null : {
|
|
2274
|
-
full: str,
|
|
2275
|
-
scheme: m[1],
|
|
2276
|
-
host: m[2],
|
|
2277
|
-
port: m[3],
|
|
2278
|
-
path: m[4]
|
|
2279
|
-
};
|
|
2280
|
-
if(url) {
|
|
2281
|
-
url.fullHost = url.host;
|
|
2282
|
-
if(url.port) {
|
|
2283
|
-
if(url.port !== 80 && url.scheme === 'http') {
|
|
2284
|
-
url.fullHost += ':' + url.port;
|
|
2285
|
-
} else if(url.port !== 443 && url.scheme === 'https') {
|
|
2286
|
-
url.fullHost += ':' + url.port;
|
|
2287
|
-
}
|
|
2288
|
-
} else if(url.scheme === 'http') {
|
|
2289
|
-
url.port = 80;
|
|
2290
|
-
} else if(url.scheme === 'https') {
|
|
2291
|
-
url.port = 443;
|
|
2292
|
-
}
|
|
2293
|
-
url.full = url.scheme + '://' + url.fullHost;
|
|
2294
|
-
}
|
|
2295
|
-
return url;
|
|
2296
|
-
};
|
|
2297
|
-
|
|
2298
|
-
/* Storage for query variables */
|
|
2299
|
-
var _queryVariables = null;
|
|
2300
|
-
|
|
2301
|
-
/**
|
|
2302
|
-
* Returns the window location query variables. Query is parsed on the first
|
|
2303
|
-
* call and the same object is returned on subsequent calls. The mapping
|
|
2304
|
-
* is from keys to an array of values. Parameters without values will have
|
|
2305
|
-
* an object key set but no value added to the value array. Values are
|
|
2306
|
-
* unescaped.
|
|
2307
|
-
*
|
|
2308
|
-
* ...?k1=v1&k2=v2:
|
|
2309
|
-
* {
|
|
2310
|
-
* "k1": ["v1"],
|
|
2311
|
-
* "k2": ["v2"]
|
|
2312
|
-
* }
|
|
2313
|
-
*
|
|
2314
|
-
* ...?k1=v1&k1=v2:
|
|
2315
|
-
* {
|
|
2316
|
-
* "k1": ["v1", "v2"]
|
|
2317
|
-
* }
|
|
2318
|
-
*
|
|
2319
|
-
* ...?k1=v1&k2:
|
|
2320
|
-
* {
|
|
2321
|
-
* "k1": ["v1"],
|
|
2322
|
-
* "k2": []
|
|
2323
|
-
* }
|
|
2324
|
-
*
|
|
2325
|
-
* ...?k1=v1&k1:
|
|
2326
|
-
* {
|
|
2327
|
-
* "k1": ["v1"]
|
|
2328
|
-
* }
|
|
2329
|
-
*
|
|
2330
|
-
* ...?k1&k1:
|
|
2331
|
-
* {
|
|
2332
|
-
* "k1": []
|
|
2333
|
-
* }
|
|
2334
|
-
*
|
|
2335
|
-
* @param query the query string to parse (optional, default to cached
|
|
2336
|
-
* results from parsing window location search query).
|
|
2337
|
-
*
|
|
2338
|
-
* @return object mapping keys to variables.
|
|
2339
|
-
*/
|
|
2340
|
-
util.getQueryVariables = function(query) {
|
|
2341
|
-
var parse = function(q) {
|
|
2342
|
-
var rval = {};
|
|
2343
|
-
var kvpairs = q.split('&');
|
|
2344
|
-
for(var i = 0; i < kvpairs.length; i++) {
|
|
2345
|
-
var pos = kvpairs[i].indexOf('=');
|
|
2346
|
-
var key;
|
|
2347
|
-
var val;
|
|
2348
|
-
if(pos > 0) {
|
|
2349
|
-
key = kvpairs[i].substring(0, pos);
|
|
2350
|
-
val = kvpairs[i].substring(pos + 1);
|
|
2351
|
-
} else {
|
|
2352
|
-
key = kvpairs[i];
|
|
2353
|
-
val = null;
|
|
2354
|
-
}
|
|
2355
|
-
if(!(key in rval)) {
|
|
2356
|
-
rval[key] = [];
|
|
2357
|
-
}
|
|
2358
|
-
// disallow overriding object prototype keys
|
|
2359
|
-
if(!(key in Object.prototype) && val !== null) {
|
|
2360
|
-
rval[key].push(unescape(val));
|
|
2361
|
-
}
|
|
2362
|
-
}
|
|
2363
|
-
return rval;
|
|
2364
|
-
};
|
|
2365
|
-
|
|
2366
|
-
var rval;
|
|
2367
|
-
if(typeof(query) === 'undefined') {
|
|
2368
|
-
// set cached variables if needed
|
|
2369
|
-
if(_queryVariables === null) {
|
|
2370
|
-
if(typeof(window) !== 'undefined' && window.location && window.location.search) {
|
|
2371
|
-
// parse window search query
|
|
2372
|
-
_queryVariables = parse(window.location.search.substring(1));
|
|
2373
|
-
} else {
|
|
2374
|
-
// no query variables available
|
|
2375
|
-
_queryVariables = {};
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
|
-
rval = _queryVariables;
|
|
2379
|
-
} else {
|
|
2380
|
-
// parse given query
|
|
2381
|
-
rval = parse(query);
|
|
2382
|
-
}
|
|
2383
|
-
return rval;
|
|
2384
|
-
};
|
|
2385
|
-
|
|
2386
|
-
/**
|
|
2387
|
-
* Parses a fragment into a path and query. This method will take a URI
|
|
2388
|
-
* fragment and break it up as if it were the main URI. For example:
|
|
2389
|
-
* /bar/baz?a=1&b=2
|
|
2390
|
-
* results in:
|
|
2391
|
-
* {
|
|
2392
|
-
* path: ["bar", "baz"],
|
|
2393
|
-
* query: {"k1": ["v1"], "k2": ["v2"]}
|
|
2394
|
-
* }
|
|
2395
|
-
*
|
|
2396
|
-
* @return object with a path array and query object.
|
|
2397
|
-
*/
|
|
2398
|
-
util.parseFragment = function(fragment) {
|
|
2399
|
-
// default to whole fragment
|
|
2400
|
-
var fp = fragment;
|
|
2401
|
-
var fq = '';
|
|
2402
|
-
// split into path and query if possible at the first '?'
|
|
2403
|
-
var pos = fragment.indexOf('?');
|
|
2404
|
-
if(pos > 0) {
|
|
2405
|
-
fp = fragment.substring(0, pos);
|
|
2406
|
-
fq = fragment.substring(pos + 1);
|
|
2407
|
-
}
|
|
2408
|
-
// split path based on '/' and ignore first element if empty
|
|
2409
|
-
var path = fp.split('/');
|
|
2410
|
-
if(path.length > 0 && path[0] === '') {
|
|
2411
|
-
path.shift();
|
|
2412
|
-
}
|
|
2413
|
-
// convert query into object
|
|
2414
|
-
var query = (fq === '') ? {} : util.getQueryVariables(fq);
|
|
2415
|
-
|
|
2416
|
-
return {
|
|
2417
|
-
pathString: fp,
|
|
2418
|
-
queryString: fq,
|
|
2419
|
-
path: path,
|
|
2420
|
-
query: query
|
|
2421
|
-
};
|
|
2422
|
-
};
|
|
2423
|
-
|
|
2424
|
-
/**
|
|
2425
|
-
* Makes a request out of a URI-like request string. This is intended to
|
|
2426
|
-
* be used where a fragment id (after a URI '#') is parsed as a URI with
|
|
2427
|
-
* path and query parts. The string should have a path beginning and
|
|
2428
|
-
* delimited by '/' and optional query parameters following a '?'. The
|
|
2429
|
-
* query should be a standard URL set of key value pairs delimited by
|
|
2430
|
-
* '&'. For backwards compatibility the initial '/' on the path is not
|
|
2431
|
-
* required. The request object has the following API, (fully described
|
|
2432
|
-
* in the method code):
|
|
2433
|
-
* {
|
|
2434
|
-
* path: <the path string part>.
|
|
2435
|
-
* query: <the query string part>,
|
|
2436
|
-
* getPath(i): get part or all of the split path array,
|
|
2437
|
-
* getQuery(k, i): get part or all of a query key array,
|
|
2438
|
-
* getQueryLast(k, _default): get last element of a query key array.
|
|
2439
|
-
* }
|
|
2440
|
-
*
|
|
2441
|
-
* @return object with request parameters.
|
|
2442
|
-
*/
|
|
2443
|
-
util.makeRequest = function(reqString) {
|
|
2444
|
-
var frag = util.parseFragment(reqString);
|
|
2445
|
-
var req = {
|
|
2446
|
-
// full path string
|
|
2447
|
-
path: frag.pathString,
|
|
2448
|
-
// full query string
|
|
2449
|
-
query: frag.queryString,
|
|
2450
|
-
/**
|
|
2451
|
-
* Get path or element in path.
|
|
2452
|
-
*
|
|
2453
|
-
* @param i optional path index.
|
|
2454
|
-
*
|
|
2455
|
-
* @return path or part of path if i provided.
|
|
2456
|
-
*/
|
|
2457
|
-
getPath: function(i) {
|
|
2458
|
-
return (typeof(i) === 'undefined') ? frag.path : frag.path[i];
|
|
2459
|
-
},
|
|
2460
|
-
/**
|
|
2461
|
-
* Get query, values for a key, or value for a key index.
|
|
2462
|
-
*
|
|
2463
|
-
* @param k optional query key.
|
|
2464
|
-
* @param i optional query key index.
|
|
2465
|
-
*
|
|
2466
|
-
* @return query, values for a key, or value for a key index.
|
|
2467
|
-
*/
|
|
2468
|
-
getQuery: function(k, i) {
|
|
2469
|
-
var rval;
|
|
2470
|
-
if(typeof(k) === 'undefined') {
|
|
2471
|
-
rval = frag.query;
|
|
2472
|
-
} else {
|
|
2473
|
-
rval = frag.query[k];
|
|
2474
|
-
if(rval && typeof(i) !== 'undefined') {
|
|
2475
|
-
rval = rval[i];
|
|
2476
|
-
}
|
|
2477
|
-
}
|
|
2478
|
-
return rval;
|
|
2479
|
-
},
|
|
2480
|
-
getQueryLast: function(k, _default) {
|
|
2481
|
-
var rval;
|
|
2482
|
-
var vals = req.getQuery(k);
|
|
2483
|
-
if(vals) {
|
|
2484
|
-
rval = vals[vals.length - 1];
|
|
2485
|
-
} else {
|
|
2486
|
-
rval = _default;
|
|
2487
|
-
}
|
|
2488
|
-
return rval;
|
|
2489
|
-
}
|
|
2490
|
-
};
|
|
2491
|
-
return req;
|
|
2492
|
-
};
|
|
2493
|
-
|
|
2494
|
-
/**
|
|
2495
|
-
* Makes a URI out of a path, an object with query parameters, and a
|
|
2496
|
-
* fragment. Uses jQuery.param() internally for query string creation.
|
|
2497
|
-
* If the path is an array, it will be joined with '/'.
|
|
2498
|
-
*
|
|
2499
|
-
* @param path string path or array of strings.
|
|
2500
|
-
* @param query object with query parameters. (optional)
|
|
2501
|
-
* @param fragment fragment string. (optional)
|
|
2502
|
-
*
|
|
2503
|
-
* @return string object with request parameters.
|
|
2504
|
-
*/
|
|
2505
|
-
util.makeLink = function(path, query, fragment) {
|
|
2506
|
-
// join path parts if needed
|
|
2507
|
-
path = jQuery.isArray(path) ? path.join('/') : path;
|
|
2508
|
-
|
|
2509
|
-
var qstr = jQuery.param(query || {});
|
|
2510
|
-
fragment = fragment || '';
|
|
2511
|
-
return path +
|
|
2512
|
-
((qstr.length > 0) ? ('?' + qstr) : '') +
|
|
2513
|
-
((fragment.length > 0) ? ('#' + fragment) : '');
|
|
2514
|
-
};
|
|
2515
|
-
|
|
2516
|
-
/**
|
|
2517
|
-
* Follows a path of keys deep into an object hierarchy and set a value.
|
|
2518
|
-
* If a key does not exist or it's value is not an object, create an
|
|
2519
|
-
* object in it's place. This can be destructive to a object tree if
|
|
2520
|
-
* leaf nodes are given as non-final path keys.
|
|
2521
|
-
* Used to avoid exceptions from missing parts of the path.
|
|
2522
|
-
*
|
|
2523
|
-
* SECURITY NOTE: Do not use unsafe inputs. Doing so could expose a prototype
|
|
2524
|
-
* pollution security issue.
|
|
2525
|
-
*
|
|
2526
|
-
* @param object the starting object.
|
|
2527
|
-
* @param keys an array of string keys.
|
|
2528
|
-
* @param value the value to set.
|
|
2529
|
-
*/
|
|
2530
|
-
util.setPath = function(object, keys, value) {
|
|
2531
|
-
// need to start at an object
|
|
2532
|
-
if(typeof(object) === 'object' && object !== null) {
|
|
2533
|
-
var i = 0;
|
|
2534
|
-
var len = keys.length;
|
|
2535
|
-
while(i < len) {
|
|
2536
|
-
var next = keys[i++];
|
|
2537
|
-
if(i == len) {
|
|
2538
|
-
// last
|
|
2539
|
-
object[next] = value;
|
|
2540
|
-
} else {
|
|
2541
|
-
// more
|
|
2542
|
-
var hasNext = (next in object);
|
|
2543
|
-
if(!hasNext ||
|
|
2544
|
-
(hasNext && typeof(object[next]) !== 'object') ||
|
|
2545
|
-
(hasNext && object[next] === null)) {
|
|
2546
|
-
object[next] = {};
|
|
2547
|
-
}
|
|
2548
|
-
object = object[next];
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
}
|
|
2552
|
-
};
|
|
2553
|
-
|
|
2554
|
-
/**
|
|
2555
|
-
* Follows a path of keys deep into an object hierarchy and return a value.
|
|
2556
|
-
* If a key does not exist, create an object in it's place.
|
|
2557
|
-
* Used to avoid exceptions from missing parts of the path.
|
|
2558
|
-
*
|
|
2559
|
-
* @param object the starting object.
|
|
2560
|
-
* @param keys an array of string keys.
|
|
2561
|
-
* @param _default value to return if path not found.
|
|
2562
|
-
*
|
|
2563
|
-
* @return the value at the path if found, else default if given, else
|
|
2564
|
-
* undefined.
|
|
2565
|
-
*/
|
|
2566
|
-
util.getPath = function(object, keys, _default) {
|
|
2567
|
-
var i = 0;
|
|
2568
|
-
var len = keys.length;
|
|
2569
|
-
var hasNext = true;
|
|
2570
|
-
while(hasNext && i < len &&
|
|
2571
|
-
typeof(object) === 'object' && object !== null) {
|
|
2572
|
-
var next = keys[i++];
|
|
2573
|
-
hasNext = next in object;
|
|
2574
|
-
if(hasNext) {
|
|
2575
|
-
object = object[next];
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
return (hasNext ? object : _default);
|
|
2579
|
-
};
|
|
2580
|
-
|
|
2581
|
-
/**
|
|
2582
|
-
* Follow a path of keys deep into an object hierarchy and delete the
|
|
2583
|
-
* last one. If a key does not exist, do nothing.
|
|
2584
|
-
* Used to avoid exceptions from missing parts of the path.
|
|
2585
|
-
*
|
|
2586
|
-
* @param object the starting object.
|
|
2587
|
-
* @param keys an array of string keys.
|
|
2588
|
-
*/
|
|
2589
|
-
util.deletePath = function(object, keys) {
|
|
2590
|
-
// need to start at an object
|
|
2591
|
-
if(typeof(object) === 'object' && object !== null) {
|
|
2592
|
-
var i = 0;
|
|
2593
|
-
var len = keys.length;
|
|
2594
|
-
while(i < len) {
|
|
2595
|
-
var next = keys[i++];
|
|
2596
|
-
if(i == len) {
|
|
2597
|
-
// last
|
|
2598
|
-
delete object[next];
|
|
2599
|
-
} else {
|
|
2600
|
-
// more
|
|
2601
|
-
if(!(next in object) ||
|
|
2602
|
-
(typeof(object[next]) !== 'object') ||
|
|
2603
|
-
(object[next] === null)) {
|
|
2604
|
-
break;
|
|
2605
|
-
}
|
|
2606
|
-
object = object[next];
|
|
2607
|
-
}
|
|
2608
|
-
}
|
|
2609
|
-
}
|
|
2610
|
-
};
|
|
2611
|
-
|
|
2612
2261
|
/**
|
|
2613
2262
|
* Check if an object is empty.
|
|
2614
2263
|
*
|