Node js 中基于 ZeroMQ 曲线的安全性
ZeroMQ curve-based security in Node js
我正在尝试将我的网络应用程序 (Node js) 连接到用 python 编写并使用 zmq 曲线加密的 zmq 后端。但我无法在 Node js 中找到任何关于曲线加密的有用示例或其他资源。我试过这段代码:
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()
但是连接不上服务器。我想我缺少正确的语法。任何帮助或 link 文档(已搜索但没有运气)以降低 zmq(Node js)中的安全性将非常有帮助。
服务器:
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"));
客户:
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"));
这是使用最新版本 6.x.x
的方法。
var zmq = require('zeromq');
const serverKeypair = zmq.curveKeyPair();
const clientKeypair = zmq.curveKeyPair();
// SERVER
(async () => {
const sock = new zmq.Publisher({
linger: 0,
curveServer: true,
curvePublicKey: serverKeypair.publicKey,
curveSecretKey: serverKeypair.secretKey,
});
await sock.bind("tcp://127.0.0.1:3000");
...
})();
// CLIENT
(async () => {
const sock = new zmq.Subscriber({
linger: 0,
curveServerKey: serverKeypair.publicKey,
curvePublicKey: clientKeypair.publicKey,
curveSecretKey: clientKeypair.secretKey,
});
sock.connect("tcp://127.0.0.1:3000")
...
})();
我正在尝试将我的网络应用程序 (Node js) 连接到用 python 编写并使用 zmq 曲线加密的 zmq 后端。但我无法在 Node js 中找到任何关于曲线加密的有用示例或其他资源。我试过这段代码:
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()
但是连接不上服务器。我想我缺少正确的语法。任何帮助或 link 文档(已搜索但没有运气)以降低 zmq(Node js)中的安全性将非常有帮助。
服务器:
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"));
客户:
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"));
这是使用最新版本 6.x.x
的方法。
var zmq = require('zeromq');
const serverKeypair = zmq.curveKeyPair();
const clientKeypair = zmq.curveKeyPair();
// SERVER
(async () => {
const sock = new zmq.Publisher({
linger: 0,
curveServer: true,
curvePublicKey: serverKeypair.publicKey,
curveSecretKey: serverKeypair.secretKey,
});
await sock.bind("tcp://127.0.0.1:3000");
...
})();
// CLIENT
(async () => {
const sock = new zmq.Subscriber({
linger: 0,
curveServerKey: serverKeypair.publicKey,
curvePublicKey: clientKeypair.publicKey,
curveSecretKey: clientKeypair.secretKey,
});
sock.connect("tcp://127.0.0.1:3000")
...
})();