Skip to content

Conversation

@larabr
Copy link
Collaborator

@larabr larabr commented Sep 11, 2023

Key flags are needed to restrict key usage to specific purposes: https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-10.html#section-5.2.3.29 . Some older keys (e.g. from OpenPGP.js v0) do not declare any key flags. In previous OpenPGP.js versions, we've allowed such keys to be used for any operation for which they were compatible. This behaviour has now changed, and these keys are not allowed to be used for any operation.

The setting config.allowMissingKeyFlags has been added to selectively revert to the past behaviour.

@larabr larabr requested a review from twiss September 11, 2023 15:33
@larabr larabr requested a review from twiss October 4, 2023 08:41
Comment on lines 365 to 372
case enums.publicKey.ed25519: {
if (!signature.keyFlags && !config.allowMissingKeyFlags) {
throw new Error('None of the key flags is set: consider passing `config.allowMissingKeyFlags`');
}

return !signature.keyFlags ||
(signature.keyFlags[0] & enums.keyFlags.signData) !== 0;
}
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for missing these last time (and being very nitpicky ^.^), but these brackets are also not necessary. They're only necessary if you need a block scope, e.g. if you're creating block-scoped variables.

Suggested change
case enums.publicKey.ed25519: {
if (!signature.keyFlags && !config.allowMissingKeyFlags) {
throw new Error('None of the key flags is set: consider passing `config.allowMissingKeyFlags`');
}
return !signature.keyFlags ||
(signature.keyFlags[0] & enums.keyFlags.signData) !== 0;
}
case enums.publicKey.ed25519:
if (!signature.keyFlags && !config.allowMissingKeyFlags) {
throw new Error('None of the key flags is set: consider passing `config.allowMissingKeyFlags`');
}
return !signature.keyFlags ||
(signature.keyFlags[0] & enums.keyFlags.signData) !== 0;

Copy link
Collaborator Author

@larabr larabr Oct 17, 2023

Choose a reason for hiding this comment

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

I know they are not needed, but it's not a big deal to add them IMO -- I just find it confusing to have a lot of code without brackets.

Copy link
Member

Choose a reason for hiding this comment

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

Er, OK, but I think it's more important to have a consistent code style. JS cases normally don't have brackets, and most other code in the library doesn't have them, so we should only add them when needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, but then I'll add a linting rule for this, so that it's automatically enforced

@larabr larabr mentioned this pull request Oct 17, 2023
Merged
20 tasks
@larabr larabr force-pushed the v6-reject-no-key-flags branch from 0c2a1be to 91fa87b Compare October 19, 2023 13:15
@larabr larabr force-pushed the v6-reject-no-key-flags branch 2 times, most recently from 3160172 to a28ae91 Compare October 23, 2023 15:50
Key flags are needed to restrict key usage to specific purposes:
https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-10.html#section-5.2.3.29 .
Some older keys (e.g. from OpenPGP.js v1) do not declare any key flags.
In previous OpenPGP.js versions, we've allowed such keys to be used for any operation for which they were compatible.
This behaviour has now changed, and these keys are not allowed to be used for any operation.

The setting  `config.allowMissingKeyFlags` has been added to selectively revert to the past behaviour.
Also fix some indent issues with armoring code detected after required ESLint update.

s
@larabr larabr force-pushed the v6-reject-no-key-flags branch from a28ae91 to e69b1db Compare October 23, 2023 16:46
@larabr larabr merged commit de9b4d5 into openpgpjs:v6 Oct 23, 2023
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