]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail-crypt: Use crypt_settings_to_flags()
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 8 Apr 2026 12:38:48 +0000 (15:38 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 20 Apr 2026 12:08:40 +0000 (12:08 +0000)
Fixes crash in mail crypt plugin when HMAC based algorithm
is used.

Also fixes that ChaCha20-Poly1305 will use AEAD instead of HMAC.

src/plugins/mail-crypt/fs-crypt.c
src/plugins/mail-crypt/mail-crypt-plugin.c

index e4282fa07d089e45b17e1bf73108a45596dfbac2..058af95eea5ab20ece4aca700180a5919897c93d 100644 (file)
@@ -239,15 +239,8 @@ static void fs_crypt_write_stream(struct fs_file *_file)
                return;
        }
 
-       enum io_stream_encrypt_flags flags;
-       if (strstr(file->fs->set->crypt_write_algorithm, "gcm") != NULL ||
-           strstr(file->fs->set->crypt_write_algorithm, "ccm") != NULL ||
-           str_begins_with(file->fs->set->crypt_write_algorithm,
-                           "chacha20-poly1305")) {
-               flags = IO_STREAM_ENC_INTEGRITY_AEAD;
-       } else {
-               flags = IO_STREAM_ENC_INTEGRITY_HMAC;
-       }
+       enum io_stream_encrypt_flags flags =
+               crypt_settings_to_flags(file->fs->set);
 
        file->temp_output =
                iostream_temp_create_named(_file->fs->temp_path_prefix,
index e4b171e827242b33bca5d395fc39bacea3a710a1..a2d81d7ca13b96796d747a95ae83025c2b6bb670 100644 (file)
@@ -260,15 +260,8 @@ mail_crypt_mail_save_begin(struct mail_save_context *ctx,
        struct mail_crypt_user *muser = MAIL_CRYPT_USER_CONTEXT(box->storage->user);
 
        enum io_stream_encrypt_flags enc_flags = 0;
-       if (muser != NULL && muser->set->crypt_write_algorithm[0] != '\0') {
-               if (strstr(muser->set->crypt_write_algorithm, "gcm") != NULL ||
-                   strstr(muser->set->crypt_write_algorithm, "ccm") != NULL ||
-                   strstr(muser->set->crypt_write_algorithm,
-                      "chacha20-poly1305") == 0)
-                       enc_flags = IO_STREAM_ENC_INTEGRITY_AEAD;
-               else
-                       enc_flags = IO_STREAM_ENC_INTEGRITY_HMAC;
-       }
+       if (muser != NULL && muser->set->crypt_write_algorithm[0] != '\0')
+               enc_flags = crypt_settings_to_flags(muser->set);
 
        if (mbox->module_ctx.super.save_begin(ctx, input) < 0)
                return -1;