11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto) common.skip('missing crypto');
41cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// Test sigalgs: option for TLS.
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst {
91cb0ef41Sopenharmony_ci  assert, connect, keys
101cb0ef41Sopenharmony_ci} = require(fixtures.path('tls-connect'));
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifunction assert_arrays_equal(left, right) {
131cb0ef41Sopenharmony_ci  assert.strictEqual(left.length, right.length);
141cb0ef41Sopenharmony_ci  for (let i = 0; i < left.length; i++) {
151cb0ef41Sopenharmony_ci    assert.strictEqual(left[i], right[i]);
161cb0ef41Sopenharmony_ci  }
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cifunction test(csigalgs, ssigalgs, shared_sigalgs, cerr, serr) {
201cb0ef41Sopenharmony_ci  assert(shared_sigalgs || serr || cerr, 'test missing any expectations');
211cb0ef41Sopenharmony_ci  connect({
221cb0ef41Sopenharmony_ci    client: {
231cb0ef41Sopenharmony_ci      checkServerIdentity: (servername, cert) => { },
241cb0ef41Sopenharmony_ci      ca: `${keys.agent1.cert}\n${keys.agent6.ca}`,
251cb0ef41Sopenharmony_ci      cert: keys.agent2.cert,
261cb0ef41Sopenharmony_ci      key: keys.agent2.key,
271cb0ef41Sopenharmony_ci      sigalgs: csigalgs
281cb0ef41Sopenharmony_ci    },
291cb0ef41Sopenharmony_ci    server: {
301cb0ef41Sopenharmony_ci      cert: keys.agent6.cert,
311cb0ef41Sopenharmony_ci      key: keys.agent6.key,
321cb0ef41Sopenharmony_ci      ca: keys.agent2.ca,
331cb0ef41Sopenharmony_ci      context: {
341cb0ef41Sopenharmony_ci        requestCert: true,
351cb0ef41Sopenharmony_ci        rejectUnauthorized: true
361cb0ef41Sopenharmony_ci      },
371cb0ef41Sopenharmony_ci      sigalgs: ssigalgs
381cb0ef41Sopenharmony_ci    },
391cb0ef41Sopenharmony_ci  }, common.mustCall((err, pair, cleanup) => {
401cb0ef41Sopenharmony_ci    if (shared_sigalgs) {
411cb0ef41Sopenharmony_ci      assert.ifError(err);
421cb0ef41Sopenharmony_ci      assert.ifError(pair.server.err);
431cb0ef41Sopenharmony_ci      assert.ifError(pair.client.err);
441cb0ef41Sopenharmony_ci      assert(pair.server.conn);
451cb0ef41Sopenharmony_ci      assert(pair.client.conn);
461cb0ef41Sopenharmony_ci      assert_arrays_equal(pair.server.conn.getSharedSigalgs(), shared_sigalgs);
471cb0ef41Sopenharmony_ci    } else {
481cb0ef41Sopenharmony_ci      if (serr) {
491cb0ef41Sopenharmony_ci        assert(pair.server.err);
501cb0ef41Sopenharmony_ci        assert(pair.server.err.code, serr);
511cb0ef41Sopenharmony_ci      }
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci      if (cerr) {
541cb0ef41Sopenharmony_ci        assert(pair.client.err);
551cb0ef41Sopenharmony_ci        assert(pair.client.err.code, cerr);
561cb0ef41Sopenharmony_ci      }
571cb0ef41Sopenharmony_ci    }
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci    return cleanup();
601cb0ef41Sopenharmony_ci  }));
611cb0ef41Sopenharmony_ci}
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci// Have shared sigalgs
641cb0ef41Sopenharmony_citest('RSA-PSS+SHA384', 'RSA-PSS+SHA384', ['RSA-PSS+SHA384']);
651cb0ef41Sopenharmony_citest('RSA-PSS+SHA256:RSA-PSS+SHA512:ECDSA+SHA256',
661cb0ef41Sopenharmony_ci     'RSA-PSS+SHA256:ECDSA+SHA256',
671cb0ef41Sopenharmony_ci     ['RSA-PSS+SHA256', 'ECDSA+SHA256']);
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci// Do not have shared sigalgs.
701cb0ef41Sopenharmony_citest('RSA-PSS+SHA384', 'ECDSA+SHA256',
711cb0ef41Sopenharmony_ci     undefined, 'ECONNRESET', 'ERR_SSL_NO_SHARED_SIGNATURE_ALGORITMS');
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_citest('RSA-PSS+SHA384:ECDSA+SHA256', 'ECDSA+SHA384:RSA-PSS+SHA256',
741cb0ef41Sopenharmony_ci     undefined, 'ECONNRESET', 'ERR_SSL_NO_SHARED_SIGNATURE_ALGORITMS');
75