|
25 | 25 | var common = require('../common');
|
26 | 26 | var assert = require('assert');
|
27 | 27 | var util = require('util');
|
| 28 | +var spawn = require('child_process').spawn; |
28 | 29 |
|
29 | 30 | try {
|
30 | 31 | var crypto = require('crypto');
|
@@ -855,6 +856,40 @@ var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' +
|
855 | 856 | var bad_dh = crypto.createDiffieHellman(p, 'hex');
|
856 | 857 | assert.equal(bad_dh.verifyError, constants.DH_NOT_SUITABLE_GENERATOR);
|
857 | 858 |
|
| 859 | +function node_output(code, args, env, cb) { |
| 860 | + var out = '', err = ''; |
| 861 | + var p = spawn(process.execPath, [ '-e', code ].concat(args), { env: env }); |
| 862 | + p.stdout.on('data', function(data) { out += data; }); |
| 863 | + p.stderr.on('data', function(data) { err += data; }); |
| 864 | + p.on('close', function(code, signal) { cb(out, err, code); }); |
| 865 | +} |
| 866 | + |
| 867 | +function no_output(out, err, code) { |
| 868 | + assert.equal(out + err, ''); |
| 869 | + assert.equal(code, 0); |
| 870 | +} |
| 871 | + |
| 872 | +// test if fails on deprecated group |
| 873 | +node_output("require('crypto').getDiffieHellman('modp1')", |
| 874 | + [], {}, function(out, err, code) { |
| 875 | + assert.equal(out, ''); |
| 876 | + assert.ok(err.indexOf('Small DH groups disabled') > -1); |
| 877 | + assert.equal(code, 1); |
| 878 | + }); |
| 879 | + |
| 880 | +// test if the environment variable makes it work |
| 881 | +node_output("require('crypto').getDiffieHellman('modp1')", |
| 882 | + [], { 'ENABLE_SMALL_DH_GROUPS': '' }, no_output); |
| 883 | + |
| 884 | +// test if the cmdline switch makes it work |
| 885 | +node_output("require('crypto').getDiffieHellman('modp1')", |
| 886 | + [ '--enable-small-dh-groups' ], {}, no_output); |
| 887 | + |
| 888 | +// test if does not fail on the next group |
| 889 | +node_output("require('crypto').getDiffieHellman('modp2')", |
| 890 | + [], {}, no_output); |
| 891 | + |
| 892 | + |
858 | 893 | // Test RSA encryption/decryption
|
859 | 894 | (function() {
|
860 | 895 | var input = 'I AM THE WALRUS';
|
|
0 commit comments