Switch from Godep to go vendoring
This commit is contained in:
parent
6b37713bc0
commit
cd317761c5
1504 changed files with 263076 additions and 34441 deletions
59
vendor/github.com/square/go-jose/jose-util/README.md
generated
vendored
Normal file
59
vendor/github.com/square/go-jose/jose-util/README.md
generated
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
# JOSE CLI
|
||||
|
||||
The `jose-util` command line utility allows for encryption, decryption, signing
|
||||
and verification of JOSE messages. Its main purpose is to facilitate dealing
|
||||
with JOSE messages when testing or debugging.
|
||||
|
||||
## Usage
|
||||
|
||||
The utility includes the subcommands `encrypt`, `decrypt`, `sign`, `verify` and
|
||||
`expand`. Examples for each command can be found below.
|
||||
|
||||
Algorithms are selected via the `--alg` and `--enc` flags, which influence the
|
||||
`alg` and `enc` headers in respectively. For JWE, `--alg` specifies the key
|
||||
managment algorithm (e.g. `RSA-OAEP`) and `--enc` specifies the content
|
||||
encryption algorithm (e.g. `A128GCM`). For JWS, `--alg` specifies the
|
||||
signature algorithm (e.g. `PS256`).
|
||||
|
||||
Input and output files can be specified via the `--in` and `--out` flags.
|
||||
Either flag can be omitted, in which case `jose-util` uses stdin/stdout for
|
||||
input/output respectively. By default each command will output a compact
|
||||
message, but it's possible to get the full serialization by supplying the
|
||||
`--full` flag.
|
||||
|
||||
Keys are specified via the `--key` flag. Supported key types are naked RSA/EC
|
||||
keys and X.509 certificates with embedded RSA/EC keys. Keys must be in PEM
|
||||
or DER formats.
|
||||
|
||||
## Examples
|
||||
|
||||
### Encrypt
|
||||
|
||||
Takes a plaintext as input, encrypts, and prints the encrypted message.
|
||||
|
||||
jose-util encrypt -k public-key.pem --alg RSA-OAEP --enc A128GCM
|
||||
|
||||
### Decrypt
|
||||
|
||||
Takes an encrypted message (JWE) as input, decrypts, and prints the plaintext.
|
||||
|
||||
jose-util decrypt -k private-key.pem
|
||||
|
||||
### Sign
|
||||
|
||||
Takes a payload as input, signs it, and prints the signed message with the embedded payload.
|
||||
|
||||
jose-util sign -k private-key.pem --alg PS256
|
||||
|
||||
### Verify
|
||||
|
||||
Reads a signed message (JWS), verifies it, and extracts the payload.
|
||||
|
||||
jose-util verify -k public-key.pem
|
||||
|
||||
### Expand
|
||||
|
||||
Expands a compact message to the full serialization format.
|
||||
|
||||
jose-util expand --format JWE # Expands a compact JWE to full format
|
||||
jose-util expand --format JWS # Expands a compact JWS to full format
|
88
vendor/github.com/square/go-jose/jose-util/jose-util.t
generated
vendored
Normal file
88
vendor/github.com/square/go-jose/jose-util/jose-util.t
generated
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
Set up test keys.
|
||||
|
||||
$ cat > rsa.pub <<EOF
|
||||
> -----BEGIN PUBLIC KEY-----
|
||||
> MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAslWybuiNYR7uOgKuvaBw
|
||||
> qVk8saEutKhOAaW+3hWF65gJei+ZV8QFfYDxs9ZaRZlWAUMtncQPnw7ZQlXO9ogN
|
||||
> 5cMcN50C6qMOOZzghK7danalhF5lUETC4Hk3Eisbi/PR3IfVyXaRmqL6X66MKj/J
|
||||
> AKyD9NFIDVy52K8A198Jojnrw2+XXQW72U68fZtvlyl/BTBWQ9Re5JSTpEcVmpCR
|
||||
> 8FrFc0RPMBm+G5dRs08vvhZNiTT2JACO5V+J5ZrgP3s5hnGFcQFZgDnXLInDUdoi
|
||||
> 1MuCjaAU0ta8/08pHMijNix5kFofdPEB954MiZ9k4kQ5/utt02I9x2ssHqw71ojj
|
||||
> vwIDAQAB
|
||||
> -----END PUBLIC KEY-----
|
||||
> EOF
|
||||
|
||||
$ cat > rsa.key <<EOF
|
||||
> -----BEGIN RSA PRIVATE KEY-----
|
||||
> MIIEogIBAAKCAQEAslWybuiNYR7uOgKuvaBwqVk8saEutKhOAaW+3hWF65gJei+Z
|
||||
> V8QFfYDxs9ZaRZlWAUMtncQPnw7ZQlXO9ogN5cMcN50C6qMOOZzghK7danalhF5l
|
||||
> UETC4Hk3Eisbi/PR3IfVyXaRmqL6X66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yNZAAe7Q0stxL44K4NWEmxC80x7lX
|
||||
> ZKozz96WOpNnO16qGC3IMHAT/JD5Or+04WTT14Ue7UEp8qcIQDTpbJ9DxKk/eglS
|
||||
> jH+SIHeKULOXw7fSu7p4IQKBgBnyVchIUMSnBtCagpn4DKwDjif3nEY+GNmb/D2g
|
||||
> ArNiy5UaYk5qwEmV5ws5GkzbiSU07AUDh5ieHgetk5dHhUayZcOSLWeBRFCLVnvU
|
||||
> i0nZYEZNb1qZGdDG8zGcdNXz9qMd76Qy/WAA/nZT+Zn1AiweAovFxQ8a/etRPf2Z
|
||||
> DbU1AoGAHpCgP7B/4GTBe49H0AQueQHBn4RIkgqMy9xiMeR+U+U0vaY0TlfLhnX+
|
||||
> 5PkNfkPXohXlfL7pxwZNYa6FZhCAubzvhKCdUASivkoGaIEk6g1VTVYS/eDVQ4CA
|
||||
> slfl+elXtLq/l1kQ8C14jlHrQzSXx4PQvjDEnAmaHSJNz4mP9Fg=
|
||||
> -----END RSA PRIVATE KEY-----
|
||||
> EOF
|
||||
|
||||
$ cat > ec.pub <<EOF
|
||||
> -----BEGIN PUBLIC KEY-----
|
||||
> MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE9yoUEAgxTd9svwe9oPqjhcP+f2jcdTL2
|
||||
> Wq8Aw2v9ht1dBy00tFRPNrCxFCkvMcJFhSPoDUV5NL7zfh3/psiSNYziGPrWEJYf
|
||||
> gmYihjSeoOf0ru1erpBrTflImPrMftCy
|
||||
> -----END PUBLIC KEY-----
|
||||
> EOF
|
||||
|
||||
$ cat > ec.key <<EOF
|
||||
> -----BEGIN EC PRIVATE KEY-----
|
||||
> MIGkAgEBBDDvoj/bM1HokUjYWO/IDFs26Jo0GIFtU3tMQQu7ZabKscDMK3dZA0mK
|
||||
> v97ij7BBFbCgBwYFK4EEACKhZANiAAT3KhQQCDFN32y/B72g+qOFw/5/aNx1MvZa
|
||||
> rwDDa/2G3V0HLTS0VE82sLEUKS8xwkWFI+gNRXk0vvN+Hf+myJI1jOIY+tYQlh+C
|
||||
> ZiKGNJ6g5/Su7V6ukGtN+UiY+sx+0LI=
|
||||
> -----END EC PRIVATE KEY-----
|
||||
> EOF
|
||||
|
||||
Encrypt and then decrypt a test message (RSA).
|
||||
|
||||
$ echo "Lorem ipsum dolor sit amet" |
|
||||
> jose-util encrypt --alg RSA-OAEP --enc A128GCM --key rsa.pub |
|
||||
> jose-util decrypt --key rsa.key
|
||||
Lorem ipsum dolor sit amet
|
||||
|
||||
Encrypt and then decrypt a test message (EC).
|
||||
|
||||
$ echo "Lorem ipsum dolor sit amet" |
|
||||
> jose-util encrypt --alg ECDH-ES+A128KW --enc A128GCM --key ec.pub |
|
||||
> jose-util decrypt --key ec.key
|
||||
Lorem ipsum dolor sit amet
|
||||
|
||||
Sign and verify a test message (RSA).
|
||||
|
||||
$ echo "Lorem ipsum dolor sit amet" |
|
||||
> jose-util sign --alg PS256 --key rsa.key |
|
||||
> jose-util verify --key rsa.pub
|
||||
Lorem ipsum dolor sit amet
|
||||
|
||||
Sign and verify a test message (EC).
|
||||
|
||||
$ echo "Lorem ipsum dolor sit amet" |
|
||||
> jose-util sign --alg ES384 --key ec.key |
|
||||
> jose-util verify --key ec.pub
|
||||
Lorem ipsum dolor sit amet
|
300
vendor/github.com/square/go-jose/jose-util/main.go
generated
vendored
Normal file
300
vendor/github.com/square/go-jose/jose-util/main.go
generated
vendored
Normal file
|
@ -0,0 +1,300 @@
|
|||
/*-
|
||||
* Copyright 2014 Square Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/square/go-jose"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "jose-util"
|
||||
app.Usage = "command-line utility to deal with JOSE objects"
|
||||
app.Version = "0.0.2"
|
||||
app.Author = ""
|
||||
app.Email = ""
|
||||
|
||||
app.Commands = []cli.Command{
|
||||
{
|
||||
Name: "encrypt",
|
||||
Usage: "encrypt a plaintext",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "key, k",
|
||||
Usage: "Path to key file (PEM/DER)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "input, in",
|
||||
Usage: "Path to input file (stdin if missing)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "output, out",
|
||||
Usage: "Path to output file (stdout if missing)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "algorithm, alg",
|
||||
Usage: "Key management algorithm (e.g. RSA-OAEP)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "encryption, enc",
|
||||
Usage: "Content encryption algorithm (e.g. A128GCM)",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "full, f",
|
||||
Usage: "Use full serialization format (instead of compact)",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) {
|
||||
keyBytes, err := ioutil.ReadFile(requiredFlag(c, "key"))
|
||||
exitOnError(err, "unable to read key file")
|
||||
|
||||
pub, err := jose.LoadPublicKey(keyBytes)
|
||||
exitOnError(err, "unable to read public key")
|
||||
|
||||
alg := jose.KeyAlgorithm(requiredFlag(c, "alg"))
|
||||
enc := jose.ContentEncryption(requiredFlag(c, "enc"))
|
||||
|
||||
crypter, err := jose.NewEncrypter(alg, enc, pub)
|
||||
exitOnError(err, "unable to instantiate encrypter")
|
||||
|
||||
obj, err := crypter.Encrypt(readInput(c.String("input")))
|
||||
exitOnError(err, "unable to encrypt")
|
||||
|
||||
var msg string
|
||||
if c.Bool("full") {
|
||||
msg = obj.FullSerialize()
|
||||
} else {
|
||||
msg, err = obj.CompactSerialize()
|
||||
exitOnError(err, "unable to serialize message")
|
||||
}
|
||||
|
||||
writeOutput(c.String("output"), []byte(msg))
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "decrypt",
|
||||
Usage: "decrypt a ciphertext",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "key, k",
|
||||
Usage: "Path to key file (PEM/DER)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "input, in",
|
||||
Usage: "Path to input file (stdin if missing)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "output, out",
|
||||
Usage: "Path to output file (stdout if missing)",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) {
|
||||
keyBytes, err := ioutil.ReadFile(requiredFlag(c, "key"))
|
||||
exitOnError(err, "unable to read private key")
|
||||
|
||||
priv, err := jose.LoadPrivateKey(keyBytes)
|
||||
exitOnError(err, "unable to read private key")
|
||||
|
||||
obj, err := jose.ParseEncrypted(string(readInput(c.String("input"))))
|
||||
exitOnError(err, "unable to parse message")
|
||||
|
||||
plaintext, err := obj.Decrypt(priv)
|
||||
exitOnError(err, "unable to decrypt message")
|
||||
|
||||
writeOutput(c.String("output"), plaintext)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "sign",
|
||||
Usage: "sign a plaintext",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "algorithm, alg",
|
||||
Usage: "Signing algorithm (e.g. PS256)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "key, k",
|
||||
Usage: "Path to key file (PEM/DER)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "input, in",
|
||||
Usage: "Path to input file (stdin if missing)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "output, out",
|
||||
Usage: "Path to output file (stdout if missing)",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "full, f",
|
||||
Usage: "Use full serialization format (instead of compact)",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) {
|
||||
keyBytes, err := ioutil.ReadFile(requiredFlag(c, "key"))
|
||||
exitOnError(err, "unable to read key file")
|
||||
|
||||
signingKey, err := jose.LoadPrivateKey(keyBytes)
|
||||
exitOnError(err, "unable to read private key")
|
||||
|
||||
alg := jose.SignatureAlgorithm(requiredFlag(c, "algorithm"))
|
||||
signer, err := jose.NewSigner(alg, signingKey)
|
||||
exitOnError(err, "unable to make signer")
|
||||
|
||||
obj, err := signer.Sign(readInput(c.String("input")))
|
||||
exitOnError(err, "unable to sign")
|
||||
|
||||
var msg string
|
||||
if c.Bool("full") {
|
||||
msg = obj.FullSerialize()
|
||||
} else {
|
||||
msg, err = obj.CompactSerialize()
|
||||
exitOnError(err, "unable to serialize message")
|
||||
}
|
||||
|
||||
writeOutput(c.String("output"), []byte(msg))
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "verify",
|
||||
Usage: "verify a signature",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "key, k",
|
||||
Usage: "Path to key file (PEM/DER)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "input, in",
|
||||
Usage: "Path to input file (stdin if missing)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "output, out",
|
||||
Usage: "Path to output file (stdout if missing)",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) {
|
||||
keyBytes, err := ioutil.ReadFile(requiredFlag(c, "key"))
|
||||
exitOnError(err, "unable to read key file")
|
||||
|
||||
verificationKey, err := jose.LoadPublicKey(keyBytes)
|
||||
exitOnError(err, "unable to read private key")
|
||||
|
||||
obj, err := jose.ParseSigned(string(readInput(c.String("input"))))
|
||||
exitOnError(err, "unable to parse message")
|
||||
|
||||
plaintext, err := obj.Verify(verificationKey)
|
||||
exitOnError(err, "invalid signature")
|
||||
|
||||
writeOutput(c.String("output"), plaintext)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "expand",
|
||||
Usage: "expand compact message to full format",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "input, in",
|
||||
Usage: "Path to input file (stdin if missing)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "output, out",
|
||||
Usage: "Path to output file (stdout if missing)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "format, f",
|
||||
Usage: "Message format (JWE/JWS, defaults to JWE)",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) {
|
||||
input := string(readInput(c.String("input")))
|
||||
|
||||
var serialized string
|
||||
var err error
|
||||
switch c.String("format") {
|
||||
case "", "JWE":
|
||||
var jwe *jose.JsonWebEncryption
|
||||
jwe, err = jose.ParseEncrypted(input)
|
||||
if err == nil {
|
||||
serialized = jwe.FullSerialize()
|
||||
}
|
||||
case "JWS":
|
||||
var jws *jose.JsonWebSignature
|
||||
jws, err = jose.ParseSigned(input)
|
||||
if err == nil {
|
||||
serialized = jws.FullSerialize()
|
||||
}
|
||||
}
|
||||
|
||||
exitOnError(err, "unable to expand message")
|
||||
writeOutput(c.String("output"), []byte(serialized))
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := app.Run(os.Args)
|
||||
exitOnError(err, "unable to run application")
|
||||
}
|
||||
|
||||
// Retrieve value of a required flag
|
||||
func requiredFlag(c *cli.Context, flag string) string {
|
||||
value := c.String(flag)
|
||||
if value == "" {
|
||||
fmt.Fprintf(os.Stderr, "missing required flag --%s\n", flag)
|
||||
os.Exit(1)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// Exit and print error message if we encountered a problem
|
||||
func exitOnError(err error, msg string) {
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s: %s\n", msg, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Read input from file or stdin
|
||||
func readInput(path string) []byte {
|
||||
var bytes []byte
|
||||
var err error
|
||||
|
||||
if path != "" {
|
||||
bytes, err = ioutil.ReadFile(path)
|
||||
} else {
|
||||
bytes, err = ioutil.ReadAll(os.Stdin)
|
||||
}
|
||||
|
||||
exitOnError(err, "unable to read input")
|
||||
return bytes
|
||||
}
|
||||
|
||||
// Write output to file or stdin
|
||||
func writeOutput(path string, data []byte) {
|
||||
var err error
|
||||
|
||||
if path != "" {
|
||||
err = ioutil.WriteFile(path, data, 0644)
|
||||
} else {
|
||||
_, err = os.Stdout.Write(data)
|
||||
}
|
||||
|
||||
exitOnError(err, "unable to write output")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue