Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
gpgx: only decrypt private key if it has a password
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Jun 15, 2020
1 parent 7d0089f commit 4cc5b73
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 6 additions & 2 deletions internal/gpgx/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ func ReadPrivateKeyFile(path string, password []byte) (openpgp.EntityList, error
entity := entityList[0]

// Get the passphrase and read the private key.
entity.PrivateKey.Decrypt(password)
if entity.PrivateKey != nil && len(password) > 0 {
entity.PrivateKey.Decrypt(password)
}
for _, subkey := range entity.Subkeys {
subkey.PrivateKey.Decrypt(password)
if subkey.PrivateKey != nil && len(password) > 0 {
subkey.PrivateKey.Decrypt(password)
}
}

return entityList, nil
Expand Down
1 change: 0 additions & 1 deletion internal/gpgx/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package gpgx

import (
"io/ioutil"
"path/filepath"
"testing"
)
Expand Down

0 comments on commit 4cc5b73

Please sign in to comment.