From: Simon Josefsson Date: Thu Dec 11 10:24:09 2025 +0100 Subject: [PATCH] Disable vault Forwarded: not-needed diff --git a/integration/hcvault/hcvault_aead.go b/integration/hcvault/hcvault_aead.go index 94a7346..4253a10 100644 --- a/integration/hcvault/hcvault_aead.go +++ b/integration/hcvault/hcvault_aead.go @@ -15,12 +15,10 @@ package hcvault import ( - "encoding/base64" "errors" "fmt" "strings" - "github.com/hashicorp/vault/api" "github.com/tink-crypto/tink-go/v2/tink" ) @@ -28,7 +26,6 @@ import ( type vaultAEAD struct { encKeyPath string decKeyPath string - client *api.Logical associatedDataName string } @@ -80,97 +77,16 @@ func WithLegacyContextParamater() AEADOption { }) } -// NewAEAD returns a new remote AEAD primitive for a HashiCorp Vault service. -func NewAEAD(keyPath string, client *api.Logical, opts ...AEADOption) (tink.AEAD, error) { - params := &aeadParams{ - associatedDataName: defaultAssociatedDataName, - } - // Process options, if any. - for _, opt := range opts { - if err := opt.set(params); err != nil { - return nil, fmt.Errorf("failed setting option: %v", err) - } - } - encKeyPath, decKeyPath, err := getEndpointPaths(keyPath) - if err != nil { - return nil, err - } - a := &vaultAEAD{ - encKeyPath: encKeyPath, - decKeyPath: decKeyPath, - client: client, - associatedDataName: params.associatedDataName, - } - return a, nil -} - -func extractCiphertext(secret *api.Secret) ([]byte, error) { - if secret == nil { - return nil, errors.New("secret is nil") - } - c, ok := secret.Data["ciphertext"] - if !ok { - return nil, errors.New("no ciphertext") - } - ciphertext, ok := c.(string) - if !ok { - return nil, errors.New("invalid ciphertext") - } - if len(ciphertext) == 0 { - return nil, errors.New("empty ciphertext") - } - return []byte(ciphertext), nil -} // Encrypt encrypts the plaintext data using a key stored in HashiCorp Vault. func (a *vaultAEAD) Encrypt(plaintext, associatedData []byte) ([]byte, error) { - // Create an encryption request map according to Vault REST API: - // https://www.vaultproject.io/api/secret/transit/index.html#encrypt-data. - req := map[string]any{ - "plaintext": base64.StdEncoding.EncodeToString(plaintext), - a.associatedDataName: base64.StdEncoding.EncodeToString(associatedData), - } - secret, err := a.client.Write(a.encKeyPath, req) - if err != nil { - return nil, err - } - return extractCiphertext(secret) + return nil, fmt.Errorf("Debian Vault support incomplete") } -func extractPlaintext(secret *api.Secret) ([]byte, error) { - // Note that when a valid ciphertext of the empty string is decrypted, - // secret.Data["plaintext"] may not be set. So we allow that. - if secret == nil { - return []byte{}, nil - } - p, ok := secret.Data["plaintext"] - if !ok { - return []byte{}, nil - } - plaintext64, ok := p.(string) - if !ok { - return nil, errors.New("invalid plaintext") - } - plaintext, err := base64.StdEncoding.DecodeString(plaintext64) - if err != nil { - return nil, err - } - return plaintext, nil -} // Decrypt decrypts the ciphertext using a key stored in HashiCorp Vault. func (a *vaultAEAD) Decrypt(ciphertext, associatedData []byte) ([]byte, error) { - // Create a decryption request map according to Vault REST API: - // https://www.vaultproject.io/api/secret/transit/index.html#decrypt-data. - req := map[string]any{ - "ciphertext": string(ciphertext), - a.associatedDataName: base64.StdEncoding.EncodeToString(associatedData), - } - secret, err := a.client.Write(a.decKeyPath, req) - if err != nil { - return nil, err - } - return extractPlaintext(secret) + return nil, fmt.Errorf("Debian Vault support incomplete") } // getEndpointPaths transforms keyPath into the Vault transit encrypt and decrypt diff --git a/integration/hcvault/hcvault_client.go b/integration/hcvault/hcvault_client.go index 6b11997..9ea7948 100644 --- a/integration/hcvault/hcvault_client.go +++ b/integration/hcvault/hcvault_client.go @@ -21,11 +21,9 @@ import ( "crypto/tls" "errors" "fmt" - "net/http" "net/url" "strings" - "github.com/hashicorp/vault/api" "github.com/tink-crypto/tink-go/v2/core/registry" "github.com/tink-crypto/tink-go/v2/tink" ) @@ -37,28 +35,11 @@ const ( // vaultClient represents a client that connects to the HashiCorp Vault backend. type vaultClient struct { keyURIPrefix string - client *api.Logical aeadOpts []AEADOption } var _ registry.KMSClient = (*vaultClient)(nil) -// NewClientWithAEADOptions returns a new client. -// uriPrefix parameter is a valid URI which must have "hcvault" scheme and -// vault server address and port. Specific key URIs will be matched against this -// prefix to determine if the client supports the key or not. -func NewClientWithAEADOptions(uriPrefix string, client *api.Logical, aeadOpts ...AEADOption) (registry.KMSClient, error) { - if !strings.HasPrefix(strings.ToLower(uriPrefix), vaultPrefix) { - return nil, fmt.Errorf("key URI must start with %s", vaultPrefix) - } - - return &vaultClient{ - keyURIPrefix: uriPrefix, - client: client, - aeadOpts: aeadOpts, - }, nil -} - // NewClient returns a new client to HashiCorp Vault. // // # Warning regarding associated data @@ -83,32 +64,7 @@ func NewClientWithAEADOptions(uriPrefix string, client *api.Logical, aeadOpts .. // // Deprecated. Use NewClientWithAEADOptions instead. func NewClient(uriPrefix string, tlsCfg *tls.Config, token string) (registry.KMSClient, error) { - httpClient := api.DefaultConfig().HttpClient - transport := httpClient.Transport.(*http.Transport) - if tlsCfg == nil { - tlsCfg = &tls.Config{} - } else { - tlsCfg = tlsCfg.Clone() - } - transport.TLSClientConfig = tlsCfg - - vurl, err := url.Parse(uriPrefix) - if err != nil { - return nil, err - } - - cfg := &api.Config{ - Address: "https://" + vurl.Host, - HttpClient: httpClient, - } - - client, err := api.NewClient(cfg) - if err != nil { - return nil, err - } - - client.SetToken(token) - return NewClientWithAEADOptions(uriPrefix, client.Logical(), WithLegacyContextParamater()) + return nil, fmt.Errorf("Debian Vault support incomplete") } // Supported returns true if this client does support keyURI. @@ -125,6 +81,5 @@ func (c *vaultClient) GetAEAD(keyURI string) (tink.AEAD, error) { if err != nil || u.Scheme != "hcvault" { return nil, errors.New("malformed keyURI") } - keyPath := u.EscapedPath() - return NewAEAD(keyPath, c.client, c.aeadOpts...) + return nil, fmt.Errorf("Debian Vault support incomplete") }