Skip to content

feat: [NET-1445] quantum resistant key exchange using ML-KEM#3060

Merged
hpihkala merged 15 commits intomainfrom
quantum-resistant-key-exchange
Apr 3, 2025
Merged

feat: [NET-1445] quantum resistant key exchange using ML-KEM#3060
hpihkala merged 15 commits intomainfrom
quantum-resistant-key-exchange

Conversation

@hpihkala
Copy link
Copy Markdown
Contributor

@hpihkala hpihkala commented Apr 1, 2025

Summary

This PR introduces the ability to use (and to require the use of) ML-KEM for key exchange instead of RSA. The former is considered quantum resistant, while the latter is not. This PR does not change the defaults, but introduces a new config option to enable the use of the new quantum resistant algorithm.

Implementing the new algorithm itself was straight forward, but certain refactoring was necessary to use it. Most of the line changes in this PR are actually related to that refactoring instead of the core feature itself.

Backwards compatibility

The change is backwards compatible with the default settings, ie. the change is not breaking as such. However, the new feature can obviously only be used if both the publisher and subscriber have the new version.

Backwards compatibility with the previous version was tested manually, and the results are as expected - ie. key exchange works with default (non-quantum-secure) settings, but fails if requireQuantumResistantKeyExchange is true, as the other side running the old version doesn't support the new algorithm.

Changes

  • Implement encryption and decryption using ML-KEM in EncryptionUtil
  • Refactor interfaces in EncryptionUtil to be unified across different algorithms
  • Add a new StreamrClient config option under the encryption block: requireQuantumResistantKeyExchange: <boolean> (default: false)
  • Update SubscriberKeyExchange and PublisherKeyExchange to read that config option and act accordingly
  • Add to GroupKeyRequest and GroupKeyResponse protobuf messages an encryptionType field, the value of which is an AsymmetricEncryptionType enum. For backwards compatibility, the absence of this field is interpreted to imply RSA.
  • Refactor away the technical debt of OldGroupKeyRequest and OldGroupKeyResponse vs. NewGroupKeyRequest and NewGroupKeyResponse mess and get rid of GroupKeyRequestTranslator. Now, the "new" group key classes (generated from protobuf) are used everywhere, and the old hand-rolled ones have been deleted.
  • Add unit test cases for EncryptionUtil and integration test cases for SubscriberKeyExchange and PublisherKeyExchange
  • Add a section to the end-to-end encryption page in the docs, describing the new feature
  • Add a --quantum flag to the CLI tool to flip on the new switch

Limitations and future improvements

  • Refactoring away the OldStreamMessage / NewStreamMessage / StreamMessageTranslator debt is out of scope, the old vs. new classes issue was only cleaned up in relation to the group key classes, as only they were relevant to the feature.
  • In the future, encryption preferences could come from stream metadata by default, instead of explicit local config

Checklist before requesting a review

  • Is this a breaking change? If it is, be clear in summary. -> (No)
  • Read through code myself one more time.
  • Make sure any and all TODO comments left behind are meant to be left in.
  • Has reasonable passing test coverage?
  • Updated changelog if applicable.
  • Updated documentation if applicable.

@github-actions github-actions bot added network Related to Network Package cli-tools Related to CLI Tools Package sdk labels Apr 1, 2025
@hpihkala hpihkala changed the title Quantum resistant key exchange feat: quantum resistant key exchange using ML-KEM Apr 1, 2025
@github-actions github-actions bot added the docs label Apr 1, 2025
@hpihkala hpihkala changed the title feat: quantum resistant key exchange using ML-KEM feat: [NET-1445] quantum resistant key exchange using ML-KEM Apr 1, 2025
@linear
Copy link
Copy Markdown

linear bot commented Apr 1, 2025

@hpihkala hpihkala requested a review from teogeb April 1, 2025 13:24
@hpihkala hpihkala marked this pull request as ready for review April 1, 2025 16:19
Copy link
Copy Markdown
Contributor

@teogeb teogeb left a comment

Choose a reason for hiding this comment

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

Looks good! 👍 We should keep the EncryptedGroupKey type in the exports.ts, otherwise all ok.

Comment thread packages/sdk/src/encryption/EncryptionUtil.ts Outdated
Comment thread packages/sdk/test/integration/PublisherKeyExchange.test.ts Outdated
Comment thread packages/sdk/src/encryption/SubscriberKeyExchange.ts Outdated
Comment thread packages/sdk/src/exports.ts
Comment thread packages/sdk/src/utils/crossPlatformCrypto.ts
@hpihkala hpihkala requested a review from teogeb April 2, 2025 13:30
@hpihkala hpihkala merged commit e380eee into main Apr 3, 2025
24 checks passed
@hpihkala hpihkala deleted the quantum-resistant-key-exchange branch April 3, 2025 13:50
jtakalai pushed a commit that referenced this pull request May 20, 2025
## Summary

This PR introduces the ability to use (and to require the use of)
`ML-KEM` for key exchange instead of `RSA`. The former is considered
quantum resistant, while the latter is not. This PR does not change the
defaults, but introduces a new config option to enable the use of the
new quantum resistant algorithm.

Implementing the new algorithm itself was straight forward, but certain
refactoring was necessary to use it. Most of the line changes in this PR
are actually related to that refactoring instead of the core feature
itself.

**Backwards compatibility**

The change is backwards compatible with the default settings, ie. the
change is not breaking as such. However, the new feature can obviously
only be used if both the publisher and subscriber have the new version.

Backwards compatibility with the previous version was tested manually,
and the results are as expected - ie. key exchange works with default
(non-quantum-secure) settings, but fails if
`requireQuantumResistantKeyExchange` is `true`, as the other side
running the old version doesn't support the new algorithm.

## Changes

- Implement encryption and decryption using `ML-KEM` in `EncryptionUtil`
- Refactor interfaces in `EncryptionUtil` to be unified across different
algorithms
- Add a new `StreamrClient` config option under the `encryption` block:
`requireQuantumResistantKeyExchange: <boolean>` (default: false)
- Update `SubscriberKeyExchange` and `PublisherKeyExchange` to read that
config option and act accordingly
- Add to `GroupKeyRequest` and `GroupKeyResponse` protobuf messages an
`encryptionType` field, the value of which is an
`AsymmetricEncryptionType` enum. For backwards compatibility, the
absence of this field is interpreted to imply RSA.
- Refactor away the technical debt of `OldGroupKeyRequest` and
`OldGroupKeyResponse` vs. `NewGroupKeyRequest` and `NewGroupKeyResponse`
mess and get rid of `GroupKeyRequestTranslator`. Now, the "new" group
key classes (generated from protobuf) are used everywhere, and the old
hand-rolled ones have been deleted.
- Add unit test cases for `EncryptionUtil` and integration test cases
for `SubscriberKeyExchange` and `PublisherKeyExchange`
- Add a section to the end-to-end encryption page in the docs,
describing the new feature
- Add a `--quantum` flag to the CLI tool to flip on the new switch


## Limitations and future improvements

- Refactoring away the `OldStreamMessage` / `NewStreamMessage` /
`StreamMessageTranslator` debt is out of scope, the old vs. new classes
issue was only cleaned up in relation to the group key classes, as only
they were relevant to the feature.
- In the future, encryption preferences could come from stream metadata
by default, instead of explicit local config

## Checklist before requesting a review

- [x] Is this a breaking change? If it is, be clear in summary. **->
(No)**
- [x] Read through code myself one more time.
- [x] Make sure any and all `TODO` comments left behind are meant to be
left in.
- [x] Has reasonable passing test coverage?
- [x] Updated changelog if applicable.
- [x] Updated documentation if applicable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli-tools Related to CLI Tools Package docs network Related to Network Package sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants