From 818d68126da6680228cbae1fdd88e126647dbd52 Mon Sep 17 00:00:00 2001 From: Johannes Roth Date: Tue, 25 Apr 2023 16:49:07 +0200 Subject: [PATCH] rework some AEAD/SEIPDv2 logic, address issue #21 --- src/lib/rnp.cpp | 8 +++++++- src/librepgp/stream-write.cpp | 13 ++++++------- src/tests/ffi-enc.cpp | 9 ++++++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/lib/rnp.cpp b/src/lib/rnp.cpp index e06495b6..d4dc75be 100644 --- a/src/lib/rnp.cpp +++ b/src/lib/rnp.cpp @@ -2743,6 +2743,11 @@ try { FFI_LOG(op->ffi, "Invalid AEAD algorithm: %s", alg); return RNP_ERROR_BAD_PARAMETERS; } + + if(op->rnpctx.aalg == PGP_AEAD_NONE && op->rnpctx.enable_pkesk_v6) { + FFI_LOG(op->ffi, "Setting AEAD algorithm to PGP_AEAD_NONE (%s) would contradict the previously enabled PKESKv6 setting", alg); + return RNP_ERROR_BAD_PARAMETERS; + } return RNP_SUCCESS; } FFI_GUARD @@ -2851,7 +2856,8 @@ try { // set the default hash alg if none was specified if (!op->rnpctx.halg) { op->rnpctx.halg = DEFAULT_PGP_HASH_ALG; - } + } + pgp_write_handler_t handler = pgp_write_handler(&op->ffi->pass_provider, &op->rnpctx, NULL, &op->ffi->key_provider); diff --git a/src/librepgp/stream-write.cpp b/src/librepgp/stream-write.cpp index 23064850..409cc142 100644 --- a/src/librepgp/stream-write.cpp +++ b/src/librepgp/stream-write.cpp @@ -1086,14 +1086,13 @@ init_encrypted_dst(pgp_write_handler_t *handler, pgp_dest_t *dst, pgp_dest_t *wr for (auto recipient : handler->ctx->recipients) { pgp_pkesk_version_t pkesk_version = PGP_PKSK_V3; #if defined(ENABLE_CRYPTO_REFRESH) - if (handler->ctx->enable_pkesk_v6 && handler->ctx->pkeskv6_capable()) { + if (param->auth_type == rnp::AuthType::AEADv2) { pkesk_version = PGP_PKSK_V6; - param->auth_type = rnp::AuthType::AEADv2; - if(param->ctx->aalg == PGP_AEAD_NONE) - { - param->ctx->aalg = PGP_AEAD_OCB; // TODO-V6: is this the right place to set the default algorithm? - } - dst->write = encrypted_dst_write_aead; // currently necessary + } + if(handler->ctx->aalg == PGP_AEAD_NONE) { + // set default AEAD if not set + // TODO-V6: is this the right place to set the default algorithm? + param->aalg = DEFAULT_AEAD_ALG; } #endif ret = encrypted_add_recipient( diff --git a/src/tests/ffi-enc.cpp b/src/tests/ffi-enc.cpp index c40ec288..b5e081c4 100644 --- a/src/tests/ffi-enc.cpp +++ b/src/tests/ffi-enc.cpp @@ -787,8 +787,15 @@ TEST_F(rnp_tests, test_ffi_encrypt_pk_with_v6_key) key = NULL; // set the data encryption cipher - assert_rnp_success(rnp_op_encrypt_set_aead(op, aead.c_str())); + if((aead == "None") && enable_pkeskv6) { + // already enabled v6 pkesk, does not make any sense to set AEAD to None explicitly. + assert_rnp_failure(rnp_op_encrypt_set_aead(op, aead.c_str())); + } + else { + assert_rnp_success(rnp_op_encrypt_set_aead(op, aead.c_str())); + } assert_rnp_success(rnp_op_encrypt_set_cipher(op, cipher.c_str())); + // execute the operation assert_rnp_success(rnp_op_encrypt_execute(op));