| 1 |
# JOSE CLI |
| 2 |
|
| 3 |
The `jose-util` command line utility allows for encryption, decryption, signing |
| 4 |
and verification of JOSE messages. Its main purpose is to facilitate dealing |
| 5 |
with JOSE messages when testing or debugging. |
| 6 |
|
| 7 |
## Installation |
| 8 |
|
| 9 |
``` |
| 10 |
$ go get -u github.com/go-jose/go-jose/jose-util |
| 11 |
$ go install github.com/go-jose/go-jose/jose-util |
| 12 |
``` |
| 13 |
|
| 14 |
## Usage |
| 15 |
|
| 16 |
The utility includes the subcommands `encrypt`, `decrypt`, `sign`, `verify` and |
| 17 |
`expand`. Examples for each command can be found below. |
| 18 |
|
| 19 |
Algorithms are selected via the `--alg` and `--enc` flags, which influence the |
| 20 |
`alg` and `enc` headers in respectively. For JWE, `--alg` specifies the key |
| 21 |
management algorithm (e.g. `RSA-OAEP`) and `--enc` specifies the content |
| 22 |
encryption algorithm (e.g. `A128GCM`). For JWS, `--alg` specifies the |
| 23 |
signature algorithm (e.g. `PS256`). |
| 24 |
|
| 25 |
Input and output files can be specified via the `--in` and `--out` flags. |
| 26 |
Either flag can be omitted, in which case `jose-util` uses stdin/stdout for |
| 27 |
input/output respectively. By default each command will output a compact |
| 28 |
message, but it's possible to get the JSON Serialization by supplying the |
| 29 |
`--full` flag. |
| 30 |
|
| 31 |
Keys are specified via the `--key` flag. Supported key types are naked RSA/EC |
| 32 |
keys and X.509 certificates with embedded RSA/EC keys. Keys must be in PEM, |
| 33 |
DER or JWK formats. |
| 34 |
|
| 35 |
|
| 36 |
## Testing |
| 37 |
|
| 38 |
`cram` is used for testing. This can be installed with pip or `sudo apt install |
| 39 |
python-cram` See the travis file for how this is used in testing. For example, |
| 40 |
`go build && PATH=$PWD:$PATH cram -v jose-util.t` |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
## Testing |
| 45 |
|
| 46 |
`cram` is used for testing. This can be installed with pip or `sudo apt install |
| 47 |
python-cram` See the travis file for how this is used in testing. For example, |
| 48 |
`go build && PATH=$PWD:$PATH cram -v jose-util.t` |
| 49 |
|
| 50 |
|
| 51 |
## Examples |
| 52 |
|
| 53 |
### Generate key pair |
| 54 |
|
| 55 |
Generates a key pair, either for signing/verification or encryption/decryption. Generated keys will be written to the current directory. |
| 56 |
|
| 57 |
# Generate keys for signing (for RSA-PSS) |
| 58 |
jose-util generate-key --use sig --alg RS256 |
| 59 |
|
| 60 |
# Generate keys for signing (for EdDSA) |
| 61 |
jose-util generate-key --use sig --alg EdDSA |
| 62 |
|
| 63 |
# Generate keys for encryption (for RSA-OAEP) |
| 64 |
jose-util generate-key --use enc --alg RSA-OAEP |
| 65 |
|
| 66 |
# Generate keys for encryption (for ECDH-ES) |
| 67 |
jose-util generate-key --use enc --alg ECDH-ES+A128KW |
| 68 |
|
| 69 |
### Encrypt |
| 70 |
|
| 71 |
Takes a plaintext as input, encrypts, and prints the encrypted message. |
| 72 |
|
| 73 |
# From stdin, to stdout |
| 74 |
jose-util encrypt --key public-key.pem --alg RSA-OAEP --enc A128GCM |
| 75 |
|
| 76 |
# Operating on files |
| 77 |
jose-util encrypt --key public-key.pem --alg RSA-OAEP --enc A128GCM --in plaintext.txt --out ciphertext.txt |
| 78 |
|
| 79 |
### Decrypt |
| 80 |
|
| 81 |
Takes an encrypted message (JWE) as input, decrypts, and prints the plaintext. |
| 82 |
|
| 83 |
# From stdin, to stdout |
| 84 |
jose-util decrypt --key private-key.pem |
| 85 |
|
| 86 |
# Operating on files |
| 87 |
jose-util decrypt --key private-key.pem --in ciphertext.txt --out plaintext.txt |
| 88 |
|
| 89 |
### Sign |
| 90 |
|
| 91 |
Takes a payload as input, signs it, and prints the signed message with the embedded payload. |
| 92 |
|
| 93 |
# From stdin, to stdout |
| 94 |
jose-util sign --key private-key.pem --alg PS256 |
| 95 |
|
| 96 |
# Operating on files |
| 97 |
jose-util sign --key private-key.pem --alg PS256 --in message.txt --out signed-message.txt |
| 98 |
|
| 99 |
### Verify |
| 100 |
|
| 101 |
Reads a signed message (JWS), verifies it, and extracts the payload. |
| 102 |
|
| 103 |
# From stdin, to stdout |
| 104 |
jose-util verify --key public-key.pem |
| 105 |
|
| 106 |
# Operating on files |
| 107 |
jose-util verify --key public-key.pem --in signed-message.txt --out message.txt |
| 108 |
|
| 109 |
### Expand |
| 110 |
|
| 111 |
Expands a compact message to the JWE/JWS JSON Serialization format. |
| 112 |
|
| 113 |
jose-util expand --format JWE # Expands a compact JWE to JWE JSON Serialization |
| 114 |
jose-util expand --format JWS # Expands a compact JWS to JWS JSON Serialization |
| 115 |
|
| 116 |
### Decode base64 |
| 117 |
|
| 118 |
The JOSE format uses url-safe base64 in payloads, but the `base64` utility that ships with |
| 119 |
most Linux distributions (or macOS) only supports the standard base64 encoding. To make it easier |
| 120 |
to deal with these payloads a `b64decode` command is available in `jose-util` that can decode |
| 121 |
both regular and url-safe base64 data. |
| 122 |
|
| 123 |
echo "8J-Ukgo" | jose-util b64decode |