Skip to content

Conversation

@sai-sunder-s
Copy link
Contributor

This commit removes the rsa library as a dependency and makes the cryptography library a required, core dependency.

Previously, cryptography was an optional dependency, and the library would fall back to a pure Python RSA implementation using the rsa library if cryptography was not installed.

Changes made:

  • Modified setup.py to remove rsa from dependencies and add cryptography with version constraints.
  • Updated google/auth/crypt/rsa.py to directly use the cryptography-based RSA implementation (_cryptography_rsa.py) and remove the fallback mechanism.
  • Removed the pure Python RSA implementation file (google/auth/crypt/_python_rsa.py).
  • Removed the corresponding tests for the pure Python RSA implementation (tests/crypt/test__python_rsa.py).

Core unit tests pass after these changes.

This commit removes the `rsa` library as a dependency and makes the `cryptography` library a required, core dependency.

Previously, `cryptography` was an optional dependency, and the library would fall back to a pure Python RSA implementation using the `rsa` library if `cryptography` was not installed.

Changes made:
- Modified `setup.py` to remove `rsa` from dependencies and add `cryptography` with version constraints.
- Updated `google/auth/crypt/rsa.py` to directly use the `cryptography`-based RSA implementation (`_cryptography_rsa.py`) and remove the fallback mechanism.
- Removed the pure Python RSA implementation file (`google/auth/crypt/_python_rsa.py`).
- Removed the corresponding tests for the pure Python RSA implementation (`tests/crypt/test__python_rsa.py`).

Core unit tests pass after these changes.
@sai-sunder-s sai-sunder-s added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 23, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 23, 2025
@sai-sunder-s sai-sunder-s added the owlbot:run Add this label to trigger the Owlbot post processor. label May 28, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label May 28, 2025
Copy link
Contributor

@parthea parthea left a comment

Choose a reason for hiding this comment

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

LGTM. We should mark this as fix instead of refactor so that the change to setup.py is visible in release notes.

fix: add dependency on cryptography
fix: drop dependency on rsa

docs/conf.py Outdated

def autodoc_skip_member_handler(app, what, name, obj, skip, options):
"""
Skips members from internal modules (like _cryptography_rsa or base)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please could you file a bug for issue that requires this docs workaround, even if it will be closed with the changes in this PR. Add a link to the issue in this comment.

docs/conf.py Outdated
if public_obj is obj:
return True # Skip this internal one
except ImportError:
pass # Should not happen if the library is installed
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is not expected to happen, can we just let the error bubble up?

docs/conf.py Outdated
pass # Should not happen if the library is installed

# Handle Signer and Verifier from base
elif name in ("Signer", "Verifier") and hasattr(obj, "__module__"):
Copy link
Contributor

Choose a reason for hiding this comment

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

This code under this block is similar to the above if statement. Is it possible to refactor it?

Copy link
Contributor

@parthea parthea left a comment

Choose a reason for hiding this comment

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

Also remove rsa here:

@HiromuHota
Copy link

Any update here? rsa (https://stuvel.eu/software/rsa/) is officially archived.

@daniel-sanche daniel-sanche changed the title Refactor: Remove rsa and make cryptography a core dependency fix: replace rsa dependency with cryptography Nov 19, 2025
@daniel-sanche daniel-sanche marked this pull request as ready for review December 1, 2025 20:12
@daniel-sanche daniel-sanche requested review from a team as code owners December 1, 2025 20:12
@daniel-sanche daniel-sanche requested a review from a team as a code owner December 4, 2025 22:25
@daniel-sanche daniel-sanche changed the title fix: replace rsa dependency with cryptography fix!: replace rsa dependency with cryptography Dec 4, 2025
@daniel-sanche
Copy link
Collaborator

I looked a bit closer at the code, and it looks like this change would require a breaking change. Here's an example of some code that would break after this update:

import rsa as rsa_lib
import google.auth.crypt.rsa
# user didn't install optional `cryptography` dependency, so RSASigner and RSAVerifier 
# are imported from google.auth.crypt._python_rsa
signer = google.auth.crypt.rsa.RSASigner(priv_key)
verifier = google.auth.crypt.rsa.RSAVerifier(pub_key)

message = b"Test"

(pub_key, priv_key) = rsa_lib.newkeys(2048)
signature = signer.sign(message)
print(verifier.verify(message, signature))

I don't think there's a way to keep this flow consistent, without requiring rsa as a dependency


One thing we could do is make both rsa and cryptography optional dependencies, and raise an ImportError if both are missing? This would still be a breaking change, since they'll need to update their requirements.txt files. But they could keep using the rsa code in the mean-time.

I think it might be better to do a clean break from rsa though, since it's an archived package. I guess we could instruct users how to copy the old RSASigner/RSAVerifier classes into their codebase if they still want them

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.

5 participants