Help us shape the future of Go! Take the 2026 Go Developer Survey

awskmscrypto

package
v1.0.310 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 23 Imported by: 3

Documentation

Overview

Package awskmscrypto implements cryptoprov.Provider and cryptoprov.KeyManager over AWS KMS asymmetric signing keys (RSA 2048/3072/4096 and NIST P-256, P-384, P-521). It registers itself as manufacturer "AWSKMS"; the token config Attributes field carries "Endpoint=<url>,Region=<region>", both optional. Credentials, the default region and retries come from the default AWS SDK chain. Keys never leave KMS: ExportKey returns a pkcs11: URI and Sign calls kms:Sign with a digest, after checking the options against the algorithms KMS reports for the key. EnumKeys needs kms:ListKeys and kms:DescribeKey on every key it lists. Encryption keys (GenerateRSAKey purpose 2, ENCRYPT_DECRYPT) are not supported.

Index

Constants

View Source
const ProviderName = "AWSKMS"

ProviderName specifies a provider name

Variables

View Source
var KmsClientFactory = func(cfg aws.Config, optFns ...func(*kms.Options)) KmsClient {
	return kms.NewFromConfig(cfg, optFns...)
}

KmsClientFactory creates the KMS client for Init; tests override it.

Functions

func KmsLoader

KmsLoader provides loader for KMS provider

func NewSigner

func NewSigner(keyID string, label string, signingAlgorithms []types.SigningAlgorithmSpec, publicKey crypto.PublicKey, kmsClient KmsClient) crypto.Signer

NewSigner creates a signer for the KMS key keyID. signingAlgorithms are the algorithms KMS reports for the key (KeyMetadata.SigningAlgorithms or GetPublicKeyOutput.SigningAlgorithms); Sign accepts only those, so a key without any, such as an ENCRYPT_DECRYPT key, can not sign.

Types

type KmsClient

KmsClient interface

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements Provider interface for KMS

func Init

func Init(tc cryptoprov.TokenConfig) (*Provider, error)

Init creates a provider for tc, whose Attributes may carry "Endpoint=<url>" and "Region=<region>". Credentials, the default region and retries come from the default AWS SDK chain, which reads AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN before the shared config, so the provider does not copy them into a static provider of its own (XPKI-034). The client from KmsClientFactory makes no request until a key operation.

func (*Provider) Close

func (p *Provider) Close() error

Close allocated resources and file reloader

func (*Provider) CurrentSlotID

func (p *Provider) CurrentSlotID() uint

CurrentSlotID returns current slot id. For KMS only one slot is assumed to be available.

func (*Provider) DestroyKeyPairOnSlot

func (p *Provider) DestroyKeyPairOnSlot(slotID uint, keyID string) error

DestroyKeyPairOnSlot destroys key pair on slot. For KMS slotID is ignored and KMS retire API is used to destroy the key.

func (*Provider) EnumKeys

func (p *Provider) EnumKeys(slotID uint, prefix string) ([]cryptoprov.KeyInfo, error)

EnumKeys lists the signing keys (usage SIGN_VERIFY, not pending deletion) whose label, the KMS key description, starts with prefix; an empty prefix lists all of them. slotID is ignored. KMS lists key ids only, so every key of the account is described (XPKI-032), describeConcurrency calls at a time, with the SDK retrying throttled calls; the caller needs kms:ListKeys and kms:DescribeKey. A key the caller may not describe (AccessDeniedException) is not listed and is logged. Any other ListKeys or DescribeKey failure ends the listing and is returned wrapped, so errors.As still finds the service error; there is no partial result (XPKI-033). Keys are returned in the KMS listing order.

func (*Provider) EnumTokens

func (p *Provider) EnumTokens(currentSlotOnly bool) ([]cryptoprov.TokenInfo, error)

EnumTokens lists tokens. For KMS currentSlotOnly is ignored and only one slot is assumed to be available.

func (*Provider) ExportKey

func (p *Provider) ExportKey(keyID string) (string, []byte, error)

ExportKey returns PKCS#11 URI for specified key ID. It does not return key bytes

func (*Provider) FindKeyPairOnSlot

func (p *Provider) FindKeyPairOnSlot(slotID uint, keyID, label string) (crypto.PrivateKey, error)

FindKeyPairOnSlot retrieves a previously created asymmetric key, using a specified slot.

func (*Provider) GenerateECDSAKey

func (p *Provider) GenerateECDSAKey(label string, curve elliptic.Curve) (crypto.PrivateKey, error)

GenerateECDSAKey creates a KMS signing key on curve (P-256, P-384 or P-521) with label as its description and alias, and returns its Signer.

func (*Provider) GenerateRSAKey

func (p *Provider) GenerateRSAKey(label string, bits int, purpose int) (crypto.PrivateKey, error)

GenerateRSAKey creates a KMS signing key of bits (2048, 3072 or 4096) with label as its description and alias, and returns its Signer. This provider has no decrypter, so the encryption purpose (2) is an error before any RPC (XPKI-031); any other purpose is a signing key.

func (*Provider) GetKey

func (p *Provider) GetKey(keyID string) (crypto.PrivateKey, error)

GetKey returns the Signer of the KMS key keyID (a key id, ARN, alias name or alias ARN), labelled with the key description. The key usage must be SIGN_VERIFY and the key must not be pending deletion: neither can sign, so no signer is returned for them (XPKI-031). A disabled key gets a signer, since it can be enabled again; its Sign fails until then.

func (*Provider) IdentifyKey

func (p *Provider) IdentifyKey(priv crypto.PrivateKey) (keyID, label string, err error)

IdentifyKey returns key id and label for the given private key

func (*Provider) KeyInfo

func (p *Provider) KeyInfo(slotID uint, keyID string, includePublic bool) (*cryptoprov.KeyInfo, error)

KeyInfo retrieves info about key with the specified id

func (*Provider) Manufacturer

func (p *Provider) Manufacturer() string

Manufacturer returns manufacturer for the provider

func (*Provider) Model

func (p *Provider) Model() string

Model returns model for the provider

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

Signer implements crypto.Signer interface

func (*Signer) KeyID

func (s *Signer) KeyID() string

KeyID returns key id of the signer

func (*Signer) Label

func (s *Signer) Label() string

Label returns key label of the signer

func (*Signer) Public

func (s *Signer) Public() crypto.PublicKey

Public returns public key for the signer

func (*Signer) Sign

func (s *Signer) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) (signature []byte, err error)

Sign signs digest with the KMS key. opts is required (XPKI-025): its hash selects the KMS algorithm and digest must have that hash's length. *rsa.PSSOptions select RSASSA_PSS for an RSA key and are rejected for an ECDSA key; the salt must be rsa.PSSSaltLengthEqualsHash or the hash size, the only salt KMS produces (rsa.PSSSaltLengthAuto asks for a maximal salt and is rejected). The algorithm must be one the key supports, as KMS reported when the signer was created; for an ECDSA key that is the algorithm of its curve. Invalid options fail before any RPC.

func (*Signer) SigningAlgorithms added in v0.29.306

func (s *Signer) SigningAlgorithms() []types.SigningAlgorithmSpec

SigningAlgorithms returns the KMS signing algorithms the key supports.

func (*Signer) String

func (s *Signer) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL