1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
defmodule JOSE do
@moduledoc ~S"""
JOSE stands for JSON Object Signing and Encryption which is a is a set of
standards established by the [JOSE Working Group](https://datatracker.ietf.org/wg/jose).
JOSE is split into 5 main components:
* `JOSE.JWA` - JSON Web Algorithms (JWA) [RFC 7518](https://tools.ietf.org/html/rfc7518)
* `JOSE.JWE` - JSON Web Encryption (JWE) [RFC 7516](https://tools.ietf.org/html/rfc7516)
* `JOSE.JWK` - JSON Web Key (JWK) [RFC 7517](https://tools.ietf.org/html/rfc7517)
* `JOSE.JWS` - JSON Web Signature (JWS) [RFC 7515](https://tools.ietf.org/html/rfc7515)
* `JOSE.JWT` - JSON Web Token (JWT) [RFC 7519](https://tools.ietf.org/html/rfc7519)
Additional specifications and drafts implemented:
* JSON Web Key (JWK) Thumbprint [RFC 7638](https://tools.ietf.org/html/rfc7638)
* JWS Unencoded Payload Option [RFC 7797](https://tools.ietf.org/html/rfc7797)
"""
## Functions
@doc """
Gets the current ChaCha20/Poly1305 module used by `jose_chacha20_poly1305`.
See `chacha20_poly1305_module/1` for default.
"""
@spec chacha20_poly1305_module() :: module()
defdelegate chacha20_poly1305_module(), to: :jose
@doc """
Sets the current ChaCha20/Poly1305 module used by `jose_chacha20_poly1305`.
Currently supported ChaCha20/Poly1305 modules (first found is used as default):
* `crypto` - only when 96-bit nonce is supported
* [`libsodium`](https://github.com/potatosalad/erlang-libsodium)
* `jose_jwa_chacha20_poly1305` - only supported when `crypto_fallback/0` is `true`
Additional modules that implement the `jose_chacha20_poly1305` behavior may also be used.
"""
@spec chacha20_poly1305_module(module()) :: :ok
defdelegate chacha20_poly1305_module(module), to: :jose
@doc """
Gets the current Cryptographic Algorithm Fallback state
Defaults to `false`.
"""
@spec crypto_fallback() :: boolean()
defdelegate crypto_fallback(), to: :jose
@doc """
Sets the current Cryptographic Algorithm Fallback state.
"""
@spec crypto_fallback(boolean()) :: :ok
defdelegate crypto_fallback(boolean), to: :jose
@doc """
Gets the current Curve25519 module used by `jose_curve25519`
See `curve25519_module/1` for default.
"""
@spec curve25519_module() :: module()
defdelegate curve25519_module(), to: :jose
@doc """
Sets the current Curve25519 module used by `jose_curve25519`.
Currently supported Curve25519 modules (first found is used as default):
* [`libdecaf`](https://github.com/potatosalad/erlang-libdecaf)
* [`libsodium`](https://github.com/potatosalad/erlang-libsodium)
* `jose_jwa_curve25519` - only supported when `crypto_fallback/0` is `true`
Additional modules that implement the `jose_curve25519` behavior may also be used.
"""
@spec curve25519_module(module()) :: :ok
defdelegate curve25519_module(module), to: :jose
@doc """
Gets the current Curve448 module used by `jose_curve448`
See `curve448_module/1` for default.
"""
@spec curve448_module() :: module()
defdelegate curve448_module(), to: :jose
@doc """
Sets the current Curve448 module used by `jose_curve448`.
Currently supported Curve448 modules (first found is used as default):
* [`libdecaf`](https://github.com/potatosalad/erlang-libdecaf)
* `jose_jwa_curve448` - only supported when `crypto_fallback/0` is `true`
Additional modules that implement the `jose_curve448` behavior may also be used.
"""
@spec curve448_module(module()) :: :ok
defdelegate curve448_module(module), to: :jose
@doc """
Decodes JSON to a term using the module returned by `json_module/0`.
Returns the decoded term, or raises if `binary` contains invalid JSON.
"""
@spec decode(binary()) :: term()
defdelegate decode(binary), to: :jose
@doc """
Encodes a term to JSON using the module returned by `json_module/0`.
Returns the encoded JSON, or raises if `term` cannot be encoded.
"""
@spec encode(term()) :: binary()
defdelegate encode(term), to: :jose
@doc """
Gets the current JSON module used by `decode/1` and `encode/1`, see `json_module/1` for default.
"""
@spec json_module() :: module()
defdelegate json_module(), to: :jose
@doc """
Sets the current JSON module used by `decode/1` and `encode/1`.
Currently supported JSON modules (first found is used as default):
* [`ojson`](https://github.com/potatosalad/erlang-ojson)
* [`Jason`](https://github.com/michalmuskala/jason)
* [`Poison`](https://github.com/devinus/poison)
* [`jiffy`](https://github.com/davisp/jiffy)
* [`jsone`](https://github.com/sile/jsone)
* [`jsx`](https://github.com/talentdeficit/jsx)
Additional modules that implement the `:jose_json` behavior may also be used.
"""
@spec json_module(module()) :: :ok
defdelegate json_module(module), to: :jose
@doc """
Gets the current SHA3 module used by `jose_sha3`, see `sha3_module/1` for default.
"""
@spec sha3_module() :: module()
defdelegate sha3_module(), to: :jose
@doc """
Sets the current SHA3 module used by `jose_sha3`.
Currently supported SHA3 modules (first found is used as default):
* [`keccakf1600`](https://github.com/potatosalad/erlang-keccakf1600)
* [`libdecaf`](https://github.com/potatosalad/erlang-libdecaf)
* `jose_jwa_sha3` - only supported when `crypto_fallback/0` is `true`
Additional modules that implement the `jose_sha3` behavior may also be used.
"""
@spec sha3_module(module()) :: :ok
defdelegate sha3_module(module), to: :jose
@doc """
Gets the current Unsecured Signing state, defaults to `false`.
"""
@spec unsecured_signing() :: boolean()
defdelegate unsecured_signing(), to: :jose
@doc """
Sets the current Unsecured Signing state.
Enables/disables the `"none"` algorithm used for signing and verifying.
See [Critical vulnerabilities in JSON Web Token libraries](https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/) for more information.
"""
@spec unsecured_signing(boolean()) :: :ok
defdelegate unsecured_signing(boolean), to: :jose
end
|