shared: Decrypt signed file

Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
This commit is contained in:
Thomas Hipp 2019-02-26 16:29:34 +01:00
parent 7bd8c43fd2
commit 164decd43f
No known key found for this signature in database
GPG Key ID: 993408D1137B7D51

View File

@ -78,6 +78,25 @@ func RunScript(content string) error {
return cmd.Run()
}
// GetSignedContent verifies the provided file, and returns its decrypted (plain) content.
func GetSignedContent(signedFile string, keys []string, keyserver string) ([]byte, error) {
keyring, err := CreateGPGKeyring(keyserver, keys)
if err != nil {
return nil, err
}
gpgDir := path.Dir(keyring)
defer os.RemoveAll(gpgDir)
out, err := exec.Command("gpg", "--homedir", gpgDir, "--keyring", keyring,
"--decrypt", signedFile).Output()
if err != nil {
return nil, fmt.Errorf("Failed to get file content: %v", err)
}
return out, nil
}
// VerifyFile verifies a file using gpg.
func VerifyFile(signedFile, signatureFile string, keys []string, keyserver string) (bool, error) {
keyring, err := CreateGPGKeyring(keyserver, keys)