Debian Codegraph @

debian/patches/disable-vault.patch

raw
1 From: Simon Josefsson <[email protected]>
2 Date: Thu Dec 11 10:24:09 2025 +0100
3 Subject: [PATCH] Disable vault
4 Forwarded: not-needed
5
6 diff --git a/integration/hcvault/hcvault_aead.go b/integration/hcvault/hcvault_aead.go
7 index 94a7346..4253a10 100644
8 --- a/integration/hcvault/hcvault_aead.go
9 +++ b/integration/hcvault/hcvault_aead.go
10 @@ -15,12 +15,10 @@
11 package hcvault
12
13 import (
14 - "encoding/base64"
15 "errors"
16 "fmt"
17 "strings"
18
19 - "github.com/hashicorp/vault/api"
20 "github.com/tink-crypto/tink-go/v2/tink"
21 )
22
23 @@ -28,7 +26,6 @@ import (
24 type vaultAEAD struct {
25 encKeyPath string
26 decKeyPath string
27 - client *api.Logical
28 associatedDataName string
29 }
30
31 @@ -80,97 +77,16 @@ func WithLegacyContextParamater() AEADOption {
32 })
33 }
34
35 -// NewAEAD returns a new remote AEAD primitive for a HashiCorp Vault service.
36 -func NewAEAD(keyPath string, client *api.Logical, opts ...AEADOption) (tink.AEAD, error) {
37 - params := &aeadParams{
38 - associatedDataName: defaultAssociatedDataName,
39 - }
40 - // Process options, if any.
41 - for _, opt := range opts {
42 - if err := opt.set(params); err != nil {
43 - return nil, fmt.Errorf("failed setting option: %v", err)
44 - }
45 - }
46 - encKeyPath, decKeyPath, err := getEndpointPaths(keyPath)
47 - if err != nil {
48 - return nil, err
49 - }
50 - a := &vaultAEAD{
51 - encKeyPath: encKeyPath,
52 - decKeyPath: decKeyPath,
53 - client: client,
54 - associatedDataName: params.associatedDataName,
55 - }
56 - return a, nil
57 -}
58 -
59 -func extractCiphertext(secret *api.Secret) ([]byte, error) {
60 - if secret == nil {
61 - return nil, errors.New("secret is nil")
62 - }
63 - c, ok := secret.Data["ciphertext"]
64 - if !ok {
65 - return nil, errors.New("no ciphertext")
66 - }
67 - ciphertext, ok := c.(string)
68 - if !ok {
69 - return nil, errors.New("invalid ciphertext")
70 - }
71 - if len(ciphertext) == 0 {
72 - return nil, errors.New("empty ciphertext")
73 - }
74 - return []byte(ciphertext), nil
75 -}
76
77 // Encrypt encrypts the plaintext data using a key stored in HashiCorp Vault.
78 func (a *vaultAEAD) Encrypt(plaintext, associatedData []byte) ([]byte, error) {
79 - // Create an encryption request map according to Vault REST API:
80 - // https://www.vaultproject.io/api/secret/transit/index.html#encrypt-data.
81 - req := map[string]any{
82 - "plaintext": base64.StdEncoding.EncodeToString(plaintext),
83 - a.associatedDataName: base64.StdEncoding.EncodeToString(associatedData),
84 - }
85 - secret, err := a.client.Write(a.encKeyPath, req)
86 - if err != nil {
87 - return nil, err
88 - }
89 - return extractCiphertext(secret)
90 + return nil, fmt.Errorf("Debian Vault support incomplete")
91 }
92
93 -func extractPlaintext(secret *api.Secret) ([]byte, error) {
94 - // Note that when a valid ciphertext of the empty string is decrypted,
95 - // secret.Data["plaintext"] may not be set. So we allow that.
96 - if secret == nil {
97 - return []byte{}, nil
98 - }
99 - p, ok := secret.Data["plaintext"]
100 - if !ok {
101 - return []byte{}, nil
102 - }
103 - plaintext64, ok := p.(string)
104 - if !ok {
105 - return nil, errors.New("invalid plaintext")
106 - }
107 - plaintext, err := base64.StdEncoding.DecodeString(plaintext64)
108 - if err != nil {
109 - return nil, err
110 - }
111 - return plaintext, nil
112 -}
113
114 // Decrypt decrypts the ciphertext using a key stored in HashiCorp Vault.
115 func (a *vaultAEAD) Decrypt(ciphertext, associatedData []byte) ([]byte, error) {
116 - // Create a decryption request map according to Vault REST API:
117 - // https://www.vaultproject.io/api/secret/transit/index.html#decrypt-data.
118 - req := map[string]any{
119 - "ciphertext": string(ciphertext),
120 - a.associatedDataName: base64.StdEncoding.EncodeToString(associatedData),
121 - }
122 - secret, err := a.client.Write(a.decKeyPath, req)
123 - if err != nil {
124 - return nil, err
125 - }
126 - return extractPlaintext(secret)
127 + return nil, fmt.Errorf("Debian Vault support incomplete")
128 }
129
130 // getEndpointPaths transforms keyPath into the Vault transit encrypt and decrypt
131 diff --git a/integration/hcvault/hcvault_client.go b/integration/hcvault/hcvault_client.go
132 index 6b11997..9ea7948 100644
133 --- a/integration/hcvault/hcvault_client.go
134 +++ b/integration/hcvault/hcvault_client.go
135 @@ -21,11 +21,9 @@ import (
136 "crypto/tls"
137 "errors"
138 "fmt"
139 - "net/http"
140 "net/url"
141 "strings"
142
143 - "github.com/hashicorp/vault/api"
144 "github.com/tink-crypto/tink-go/v2/core/registry"
145 "github.com/tink-crypto/tink-go/v2/tink"
146 )
147 @@ -37,28 +35,11 @@ const (
148 // vaultClient represents a client that connects to the HashiCorp Vault backend.
149 type vaultClient struct {
150 keyURIPrefix string
151 - client *api.Logical
152 aeadOpts []AEADOption
153 }
154
155 var _ registry.KMSClient = (*vaultClient)(nil)
156
157 -// NewClientWithAEADOptions returns a new client.
158 -// uriPrefix parameter is a valid URI which must have "hcvault" scheme and
159 -// vault server address and port. Specific key URIs will be matched against this
160 -// prefix to determine if the client supports the key or not.
161 -func NewClientWithAEADOptions(uriPrefix string, client *api.Logical, aeadOpts ...AEADOption) (registry.KMSClient, error) {
162 - if !strings.HasPrefix(strings.ToLower(uriPrefix), vaultPrefix) {
163 - return nil, fmt.Errorf("key URI must start with %s", vaultPrefix)
164 - }
165 -
166 - return &vaultClient{
167 - keyURIPrefix: uriPrefix,
168 - client: client,
169 - aeadOpts: aeadOpts,
170 - }, nil
171 -}
172 -
173 // NewClient returns a new client to HashiCorp Vault.
174 //
175 // # Warning regarding associated data
176 @@ -83,32 +64,7 @@ func NewClientWithAEADOptions(uriPrefix string, client *api.Logical, aeadOpts ..
177 //
178 // Deprecated. Use NewClientWithAEADOptions instead.
179 func NewClient(uriPrefix string, tlsCfg *tls.Config, token string) (registry.KMSClient, error) {
180 - httpClient := api.DefaultConfig().HttpClient
181 - transport := httpClient.Transport.(*http.Transport)
182 - if tlsCfg == nil {
183 - tlsCfg = &tls.Config{}
184 - } else {
185 - tlsCfg = tlsCfg.Clone()
186 - }
187 - transport.TLSClientConfig = tlsCfg
188 -
189 - vurl, err := url.Parse(uriPrefix)
190 - if err != nil {
191 - return nil, err
192 - }
193 -
194 - cfg := &api.Config{
195 - Address: "https://" + vurl.Host,
196 - HttpClient: httpClient,
197 - }
198 -
199 - client, err := api.NewClient(cfg)
200 - if err != nil {
201 - return nil, err
202 - }
203 -
204 - client.SetToken(token)
205 - return NewClientWithAEADOptions(uriPrefix, client.Logical(), WithLegacyContextParamater())
206 + return nil, fmt.Errorf("Debian Vault support incomplete")
207 }
208
209 // Supported returns true if this client does support keyURI.
210 @@ -125,6 +81,5 @@ func (c *vaultClient) GetAEAD(keyURI string) (tink.AEAD, error) {
211 if err != nil || u.Scheme != "hcvault" {
212 return nil, errors.New("malformed keyURI")
213 }
214 - keyPath := u.EscapedPath()
215 - return NewAEAD(keyPath, c.client, c.aeadOpts...)
216 + return nil, fmt.Errorf("Debian Vault support incomplete")
217 }