Ошибка с node.js и SSL

Я создал все необходимые сертификаты для связи между client.js и server.js. Я запускаю client.js с node client.js во время работы сервера. Я получаю ошибку: самоподписанный сертификат. Но у меня постоянно проблемы с ca авторитетом. Как создать действительный сертификат, если это проблема?

Это мой сценарий client.js:

var tls = require('tls');
var fs = require('fs');

var options = {
  // These are necessary only if using the client certificate authentication (so yeah, you need them)
  key: fs.readFileSync('client-private-key.pem'),
  cert: fs.readFileSync('client-certificate.pem'),

  // This is necessary only if the server uses the self-signed certificate
  ca: [ fs.readFileSync('../server/server-certificate.pem') ]
};

var cleartextStream = tls.connect(443, options, function() {
  console.log('client connected',
              cleartextStream.authorized ? 'authorized' : 'unauthorized');
  process.stdin.pipe(cleartextStream);
  process.stdin.resume();
});
cleartextStream.setEncoding('utf8');
cleartextStream.on('data', function(data) {
  console.log(data);
});
cleartextStream.on('end', function() {
  server.close();
});    

Это мой server.js:

var tls = require('tls');
var fs = require('fs');

var options = {
  key: fs.readFileSync('server-private-key.pem'),
  cert: fs.readFileSync('server-certificate.pem'),

  // This is necessary only if using the client certificate authentication.
  // Without this some clients don't bother sending certificates at all, some do
  requestCert: true,

  // Do we reject anyone who certs who haven't been signed by our recognised certificate authorities
  rejectUnauthorized: true,

  // This is necessary only if the client uses the self-signed certificate and you care about implicit authorization
  ca: [ fs.readFileSync('../client/client-certificate.pem') ]

};

var server = tls.createServer(options, function(cleartextStream) {

  //Show the certificate info as supplied by the client
  console.log(cleartextStream.getPeerCertificate());

  console.log('server connected',
              cleartextStream.authorized ? 'authorized' : 'unauthorized');
  cleartextStream.write("welcome!\n");
  cleartextStream.setEncoding('utf8');
  cleartextStream.pipe(cleartextStream);
});
server.listen(443, function() {
  console.log('server bound');
});

Ошибка:

Error: self signed certificate
   at Error (native)
   at TLSSocket.<anonymous> (_tls_wrap.js:1017:38)
   at emitNone (events.js:67:13)
   at TLSSocket.emit (events.js:166:7)
   at TLSSocket._init.ssl.onclienthello.ssl.oncertcb.TLSSocket._finishInit (_tl
   s_wrap.js:582:8)
    at          TLSWrap.ssl.onclienthello.ssl.oncertcb.ssl.onnewsession.ssl.onhandshakedo
  ne (_tls_wrap.js:424:38)

P.S. Я потратил много времени (более 12 часов) на поиски этого в Интернете. Так что, пожалуйста, больше никаких уроков


person Filip Petrovic    schedule 02.08.2016    source источник
comment
Возможный дубликат Как нужно ли использовать самозаверяющий сертификат для HTTPS-сервера Node.js?   -  person Marko Gresak    schedule 02.08.2016
comment
Я немного отредактировал его. Я думаю, что это объяснено лучше сейчас.   -  person Filip Petrovic    schedule 02.08.2016