Prefer subkeys with higher algorithm IDs#1854
Merged
twiss merged 1 commit intoopenpgpjs:mainfrom May 20, 2025
Merged
Conversation
larabr
reviewed
May 20, 2025
| 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(); |
Collaborator
There was a problem hiding this comment.
Is this needed? The get*Key helpers should already verify signatures internally
Member
Author
There was a problem hiding this comment.
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.
larabr
reviewed
May 20, 2025
test/general/key.js
Outdated
| 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); |
Collaborator
There was a problem hiding this comment.
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
larabr
approved these changes
May 20, 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.
89269e4 to
855fe35
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.