|
12 | 12 | #include "config.h"
|
13 | 13 | #endif
|
14 | 14 | #include <stdarg.h>
|
15 |
| -#include <czmq.h> |
| 15 | +#include <sys/types.h> |
| 16 | +#include <sys/stat.h> |
| 17 | +#include <fcntl.h> |
16 | 18 | #include <zmq.h>
|
| 19 | +#include <unistd.h> |
| 20 | +#include <assert.h> |
17 | 21 | #include <flux/core.h>
|
18 | 22 | #include <inttypes.h>
|
19 | 23 | #include <jansson.h>
|
|
23 | 27 | #include "src/common/libzmqutil/sockopt.h"
|
24 | 28 | #include "src/common/libzmqutil/reactor.h"
|
25 | 29 | #include "src/common/libzmqutil/zap.h"
|
| 30 | +#include "src/common/libzmqutil/cert.h" |
26 | 31 | #include "src/common/libzmqutil/monitor.h"
|
27 | 32 | #include "src/common/libczmqcontainers/czmq_containers.h"
|
28 | 33 | #include "src/common/libutil/log.h"
|
|
32 | 37 | #include "src/common/libutil/monotime.h"
|
33 | 38 | #include "src/common/libutil/errprintf.h"
|
34 | 39 | #include "src/common/librouter/rpc_track.h"
|
35 |
| -#include "src/common/libccan/ccan/ptrint/ptrint.h" |
| 40 | +#include "ccan/ptrint/ptrint.h" |
| 41 | +#include "ccan/str/str.h" |
36 | 42 |
|
37 | 43 | #include "overlay.h"
|
38 | 44 | #include "attr.h"
|
@@ -140,7 +146,7 @@ struct overlay_monitor {
|
140 | 146 |
|
141 | 147 | struct overlay {
|
142 | 148 | void *zctx;
|
143 |
| - zcert_t *cert; |
| 149 | + struct cert *cert; |
144 | 150 | struct zmqutil_zap *zap;
|
145 | 151 | int enable_ipv6;
|
146 | 152 |
|
@@ -1303,8 +1309,8 @@ int overlay_connect (struct overlay *ov)
|
1303 | 1309 | return -1;
|
1304 | 1310 | }
|
1305 | 1311 | #endif
|
1306 |
| - zcert_apply (ov->cert, ov->parent.zsock); |
1307 |
| - |
| 1312 | + if (cert_apply (ov->cert, ov->parent.zsock) < 0) |
| 1313 | + return -1; |
1308 | 1314 | if (zmq_connect (ov->parent.zsock, ov->parent.uri) < 0)
|
1309 | 1315 | return -1;
|
1310 | 1316 | if (!(ov->parent.w = zmqutil_watcher_create (ov->reactor,
|
@@ -1373,8 +1379,10 @@ int overlay_bind (struct overlay *ov, const char *uri)
|
1373 | 1379 | }
|
1374 | 1380 | }
|
1375 | 1381 | #endif
|
1376 |
| - zcert_apply (ov->cert, ov->bind_zsock); |
1377 |
| - |
| 1382 | + if (cert_apply (ov->cert, ov->bind_zsock) < 0) { |
| 1383 | + log_err ("error setting curve socket options"); |
| 1384 | + return -1; |
| 1385 | + } |
1378 | 1386 | if (zmq_bind (ov->bind_zsock, uri) < 0) {
|
1379 | 1387 | log_err ("error binding to %s", uri);
|
1380 | 1388 | return -1;
|
@@ -1713,35 +1721,46 @@ static void overlay_disconnect_subtree_cb (flux_t *h,
|
1713 | 1721 | int overlay_cert_load (struct overlay *ov, const char *path)
|
1714 | 1722 | {
|
1715 | 1723 | struct stat sb;
|
1716 |
| - zcert_t *cert; |
| 1724 | + int fd; |
| 1725 | + FILE *f = NULL; |
| 1726 | + struct cert *cert; |
1717 | 1727 |
|
1718 |
| - if (stat (path, &sb) < 0) { |
1719 |
| - log_err ("%s", path); |
1720 |
| - return -1; |
| 1728 | + if ((fd = open (path, O_RDONLY)) < 0 |
| 1729 | + || fstat (fd, &sb) < 0) { |
| 1730 | + goto error; |
1721 | 1731 | }
|
1722 | 1732 | if ((sb.st_mode & S_IROTH) | (sb.st_mode & S_IRGRP)) {
|
1723 | 1733 | log_msg ("%s: readable by group/other", path);
|
1724 | 1734 | errno = EPERM;
|
1725 |
| - return -1; |
| 1735 | + goto error_quiet; |
1726 | 1736 | }
|
1727 |
| - if (!(cert = zcert_load (path))) { |
1728 |
| - log_msg ("%s: invalid CURVE certificate", path); |
1729 |
| - errno = EINVAL; |
1730 |
| - return -1; |
1731 |
| - } |
1732 |
| - zcert_destroy (&ov->cert); |
| 1737 | + if (!(f = fdopen (fd, "r"))) |
| 1738 | + goto error; |
| 1739 | + fd = -1; // now owned by 'f' |
| 1740 | + if (!(cert = cert_read (f))) |
| 1741 | + goto error; |
| 1742 | + cert_destroy (ov->cert); // replace ov->cert (if any) with this |
1733 | 1743 | ov->cert = cert;
|
| 1744 | + (void)fclose (f); |
1734 | 1745 | return 0;
|
| 1746 | +error: |
| 1747 | + log_err ("%s", path); |
| 1748 | +error_quiet: |
| 1749 | + if (fd >= 0) |
| 1750 | + (void)close (fd); |
| 1751 | + if (f) |
| 1752 | + (void)fclose (f); |
| 1753 | + return -1; |
1735 | 1754 | }
|
1736 | 1755 |
|
1737 | 1756 | const char *overlay_cert_pubkey (struct overlay *ov)
|
1738 | 1757 | {
|
1739 |
| - return zcert_public_txt (ov->cert); |
| 1758 | + return cert_public_txt (ov->cert); |
1740 | 1759 | }
|
1741 | 1760 |
|
1742 | 1761 | const char *overlay_cert_name (struct overlay *ov)
|
1743 | 1762 | {
|
1744 |
| - return zcert_meta (ov->cert, "name"); |
| 1763 | + return cert_meta_get (ov->cert, "name"); |
1745 | 1764 | }
|
1746 | 1765 |
|
1747 | 1766 | int overlay_authorize (struct overlay *ov,
|
@@ -2042,7 +2061,7 @@ void overlay_destroy (struct overlay *ov)
|
2042 | 2061 |
|
2043 | 2062 | flux_msglist_destroy (ov->health_requests);
|
2044 | 2063 |
|
2045 |
| - zcert_destroy (&ov->cert); |
| 2064 | + cert_destroy (ov->cert); |
2046 | 2065 | zmqutil_zap_destroy (ov->zap);
|
2047 | 2066 |
|
2048 | 2067 | flux_future_destroy (ov->f_sync);
|
@@ -2164,7 +2183,7 @@ struct overlay *overlay_create (flux_t *h,
|
2164 | 2183 | goto error;
|
2165 | 2184 | if (flux_msg_handler_addvec (h, htab, ov, &ov->handlers) < 0)
|
2166 | 2185 | goto error;
|
2167 |
| - if (!(ov->cert = zcert_new ())) |
| 2186 | + if (!(ov->cert = cert_create ())) |
2168 | 2187 | goto nomem;
|
2169 | 2188 | if (!(ov->health_requests = flux_msglist_create ()))
|
2170 | 2189 | goto error;
|
|
0 commit comments