From: Stefan Berger <stefanb@linux.ibm.com>
To: linux-integrity@vger.kernel.org
Cc: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com,
Stefan Berger <stefanb@linux.ibm.com>
Subject: [PATCH 3/3] libimaevm: Have sign_hash_v2 call sign_hash_v2_pkey after reading key file
Date: Tue, 20 Apr 2021 14:30:15 -0400 [thread overview]
Message-ID: <20210420183015.861644-4-stefanb@linux.ibm.com> (raw)
In-Reply-To: <20210420183015.861644-1-stefanb@linux.ibm.com>
Have sign_hash_v2 call sign_hash_v2_pkey after reading the key file.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
src/libimaevm.c | 65 ++++++++-----------------------------------------
1 file changed, 10 insertions(+), 55 deletions(-)
diff --git a/src/libimaevm.c b/src/libimaevm.c
index bb425af..f7f070c 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -991,15 +991,9 @@ err:
static int sign_hash_v2(const char *algo, const unsigned char *hash,
int size, const char *keyfile, unsigned char *sig)
{
- struct signature_v2_hdr *hdr;
- int len = -1;
+ char *error = NULL;
EVP_PKEY *pkey;
- char name[20];
- EVP_PKEY_CTX *ctx = NULL;
- const EVP_MD *md;
- size_t sigsize;
- const char *st;
- uint32_t keyid;
+ int len = -1;
if (!hash) {
log_err("sign_hash_v2: hash is null\n");
@@ -1011,16 +1005,6 @@ static int sign_hash_v2(const char *algo, const unsigned char *hash,
return -1;
}
- if (!sig) {
- log_err("sign_hash_v2: sig is null\n");
- return -1;
- }
-
- if (!algo) {
- log_err("sign_hash_v2: algo is null\n");
- return -1;
- }
-
log_info("hash(%s): ", imaevm_params.hash_algo);
log_dump(hash, size);
@@ -1028,49 +1012,20 @@ static int sign_hash_v2(const char *algo, const unsigned char *hash,
if (!pkey)
return -1;
- hdr = (struct signature_v2_hdr *)sig;
- hdr->version = (uint8_t) DIGSIG_VERSION_2;
-
- hdr->hash_algo = imaevm_get_hash_algo(algo);
- if (hdr->hash_algo == (uint8_t)-1) {
- log_err("sign_hash_v2: hash algo is unknown: %s\n", algo);
- return -1;
- }
-
- calc_keyid_v2(&keyid, name, pkey);
- hdr->keyid = keyid;
-
- st = "EVP_PKEY_CTX_new";
- if (!(ctx = EVP_PKEY_CTX_new(pkey, NULL)))
- goto err;
- st = "EVP_PKEY_sign_init";
- if (!EVP_PKEY_sign_init(ctx))
- goto err;
- st = "EVP_get_digestbyname";
- if (!(md = EVP_get_digestbyname(imaevm_params.hash_algo)))
- goto err;
- st = "EVP_PKEY_CTX_set_signature_md";
- if (!EVP_PKEY_CTX_set_signature_md(ctx, md))
- goto err;
- st = "EVP_PKEY_sign";
- sigsize = MAX_SIGNATURE_SIZE - sizeof(struct signature_v2_hdr) - 1;
- if (!EVP_PKEY_sign(ctx, hdr->sig, &sigsize, hash, size))
+ len = sign_hash_v2_pkey(algo, hash, size, pkey, sig, MAX_SIGNATURE_SIZE - 1,
+ &error);
+ if (len < 0) {
+ log_err("%s\n", error);
+ output_openssl_errors();
goto err;
- len = (int)sigsize;
+ }
- /* we add bit length of the signature to make it gnupg compatible */
- hdr->sig_size = __cpu_to_be16(len);
- len += sizeof(*hdr);
log_info("evm/ima signature: %d bytes\n", len);
err:
- if (len == -1) {
- log_err("sign_hash_v2: signing failed: (%s) in %s\n",
- ERR_reason_error_string(ERR_peek_error()), st);
- output_openssl_errors();
- }
- EVP_PKEY_CTX_free(ctx);
+ free(error);
EVP_PKEY_free(pkey);
+
return len;
}
--
2.30.2
prev parent reply other threads:[~2021-04-20 18:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-20 18:30 [PATCH 0/3] ima-evm-utils: Implement function to only create IMA signature Stefan Berger
2021-04-20 18:30 ` [PATCH 1/3] libimaevm: Implement imaevm_create_ima_signature Stefan Berger
2021-04-27 0:02 ` Colin Walters
2021-04-27 17:47 ` Stefan Berger
2021-04-27 19:13 ` Stefan Berger
2021-04-20 18:30 ` [PATCH 2/3] tests: Add program to create IMA signature with new API call Stefan Berger
2021-04-20 18:30 ` Stefan Berger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210420183015.861644-4-stefanb@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=linux-integrity@vger.kernel.org \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).