Skip to content

Commit 9ea7901

Browse files
committed
fix logic for choosing SKESK/PKESK/SEIPD versions
1 parent 1f131d1 commit 9ea7901

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/librepgp/stream-write.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,12 @@ init_encrypted_dst(pgp_write_handler_t *handler, pgp_dest_t *dst, pgp_dest_t *wr
10691069
bool singlepass = true;
10701070
unsigned pkeycount = 0;
10711071
unsigned skeycount = 0;
1072-
unsigned keylen;
1073-
rnp_result_t ret = RNP_ERROR_GENERIC;
1072+
#if defined(ENABLE_CRYPTO_REFRESH)
1073+
bool use_v6_pkesk = false;
1074+
bool use_v6_skesk = false;
1075+
#endif
1076+
unsigned keylen;
1077+
rnp_result_t ret = RNP_ERROR_GENERIC;
10741078

10751079
keylen = pgp_key_size(handler->ctx->ealg);
10761080
if (!keylen) {
@@ -1120,16 +1124,15 @@ init_encrypted_dst(pgp_write_handler_t *handler, pgp_dest_t *dst, pgp_dest_t *wr
11201124
skeycount = handler->ctx->passwords.size();
11211125

11221126
#if defined(ENABLE_CRYPTO_REFRESH)
1123-
/* in the case of PKESK (pkeycount > 0) and all keys are PKESKv6/SEIPDv2 capable, ugprade
1124-
* to AEADv2 */
1125-
if (handler->ctx->enable_pkesk_v6 && handler->ctx->pkeskv6_capable() && pkeycount > 0) {
1126-
param->auth_type = rnp::AuthType::AEADv2;
1127-
}
1127+
/* We use v6 PKESK/SKESK with v2 SEIPD if all recipients support it
1128+
and the variables enable_pkesk_v6 and enable_skesk_v6 are set. */
1129+
if (handler->ctx->aalg != PGP_AEAD_NONE) {
1130+
use_v6_pkesk = handler->ctx->enable_pkesk_v6 && handler->ctx->pkeskv6_capable();
1131+
use_v6_skesk = handler->ctx->enable_skesk_v6;
11281132

1129-
/* Use SEIPDv2 for SKESK if enabled and preconditions are met */
1130-
if (handler->ctx->enable_skesk_v6 && handler->ctx->aalg != PGP_AEAD_NONE &&
1131-
skeycount > 0) {
1132-
param->auth_type = rnp::AuthType::AEADv2;
1133+
if ((use_v6_pkesk || !pkeycount) && (use_v6_skesk || !skeycount)) {
1134+
param->auth_type = rnp::AuthType::AEADv2;
1135+
}
11331136
}
11341137
#endif
11351138
param->aalg = handler->ctx->aalg;

0 commit comments

Comments
 (0)