-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reading GPG keys from files using environment variables (#173)
* Reading GPG keys from files using environment variables * Little refactor * Update crypto_comp_test.go * Little refactor * Fixes after review * Update cleanup.sh * Remove debug string * Added README.md * Fix tests * Fix README.md
- Loading branch information
1 parent
20d67c8
commit 7e7b067
Showing
11 changed files
with
231 additions
and
50 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
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
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
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,56 @@ | ||
package internal | ||
|
||
import ( | ||
"bytes" | ||
"golang.org/x/crypto/openpgp" | ||
"io" | ||
"io/ioutil" | ||
) | ||
|
||
func ReadKey(path string) (io.Reader, error) { | ||
byteData, err := ioutil.ReadFile(path) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return bytes.NewReader(byteData), nil | ||
} | ||
|
||
func ReadPGPKey(path string) (openpgp.EntityList, error) { | ||
gpgKeyReader, err := ReadKey(path) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
entityList, err := openpgp.ReadArmoredKeyRing(gpgKeyReader) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return entityList, nil | ||
} | ||
|
||
func DecryptSecretKey(entityList openpgp.EntityList, passphrase string) error { | ||
passphraseBytes := []byte(passphrase) | ||
|
||
for _, entity := range entityList { | ||
err := entity.PrivateKey.Decrypt(passphraseBytes) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, subKey := range entity.Subkeys { | ||
err := subKey.PrivateKey.Decrypt(passphraseBytes) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return 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
Oops, something went wrong.