2 Commits

Author SHA1 Message Date
72f6073e47 feat: use armored gpg signature
Some checks failed
Cadoles/go-http-peering/pipeline/head There was a failure building this commit
2024-01-04 11:35:30 +01:00
1bf8d755ed fix: load dek header-less private keys
Some checks reported warnings
Cadoles/go-http-peering/pipeline/head This commit is unstable
2023-11-21 14:13:32 +01:00
2 changed files with 12 additions and 13 deletions

View File

@ -9,6 +9,7 @@ import (
jwt "github.com/dgrijalva/jwt-go"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh"
)
func EncodePublicKeyToPEM(key crypto.PublicKey) ([]byte, error) {
@ -28,25 +29,23 @@ func DecodePEMToPublicKey(pem []byte) (crypto.PublicKey, error) {
}
func DecodePEMEncryptedPrivateKey(key []byte, passphrase []byte) (*rsa.PrivateKey, error) {
// Parse PEM block
var block *pem.Block
if block, _ = pem.Decode(key); block == nil {
return nil, errors.New("invalid PEM block")
}
var (
rawKey interface{}
err error
)
decryptedBlock, err := x509.DecryptPEMBlock(block, passphrase)
if len(passphrase) == 0 {
rawKey, err = ssh.ParseRawPrivateKey(key)
} else {
rawKey, err = ssh.ParseRawPrivateKeyWithPassphrase(key, passphrase)
}
if err != nil {
return nil, errors.WithStack(err)
}
var parsedKey interface{}
if parsedKey, err = x509.ParsePKCS1PrivateKey(decryptedBlock); err != nil {
return nil, errors.WithStack(err)
}
var privateKey *rsa.PrivateKey
var ok bool
if privateKey, ok = parsedKey.(*rsa.PrivateKey); !ok {
if privateKey, ok = rawKey.(*rsa.PrivateKey); !ok {
return nil, errors.New("invalid RSA private key")
}

View File

@ -39,7 +39,7 @@ function build {
if [ ! -z "${GPG_SIGNING_KEY}" ]; then
echo "signing '$destdir/$name' with gpg key '$GPG_SIGNING_KEY'..."
gpg --sign --default-key "${GPG_SIGNING_KEY}" --detach-sign --output "$destdir/$name.sig" "$destdir/$name"
gpg --sign --default-key "${GPG_SIGNING_KEY}" --armor --detach-sign --output "$destdir/$name.sig" "$destdir/$name"
fi
}