package jws
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=eea7319ae84c3649b4c72cd59f6308fa62f23bb51b41efb8af4a3a097dd71c3d
sha512=d27b80a04bd67641ca6ceff37d145491c6783cf1b6edac6f04dbc3bce1081e9378d8f07bc7412eb136e788c8ecdc2fa0a2f27e259c32f94fe90eb0aa88a5fb0f
doc/jws/Jws/index.html
Module JwsSource
JWS - JSON Web Signature (RFC 7515)
A straightforward implementation of JWS in OCaml using mirage-crypto and Jsont.
This library uses polymorphic variants that are compatible with X509.Public_key.t and X509.Private_key.t. For instance, given a private key obtained from x509:
let pk : X509.Private_key.t = ... in
let jws = Jws.encode (Pk.of_private_key_exn pk) ~nonce "payload"Protected header fields beyond alg and nonce can be read back via value using any Jsont.t decoder:
let url = Jws.value jws ~key:"url" Jsont.stringBase64url
JWA - JSON Web Algorithms (RFC 7518)
JWK - JSON Web Key (RFC 7517)
A Key-Value map to represent a JSON object
Private keys and signing
JWS values
A decoded JWS value.
val validate_crit :
?understood:string list ->
Jsont.json S.t ->
(unit, [> `Msg of string ]) resultvalidate_crit ?understood props validates the "crit" header parameter according to RFC 7515, 4.1.11. understood is the list of extension header names the application recognizes.
Flattened JSON Serialization (RFC 7515, 7.2.2)
val encode :
?kid:string ->
?extra:Jsont.json S.t ->
Pk.t ->
?nonce:string ->
string ->
stringencode ?kid ?extra pk ?nonce data produces a JWS Flattened JSON Serialization that signs (or MACs) data with pk. The algorithm is derived from pk.
When kid is provided, a "kid" header field is set and no JWK is embedded. Otherwise the public key is embedded as a "jwk" header field (this is the typical ACME workflow).
extra carries additional protected header members as a Jsont.json string map. For instance, to set the "url" field required by ACME:
let extra = S.singleton "url" (Jsont.Json.string url) in
Jws.encode ~extra pk ~nonce payloadval encode_exn :
?alg:Jwa.t ->
?kid:string ->
?extra:Jsont.json S.t ->
Pk.t ->
?nonce:string ->
string ->
stringencode_exn ?alg ?kid ?extra pk ?nonce data is like encode but allows overriding the algorithm via ?alg.
val decode :
?understood:string list ->
?public:Jwk.t ->
string ->
(t, [> `Msg of string ]) resultdecode ?understood ?public str decodes and verifies a JWS Flattened JSON Serialization. The public key is taken from public if provided, otherwise from the embedded "jwk" header field. Returns a descriptive error when the JSON is malformed, no public key is available, the signature is invalid, or a critical header extension is not understood.
understood lists the critical header extensions the application recognizes (see validate_crit).
decode_exn is like decode but raises Failure on error.