Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sever and client keys to eventbus #8698

Merged
merged 4 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.zeromq.SocketType;
import org.zeromq.ZContext;
import org.zeromq.ZMQ;
import zmq.io.mechanism.curve.Curve;

import java.net.Inet6Address;
import java.net.InetAddress;
Expand All @@ -42,22 +43,32 @@ class BoundZmqEventBus implements EventBus {
private final ZMQ.Socket xsub;
private final ExecutorService executor;


BoundZmqEventBus(ZContext context, String publishConnection, String subscribeConnection) {
String address = new NetworkUtils().getHostAddress();
Addresses xpubAddr = deriveAddresses(address, publishConnection);
Addresses xsubAddr = deriveAddresses(address, subscribeConnection);

Curve curve = new Curve();
String[] serverKeys = curve.keypairZ85();
String[] clientKeys = curve.keypairZ85();

LOG.info(String.format("XPUB binding to %s, XSUB binding to %s", xpubAddr, xsubAddr));

xpub = context.createSocket(SocketType.XPUB);
xpub.setIPv6(xpubAddr.isIPv6);
xpub.setImmediate(true);
xpub.bind(xpubAddr.bindTo);
xpub.setCurvePublicKey(serverKeys[0].getBytes());
xpub.setCurveSecretKey(serverKeys[1].getBytes());

xsub = context.createSocket(SocketType.XSUB);
xsub.setIPv6(xsubAddr.isIPv6);
xsub.setImmediate(true);
xsub.bind(xsubAddr.bindTo);
xsub.setCurvePublicKey(clientKeys[0].getBytes());
xsub.setCurveSecretKey(clientKeys[1].getBytes());
xsub.setCurveServerKey(serverKeys[0].getBytes());

executor = Executors.newCachedThreadPool(r -> {
Thread thread = new Thread(r, "Message Bus Proxy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.zeromq.SocketType;
import org.zeromq.ZContext;
import org.zeromq.ZMQ;
import zmq.io.mechanism.curve.Curve;

import java.net.Inet6Address;
import java.net.InetAddress;
Expand Down Expand Up @@ -69,6 +70,10 @@ class UnboundZmqEventBus implements EventBus {
return thread;
});

Curve curve = new Curve();
String[] serverKeys = curve.keypairZ85();
String[] clientKeys = curve.keypairZ85();

String connectionMessage = String.format("Connecting to %s and %s", publishConnection, subscribeConnection);
LOG.info(connectionMessage);

Expand All @@ -85,10 +90,15 @@ class UnboundZmqEventBus implements EventBus {
sub.setIPv6(isSubAddressIPv6(publishConnection));
sub.connect(publishConnection);
sub.subscribe(new byte[0]);
sub.setCurvePublicKey(clientKeys[0].getBytes());
sub.setCurveSecretKey(clientKeys[1].getBytes());
sub.setCurveServerKey(serverKeys[0].getBytes());

pub = context.createSocket(SocketType.PUB);
pub.setIPv6(isSubAddressIPv6(subscribeConnection));
pub.connect(subscribeConnection);
pub.setCurvePublicKey(serverKeys[0].getBytes());
pub.setCurveSecretKey(serverKeys[1].getBytes());
}
);
// Connections are already established
Expand Down