@@ -14,6 +14,8 @@ package age
1414import (
1515 "bufio"
1616 "bytes"
17+ "crypto/sha256"
18+ "encoding/base64"
1719 "errors"
1820 "fmt"
1921 "io"
@@ -124,6 +126,8 @@ func unwrapIdentities(location string, reader io.Reader) (ParsedIdentities, erro
124126 if len (contents ) == privateKeySizeLimit {
125127 return nil , fmt .Errorf ("failed to read '%s': file too long" , location )
126128 }
129+ contentsHash := sha256 .Sum256 (contents )
130+ cacheKey := fmt .Sprintf ("SopsAge%s" , base64 .StdEncoding .EncodeToString (contentsHash [:30 ]))
127131 IncorrectPassphrase := func () {
128132 conn , err := gpgagent .NewConn ()
129133 if err != nil {
@@ -134,7 +138,7 @@ func unwrapIdentities(location string, reader io.Reader) (ParsedIdentities, erro
134138 log .Errorf ("failed to close connection with gpg-agent: %s" , err )
135139 }
136140 }(conn )
137- err = conn .RemoveFromCache (location )
141+ err = conn .RemoveFromCache (cacheKey )
138142 if err != nil {
139143 log .Warnf ("gpg-agent remove cache request errored: %s" , err )
140144 return
@@ -154,8 +158,7 @@ func unwrapIdentities(location string, reader io.Reader) (ParsedIdentities, erro
154158 }(conn )
155159
156160 req := gpgagent.PassphraseRequest {
157- // TODO is the cachekey good enough?
158- CacheKey : location ,
161+ CacheKey : cacheKey ,
159162 Prompt : "Passphrase" ,
160163 Desc : fmt .Sprintf ("Enter passphrase for identity '%s':" , location ),
161164 }
0 commit comments