Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript node.js和SSL错误_Javascript_Node.js_Ssl_Handshake - Fatal编程技术网

Javascript node.js和SSL错误

Javascript node.js和SSL错误,javascript,node.js,ssl,handshake,Javascript,Node.js,Ssl,Handshake,我为client.js和server.js.Wenn之间的通信创建了所有需要的证书。在服务器运行时,我使用节点client.js启动client.js。我得到错误:自签名证书。但我一直对ca权威有问题。如果存在问题,如何创建有效证书 这是我的client.js脚本: var tls = require('tls'); var fs = require('fs'); var options = { // These are necessary only if using the client

我为client.js和server.js.Wenn之间的通信创建了所有需要的证书。在服务器运行时,我使用
节点client.js启动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)
错误:自签名证书
错误(本机)
在TLSSocket。(_tls_wrap.js:1017:38)
在emitNone(events.js:67:13)
在TLSSocket.emit(events.js:166:7)
在TLSSocket.\u init.ssl.onclienthlo.ssl.oncertcb.TLSSocket.\u finishini(\u tl
s_wrap.js:582:8)
位于TLSWrap.ssl.onclienthello.ssl.oncertcb.ssl.onnewsession.ssl.onhandshakedo
ne(_tls_wrap.js:424:38)

另外,我花了很多时间(超过12个小时)在互联网上搜索这个。因此,请不要再有教程了

可能是我编辑了一点的副本。我想现在解释得更好了。