Categorygithub.com/hashicorp/go-kms-wrapping/v2
modulepackage
2.0.18
Repository: https://github.com/hashicorp/go-kms-wrapping.git
Documentation: pkg.go.dev

# README

Go-KMS-Wrapping - Go library for encrypting values through various KMS providers

Go Reference

NOTE: This is version 2 of the library. The v0 branch contains version 0, which may be needed for legacy applications or while transitioning to version 2.

Go-KMS-Wrapping is a library that can be used to encrypt things through various KMS providers -- public clouds, Vault's Transit plugin, etc. It is similar in concept to various other cryptosystems (like NaCl) but focuses on using third party KMSes. This library is the underpinning of Vault's auto-unseal functionality, and should be ready to use for many other applications.

For KMS providers that do not support encrypting arbitrarily large values, the library will generate an envelope data encryption key (DEK), encrypt the value with it using an authenticated cipher, and use the KMS to encrypt the DEK.

The key being used by a given implementation can change; the library stores information about which key was actually used to encrypt a given value as part of the returned data, and this key will be used for decryption. By extension, this means that users should be careful not to delete keys in KMS systems simply because they're not configured to be used by this library currently, as they may have been used for past encryption operations.

Features

  • Supports many KMSes:
    • AEAD using AES-GCM and a provided key
    • Alibaba Cloud KMS (uses envelopes)
    • AWS KMS (uses envelopes)
    • Azure KeyVault (uses envelopes)
    • GCP CKMS (uses envelopes)
    • Huawei Cloud KMS (uses envelopes)
    • OCI KMS (uses envelopes)
    • Tencent Cloud KMS (uses envelopes)
    • Vault Transit mount
  • Transparently supports multiple decryption targets, allowing for key rotation
  • Supports Additional Authenticated Data (AAD) for all KMSes except Vault Transit.

Extras

There are several extra(s) packages included which build upon the base go-kms-wrapping features to provide "extra" capabilities.

  • The multi package is capable of encrypting to a specified wrapper and decrypting using one of several wrappers switched on key ID. This can allow easy key rotation for KMSes that do not natively support it.

  • The structwrapping package allows for structs to have members encrypted and decrypted in a single pass via a single wrapper. This can be used for workflows such as database library callback functions to easily encrypt/decrypt data as it goes to/from storage.

  • The kms package provides key management system features for wrappers including scoped KEKs and DEKs which are wrapped with an external KMS when stored in sqlite or postgres.

  • The crypto package provides additional operations like HMAC-SHA256 and a derived reader from which keys can be read.

Installation

go get github.com/hashicorp/go-kms-wrapping/v2

Overview

The library exports a Wrapper interface that is implemented by multiple providers. For each provider, the standard flow is as follows:

  1. Create a wrapper using the New method
  2. Call SetConfig to pass either wrapper-specific options or use the wrapping.WithConfigMap option to pass a configuration map
  3. Use the wrapper as needed

It is possible, in v2 of this library, to instantiate a wrapper as a plugin. This allows avoiding pulling dependencies of the wrapper directly into another system's process space. See the example plugin-cli for a complete example on how to do build wrapper plugins and use them in an application or the test plugins for guidance in how to build a plugin; in this case, you'll definitely want to use wrapping.WithConfigMap to pass configuration to avoid pulling in package-specific options.

The best place to find the currently available set of configuration options supported by each provider is its code, but it can also be found in Vault's seal configuration documentation. All environment variables noted there also work in this library, however, non-Vault-specific variants of the environment variables are also available for each provider. See the code/comments in each given provider for the currently allowed env vars.

Usage

Following is an example usage of the AWS KMS provider.

// Context used in this library is passed to various underlying provider
// libraries; how it's used is dependent on the provider libraries
ctx := context.Background()

wrapper := awskms.NewWrapper()
_, err := wrapper.SetConfig(ctx, wrapping.WithConfigMap(map[string]string{
    "kms_key_id": "1234abcd-12ab-34cd-56ef-1234567890ab",
}))
if err != nil {
    return err
}
blobInfo, err := wrapper.Encrypt(ctx, []byte("foo"))
if err != nil {
    return err
}

//
// Do some things...
//

plaintext, err := wrapper.Decrypt(ctx, blobInfo)
if err != nil {
    return err
}
if string(plaintext) != "foo" {
    return errors.New("mismatch between input and output")
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
EnvelopeDecrypt takes in EnvelopeInfo and potentially additional options and decrypts.
EnvelopeEncrypt takes in plaintext and envelope encrypts it, generating an EnvelopeInfo value.
GetOpts iterates the inbound Options and returns a struct.
No description provided by the author
NewTestWrapper constructs a test wrapper.
NewTestInitFinalizer constructs a test wrapper.
NewTestInitFinalizerHmacComputer constructs a test wrapper.
NewTestWrapper constructs a test wrapper.
ParsePaths is a helper function to take each string pointer argument and call parseutil.ParsePath, replacing the contents of the target string with the result if no error occurs.
WithAad provides optional additional authenticated data.
WithConfigMap is an option accepted by wrappers at configuration time and/or in other function calls to control wrapper-specific behavior.
WithDisallowEnvVars provides a common way to configure ignoring environment variables.
WithIV provides.
WithKeyEncoding provides a common way to pass in a key encoding.
WithKeyId provides a common way to pass in a key identifier.
WithKeyPurpose provides a common way to pass in a key purpose.
WithKeyType provides a common way to pass in a key type.
WithoutHMAC disables the requirement for an HMAC to be included with the mechanism.
WithRandomBytes provides a common way to pass in entropy.
WithWrappedKeyEncoding provides a common way to pass in a wrapped_key encoding.

# Constants

These values define supported types of AEADs.
These values define supported types of AEADs.
These values define supported types of hashes.
These values define supported types of hashes.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.
These values define known types of Wrappers.

# Variables

ErrFunctionNotImplemented represents a function that hasn't been implemented.
ErrInvalidParameter represents an invalid parameter error.
No description provided by the author
Enum value maps for HmacType.
Enum value maps for HmacType.
Enum value maps for KeyEncoding.
Enum value maps for KeyEncoding.
Enum value maps for KeyPurpose.
Enum value maps for KeyPurpose.
Enum value maps for KeyType.
Enum value maps for KeyType.

# Structs

BlobInfo contains information about the encrypted value along with information about the key used to encrypt it.
EnvelopeInfo contains the information necessary to perfom encryption or decryption in an envelope fashion.
KeyInfo contains information regarding which Wrapper key was used to encrypt the entry.
Options holds options common to all wrappers.
SigInfo contains information about a cryptographic signature.
No description provided by the author
No description provided by the author
TestWrapper is a wrapper that can be used for tests.
WrapperConfig is the result of a call to SetConfig on a wrapper, returning relevant information about the wrapper and its updated configuration.

# Interfaces

No description provided by the author
No description provided by the author
KeyExporter defines an optional interface for wrappers to implement that returns the "current" key bytes.
SigInfoSigner defines common capabilities for creating a msg signature in the form of a SigInfo.
SigInfoVerifier defines common capabilities for verifying a msg signature in the form of a SigInfo.
Wrapper is an an interface where supporting implementations allow for encrypting and decrypting data.

# Type aliases

No description provided by the author
No description provided by the author
HmacType defines the hmac algorithm type.
No description provided by the author
KeyPurpose defines the cryptographic capabilities of a key.
KeyType defines the key's type.
Option - a type that wraps an interface for compile-time safety but can contain an option for this package or for wrappers implementing this interface.
OptionFunc - a type for funcs that operate on the shared Options struct.
No description provided by the author