Skip to content

Commit

Permalink
rework some AEAD/SEIPDv2 logic, address issue #21
Browse files Browse the repository at this point in the history
  • Loading branch information
TJ-91 committed Apr 25, 2023
1 parent 5e6d3a1 commit 818d681
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/lib/rnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
13 changes: 6 additions & 7 deletions src/librepgp/stream-write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion src/tests/ffi-enc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 818d681

Please sign in to comment.