Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/crypto: restrict RSA keys to <= 8192 bits #2454

Merged
merged 5 commits into from
Aug 3, 2023

Conversation

MarcoPolo
Copy link
Contributor

At a certain point these become too much effort to compute. This limits the max size.

Copy link
Contributor

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

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

Could it be that you missed a few cases? I'm less worried about the code path where you generate the RSA key yourself (although we should prevent that footgun as well), but more about those where the peer sends us its pubkey. What could path would be taken during the TLS / Noise handshake when we receive the peer's key?

image

core/crypto/rsa_common.go Outdated Show resolved Hide resolved
core/crypto/rsa_common.go Outdated Show resolved Hide resolved
@marten-seemann marten-seemann changed the title Error if RSA key is too big core/crypto: restrict RSA keys to <= 8192 bits Aug 2, 2023
MarcoPolo and others added 2 commits August 2, 2023 16:51
Co-authored-by: Marten Seemann <martenseemann@gmail.com>
Co-authored-by: Marten Seemann <martenseemann@gmail.com>
@MarcoPolo
Copy link
Contributor Author

Could it be that you missed a few cases? I'm less worried about the code path where you generate the RSA key yourself (although we should prevent that footgun as well), but more about those where the peer sends us its pubkey. What could path would be taken during the TLS / Noise handshake when we receive the peer's key?

image

PublicKeyFromProto uses UnmarshalRsaPublicKey under the hood which is covered by this patch. I think only UnmarshalRsaPublicKey and GenerateRSAKeyPair give you an RSA public key.

@MarcoPolo MarcoPolo enabled auto-merge (squash) August 3, 2023 00:26
@marten-seemann marten-seemann merged commit 9e01af8 into master Aug 3, 2023
20 checks passed
marten-seemann added a commit that referenced this pull request Aug 3, 2023
* Error if RSA key is too big

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Fix rename

* Make this var again so the tests work

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
marten-seemann added a commit that referenced this pull request Aug 3, 2023
* Error if RSA key is too big

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Fix rename

* Make this var again so the tests work

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
marten-seemann added a commit that referenced this pull request Aug 3, 2023
* Error if RSA key is too big

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Fix rename

* Make this var again so the tests work

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
marten-seemann added a commit that referenced this pull request Aug 3, 2023
* Error if RSA key is too big

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Fix rename

* Make this var again so the tests work

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
marten-seemann added a commit that referenced this pull request Aug 3, 2023
* Error if RSA key is too big

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Fix rename

* Make this var again so the tests work

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
marten-seemann added a commit that referenced this pull request Aug 4, 2023
* Error if RSA key is too big

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Update core/crypto/rsa_common.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* Fix rename

* Make this var again so the tests work

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
achingbrain added a commit to libp2p/js-libp2p that referenced this pull request Aug 4, 2023
Restrict the RSA key sizes we expect from peers. Protects us from spending a lot of compute on verifying signatures from big keys. Similar to libp2p/go-libp2p#2454

---------

Co-authored-by: achingbrain <alex@achingbrain.net>
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.

None yet

2 participants