Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions age/encrypted_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ package age
import (
"bufio"
"bytes"
"crypto/sha256"
"encoding/base64"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -124,6 +126,8 @@ func unwrapIdentities(location string, reader io.Reader) (ParsedIdentities, erro
if len(contents) == privateKeySizeLimit {
return nil, fmt.Errorf("failed to read '%s': file too long", location)
}
contentsHash := sha256.Sum256(contents)
cacheKey := fmt.Sprintf("SopsAge%s", base64.StdEncoding.EncodeToString(contentsHash[:30]))
IncorrectPassphrase := func() {
conn, err := gpgagent.NewConn()
if err != nil {
Expand All @@ -134,7 +138,7 @@ func unwrapIdentities(location string, reader io.Reader) (ParsedIdentities, erro
log.Errorf("failed to close connection with gpg-agent: %s", err)
}
}(conn)
err = conn.RemoveFromCache(location)
err = conn.RemoveFromCache(cacheKey)
if err != nil {
log.Warnf("gpg-agent remove cache request errored: %s", err)
return
Expand All @@ -154,8 +158,7 @@ func unwrapIdentities(location string, reader io.Reader) (ParsedIdentities, erro
}(conn)

req := gpgagent.PassphraseRequest{
// TODO is the cachekey good enough?
CacheKey: location,
CacheKey: cacheKey,
Prompt: "Passphrase",
Desc: fmt.Sprintf("Enter passphrase for identity '%s':", location),
}
Expand Down
Loading