【发布时间】:2016-10-13 20:45:21
【问题描述】:
目前,我正在研究将 ZeroMQ 与 Curve 结合使用以保护我的发布者和订阅者之间的流量的可能性。
我已经成功实现了一个使用 CZMQ 的 pub 子系统。
目前,我的发布者正在使用他的私钥加密他想要发送的数据,订阅者可以使用发布者的公钥解密这些数据。这比“加密”数据更“验证”数据。因为当中间有一个人时,他仍然可以解密所有数据,因为发布者的公钥是公开的。
我正在使用最新版本的 ZeroMQ 和 CZMQ 用 C 编写代码。
我的发布者.c
zctx_t* zmq_context = zctx_new();
zauth_t* auth = zauth_new (zmq_context);
zauth_set_verbose (auth, true);
zauth_configure_curve (auth, "*", CURVE_ALLOW_ANY);
zcert_t* pub_cert = zcert_load("cert.key"); // private key of publisher
void* socket = zsocket_new(zmq_context, ZMQ_PUB);
zcert_apply(pub_cert, socket);
zsocket_set_curve_server(socket, true);
//start publishing from here
我的订阅者.c
zctx_t* zmq_context = zctx_new();
zcert_t* sub_cert = zcert_new();
zcert_t* pub_cert = zcert_load("cert.pub"); // public key of publisher
char* pub_key = zcert_public_txt(pub_cert);
void* zmq_s = zsocket_new(zmq_context, ZMQ_SUB);
zcert_apply(sub_cert, zmq_s);
zsocket_set_curve_serverkey(zmq_s, pub_key);
//start subscribing to topics and receiving messages from here
从这一点开始,发布者使用他的私钥加密所有数据,订阅者使用发布者的公钥解密所有数据。我想换掉这个系统。
所以,我想用发布者的公钥加密所有数据,用发布者的私钥解密所有数据。
我已经对其进行了测试,并将我的 publisher.c 中的 zcert_load("cert.key") 更改为 zcert_load("cert.pub")。
我还在subscriber.c 中更改了此代码:
zcert_t* pub_cert = zcert_load("cert.pub"); // public key of publisher
char* pub_key = zcert_public_txt(pub_cert);
到此代码:
zcert_t* pub_cert = zcert_load("cert.key"); // private key of publisher
char* pub_key = zcert_secret_txt(pub_cert);
当我使用这些代码更改运行我的发布者和订阅者时,发布者不断给我消息:CURVE I: cannot open client HELLO -- wrong server key?
我的问题:在 ZeroMQ 和 CZMQ 的架构下,是否可以使用公钥加密数据(发布者套接字)和私钥解密数据(订阅者套接字)?
非常感谢,
罗伊
【问题讨论】:
标签: c encryption zeromq