aboutsummaryrefslogtreecommitdiffstats
path: root/src/rspamadm/dkim_keygen.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-17 15:08:15 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-17 15:08:15 +0100
commitfa035f5d6dfd643b6629988a3e8138ec7c6b3ec4 (patch)
treef600255765b416e6f4c7f0885bb78209c2a21c27 /src/rspamadm/dkim_keygen.c
parentbd4a2300c2190ffb5984d4d603788c84bdad3b18 (diff)
downloadrspamd-fa035f5d6dfd643b6629988a3e8138ec7c6b3ec4.tar.gz
rspamd-fa035f5d6dfd643b6629988a3e8138ec7c6b3ec4.zip
[Feature] Split long DKIM public keys
Issue: #1676
Diffstat (limited to 'src/rspamadm/dkim_keygen.c')
-rw-r--r--src/rspamadm/dkim_keygen.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/rspamadm/dkim_keygen.c b/src/rspamadm/dkim_keygen.c
index 42922ed35..14a2e18f2 100644
--- a/src/rspamadm/dkim_keygen.c
+++ b/src/rspamadm/dkim_keygen.c
@@ -81,6 +81,7 @@ rspamadm_dkim_keygen (gint argc, gchar **argv)
EVP_PKEY *pk;
gint rc;
glong publen;
+ gsize b64_len;
gchar *pubdata, *b64_data;
context = g_option_context_new (
@@ -140,11 +141,33 @@ rspamadm_dkim_keygen (gint argc, gchar **argv)
publen = BIO_get_mem_data (pubout, &pubdata);
g_assert (publen > 0);
- b64_data = rspamd_encode_base64 (pubdata, publen, -1, NULL);
- rspamd_printf ("%s._domainkey IN TXT ( \"v=DKIM1; k=rsa; \"\n"
- "\t\"p=%s\" ) ;\n",
- selector ? selector : "selector",
- b64_data);
+ b64_data = rspamd_encode_base64 (pubdata, publen, -1, &b64_len);
+
+ if (b64_len < 255 - 2) {
+ rspamd_printf ("%s._domainkey IN TXT ( \"v=DKIM1; k=rsa; \"\n"
+ "\t\"p=%s\" ) ;\n",
+ selector ? selector : "selector",
+ b64_data);
+ }
+ else {
+ guint i;
+ gint step = 253, remain = b64_len;
+
+ rspamd_printf ("%s._domainkey IN TXT ( \"v=DKIM1; k=rsa; \"\n",
+ selector ? selector : "selector");
+
+ for (i = 0; i < b64_len; i += step, remain -= step) {
+ if (i == 0) {
+ rspamd_printf ("\t\"p=%*s\"\n", MIN(step, remain), &b64_data[i]);
+ }
+ else {
+ step = 255;
+ rspamd_printf ("\t\"%*s\"\n", MIN(step, remain), &b64_data[i]);
+ }
+ }
+
+ rspamd_printf (") ; \n");
+ }
g_free (b64_data);
BIO_free (pubout);