Skip to content

Conversation

@vyperdon
Copy link

@vyperdon vyperdon commented Oct 8, 2025

Summary

This PR adds support for three new key management algorithms: A128GCMKW, A192GCMKW, and A256GCMKW as defined in RFC 7518.

Changes

New Features:

  • Added A128GCMKW, A192GCMKW, and A256GCMKW algorithm implementations
  • Added Base class for algorithm implementations to enable header parameter configuration
  • Added Validator, Header, and NameResolver classes to improve code organization
  • Fixed missing attribute reader for cek in JWE::Alg::AesGcm module

Backward Compatibility:

  • All existing public APIs remain functional
  • Deprecated several public methods that were not tested and should be internal:
    • JWE.check_params, JWE.check_alg, JWE.check_enc, JWE.check_zip, JWE.check_key
    • JWE.param_to_class_name
    • JWE.apply_zip, JWE.generate_header, JWE.generate_serialization
  • All deprecated methods include warning messages with migration guidance

Architecture Changes:

I had to introduce a Base class for algorithms because the new AES-GCM key wrap algorithms need to configure
additional parameters in the JWE header (IV and authentication tag). This was not possible with the previous
architecture.

I also found it strange that some methods were publicly available but had no tests. Since I wasn't sure if
they were intended for external use, I marked them as deprecated instead of making them private. This
preserves backward compatibility while discouraging their use.


Let me know if you'd like me to adjust the wording or add anything!

@vyperdon vyperdon force-pushed the feature-add-support-aes-gcm-algorithms branch from 7b803be to 9643786 Compare October 8, 2025 21:22
@vyperdon vyperdon marked this pull request as draft October 8, 2025 21:30
…A256GCMKW)

- Add new internal architecture with `Base`, `Validator`, `Header`, and `NameResolver` classes
- Improve code organization with refactored module structure
- RuboCop compliance improvements
- Deprecated `JWE.check_params`, `JWE.check_alg`, `JWE.check_enc`, `JWE.check_zip`, `JWE.check_key` (use `JWE::Validator` instead)
- Deprecated `JWE.param_to_class_name` (use `JWE::NameResolver` instead)
- Deprecated internal methods `JWE.apply_zip`, `JWE.generate_header`, `JWE.generate_serialization`
@vyperdon vyperdon force-pushed the feature-add-support-aes-gcm-algorithms branch from 9643786 to 8c0c9ee Compare October 8, 2025 22:30
@vyperdon vyperdon marked this pull request as ready for review October 8, 2025 22:31
@pandwoter
Copy link

@anakinj Hey 👋, could you please look into this? We are motivated to get those new algorithms supported, please share your feedback, we are happy to adjust the implementation accordingly 🫡

@anakinj
Copy link
Member

anakinj commented Nov 25, 2025

Hi @pandwoter I'll try to find time in the very near future to check this out.

Copy link
Member

@anakinj anakinj left a comment

Choose a reason for hiding this comment

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

Really nice refactoring happening here. Jotted down a few opinions and questions.


header_parameters.merge!(zip: zip) if zip

header_parameters.merge!(alg_cipher.header_parameters) if alg_cipher.need_additional_header_parameters?
Copy link
Member

Choose a reason for hiding this comment

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

This need_additional_header_parameters method name bugs me a bit as there is two different additional header parameters in this logic.

Could it be just alg_cipher.require_header_parameters?

Or could the alg specific header_parameters return nothing in the cases it's not required?


gemspec

gem 'pry'
Copy link
Member

Choose a reason for hiding this comment

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

Just out of curiosity, what extra does pry give over irb.

I feel that irb has gotten pretty powerful over the years and I have moved back to the vanilla tooling when it comes to console debugging.


module JWE
# Generates JWE header from algorithm, encryption, and compression parameters
class Header
Copy link
Member

Choose a reason for hiding this comment

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

As there is no state I would prefer module and static methods over a class that needs instantiation in this case.


module JWE
# Validates JWE parameters (algorithm, encryption, compression, and key)
class Validator
Copy link
Member

Choose a reason for hiding this comment

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

As the validator has no state I would prefer module and static methods over a class that needs instantiation in this case.

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.

3 participants