diff options
| author | grunfink <grunfink@comam.es> | 2026-06-01 08:21:13 +0200 |
|---|---|---|
| committer | grunfink <grunfink@comam.es> | 2026-06-01 08:21:13 +0200 |
| commit | be54d22340814efa47439de5e784856010c44af6 (patch) | |
| tree | 4ea0e85431617bd89b1f6fcee48bf80cf7bff861 | |
| parent | 7b40d93784940a3bb1fdd9f50378332f04c3ac8f (diff) | |
Ensure publicKeyPem never contain trailing text after the end marker.
| -rw-r--r-- | activitypub.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c index 49e81f4..29a4b66 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1829,7 +1829,18 @@ xs_dict *msg_actor(snac *snac) keys = xs_dict_append(keys, "id", kid); keys = xs_dict_append(keys, "owner", snac->actor); - keys = xs_dict_append(keys, "publicKeyPem", xs_dict_get(snac->key, "public")); + + xs *public_key_pem = xs_dup(xs_dict_get(snac->key, "public")); + + if (xs_is_string(public_key_pem)) { + /* crop any garbage after the PEM */ + const char *pem_trailer = "END PUBLIC KEY-----\n"; + int i = xs_str_in(public_key_pem, pem_trailer); + if (i > 0) + public_key_pem[i + strlen(pem_trailer)] = '\0'; + } + + keys = xs_dict_append(keys, "publicKeyPem", public_key_pem); msg = xs_dict_set(msg, "publicKey", keys); /* if the "bot" config field is set to true, change type to "Service" */ |