@@ -127,6 +127,7 @@ func (a *Agent) List() ([]*agent.Key, error) {
127127 Comment : string (k .Comment ),
128128 })
129129 }
130+
130131 return agentKeys , nil
131132}
132133
@@ -268,35 +269,46 @@ func (a *Agent) Unlock(passphrase []byte) error {
268269}
269270
270271func LoadKeys (keyDir string ) (map [string ]* key.Key , error ) {
271- keys := map [string ]* key.Key {}
272- err := filepath .WalkDir (keyDir ,
273- func (path string , d fs.DirEntry , err error ) error {
274- if err != nil {
275- return err
276- }
277- if d .IsDir () {
278- return nil
279- }
280- if ! strings .HasSuffix (path , "tpm" ) {
281- return nil
282- }
283- f , err := os .ReadFile (path )
284- if err != nil {
285- return fmt .Errorf ("failed reading %s" , path )
286- }
287- k , err := key .DecodeKey (f )
288- if err != nil {
289- slog .Debug ("not a TPM-sealed key" , slog .String ("key_path" , path ), slog .String ("error" , err .Error ()))
290- return nil
291- }
292- keys [k .Fingerprint ()] = k
293- return nil
294- },
295- )
272+ keyDir , err := filepath .EvalSymlinks (keyDir )
296273 if err != nil {
297274 return nil , err
298275 }
299- return keys , nil
276+
277+ keys := make (map [string ]* key.Key )
278+
279+ walkFunc := func (path string , d fs.DirEntry , err error ) error {
280+ if err != nil {
281+ return err
282+ }
283+
284+ if d .IsDir () {
285+ return nil
286+ }
287+
288+ if ! strings .HasSuffix (path , ".tpm" ) {
289+ slog .Debug ("skipping key: does not have .tpm suffix" , slog .String ("name" , path ))
290+ return nil
291+ }
292+
293+ f , err := os .ReadFile (path )
294+ if err != nil {
295+ return fmt .Errorf ("failed reading %s" , path )
296+ }
297+
298+ k , err := key .DecodeKey (f )
299+ if err != nil {
300+ slog .Debug ("not a TPM sealed key" , slog .String ("key_path" , path ), slog .String ("error" , err .Error ()))
301+ return nil
302+ }
303+
304+ keys [k .Fingerprint ()] = k
305+
306+ slog .Debug ("added TPM key" , slog .String ("name" , path ))
307+ return nil
308+ }
309+
310+ err = filepath .WalkDir (keyDir , walkFunc )
311+ return keys , err
300312}
301313
302314func NewAgent (listener * net.UnixListener , agents []agent.ExtendedAgent , tpmFetch func () transport.TPMCloser , pin func (* key.Key ) ([]byte , error )) * Agent {
0 commit comments