Skip to content

Commit 059acad

Browse files
committed
fix logic for choosing SKESK/PKESK/SEIPD versions
1 parent 712261b commit 059acad

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/librepgp/stream-write.cpp

+14-11
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,12 @@ init_encrypted_dst(pgp_write_handler_t *handler, pgp_dest_t *dst, pgp_dest_t *wr
988988
bool singlepass = true;
989989
unsigned pkeycount = 0;
990990
unsigned skeycount = 0;
991-
unsigned keylen;
992-
rnp_result_t ret = RNP_ERROR_GENERIC;
991+
#if defined(ENABLE_CRYPTO_REFRESH)
992+
bool use_v6_pkesk = false;
993+
bool use_v6_skesk = false;
994+
#endif
995+
unsigned keylen;
996+
rnp_result_t ret = RNP_ERROR_GENERIC;
993997

994998
keylen = pgp_key_size(handler->ctx->ealg);
995999
if (!keylen) {
@@ -1039,16 +1043,15 @@ init_encrypted_dst(pgp_write_handler_t *handler, pgp_dest_t *dst, pgp_dest_t *wr
10391043
skeycount = handler->ctx->passwords.size();
10401044

10411045
#if defined(ENABLE_CRYPTO_REFRESH)
1042-
/* in the case of PKESK (pkeycount > 0) and all keys are PKESKv6/SEIPDv2 capable, upgrade
1043-
* to AEADv2 */
1044-
if (handler->ctx->enable_pkesk_v6 && handler->ctx->pkeskv6_capable() && pkeycount > 0) {
1045-
param->auth_type = rnp::AuthType::AEADv2;
1046-
}
1046+
/* We use v6 PKESK/SKESK with v2 SEIPD if all recipients support it
1047+
and the variables enable_pkesk_v6 and enable_skesk_v6 are set. */
1048+
if (handler->ctx->aalg != PGP_AEAD_NONE) {
1049+
use_v6_pkesk = handler->ctx->enable_pkesk_v6 && handler->ctx->pkeskv6_capable();
1050+
use_v6_skesk = handler->ctx->enable_skesk_v6;
10471051

1048-
/* Use SEIPDv2 for SKESK if enabled and preconditions are met */
1049-
if (handler->ctx->enable_skesk_v6 && handler->ctx->aalg != PGP_AEAD_NONE &&
1050-
skeycount > 0) {
1051-
param->auth_type = rnp::AuthType::AEADv2;
1052+
if ((use_v6_pkesk || !pkeycount) && (use_v6_skesk || !skeycount)) {
1053+
param->auth_type = rnp::AuthType::AEADv2;
1054+
}
10521055
}
10531056
#endif
10541057
param->aalg = handler->ctx->aalg;

0 commit comments

Comments
 (0)