Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
370bc35
Refactor: Remove rsa and make cryptography a core dependency
google-labs-jules[bot] May 23, 2025
1d665b3
update secret
sai-sunder-s May 23, 2025
c6ad0e6
fix doc issue
sai-sunder-s May 24, 2025
2c461ce
fix es256 sphix error
sai-sunder-s May 27, 2025
6170a48
lint
sai-sunder-s May 27, 2025
94819ad
removed autodoc custimizations
daniel-sanche Nov 19, 2025
4de2dde
removed conditional imports
daniel-sanche Nov 19, 2025
4c0de25
fixed docs reference
daniel-sanche Nov 19, 2025
433ee28
revert docs change
daniel-sanche Nov 19, 2025
e587b28
remove conditional import
daniel-sanche Nov 19, 2025
63d8a27
Merge branch 'main' into remove-rsa-dependency
daniel-sanche Nov 19, 2025
8659ec5
fixed lint
daniel-sanche Nov 21, 2025
29cc7be
Merge branch 'main' into remove-rsa-dependency
daniel-sanche Nov 26, 2025
fd53d0b
update secret
daniel-sanche Nov 26, 2025
d49c969
fixed docs issue
daniel-sanche Nov 26, 2025
64f7be8
Apply suggestion from @parthea
daniel-sanche Nov 26, 2025
fb84373
avoid circular dependency
daniel-sanche Dec 4, 2025
91beb2d
Merge branch 'main' into remove-rsa-dependency
daniel-sanche Dec 4, 2025
05606b4
Merge branch 'main' into remove-rsa-dependency
daniel-sanche Dec 18, 2025
165377e
make cryptography extra optional
daniel-sanche Dec 18, 2025
1c2c496
revert file
daniel-sanche Dec 18, 2025
58a7df9
add backwards compatibility
daniel-sanche Jan 6, 2026
944bf4d
Merge branch 'main' into remove-rsa-dependency
daniel-sanche Jan 6, 2026
ca66169
only emit one warning
daniel-sanche Jan 6, 2026
57f9d69
added rsa module tests
daniel-sanche Jan 6, 2026
23c8865
added comments
daniel-sanche Jan 6, 2026
7e5cafd
support running without rsa
daniel-sanche Jan 6, 2026
0d744bb
fixed name collision
daniel-sanche Jan 6, 2026
f06a087
updated docstring
daniel-sanche Jan 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion google/auth/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@

import abc
from enum import Enum
import logging
import os
from typing import List

from google.auth import _helpers, environment_vars
from google.auth import exceptions
from google.auth import metrics
from google.auth._credentials_base import _BaseCredentials
from google.auth._default import _LOGGER
from google.auth._refresh_worker import RefreshThreadManager

DEFAULT_UNIVERSE_DOMAIN = "googleapis.com"
NO_OP_TRUST_BOUNDARY_LOCATIONS: List[str] = []
NO_OP_TRUST_BOUNDARY_ENCODED_LOCATIONS = "0x0"

_LOGGER = logging.getLogger("google.auth._default")


class Credentials(_BaseCredentials):
"""Base class for all credentials.
Expand Down
46 changes: 17 additions & 29 deletions google/auth/crypt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,31 @@
"""

from google.auth.crypt import base
from google.auth.crypt import es
from google.auth.crypt import es256
from google.auth.crypt import rsa

# google.auth.crypt.es depends on the crytpography module which may not be
# successfully imported depending on the system.
try:
from google.auth.crypt import es
from google.auth.crypt import es256
except ImportError: # pragma: NO COVER
es = None # type: ignore
es256 = None # type: ignore

if es is not None and es256 is not None: # pragma: NO COVER
__all__ = [
"EsSigner",
"EsVerifier",
"ES256Signer",
"ES256Verifier",
"RSASigner",
"RSAVerifier",
"Signer",
"Verifier",
]

EsSigner = es.EsSigner
EsVerifier = es.EsVerifier
ES256Signer = es256.ES256Signer
ES256Verifier = es256.ES256Verifier
else: # pragma: NO COVER
__all__ = ["RSASigner", "RSAVerifier", "Signer", "Verifier"]


# Aliases to maintain the v1.0.0 interface, as the crypt module was split
# into submodules.
Signer = base.Signer
Verifier = base.Verifier
RSASigner = rsa.RSASigner
RSAVerifier = rsa.RSAVerifier
EsSigner = es.EsSigner
EsVerifier = es.EsVerifier
ES256Signer = es256.ES256Signer
ES256Verifier = es256.ES256Verifier

__all__ = [
"EsSigner",
"EsVerifier",
"ES256Signer",
"ES256Verifier",
"RSASigner",
"RSAVerifier",
"Signer",
"Verifier",
]


def verify_signature(message, signature, certs, verifier_cls=rsa.RSAVerifier):
Expand Down
44 changes: 43 additions & 1 deletion google/auth/crypt/_cryptography_rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,55 @@
from google.auth import _helpers
from google.auth.crypt import base

import warnings

try:
# attempt to import deprecated rsa module if available,
# for backwards compatibility
import rsa
except ImportError:
rsa = None

# Global flag for the module
_RSA_DEPRECATION_WARNED = False

_CERTIFICATE_MARKER = b"-----BEGIN CERTIFICATE-----"
_BACKEND = backends.default_backend()
_PADDING = padding.PKCS1v15()
_SHA256 = hashes.SHA256()


def _warn_rsa_type(key_type):
global _RSA_DEPRECATION_WARNED
if not _RSA_DEPRECATION_WARNED:
deprecation_msg = (
"The 'rsa' library is deprecated and unmaintained. Support for "
f"{key_type.__module__}.{key_type.__name__} keys will be removed in a future release. Please migrate to "
"'cryptography' keys or use the '.from_string()' factory method."
)
warnings.warn(deprecation_msg, DeprecationWarning, stacklevel=3)
_RSA_DEPRECATION_WARNED = True


class RSAVerifier(base.Verifier):
"""Verifies RSA cryptographic signatures using public keys.

Note: rsa.key.PublicKey keys are currently accepted, but the `rsa` library
is deprecated. Please migrate to `cryptography` keys or use
`.from_string()` instead

Args:
public_key (
cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey):
The public key used to verify signatures.
"""

def __init__(self, public_key):
if rsa is not None and isinstance(public_key, rsa.key.PublicKey):
# convert rsa.key.PublicKey to cryptography type
_warn_rsa_type(type(public_key))
der_bytes = public_key.save_pkcs1(format='DER')
public_key = serialization.load_der_public_key(der_bytes)
self._pubkey = public_key

@_helpers.copy_docstring(base.Verifier)
Expand All @@ -66,7 +99,7 @@ def from_string(cls, public_key):
x509 public key certificate.

Returns:
Verifier: The constructed verifier.
google.auth.crypt.base.Verifier: The constructed verifier.

Raises:
ValueError: If the public key can't be parsed.
Expand All @@ -88,6 +121,10 @@ def from_string(cls, public_key):
class RSASigner(base.Signer, base.FromServiceAccountMixin):
"""Signs messages with an RSA private key.

Note: rsa.key.PrivateKey keys are currently accepted, but the `rsa` library
is deprecated. Please migrate to `cryptography` keys or use
`.from_string()` instead

Args:
private_key (
cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey):
Expand All @@ -98,6 +135,11 @@ class RSASigner(base.Signer, base.FromServiceAccountMixin):
"""

def __init__(self, private_key, key_id=None):
if rsa is not None and isinstance(private_key, rsa.key.PrivateKey):
# convert rsa.key.PublicKey to cryptography type
_warn_rsa_type(type(private_key))
der_bytes = private_key.save_pkcs1(format='DER')
private_key = serialization.load_der_private_key(der_bytes, password=None)
self._key = private_key
self._key_id = key_id

Expand Down
175 changes: 0 additions & 175 deletions google/auth/crypt/_python_rsa.py

This file was deleted.

2 changes: 1 addition & 1 deletion google/auth/crypt/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def from_string(cls, public_key: Union[str, bytes]) -> "EsVerifier":
x509 public key certificate.
Returns:
Verifier: The constructed verifier.
google.auth.crypt.base.Verifier: The constructed verifier.
Raises:
ValueError: If the public key can't be parsed.
Expand Down
16 changes: 3 additions & 13 deletions google/auth/crypt/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@

"""RSA cryptography signer and verifier."""

from google.auth.crypt import _cryptography_rsa

try:
# Prefer cryptograph-based RSA implementation.
from google.auth.crypt import _cryptography_rsa

RSASigner = _cryptography_rsa.RSASigner
RSAVerifier = _cryptography_rsa.RSAVerifier
except ImportError: # pragma: NO COVER
# Fallback to pure-python RSA implementation if cryptography is
# unavailable.
from google.auth.crypt import _python_rsa

RSASigner = _python_rsa.RSASigner # type: ignore
RSAVerifier = _python_rsa.RSAVerifier # type: ignore
RSASigner = _cryptography_rsa.RSASigner
RSAVerifier = _cryptography_rsa.RSAVerifier
Loading