Connect to Cassandra Apache with SSL using cassandra-driver in Node.js

后端 未结 2 1336
伪装坚强ぢ
伪装坚强ぢ 2020-12-21 01:32

I try connect to my Cassandra but I have probably wrongly configured. I run it on localhost. Cassandra has generated certificated and add on. In cqlsh there are no errors wi

2条回答
  •  时光取名叫无心
    2020-12-21 02:11

    You must specify an Object instance in sslOption property to enable ssl on the driver.

    Using your code sample:

    var fs = require('fs');
    var sslOptions = {
      key : fs.readFileSync('client-key.pem'),
      cert : fs.readFileSync('client-cert.pem'),
      ca : [fs.readFileSync('server-cert.pem')]
    };
    var client = new cassandra.Client({
      contactPoints : ['127.0.0.1'],
      authProvider : new cassandra.auth.PlainTextAuthProvider('cassandra', 'cassandra'),
      sslOptions : sslOptions
    });
    

    If you do not use client certificates, you can just use an empty object instance:

    var client = new cassandra.Client({
      contactPoints : ['127.0.0.1'],
      authProvider : new cassandra.auth.PlainTextAuthProvider('cassandra', 'cassandra'),
      sslOptions : {}
    });
    

    And it will use the defaults specified in the Node.js tls module.

提交回复
热议问题