Skip to content

Commit

Permalink
keygen: check for zero keys in gencurve
Browse files Browse the repository at this point in the history
Make an attempt to check for zero keys from zcert_new()
in libflux/security.c:gencurve(). This is a workaround for
zeromq issue 325 (zcert_new doesn't return NULL when libsodium
isn't installed.)
  • Loading branch information
grondo committed Sep 29, 2014
1 parent 298e81d commit 76601b5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/common/libflux/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,22 @@ static char * ctime_iso8601_now (char *buf, size_t sz)
return (buf);
}

static bool zcert_is_zero (zcert_t *cert)
{
bool rc;
byte z[64]; /* XXX: ZMQ cert is 32 bytes, but pad here for safety */
zcert_t *zero;

/*
* Create cert from zero keys, compare to argument:
*/
memset (z, 0, sizeof (z));
zero = zcert_new_from (z, z);
rc = zcert_eq (cert, zero);
zcert_destroy (&zero);
return (rc);
}

static int gencurve (flux_sec_t c, const char *role, bool force, bool verbose)
{
char *path = NULL, *priv = NULL;;
Expand Down Expand Up @@ -553,6 +569,12 @@ static int gencurve (flux_sec_t c, const char *role, bool force, bool verbose)
}
if (!(cert = zcert_new ()))
oom ();
if (zcert_is_zero (cert)) {
seterrstr (c, "Failed to create non-zero keys."
" Is libzmq compiled with libsodium?");
errno = EINVAL;
goto done;
}
zcert_set_meta (cert, "time", "%s", ctime_iso8601_now (buf, sizeof (buf)));
zcert_set_meta (cert, "role", (char *)role);
if (verbose) {
Expand Down

0 comments on commit 76601b5

Please sign in to comment.