fix!: remove node-forge dependency from @libp2p/crypto#2355
Merged
achingbrain merged 7 commits intomainfrom Jan 12, 2024
Merged
fix!: remove node-forge dependency from @libp2p/crypto#2355achingbrain merged 7 commits intomainfrom
achingbrain merged 7 commits intomainfrom
Conversation
TLDR: the bundle size has been reduced by ~50KB - parsing/creating PEM/pkix/pkcs1 files is now done by asn1.js - Streaming AES-CTR ciphers are now in @libp2p/crypto-aes-ctr - RSA encryption/decryption and PEM import/export are now in @libp2p/crypto-rsa WebCrypto [doesn't support streaming ciphers](w3c/webcrypto#73). We have a node-forge-backed shim that allows using streaming AES-CTR in browsers but we don't use it anywhere, so this has been split out into it's own module as `@libp2p/aes-ctr`. This was added to `@libp2p/crypto` to [support webrtc-stardust](libp2p/js-libp2p-crypto#125 (comment)) but that effort didn't go anywhere and we don't use these methods anywhere else in the stack. For reasons lost to the mists of time, we chose to require a padding algorithm that WebCrypto doesn't support so node-forge (or some other userland implemenation) will always be necessary in browsers, so these ops have been pull out into @libp2p/crypto-rsa which people can use if they need it. This is now done by manipulating the asn1 structures directly. The previous PEM import/export is also ported to `@libp2p/crypto-rsa` because it seems to handle more weird edge cases introduced by OpenSSL. These could be handled in `@libp2p/crypto` eventually but for now it at least supports round-tripping it's own PEM files. BREAKING CHANGE: Legacy RSA operations are now in @libp2p/crypto-rsa, streaming AES-CTR ciphers are in @libp2p/crypto-aes-ctr
c2f5274 to
41e2551
Compare
This was referenced Jan 12, 2024
Merged
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.
TLDR: the bundle size has been reduced by about 1/3rd
AES-CTR
WebCrypto doesn't support streaming ciphers.
We have a node-forge-backed shim that allows using streaming AES-CTR in browsers but we don't use it anywhere, so this has been split out into it's own module as
@libp2p/aes-ctr.RSA encrypt/decrypt
This was added to
@libp2p/cryptoto support webrtc-stardust but that effort didn't go anywhere and we don't use these methods anywhere else in the stack.For reasons lost to the mists of time, we chose to use a padding algorithm that WebCrypto doesn't support so node-forge (or some other userland implemenation) will always be necessary in browsers, so these ops have been pulled out into
@libp2p/rsawhich people can use if they need it.This is now done by manipulating the asn1 structures directly.
PEM/pkix/pkcs1
The previous PEM import/export is also ported to
@libp2p/crypto-rsabecause it seems to handle more weird edge cases introduced by OpenSSL.These could be handled in
@libp2p/cryptoeventually but for now it at least supports round-tripping it's own PEM files.Fixes #2086
BREAKING CHANGE: Legacy RSA operations are now in @libp2p/rsa, streaming AES-CTR ciphers are in @libp2p/aes-ctr
Change checklist