Skip to content

Improve RSA exponent checks #11

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

picatz
Copy link
Owner

@picatz picatz commented Jul 3, 2025

This pull request enhances RSA key validation in the pkg/jwk package by introducing stricter checks for RSA modulus size and public exponent values, along with comprehensive tests to ensure the robustness of these validations. The key changes include updates to the RSAPublicKey function and the addition of new test cases.

RSA Key Validation Enhancements:

  • Minimum RSA Modulus Size Enforcement: Updated RSAPublicKey to reject RSA keys with a modulus size smaller than 2048 bits. This ensures compliance with security best practices.
  • Public Exponent Validation: Added checks in RSAPublicKey to ensure the public exponent is a positive integer between 2 and math.MaxInt32, rejecting invalid values.

Test Coverage Improvements:

  • Test for Large Exponent: Added a test case in TestErrorMessages to verify that excessively large public exponents are correctly rejected.
  • Test for Modulus Size Validation: Introduced TestRSAModulusSizeValidation to ensure RSA keys with moduli smaller than 2048 bits are rejected, while valid moduli are accepted.
  • Test for Public Exponent Validation: Added TestRSAPublicKeyExponentValidation to test various exponent values, ensuring invalid exponents are rejected and valid ones are accepted.

These changes improve the security and reliability of RSA key handling in the pkg/jwk package.


https://chatgpt.com/codex/tasks/task_e_6866d2118ff0833195a7b340a95ffc90

@picatz picatz added the codex label Jul 3, 2025 — with ChatGPT Connector
@picatz picatz requested a review from Copilot July 3, 2025 22:25
Copilot

This comment was marked as resolved.

@picatz picatz force-pushed the codex/review-and-improve-cryptographic-package-for-go-standard-lib branch from 0a92309 to a51943f Compare July 4, 2025 03:07
@picatz picatz marked this pull request as ready for review July 4, 2025 03:12
@picatz picatz requested a review from Copilot July 4, 2025 03:12
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR strengthens RSA key validation by enforcing a minimum modulus size and stricter exponent checks, and adds corresponding tests.

  • Enforce a 2048-bit minimum RSA modulus in RSAPublicKey
  • Validate public exponent is between 2 and math.MaxInt32
  • Add tests for large exponents, small moduli, and various exponent edge cases

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/jwk/jwk.go Added modulus bit-length check and exponent range/bit-length validation
pkg/jwk/jwk_test.go Introduced tests for modulus size and exponent validation, and expanded error-message coverage
Comments suppressed due to low confidence (1)

pkg/jwk/jwk.go:308

  • [nitpick] The error messages for invalid public exponent share the same prefix but represent different failures; consider using more specific messages (e.g., 'public exponent bit length too large' vs 'public exponent out of allowed range') to improve diagnostic clarity.
	if !e.IsInt64() || e.BitLen() > 31 {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant