diff options
Diffstat (limited to 'usr.sbin/acme-client/acctproc.c')
-rw-r--r-- | usr.sbin/acme-client/acctproc.c | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/usr.sbin/acme-client/acctproc.c b/usr.sbin/acme-client/acctproc.c index ccadd8c77a6..3f80bd2da28 100644 --- a/usr.sbin/acme-client/acctproc.c +++ b/usr.sbin/acme-client/acctproc.c @@ -1,4 +1,4 @@ -/* $Id: acctproc.c,v 1.9 2016/09/13 17:13:37 deraadt Exp $ */ +/* $Id: acctproc.c,v 1.10 2017/01/24 12:05:14 jsing Exp $ */ /* * Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -45,7 +45,7 @@ bn2string(const BIGNUM *bn) /* Extract big-endian representation of BIGNUM. */ len = BN_num_bytes(bn); - if (NULL == (buf = malloc(len))) { + if ((buf = malloc(len)) == NULL) { warn("malloc"); return (NULL); } else if (len != BN_bn2bin(bn, (unsigned char *)buf)) { @@ -56,7 +56,7 @@ bn2string(const BIGNUM *bn) /* Convert to base64url. */ - if (NULL == (bbuf = base64buf_url(buf, len))) { + if ((bbuf = base64buf_url(buf, len)) == NULL) { warnx("base64buf_url"); free(buf); return (NULL); @@ -76,13 +76,13 @@ op_thumb_rsa(EVP_PKEY *pkey) char *exp = NULL, *mod = NULL, *json = NULL; RSA *r; - if (NULL == (r = EVP_PKEY_get1_RSA(pkey))) + if ((r = EVP_PKEY_get1_RSA(pkey)) == NULL) warnx("EVP_PKEY_get1_RSA"); - else if (NULL == (mod = bn2string(r->n))) + else if ((mod = bn2string(r->n)) == NULL) warnx("bn2string"); - else if (NULL == (exp = bn2string(r->e))) + else if ((exp = bn2string(r->e)) == NULL) warnx("bn2string"); - else if (NULL == (json = json_fmt_thumb_rsa(exp, mod))) + else if ((json = json_fmt_thumb_rsa(exp, mod)) == NULL) warnx("json_fmt_thumb_rsa"); free(exp); @@ -106,7 +106,7 @@ op_thumbprint(int fd, EVP_PKEY *pkey) switch (EVP_PKEY_type(pkey->type)) { case EVP_PKEY_RSA: - if (NULL != (thumb = op_thumb_rsa(pkey))) + if ((thumb = op_thumb_rsa(pkey)) != NULL) break; goto out; default: @@ -121,10 +121,10 @@ op_thumbprint(int fd, EVP_PKEY *pkey) * it up in the read loop). */ - if (NULL == (dig = malloc(EVP_MAX_MD_SIZE))) { + if ((dig = malloc(EVP_MAX_MD_SIZE)) == NULL) { warn("malloc"); goto out; - } else if (NULL == (ctx = EVP_MD_CTX_create())) { + } else if ((ctx = EVP_MD_CTX_create()) == NULL) { warnx("EVP_MD_CTX_create"); goto out; } else if (!EVP_DigestInit_ex(ctx, EVP_sha256(), NULL)) { @@ -136,7 +136,7 @@ op_thumbprint(int fd, EVP_PKEY *pkey) } else if (!EVP_DigestFinal_ex(ctx, dig, &digsz)) { warnx("EVP_SignFinal"); goto out; - } else if (NULL == (dig64 = base64buf_url((char *)dig, digsz))) { + } else if ((dig64 = base64buf_url((char *)dig, digsz)) == NULL) { warnx("base64buf_url"); goto out; } else if (writestr(fd, COMM_THUMB, dig64) < 0) @@ -144,7 +144,7 @@ op_thumbprint(int fd, EVP_PKEY *pkey) rc = 1; out: - if (NULL != ctx) + if (ctx != NULL) EVP_MD_CTX_destroy(ctx); free(thumb); @@ -169,15 +169,15 @@ op_sign_rsa(char **head, char **prot, EVP_PKEY *pkey, const char *nonce) * Finally, format the header combined with the nonce. */ - if (NULL == (r = EVP_PKEY_get1_RSA(pkey))) + if ((r = EVP_PKEY_get1_RSA(pkey)) == NULL) warnx("EVP_PKEY_get1_RSA"); - else if (NULL == (mod = bn2string(r->n))) + else if ((mod = bn2string(r->n)) == NULL) warnx("bn2string"); - else if (NULL == (exp = bn2string(r->e))) + else if ((exp = bn2string(r->e)) == NULL) warnx("bn2string"); - else if (NULL == (*head = json_fmt_header_rsa(exp, mod))) + else if ((*head = json_fmt_header_rsa(exp, mod)) == NULL) warnx("json_fmt_header_rsa"); - else if (NULL == (*prot = json_fmt_protected_rsa(exp, mod, nonce))) + else if ((*prot = json_fmt_protected_rsa(exp, mod, nonce)) == NULL) warnx("json_fmt_protected_rsa"); else rc = 1; @@ -204,14 +204,14 @@ op_sign(int fd, EVP_PKEY *pkey) /* Read our payload and nonce from the requestor. */ - if (NULL == (pay = readstr(fd, COMM_PAY))) + if ((pay = readstr(fd, COMM_PAY)) == NULL) goto out; - else if (NULL == (nonce = readstr(fd, COMM_NONCE))) + else if ((nonce = readstr(fd, COMM_NONCE)) == NULL) goto out; /* Base64-encode the payload. */ - if (NULL == (pay64 = base64buf_url(pay, strlen(pay)))) { + if ((pay64 = base64buf_url(pay, strlen(pay))) == NULL) { warnx("base64buf_url"); goto out; } @@ -228,7 +228,7 @@ op_sign(int fd, EVP_PKEY *pkey) /* The header combined with the nonce, base64. */ - if (NULL == (prot64 = base64buf_url(prot, strlen(prot)))) { + if ((prot64 = base64buf_url(prot, strlen(prot))) == NULL) { warnx("base64buf_url"); goto out; } @@ -236,13 +236,13 @@ op_sign(int fd, EVP_PKEY *pkey) /* Now the signature material. */ cc = asprintf(&sign, "%s.%s", prot64, pay64); - if (-1 == cc) { + if (cc == -1) { warn("asprintf"); sign = NULL; goto out; } - if (NULL == (dig = malloc(EVP_PKEY_size(pkey)))) { + if ((dig = malloc(EVP_PKEY_size(pkey))) == NULL) { warn("malloc"); goto out; } @@ -252,7 +252,7 @@ op_sign(int fd, EVP_PKEY *pkey) * sign a SHA256 digest of our message. */ - if (NULL == (ctx = EVP_MD_CTX_create())) { + if ((ctx = EVP_MD_CTX_create()) == NULL) { warnx("EVP_MD_CTX_create"); goto out; } else if (!EVP_SignInit_ex(ctx, EVP_sha256(), NULL)) { @@ -264,7 +264,7 @@ op_sign(int fd, EVP_PKEY *pkey) } else if (!EVP_SignFinal(ctx, dig, &digsz, pkey)) { warnx("EVP_SignFinal"); goto out; - } else if (NULL == (dig64 = base64buf_url((char *)dig, digsz))) { + } else if ((dig64 = base64buf_url((char *)dig, digsz)) == NULL) { warnx("base64buf_url"); goto out; } @@ -275,7 +275,7 @@ op_sign(int fd, EVP_PKEY *pkey) * when we next enter the read loop). */ - if (NULL == (fin = json_fmt_signed(head, prot64, pay64, dig64))) { + if ((fin = json_fmt_signed(head, prot64, pay64, dig64)) == NULL) { warnx("json_fmt_signed"); goto out; } else if (writestr(fd, COMM_REQ, fin) < 0) @@ -283,7 +283,7 @@ op_sign(int fd, EVP_PKEY *pkey) rc = 1; out: - if (NULL != ctx) + if (ctx != NULL) EVP_MD_CTX_destroy(ctx); free(pay); @@ -319,7 +319,7 @@ acctproc(int netsock, const char *acctkey, int newacct) f = fopen(acctkey, newacct ? "wx" : "r"); umask(prev); - if (NULL == f) { + if (f == NULL) { warn("%s", acctkey); goto out; } @@ -334,11 +334,11 @@ acctproc(int netsock, const char *acctkey, int newacct) } if (newacct) { - if (NULL == (pkey = rsa_key_create(f, acctkey))) + if ((pkey = rsa_key_create(f, acctkey)) == NULL) goto out; dodbg("%s: generated RSA account key", acctkey); } else { - if (NULL == (pkey = rsa_key_load(f, acctkey))) + if ((pkey = rsa_key_load(f, acctkey)) == NULL) goto out; doddbg("%s: loaded RSA account key", acctkey); } @@ -348,7 +348,7 @@ acctproc(int netsock, const char *acctkey, int newacct) /* Notify the netproc that we've started up. */ - if (0 == (cc = writeop(netsock, COMM_ACCT_STAT, ACCT_READY))) + if ((cc = writeop(netsock, COMM_ACCT_STAT, ACCT_READY)) == 0) rc = 1; if (cc <= 0) goto out; @@ -361,9 +361,9 @@ acctproc(int netsock, const char *acctkey, int newacct) for (;;) { op = ACCT__MAX; - if (0 == (lval = readop(netsock, COMM_ACCT))) + if ((lval = readop(netsock, COMM_ACCT)) == 0) op = ACCT_STOP; - else if (ACCT_SIGN == lval || ACCT_THUMBPRINT == lval) + else if (lval == ACCT_SIGN || lval == ACCT_THUMBPRINT) op = lval; if (ACCT__MAX == op) { @@ -391,9 +391,9 @@ acctproc(int netsock, const char *acctkey, int newacct) rc = 1; out: close(netsock); - if (NULL != f) + if (f != NULL) fclose(f); - if (NULL != pkey) + if (pkey != NULL) EVP_PKEY_free(pkey); ERR_print_errors_fp(stderr); ERR_free_strings(); |