Browse Source

Ensure publicKeyPem never contain trailing text after the end marker.

grunfink 2 months ago
parent
commit
be54d22340
1 changed files with 12 additions and 1 deletions
  1. 12 1
      activitypub.c

+ 12 - 1
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" */