1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23const common = require('../common'); 24 25if (!common.hasCrypto) 26 common.skip('missing crypto'); 27 28const crypto = require('crypto'); 29const tls = require('tls'); 30const fixtures = require('../common/fixtures'); 31 32const certPem = fixtures.readKey('rsa_cert.crt'); 33 34const options = { 35 key: fixtures.readKey('agent1-key.pem'), 36 cert: fixtures.readKey('agent1-cert.pem') 37}; 38 39const server = tls.Server(options, (socket) => { 40 setImmediate(() => { 41 verify(); 42 setImmediate(() => { 43 socket.destroy(); 44 }); 45 }); 46}); 47 48function verify() { 49 crypto.createVerify('SHA1') 50 .update('Test') 51 .verify(certPem, 'asdfasdfas', 'base64'); 52} 53 54server.listen(0, common.mustCall(() => { 55 tls.connect({ 56 port: server.address().port, 57 rejectUnauthorized: false 58 }, common.mustCall(() => { 59 verify(); 60 })) 61 .on('error', common.mustNotCall()) 62 .on('close', common.mustCall(() => { 63 server.close(); 64 })).resume(); 65})); 66 67server.unref(); 68