Skip to content

Commit 08b827c

Browse files
authored
add label to secrets encryption (#188)
* add label to secrets encryption * left pad 12 0s
1 parent 81202be commit 08b827c

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

cmd/secrets/common/handler.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (h *Handler) EncryptSecrets(rawSecrets UpsertSecretsInputs) ([]*vault.Encry
261261

262262
encryptedSecrets := make([]*vault.EncryptedSecret, 0, len(rawSecrets))
263263
for _, item := range rawSecrets {
264-
cipherHex, err := EncryptSecret(item.Value, pubKeyHex)
264+
cipherHex, err := EncryptSecret(item.Value, pubKeyHex, h.OwnerAddress)
265265
if err != nil {
266266
return nil, fmt.Errorf("failed to encrypt secret (key=%s ns=%s): %w", item.ID, item.Namespace, err)
267267
}
@@ -278,7 +278,7 @@ func (h *Handler) EncryptSecrets(rawSecrets UpsertSecretsInputs) ([]*vault.Encry
278278
return encryptedSecrets, nil
279279
}
280280

281-
func EncryptSecret(secret, masterPublicKeyHex string) (string, error) {
281+
func EncryptSecret(secret, masterPublicKeyHex string, ownerAddress string) (string, error) {
282282
masterPublicKey := tdh2easy.PublicKey{}
283283
masterPublicKeyBytes, err := hex.DecodeString(masterPublicKeyHex)
284284
if err != nil {
@@ -287,7 +287,11 @@ func EncryptSecret(secret, masterPublicKeyHex string) (string, error) {
287287
if err = masterPublicKey.Unmarshal(masterPublicKeyBytes); err != nil {
288288
return "", fmt.Errorf("failed to unmarshal master public key: %w", err)
289289
}
290-
cipher, err := tdh2easy.Encrypt(&masterPublicKey, []byte(secret))
290+
291+
addr := common.HexToAddress(ownerAddress) // canonical 20-byte address
292+
var label [32]byte
293+
copy(label[12:], addr.Bytes()) // left-pad with 12 zero bytes
294+
cipher, err := tdh2easy.EncryptWithLabel(&masterPublicKey, []byte(secret), label)
291295
if err != nil {
292296
return "", fmt.Errorf("failed to encrypt secret: %w", err)
293297
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/smartcontractkit/chainlink/v2 v2.29.1-cre-beta.0.0.20251105185833-fd628ed29848
3333
github.com/smartcontractkit/cre-sdk-go v1.0.0
3434
github.com/smartcontractkit/cre-sdk-go/capabilities/blockchain/evm v1.0.0-beta.0
35-
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20250624150019-e49f7e125e6b
35+
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20251120172354-e8ec0386b06c
3636
github.com/spf13/cobra v1.10.1
3737
github.com/spf13/pflag v1.0.10
3838
github.com/spf13/viper v1.20.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,8 @@ github.com/smartcontractkit/smdkg v0.0.0-20251029093710-c38905e58aeb h1:kLHdQQki
10481048
github.com/smartcontractkit/smdkg v0.0.0-20251029093710-c38905e58aeb/go.mod h1:4s5hj/nlMF9WV+T5Uhy4n9IYpRpzfJzT+vTKkNT7T+Y=
10491049
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20241009055228-33d0c0bf38de h1:n0w0rKF+SVM+S3WNlup6uabXj2zFlFNfrlsKCMMb/co=
10501050
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20241009055228-33d0c0bf38de/go.mod h1:Sl2MF/Fp3fgJIVzhdGhmZZX2BlnM0oUUyBP4s4xYb6o=
1051-
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20250624150019-e49f7e125e6b h1:hN0Aqc20PTMGkYzqJGKIZCZMR4RoFlI85WpbK9fKIns=
1052-
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20250624150019-e49f7e125e6b/go.mod h1:NSc7hgOQbXG3DAwkOdWnZzLTZENXSwDJ7Va1nBp0YU0=
1051+
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20251120172354-e8ec0386b06c h1:S1AFIjfHT95ev6gqHKBGy1zj3Tz0fIN3XzkaDUn77wY=
1052+
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20251120172354-e8ec0386b06c/go.mod h1:NSc7hgOQbXG3DAwkOdWnZzLTZENXSwDJ7Va1nBp0YU0=
10531053
github.com/smartcontractkit/wsrpc v0.8.5-0.20250502134807-c57d3d995945 h1:zxcODLrFytOKmAd8ty8S/XK6WcIEJEgRBaL7sY/7l4Y=
10541054
github.com/smartcontractkit/wsrpc v0.8.5-0.20250502134807-c57d3d995945/go.mod h1:m3pdp17i4bD50XgktkzWetcV5yaLsi7Gunbv4ZgN6qg=
10551055
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=

0 commit comments

Comments
 (0)