Support decoding PKCS#8 keys

These are generated by OpenSSL v3. Previously, key decoding would fail,
breaking federation.

This fixes #14
This commit is contained in:
Matt Baer
2022-11-11 01:56:53 -05:00
parent ab8ed5dd58
commit 73b029dffa
+2 -2
View File
@@ -69,8 +69,8 @@ func parsePublicKey(der []byte) (crypto.PublicKey, error) {
// them in that order. // them in that order.
func DecodePrivateKey(k []byte) (crypto.PrivateKey, error) { func DecodePrivateKey(k []byte) (crypto.PrivateKey, error) {
block, _ := pem.Decode(k) block, _ := pem.Decode(k)
if block == nil || block.Type != "RSA PRIVATE KEY" { if block == nil || (block.Type != "RSA PRIVATE KEY" && block.Type != "PRIVATE KEY") {
return nil, fmt.Errorf("failed to decode PEM block containing private key") return nil, fmt.Errorf("failed to decode PEM block containing private key, type %s", block.Type)
} }
return parsePrivateKey(block.Bytes) return parsePrivateKey(block.Bytes)