node-forge 0.7.5 → 0.8.2

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/lib/tls.js CHANGED
@@ -3528,40 +3528,48 @@ var _alertDescToCertError = function(desc) {
3528
3528
  */
3529
3529
  tls.verifyCertificateChain = function(c, chain) {
3530
3530
  try {
3531
- // verify chain
3532
- forge.pki.verifyCertificateChain(c.caStore, chain,
3533
- function verify(vfd, depth, chain) {
3534
- // convert pki.certificateError to tls alert description
3535
- var desc = _certErrorToAlertDesc(vfd);
3536
-
3537
- // call application callback
3538
- var ret = c.verify(c, vfd, depth, chain);
3539
- if(ret !== true) {
3540
- if(typeof ret === 'object' && !forge.util.isArray(ret)) {
3541
- // throw custom error
3542
- var error = new Error('The application rejected the certificate.');
3543
- error.send = true;
3544
- error.alert = {
3545
- level: tls.Alert.Level.fatal,
3546
- description: tls.Alert.Description.bad_certificate
3547
- };
3548
- if(ret.message) {
3549
- error.message = ret.message;
3550
- }
3551
- if(ret.alert) {
3552
- error.alert.description = ret.alert;
3553
- }
3554
- throw error;
3555
- }
3531
+ // Make a copy of c.verifyOptions so that we can modify options.verify
3532
+ // without modifying c.verifyOptions.
3533
+ var options = {};
3534
+ for (var key in c.verifyOptions) {
3535
+ options[key] = c.verifyOptions[key];
3536
+ }
3537
+
3538
+ options.verify = function(vfd, depth, chain) {
3539
+ // convert pki.certificateError to tls alert description
3540
+ var desc = _certErrorToAlertDesc(vfd);
3556
3541
 
3557
- // convert tls alert description to pki.certificateError
3558
- if(ret !== vfd) {
3559
- ret = _alertDescToCertError(ret);
3542
+ // call application callback
3543
+ var ret = c.verify(c, vfd, depth, chain);
3544
+ if(ret !== true) {
3545
+ if(typeof ret === 'object' && !forge.util.isArray(ret)) {
3546
+ // throw custom error
3547
+ var error = new Error('The application rejected the certificate.');
3548
+ error.send = true;
3549
+ error.alert = {
3550
+ level: tls.Alert.Level.fatal,
3551
+ description: tls.Alert.Description.bad_certificate
3552
+ };
3553
+ if(ret.message) {
3554
+ error.message = ret.message;
3560
3555
  }
3556
+ if(ret.alert) {
3557
+ error.alert.description = ret.alert;
3558
+ }
3559
+ throw error;
3561
3560
  }
3562
3561
 
3563
- return ret;
3564
- });
3562
+ // convert tls alert description to pki.certificateError
3563
+ if(ret !== vfd) {
3564
+ ret = _alertDescToCertError(ret);
3565
+ }
3566
+ }
3567
+
3568
+ return ret;
3569
+ };
3570
+
3571
+ // verify chain
3572
+ forge.pki.verifyCertificateChain(c.caStore, chain, options);
3565
3573
  } catch(ex) {
3566
3574
  // build tls error if not already customized
3567
3575
  var err = ex;
@@ -3718,6 +3726,7 @@ tls.createConnection = function(options) {
3718
3726
  virtualHost: options.virtualHost || null,
3719
3727
  verifyClient: options.verifyClient || false,
3720
3728
  verify: options.verify || function(cn, vfd, dpth, cts) {return vfd;},
3729
+ verifyOptions: options.verifyOptions || {},
3721
3730
  getCertificate: options.getCertificate || null,
3722
3731
  getPrivateKey: options.getPrivateKey || null,
3723
3732
  getSignature: options.getSignature || null,
@@ -4247,6 +4256,10 @@ forge.tls.createSessionCache = tls.createSessionCache;
4247
4256
  * verifyClient: true to require a client certificate in server mode,
4248
4257
  * 'optional' to request one, false not to (default: false).
4249
4258
  * verify: a handler used to custom verify certificates in the chain.
4259
+ * verifyOptions: an object with options for the certificate chain validation.
4260
+ * See documentation of pki.verifyCertificateChain for possible options.
4261
+ * verifyOptions.verify is ignored. If you wish to specify a verify handler
4262
+ * use the verify key.
4250
4263
  * getCertificate: an optional callback used to get a certificate or
4251
4264
  * a chain of certificates (as an array).
4252
4265
  * getPrivateKey: an optional callback used to get a private key.
package/lib/util.js CHANGED
@@ -13,8 +13,10 @@ var util = module.exports = forge.util = forge.util || {};
13
13
 
14
14
  // define setImmediate and nextTick
15
15
  (function() {
16
- // use native nextTick
17
- if(typeof process !== 'undefined' && process.nextTick) {
16
+ // use native nextTick (unless we're in webpack)
17
+ // webpack (or better node-libs-browser polyfill) sets process.browser.
18
+ // this way we can detect webpack properly
19
+ if(typeof process !== 'undefined' && process.nextTick && !process.browser) {
18
20
  util.nextTick = process.nextTick;
19
21
  if(typeof setImmediate === 'function') {
20
22
  util.setImmediate = setImmediate;
@@ -108,6 +110,19 @@ var util = module.exports = forge.util = forge.util || {};
108
110
  util.isNodejs =
109
111
  typeof process !== 'undefined' && process.versions && process.versions.node;
110
112
 
113
+
114
+ // 'self' will also work in Web Workers (instance of WorkerGlobalScope) while
115
+ // it will point to `window` in the main thread.
116
+ // To remain compatible with older browsers, we fall back to 'window' if 'self'
117
+ // is not available.
118
+ util.globalScope = (function() {
119
+ if(util.isNodejs) {
120
+ return global;
121
+ }
122
+
123
+ return typeof self === 'undefined' ? window : self;
124
+ })();
125
+
111
126
  // define isArray
112
127
  util.isArray = Array.isArray || function(x) {
113
128
  return Object.prototype.toString.call(x) === '[object Array]';