$ show nov/json-jwt
JSON::JWT is a Ruby library implementing the JSON Web Token (JWT) family of standards, including JWS (JSON Web Signature), JWE (JSON Web Encryption), and JWK (JSON Web Key). It provides comprehensive cryptographic operations for signing, verifying, encrypting, and decrypting tokens using various algorithms (HMAC, RSA, ECDSA, RSA-PSS, and symmetric encryption). The library also includes JWK Set management with remote fetching and caching capabilities. The architecture is modular: JSON::JWT serves as the main entry point, delegating to JSON::JWS for signing/verification and JSON::JWE for encryption/decryption. JSON::JWK handles key representation and conversion between OpenSSL keys and JWK format. The JWK Set Fetcher provides a configurable HTTP client with pluggable caching, suitable for OpenID Connect discovery. The code demonstrates strong security practices, including constant-time comparison for MAC verification, protection against padding oracle attacks in CBC mode, and proper validation of algorithm headers to prevent algorithm confusion attacks. The test suite covers interop with other JWT libraries (Nimbus JOSE, jsrsasign) and RFC examples, ensuring correctness. Key external dependencies include OpenSSL for cryptographic primitives, Faraday for HTTP, and ActiveSupport for hash extensions. The library is actively maintained with support for Ruby 3.2-4.0 and recent security fixes.
The LLM identified 3 files worth highlighting for reuse:
Implements JSON Web Key (JWK) standard, converting between OpenSSL keys (RSA, EC) and JWK format, calculating thumbprints (RFC 7638), and normalizing key representations. The class is self-contained, using only OpenSSL and Base64, and could be extracted as a standalone JWK library.
Provides a configurable fetcher for remote JWK Sets with pluggable caching, HTTP client customization via Faraday, and debugging support. Demonstrates a reusable pattern for fetching and caching remote resources with fallback, including cache key generation, error handling for invalid JWK Sets, and kid-based lookup.
Implements JWE encryption and decryption with multiple algorithms (RSA1_5, RSA-OAEP, AES key wrap, direct) and content encryption methods (AES-GCM, AES-CBC+HMAC). Includes careful security measures: constant-time MAC comparison, padding oracle attack prevention by generating fake content encryption keys on decryption failure, and proper authentication tag verification for both CBC and GCM modes.