Module github.com/bide-ai/bide/signer/gcpkms
Go module github.com/bide-ai/bide/signer/gcpkms; all modules.
signer/gcpkms
github.com/bide-ai/bide/signer/gcpkms · pkg.go.dev · Stability: core
Package gcpkms is an audit.Signer whose Ed25519 or ECDSA P-256 private key lives in Google Cloud KMS.
Constants
const DefaultTimeout = 30 * time.Second: DefaultTimeout bounds Open, and each Sign with its retries, when Config.Timeout is zero.
Variables
var ErrNoEd25519: ErrNoEd25519 means Config.Scheme is Ed25519 and the key version's algorithm is not EC_SIGN_ED25519.var ErrNoP256: ErrNoP256 means Config.Scheme is audit.AlgECDSAP256 and the key version's algorithm is not EC_SIGN_P256_SHA256.var ErrVersionState: ErrVersionState means the key version is not ENABLED.var ErrProtectionLevel: ErrProtectionLevel means the key version's protection level is not one Config allows: by default only HSM and HSM_SINGLE_TENANT; AllowSoftwareKey adds SOFTWARE and AllowExternalKey adds EXTERNAL and EXTERNAL_VPC.var ErrIntegrity: ErrIntegrity means a Cloud KMS response failed an integrity check: a checksum that does not match, a response for another resource, a missing checksum field, or a protection level that differs from the one Open pinned.var ErrBadSignature: ErrBadSignature means the signature Cloud KMS returned does not verify under the key version's public key (was the key replaced?).var ErrEmptyMessage: ErrEmptyMessage means Sign was given an empty message under Ed25519, which Cloud KMS cannot sign.var ErrAttestation: ErrAttestation means Config.VerifyAttestation is set and the key version's HSM attestation does not prove what it must: the attestation is absent, in an unknown format, not signed through chains that lead to the pinned roots, or does not show this key version's public key as an HSM-generated, non-extractable EC key.
type API
go
type API interface {
GetCryptoKeyVersion(ctx context.Context, req *kmspb.GetCryptoKeyVersionRequest, opts ...gax.CallOption) (*kmspb.CryptoKeyVersion, error)
GetPublicKey(ctx context.Context, req *kmspb.GetPublicKeyRequest, opts ...gax.CallOption) (*kmspb.PublicKey, error)
AsymmetricSign(ctx context.Context, req *kmspb.AsymmetricSignRequest, opts ...gax.CallOption) (*kmspb.AsymmetricSignResponse, error)
}API is the part of the Cloud KMS client the signer uses.
type AttestationRoots
go
type AttestationRoots struct {
Manufacturer *x509.Certificate
Owner *x509.Certificate
}AttestationRoots are the trust anchors for HSM attestation: the HSM manufacturer's root and the owner (Google) root, as certificates the caller has obtained and checked out of band.
type CodeError
go
type CodeError struct {
Code codes.Code
}CodeError is a gRPC status code a Cloud KMS call returned.
Methods
func (e CodeError) Error() string: Error names the code.
type Config
go
type Config struct {
Client API
KeyVersion string
Scheme audit.Alg
AllowSoftwareKey bool
AllowExternalKey bool
VerifyAttestation bool
AttestationRoots *AttestationRoots
Timeout time.Duration
}Config selects the Cloud KMS key version.
type Signer
go
type Signer struct {
// contains filtered or unexported fields
}Signer signs with an Ed25519 or ECDSA P-256 Cloud KMS key version (see Config.Scheme).
Constructors and functions
func Open(ctx context.Context, cfg Config) (*Signer, error): Open reads the key version, checks that it is an enabled signing key of Config.Scheme whose protection level Config allows (HSM by default), reads and checks its public key, and signs once to prove the key and the caller's cloudkms.cryptoKeyVersions.useToSign permission.
Methods
func (s *Signer) Alg() audit.Alg: Alg reports the signature scheme (Config.Scheme, audit.AlgECDSAP256 by default).func (s *Signer) Format(f fmt.State, _ rune): Format writes String for every verb.func (s *Signer) KeyVersion() string: KeyVersion is the CryptoKeyVersion resource name the signer signs with.func (s *Signer) ProtectionLevel() string: ProtectionLevel is the protection level Open found for the key version: "SOFTWARE", "HSM", "HSM_SINGLE_TENANT", "EXTERNAL" or "EXTERNAL_VPC".func (s *Signer) PublicKey() []byte: PublicKey returns the public key of the key version (32 bytes for Ed25519, the 65-byte uncompressed point for P-256), in the encoding audit.NewVerifier reads.func (s *Signer) Sign(message []byte) ([]byte, error): Sign returns Cloud KMS's signature over message in the encoding audit verifies.func (s *Signer) String() string: String describes the signer by its key identity (audit.KeyID of the public key).