-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from smlx/lazy-keyfile-decryption
Lazy decryption for keyfiles
- Loading branch information
Showing
4 changed files
with
53 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package gpg | ||
|
||
import ( | ||
"bytes" | ||
"crypto/ecdsa" | ||
"crypto/rsa" | ||
) | ||
|
||
// HaveKey takes a list of keygrips, and returns a boolean indicating if any of | ||
// the given keygrips were found, the found keygrip, and an error, if any. | ||
func (g *KeyService) HaveKey(keygrips [][]byte) (bool, []byte, error) { | ||
for _, keyfile := range g.privKeys { | ||
for _, privKey := range keyfile.keys { | ||
pubKeyRSA, ok := privKey.PublicKey.PublicKey.(*rsa.PublicKey) | ||
if ok { | ||
for _, kg := range keygrips { | ||
rsaKG, err := keygripRSA(pubKeyRSA) | ||
if err != nil { | ||
return false, nil, err | ||
} | ||
if bytes.Equal(kg, rsaKG) { | ||
return true, kg, nil | ||
} | ||
} | ||
} | ||
pubKeyECDSA, ok := privKey.PublicKey.PublicKey.(*ecdsa.PublicKey) | ||
if ok { | ||
for _, kg := range keygrips { | ||
ecdsaKG, err := KeygripECDSA(pubKeyECDSA) | ||
if err != nil { | ||
return false, nil, err | ||
} | ||
if bytes.Equal(kg, ecdsaKG) { | ||
return true, kg, nil | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return false, nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters