1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00

age: .sops.yaml support

This commit is contained in:
Cole Mickens
2020-08-07 01:58:17 -07:00
committed by Jimmy Cuadra
parent 6068838aa3
commit 50a89c8293
2 changed files with 32 additions and 2 deletions

View File

@@ -11,8 +11,16 @@ import (
"strings"
"filippo.io/age"
"github.com/sirupsen/logrus"
"go.mozilla.org/sops/v3/logging"
)
var log *logrus.Logger
func init() {
log = logging.NewLogger("AGE")
}
const privateKeySizeLimit = 1 << 24 // 16 MiB
// MasterKey is an age key used to encrypt and decrypt sops' data key.
@@ -33,6 +41,7 @@ func (key *MasterKey) Encrypt(datakey []byte) error {
parsedRecipient, err := parseRecipient(key.Recipient)
if err != nil {
log.WithField("recipient", key.parsedRecipient).Error("Encryption failed")
return err
}
@@ -40,20 +49,23 @@ func (key *MasterKey) Encrypt(datakey []byte) error {
}
w, err := age.Encrypt(buffer, key.parsedRecipient)
if err != nil {
return fmt.Errorf("failed to open file for encrypting sops data key with age: %v", err)
}
if _, err := w.Write(datakey); err != nil {
log.WithField("recipient", key.parsedRecipient).Error("Encryption failed")
return fmt.Errorf("failed to encrypt sops data key with age: %v", err)
}
if err := w.Close(); err != nil {
log.WithField("recipient", key.parsedRecipient).Error("Encryption failed")
return fmt.Errorf("failed to close file for encrypting sops data key with age: %v", err)
}
key.EncryptedKey = buffer.String()
log.WithField("recipient", key.parsedRecipient).Info("Encryption succeeded")
return nil
}