aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2024-01-21 19:30:43 +0000
committerOmar Polo <op@omarpolo.com>2024-01-21 19:30:43 +0000
commit4f3b85e6d72b0df0b6264baf711290af4661807d (patch)
treec3606b26212017ae68e78e5fae56d4fc2b11dff1
parent2a822b03ba21a85012e996136836519dd79c2aa6 (diff)
convert the remaining bit of crypto.c to the ibuf_* APIs
-rw-r--r--crypto.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/crypto.c b/crypto.c
index 35c5de2..ab6753e 100644
--- a/crypto.c
+++ b/crypto.c
@@ -117,25 +117,23 @@ crypto_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg)
EVP_PKEY *pkey;
struct imsg_crypto_req req;
struct imsg_crypto_res res;
+ struct ibuf ibuf;
struct iovec iov[2];
const void *from;
- unsigned char *data, *to;
- size_t datalen;
+ unsigned char *to;
int n, ret;
unsigned int len;
- data = imsg->data;
- datalen = IMSG_DATA_SIZE(imsg);
+ if (imsg_get_ibuf(imsg, &ibuf) == -1)
+ fatalx("%s: couldn't get an ibuf", __func__);
switch (imsg->hdr.type) {
case IMSG_CRYPTO_RSA_PRIVENC:
case IMSG_CRYPTO_RSA_PRIVDEC:
- if (datalen < sizeof(req))
- fatalx("size mismatch for imsg %d", imsg->hdr.type);
- memcpy(&req, data, sizeof(req));
- if (datalen != sizeof(req) + req.flen)
+ if (ibuf_get(&ibuf, &req, sizeof(req)) == -1 ||
+ ibuf_size(&ibuf) != req.flen)
fatalx("size mismatch for imsg %d", imsg->hdr.type);
- from = data + sizeof(req);
+ from = ibuf_data(&ibuf);
if ((pkey = get_pkey(req.hash)) == NULL ||
(rsa = EVP_PKEY_get1_RSA(pkey)) == NULL)
@@ -181,12 +179,10 @@ crypto_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg)
break;
case IMSG_CRYPTO_ECDSA_SIGN:
- if (datalen < sizeof(req))
- fatalx("size mismatch for imsg %d", imsg->hdr.type);
- memcpy(&req, data, sizeof(req));
- if (datalen != sizeof(req) + req.flen)
+ if (ibuf_get(&ibuf, &req, sizeof(req)) == -1 ||
+ ibuf_size(&ibuf) != req.flen)
fatalx("size mismatch for imsg %d", imsg->hdr.type);
- from = data + sizeof(req);
+ from = ibuf_data(&ibuf);
if ((pkey = get_pkey(req.hash)) == NULL ||
(ecdsa = EVP_PKEY_get1_EC_KEY(pkey)) == NULL)