]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Understand full ed25519 private keys
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 27 Feb 2019 14:47:29 +0000 (14:47 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 27 Feb 2019 14:59:11 +0000 (14:59 +0000)
src/libserver/dkim.c

index 2a66146ed44fc6a03c10eef46e5e77b3cbc5133c..129d78c9c3e48bfd68004c3cca06546e9450b9b0 100644 (file)
@@ -2681,13 +2681,25 @@ rspamd_dkim_sign_key_load (const gchar *key, gsize len,
                key = tmp;
        }
 
-       if (type == RSPAMD_DKIM_KEY_RAW && len == 32) {
-               unsigned char pk[32];
-               nkey->type = RSPAMD_DKIM_KEY_EDDSA;
-               nkey->key.key_eddsa = g_malloc (
-                               rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519));
-               ed25519_seed_keypair (pk, nkey->key.key_eddsa, (char *)key);
-               nkey->keylen = rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519);
+       if (type == RSPAMD_DKIM_KEY_RAW && (len == 32 ||
+               len == rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519))) {
+               if (len == 32) {
+                       /* Seeded key, need scalarmult */
+                       unsigned char pk[32];
+                       nkey->type = RSPAMD_DKIM_KEY_EDDSA;
+                       nkey->key.key_eddsa = g_malloc (
+                                       rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519));
+                       ed25519_seed_keypair (pk, nkey->key.key_eddsa, (char *) key);
+                       nkey->keylen = rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519);
+               }
+               else {
+                       /* Full ed25519 key */
+                       unsigned klen = rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519);
+                       nkey->type = RSPAMD_DKIM_KEY_EDDSA;
+                       nkey->key.key_eddsa = g_malloc (klen);
+                       memcpy (nkey->key.key_eddsa, key, klen);
+                       nkey->keylen = klen;
+               }
        }
        else {
                nkey->key_bio = BIO_new_mem_buf (key, len);