Documentation ¶
Overview ¶
See LICENSE file for license details Copyright (c) 2015 XOR Data Exchange, Inc.
Superdog - the Crypto library for Vault from Hashicorp ¶
Superdog is a library for managing strong cryptography in both development and test environments. Superdog provides an elegant wrapper to the Vault(https://www.vaultproject.io) API that allows you to manage your cryptographic keys in Vault using any code that implements the `KeyProvider` interface. An implemention of the `KeyProvider` interface is provided for Vault, but others could be supported.
Features ¶
- Versioned Keys - Key version is stored as the first few bytes of the encrypted text - Key Rotation - Rotate your keys safely, knowing that you'll always be able to decrypt older versionss - Development implementation for tests and local development - Versioned and Rotated IV/Salt - `SaltProvider` interface works the same as `KeyProvider` to allow development and testing access to the crypto libraries without requiring a live Key (Vault) server - `Reencrypt` function to simplify key rotation, decrypts with given key, reencrypts with latest key
Cypher Suites ¶
`superdog` supports AES encryption with CFB/CTR/GCM/OFB modes.
Production Usage By default, `superdog` uses the `DevKeyProvider` which is a static key with static IV. This is extremely insecure, and SHOULD NOT ever be used in production.
We reccommend using Go's [build tags](https://golang.org/pkg/go/build/) to enable strong cryptography in production usage.
Create a file with your connection routines in the init() function. Add the build tag `// +build production` to the top of that file. Incomplete example:
// +build production package main import ( "github.com/xordataexchange/superdog" "github.com/xordataexxchange/superdog/vault/hashi" "github.com/hashicorp/vault/api" ) // Assign each application a unique UUID // and use Vault's AppID authentication mechanism const ( appid = "SOME RANDOM UUID" ) func init() { user := os.Getenv("VAULT_USER") vaultaddr := os.Getenv("VAULT_ADDRESS") // TEST these for empty strings & handle appropriately in your code cfg:= api.DefaultConfig() cfg.Address = vaultaddr vault, err := hashi.NewVault(cfg) if err != nil { // handle appropriately } err = vault.AuthAppID(appid, user) if err != nil { // handle appropriately } crypto.DefaultKeyProvider = vault crypto.DefaultSaltProvider = vault }
Now compile your program with `go build -tags production` to include this code. The `KeyProvider` will be set to use Vault.
Index ¶
- Variables
- func CurrentHashes(prefix string, value []byte) ([][]byte, error)
- func CurrentHashesString(prefix string, value string) ([]string, error)
- func Decrypt(keyPrefix string, dst, src []byte) ([]byte, error)
- func Encrypt(prefix string, dst, src []byte) ([]byte, error)
- func EncryptWithVersion(keyPrefix string, keyVersion uint64, dst []byte, src []byte) ([]byte, error)
- func Hash(prefix string, value []byte) ([]byte, error)
- func HashString(prefix string, value string) (string, error)
- func HashWithVersion(prefix string, version uint64, value []byte) ([]byte, error)
- func Reencrypt(keyPrefix string, dst, src []byte) ([]byte, error)
- func Sum256String(s string) string
- type Cipher
- type CipherBlockMode
- type DevKeyProvider
- type DevSaltProvider
- type Key
- type KeyProvider
- type SaltProvider
Constants ¶
This section is empty.
Variables ¶
var (
ErrKeyNotFound = errors.New("Key not found")
)
Functions ¶
func CurrentHashes ¶
CurrentHashes returns a list of all possible hashes for the given prefix and value, used as search criteria during rotation
func CurrentHashesString ¶
CurrentHashesString returns a list of all possible hashes for the given prefix and value, used as search criteria during rotation
func Decrypt ¶
Decrypt will decrypt the provided byte slice using the provided key at the version it was encrypted with. It returns a new slice as it trims the prefixed key version and IV. It modifies the same underlying array.
func Encrypt ¶
Encrypt will encrypt the provided byte slice with the latesg key. It returns a new slice as it prepends the key version, and IV.
func EncryptWithVersion ¶
func EncryptWithVersion(keyPrefix string, keyVersion uint64, dst []byte, src []byte) ([]byte, error)
EncryptWithVersion will encrypt the provided byte slice with the supplied key version. It returns a new slice as it prepends the key version, and IV.
func HashString ¶
HashString returns a hash to be used for the given value using the current version
func HashWithVersion ¶
HashWithVersion returns a hash to be used for the given value using the supplied version
func Reencrypt ¶
Reencrypt takes encrypted ciphertext, decrypts it with the version of the key used to decrypt it, and re-encrypts the plaintext with the current version of the key.
func Sum256String ¶
Types ¶
type DevKeyProvider ¶
type DevKeyProvider struct { DisableWarn bool // Disable log messages whenever this provider is used. KeyVersion uint64 }
DevKeyProvider is a KeyProvider used for development purposes only, and contains a hardcoded key.
func (*DevKeyProvider) CurrentKeyVersion ¶
func (kp *DevKeyProvider) CurrentKeyVersion(prefix string) (uint64, error)
CurrentKeyVersion returns the version number of the latest key for a given prefix
type DevSaltProvider ¶
type DevSaltProvider struct { DisableWarn bool // Disable log messages whenever this provider is used. SaltVersion uint64 }
DevSaltProvider is a KeyProvider used for development purposes only, and contains a hardcoded key.
func (*DevSaltProvider) CurrentSaltVersion ¶
func (sp *DevSaltProvider) CurrentSaltVersion(prefix string) (uint64, error)
CurrentSaltVersion returns the version number of the latest salt for a given prefix
func (*DevSaltProvider) CurrentSalts ¶
func (sp *DevSaltProvider) CurrentSalts(prefix string) ([]uint64, error)
CurrentSalts returns a stubbed list of salts to be used for the given prefix
type Key ¶
type Key struct { Cipher Cipher CipherBlockMode CipherBlockMode Version uint64 // contains filtered or unexported fields }
type KeyProvider ¶
type KeyProvider interface { GetKey(prefix string, version uint64) (*Key, error) CurrentKeyVersion(prefix string) (uint64, error) }
KeyProvider is an interface that wraps the GetKey method, responsible for retrieving encryption keys at a specified version.
var DefaultKeyProvider KeyProvider = new(DevKeyProvider)
type SaltProvider ¶
type SaltProvider interface { CurrentSalts(prefix string) ([]uint64, error) GetSalt(prefix string, version uint64) ([]byte, error) CurrentSaltVersion(prefix string) (uint64, error) }
var DefaultSaltProvider SaltProvider = new(DevSaltProvider)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
See LICENSE file for license details Copyright (c) 2015 XOR Data Exchange, Inc.
|
See LICENSE file for license details Copyright (c) 2015 XOR Data Exchange, Inc. |
hashi
See LICENSE file for license details Copyright (c) 2015 XOR Data Exchange, Inc.
|
See LICENSE file for license details Copyright (c) 2015 XOR Data Exchange, Inc. |