Search code examples
node.jsencryptionzeromqcurve

ZeroMQ curve-based security in Node js


I am trying to connect my web app (Node js) to a zmq backend which is written in python and using zmq curve encryption. But I am unable to find any helpful example or another resource about curve encryption in Node js. I tried this code :

      const zmq = require("zeromq");

      async function run(){
          const sock = new zmq.Request;
          sock.curve_publickey =  'wka2b<1234]+x64D%/a?+l0QS*3XRfhn$i!}3lM}'  // Not the original keys. ;-)
          sock.curve_secretkey =  '?frhwU4mFY1g168tXp64(N6sr/nn{=pQdYP**Ej*'
          sock.curve_serverkey =  '4:U}SW6z?:!]uE44]46.TRGV^4z55+(TTX$}C(DC'
          
          sock.connect("tcp://localhost:9090")
          console.log("Connected to Server")
          
          await sock.send(`Request=GenerateModels|UserId=${user}|FileName=${req.params.name}`)
          const [result] = await sock.receive()
          console.log(result.toString('utf8'))
      }
      
      run()

But it doesn't connect to the server. I think I am missing the correct syntax for this. Any help or link to the documentation (searched but no luck) to curve security in zmq (Node js) would be really helpful.


Solution

  • Server:

    s.setsockopt(zmq.ZMQ_CURVE_SERVER, 1);
    s.setsockopt(zmq.ZMQ_CURVE_SECRETKEY, new Buffer.from("]W{YFJ^->}wG7*m-o/z8L$yWw}<R%c*]EcU.xDQV"));
    s.setsockopt(zmq.ZMQ_CURVE_PUBLICKEY, new Buffer.from("rHLUXzqQG$ex{KD/7B#GcT%)f}Li&wo^Ctd*+?Ir"));
    

    Client:

    ckeys = zmq.zmqCurveKeypair();
    c.setsockopt(zmq.ZMQ_CURVE_SERVER, 0);
    c.setsockopt(zmq.ZMQ_CURVE_SECRETKEY, new Buffer.from(ckeys.secret));
    c.setsockopt(zmq.ZMQ_CURVE_PUBLICKEY, new Buffer.from(ckeys.public));
    c.setsockopt(zmq.ZMQ_CURVE_SERVERKEY, new Buffer.from("rHLUXzqQG$ex{KD/7B#GcT%)f}Li&wo^Ctd*+?Ir"));