summaryrefslogtreecommitdiffstats
path: root/src/home
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-09-05 13:55:41 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2023-09-06 19:34:21 +0200
commitef65c0f6ccd0214a5af26617c43cfe7ec7af816b (patch)
tree9d979af655eae8e743494d48821e4a6e27f71a08 /src/home
parentshared/wall: use logind if build without utmp support (diff)
downloadsystemd-ef65c0f6ccd0214a5af26617c43cfe7ec7af816b.tar.xz
systemd-ef65c0f6ccd0214a5af26617c43cfe7ec7af816b.zip
openssl-util: add common implementation of digest+sign
Diffstat (limited to 'src/home')
-rw-r--r--src/home/user-record-sign.c21
1 files changed, 3 insertions, 18 deletions
diff --git a/src/home/user-record-sign.c b/src/home/user-record-sign.c
index cf72eaa556..dd099a0a6f 100644
--- a/src/home/user-record-sign.c
+++ b/src/home/user-record-sign.c
@@ -33,7 +33,6 @@ int user_record_sign(UserRecord *ur, EVP_PKEY *private_key, UserRecord **ret) {
_cleanup_(memstream_done) MemStream m = {};
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
_cleanup_(user_record_unrefp) UserRecord *signed_ur = NULL;
- _cleanup_(EVP_MD_CTX_freep) EVP_MD_CTX *md_ctx = NULL;
_cleanup_free_ char *text = NULL, *key = NULL;
_cleanup_free_ void *signature = NULL;
size_t signature_size = 0;
@@ -48,23 +47,9 @@ int user_record_sign(UserRecord *ur, EVP_PKEY *private_key, UserRecord **ret) {
if (r < 0)
return r;
- md_ctx = EVP_MD_CTX_new();
- if (!md_ctx)
- return -ENOMEM;
-
- if (EVP_DigestSignInit(md_ctx, NULL, NULL, NULL, private_key) <= 0)
- return -EIO;
-
- /* Request signature size */
- if (EVP_DigestSign(md_ctx, NULL, &signature_size, (uint8_t*) text, strlen(text)) <= 0)
- return -EIO;
-
- signature = malloc(signature_size);
- if (!signature)
- return -ENOMEM;
-
- if (EVP_DigestSign(md_ctx, signature, &signature_size, (uint8_t*) text, strlen(text)) <= 0)
- return -EIO;
+ r = digest_and_sign(/* md= */ NULL, private_key, text, SIZE_MAX, &signature, &signature_size);
+ if (r < 0)
+ return r;
f = memstream_init(&m);
if (!f)