Skip to content

Commit

Permalink
Problem: Curve doesn't works on Release build on Windows 10 msvc-2017
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekel Matalon committed Jul 16, 2020
1 parent 1b59624 commit 273432b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ Stephen Wolf
Stewart Mackenzie
Victor Perron
Wes Young
Dekel Matalon
29 changes: 24 additions & 5 deletions src/zyre_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,33 @@ zyre_node_start (zyre_node_t *self)
if (self->verbose)
zsys_debug ("applying zcert to ->inbox");

uint8_t pub[32] = { 0 }, sec[32] = { 0 };
assert (zmq_z85_decode (pub, self->public_key));
assert (zmq_z85_decode (sec, self->secret_key));
zcert_t *cert = zcert_new_from(pub, sec);
assert (self->public_key);
assert (self->secret_key);

// zarmour use for string conversion
zarmour_t *armour = zarmour_new ();
zarmour_set_mode (armour, ZARMOUR_MODE_Z85);
zarmour_set_pad (armour, false);
zarmour_set_line_breaks (armour, false);
// convert keys from Z85 strings (40 bytes) to raw byte arrays (32 bytes)

zchunk_t *decoded_public_key =
zarmour_decode (armour, self->public_key);
zchunk_t *decoded_secret_key =
zarmour_decode (armour, self->secret_key);

// create zcert from the decoded keys
zcert_t *cert = zcert_new_from (zchunk_data (decoded_public_key),
zchunk_data (decoded_secret_key));

zcert_apply(cert, self->inbox);
zsock_set_curve_server (self->inbox, 1);
zsock_set_zap_domain (self->inbox, self->zap_domain);
zcert_destroy(&cert);

zcert_destroy (&cert);
zchunk_destroy (&decoded_secret_key);
zchunk_destroy (&decoded_public_key);
zarmour_destroy (&armour);
}

if (self->beacon_port) {
Expand Down
29 changes: 23 additions & 6 deletions src/zyre_peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,31 @@ zyre_peer_connect (zyre_peer_t *self, zuuid_t *from, const char *endpoint, uint6
zrex_destroy (&rex);

if (self->server_key) {
uint8_t pub[32] = { 0 }, sec[32] = { 0 };
assert (zmq_z85_decode (pub, self->public_key));
assert (zmq_z85_decode (sec, self->secret_key));
zcert_t *cert = zcert_new_from(pub, sec);
zcert_apply(cert, self->mailbox);
zcert_destroy(&cert);
assert (self->public_key);
assert (self->secret_key);

// zarmour use for string conversion
zarmour_t *armour = zarmour_new ();
zarmour_set_mode (armour, ZARMOUR_MODE_Z85);
zarmour_set_pad (armour, false);
zarmour_set_line_breaks (armour, false);
// convert keys from Z85 strings (40 bytes) to raw byte arrays (32 bytes)

zchunk_t *decoded_public_key =
zarmour_decode (armour, self->public_key);
zchunk_t *decoded_secret_key =
zarmour_decode (armour, self->secret_key);

zcert_t *cert = zcert_new_from (zchunk_data (decoded_public_key), zchunk_data (decoded_secret_key));

zcert_apply(cert, self->mailbox);
zsock_set_curve_serverkey (self->mailbox, self->server_key);

zcert_destroy (&cert);
zchunk_destroy (&decoded_secret_key);
zchunk_destroy (&decoded_public_key);
zarmour_destroy (&armour);

#ifndef ZMQ_CURVE
// legacy ZMQ support
// inline incase the underlying assert is removed
Expand Down

0 comments on commit 273432b

Please sign in to comment.