11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// This test ensures that the value "auto" on ecdhCurve option is 51cb0ef41Sopenharmony_ci// supported to enable automatic curve selection in TLS server. 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciif (!common.hasCrypto) 81cb0ef41Sopenharmony_ci common.skip('missing crypto'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciif (!common.opensslCli) 111cb0ef41Sopenharmony_ci common.skip('missing openssl-cli'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst assert = require('assert'); 141cb0ef41Sopenharmony_ciconst tls = require('tls'); 151cb0ef41Sopenharmony_ciconst { execFile } = require('child_process'); 161cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cifunction loadPEM(n) { 191cb0ef41Sopenharmony_ci return fixtures.readKey(`${n}.pem`); 201cb0ef41Sopenharmony_ci} 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciconst options = { 231cb0ef41Sopenharmony_ci key: loadPEM('agent2-key'), 241cb0ef41Sopenharmony_ci cert: loadPEM('agent2-cert'), 251cb0ef41Sopenharmony_ci ciphers: '-ALL:ECDHE-RSA-AES128-SHA256', 261cb0ef41Sopenharmony_ci ecdhCurve: 'auto', 271cb0ef41Sopenharmony_ci maxVersion: 'TLSv1.2', 281cb0ef41Sopenharmony_ci}; 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciconst reply = 'I AM THE WALRUS'; // Something recognizable 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciconst server = tls.createServer(options, (conn) => { 331cb0ef41Sopenharmony_ci conn.end(reply); 341cb0ef41Sopenharmony_ci}).listen(0, common.mustCall(() => { 351cb0ef41Sopenharmony_ci const args = ['s_client', 361cb0ef41Sopenharmony_ci '-cipher', `${options.ciphers}`, 371cb0ef41Sopenharmony_ci '-connect', `127.0.0.1:${server.address().port}`]; 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci execFile(common.opensslCli, args, common.mustSucceed((stdout) => { 401cb0ef41Sopenharmony_ci assert(stdout.includes(reply)); 411cb0ef41Sopenharmony_ci server.close(); 421cb0ef41Sopenharmony_ci })); 431cb0ef41Sopenharmony_ci})); 44