Skip to content

Conversation

twiss
Copy link
Member

@twiss twiss commented May 19, 2025

In case of equal creation timestamps, pick the signing/encryption subkey with the highest algorithm ID, on the assumption that that's the most modern/secure algorithm.

@@ -4674,11 +4675,47 @@ I8kWVkXU6vFOi+HWvv/ira7ofJu16NnoUkhclkUrk0mXubZvyl4GBg==
expect(subkey.getAlgorithmInfo().curve).to.be.equal('nistP256');
expect(newPrivateKey.getAlgorithmInfo().algorithm).to.be.equal('eddsaLegacy');
expect(subkey.getAlgorithmInfo().algorithm).to.be.equal('ecdsa');
await subkey.verify();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? The get*Key helpers should already verify signatures internally

Copy link
Member Author

@twiss twiss May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular one is needed yeah, because the signing key we add isn't selected by the call to getSigningKey below, and we want to make sure it's not because we created an invalid subkey, but rather because we prefer the other subkey's algorithm.

Some of the other ones aren't needed, but I'd prefer to keep them for simplicity and to make it clear what's broken if something fails.

expect(subkey.getAlgorithmInfo().bits).to.be.equal(4096);
expect(subkey.getAlgorithmInfo().algorithm).to.be.equal('rsaEncryptSign');
await subkey.verify(new Date(+privateKey.subkeys[0].keyPacket.created + 1000));
expect(await newPrivateKey.getEncryptionKey(undefined, new Date(+privateKey.subkeys[0].keyPacket.created + 1000))).to.be.equal(subkey);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(await newPrivateKey.getEncryptionKey(undefined, new Date(+privateKey.subkeys[0].keyPacket.created + 1000))).to.be.equal(subkey);
expect(await newPrivateKey.getEncryptionKey(undefined, new Date(+privateKey.subkeys[0].getCreationTime() + 1000))).to.be.equal(subkey);

I'd avoid low-level access whenever possible

In case of equal creation timestamps, pick the signing/encryption subkey
with the highest algorithm ID, on the assumption that that's the most
modern/secure algorithm.
@twiss twiss force-pushed the prefer-higher-alg-ids branch from 89269e4 to 855fe35 Compare May 20, 2025 09:15
@twiss twiss merged commit aba9bb1 into openpgpjs:main May 20, 2025
29 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants