File: test-tls-no-sslv3.js

package info (click to toggle)
nodejs 4.8.2~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 62,476 kB
  • ctags: 111,183
  • sloc: cpp: 661,544; ansic: 31,406; python: 23,073; makefile: 1,418; sh: 1,384; perl: 255; lisp: 222; ruby: 76; xml: 50
file content (58 lines) | stat: -rw-r--r-- 1,737 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
const common = require('../common');
const assert = require('assert');

if (!common.hasCrypto) {
  common.skip('missing crypto');
  return;
}
const tls = require('tls');

const fs = require('fs');
const spawn = require('child_process').spawn;

if (common.opensslCli === false) {
  common.skip('node compiled without OpenSSL CLI.');
  return;
}

const cert = fs.readFileSync(common.fixturesDir + '/test_cert.pem');
const key = fs.readFileSync(common.fixturesDir + '/test_key.pem');
const server = tls.createServer({ cert: cert, key: key }, common.fail);
const errors = [];
let stderr = '';

server.listen(0, '127.0.0.1', function() {
  const address = this.address().address + ':' + this.address().port;
  const args = ['s_client',
              '-ssl3',
              '-connect', address];

  // for the performance and stability issue in s_client on Windows
  if (common.isWindows)
    args.push('-no_rand_screen');

  const client = spawn(common.opensslCli, args, { stdio: 'pipe' });
  client.stdout.pipe(process.stdout);
  client.stderr.pipe(process.stderr);
  client.stderr.setEncoding('utf8');
  client.stderr.on('data', (data) => stderr += data);

  client.once('exit', common.mustCall(function(exitCode) {
    assert.strictEqual(exitCode, 1);
    server.close();
  }));
});

server.on('clientError', (err) => errors.push(err));

process.on('exit', function() {
  if (/unknown option -ssl3/.test(stderr)) {
    common.skip('`openssl s_client -ssl3` not supported.');
  } else if (/null ssl method passed/.test(stderr)) {
    common.skip('1..0 # Skipped: `openssl s_client -ssl3` is disabled.');
  } else {
    assert.strictEqual(errors.length, 1);
    assert(/:wrong version number/.test(errors[0].message));
  }
});