| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
SDJWT.Internal.Verification
Description
SD-JWT verification: Verifying SD-JWT presentations.
This module provides functions for verifying SD-JWT presentations on the verifier side. It handles signature verification, disclosure validation, and payload processing.
Synopsis
- verifySDJWT :: JWKLike jwk => jwk -> SDJWTPresentation -> Maybe Text -> IO (Either SDJWTError ProcessedSDJWTPayload)
- verifyKeyBinding :: JWKLike jwk => HashAlgorithm -> jwk -> SDJWTPresentation -> IO (Either SDJWTError ())
- verifySDJWTSignature :: JWKLike jwk => jwk -> SDJWTPresentation -> Maybe Text -> IO (Either SDJWTError ())
- verifySDJWTWithoutSignature :: SDJWTPresentation -> IO (Either SDJWTError ProcessedSDJWTPayload)
- verifyDisclosures :: HashAlgorithm -> SDJWTPresentation -> Either SDJWTError ()
- processPayload :: HashAlgorithm -> SDJWTPayload -> [EncodedDisclosure] -> Maybe KeyBindingInfo -> Either SDJWTError ProcessedSDJWTPayload
- extractHashAlgorithm :: SDJWTPresentation -> Either SDJWTError HashAlgorithm
- parsePayloadFromJWT :: Text -> Either SDJWTError SDJWTPayload
- extractRegularClaims :: Value -> Either SDJWTError Object
- extractDigestsFromPayload :: SDJWTPayload -> Either SDJWTError [Digest]
Public API
Arguments
| :: JWKLike jwk | |
| => jwk | Issuer public key (Text or jose JWK object) |
| -> SDJWTPresentation | |
| -> Maybe Text | Required typ header value (Nothing = allow any/none, Just "sd-jwt" = require exactly "sd-jwt") |
| -> IO (Either SDJWTError ProcessedSDJWTPayload) |
Complete SD-JWT verification.
This function performs all verification steps:
- Parses the presentation
- Verifies issuer signature (required)
- Validates standard JWT claims (if present):
exp(expiration time),nbf(not before), etc. - Extracts hash algorithm
- Verifies disclosures match digests
- Verifies key binding (if present)
- Processes payload to reconstruct claims
Returns the processed payload with all claims (both regular non-selectively-disclosable
claims and disclosed selectively-disclosable claims). If a KB-JWT was present and verified,
the keyBindingInfo field will contain the holder's public key extracted from the
cnf claim, allowing the verifier to use it for subsequent operations.
Standard JWT Claims Validation
Standard JWT claims (RFC 7519) included in the issuer-signed JWT are automatically validated:
exp(expiration time): Token is rejected if expirednbf(not before): Token is rejected if not yet valid- Other standard claims are preserved but not validated by this library
For testing or debugging purposes where signature verification should be skipped,
use verifySDJWTWithoutSignature instead.
Arguments
| :: JWKLike jwk | |
| => HashAlgorithm | |
| -> jwk | Holder public key (Text or jose JWK object) |
| -> SDJWTPresentation | |
| -> IO (Either SDJWTError ()) |
Verify key binding in a presentation.
Verifies the Key Binding JWT if present in the presentation. This includes verifying the KB-JWT signature and sd_hash.
Internal/Test-only functions
Arguments
| :: JWKLike jwk | |
| => jwk | Issuer public key (Text or jose JWK object) |
| -> SDJWTPresentation | SD-JWT presentation to verify |
| -> Maybe Text | Required typ header value (Nothing = allow any typ or none, Just typValue = require typ to be exactly that value) |
| -> IO (Either SDJWTError ()) |
Verify SD-JWT issuer signature.
Verifies the signature on the issuer-signed JWT using the issuer's public key.
verifySDJWTWithoutSignature :: SDJWTPresentation -> IO (Either SDJWTError ProcessedSDJWTPayload) Source #
SD-JWT verification without signature verification.
This function performs verification steps 3-6 of verifySDJWT but skips
signature verification. This is useful for testing or debugging, but should
NOT be used in production as it does not verify the authenticity of the JWT.
WARNING: This function does not verify the issuer signature. Only use this function when signature verification is not required (e.g., in tests or when verifying locally-generated JWTs).
verifyDisclosures :: HashAlgorithm -> SDJWTPresentation -> Either SDJWTError () Source #
Verify that all disclosures match digests in the payload.
This function:
- Computes digest for each disclosure
- Verifies each digest exists in the payload's _sd array
- Checks for duplicate disclosures
Arguments
| :: HashAlgorithm | |
| -> SDJWTPayload | |
| -> [EncodedDisclosure] | |
| -> Maybe KeyBindingInfo | Key binding info if KB-JWT was present and verified |
| -> Either SDJWTError ProcessedSDJWTPayload |
Process SD-JWT payload by replacing digests with disclosure values.
This function reconstructs the full claims set by:
- Starting with regular (non-selectively disclosable) claims
- Replacing digests in _sd arrays with actual claim values from disclosures
extractHashAlgorithm :: SDJWTPresentation -> Either SDJWTError HashAlgorithm Source #
Extract hash algorithm from presentation.
Parses the JWT payload and extracts the _sd_alg claim, defaulting to SHA-256.
parsePayloadFromJWT :: Text -> Either SDJWTError SDJWTPayload Source #
Parse payload from JWT.
| Parse JWT payload from a JWT string (advanced/internal use).
Extracts and decodes the JWT payload (middle part) from a JWT string. This function properly decodes the base64url-encoded payload and parses it as JSON.
This function is exported for advanced use cases and internal library use.
Most users should use verifySDJWT or verifySDJWTWithoutSignature instead,
which handle payload parsing internally.
This function is used internally by:
Presentation- To parse payloads when selecting disclosuresverifyDisclosures- To extract digests from payloadsextractHashAlgorithm- To extract hash algorithm from payloads
Advanced/Internal Use
This function is primarily used internally by other modules (e.g., Presentation).
Most users should use higher-level functions like verifySDJWT instead.
Only use this function directly if you need fine-grained control over JWT parsing.
extractRegularClaims :: Value -> Either SDJWTError Object Source #
Extract regular (non-selectively disclosable) claims from payload.
JWT payloads must be JSON objects (RFC 7519), so this function only accepts Aeson.Object values. Returns an error if given a non-object value.
extractDigestsFromPayload :: SDJWTPayload -> Either SDJWTError [Digest] Source #
Extract digests from payload's _sd array and arrays with ellipsis objects.