Skip to content

Commit a2a78a8

Browse files
JasonPowrAlCutter
authored andcommitted
fix: allow unencrypted PEM
1 parent 23da29f commit a2a78a8

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## HEAD
44

5+
* Allow unencrypted PEM private key files by @JasonPowr
6+
* `ReadPrivateKeyFile` and `FromProto` (via `PEMKeyFile`) now accept an empty password, treating the key as unencrypted. Previously, an empty password was rejected with an error.
57
* Replace deprecated `golang.org/x/crypto/ed25519` with stdlib `crypto/ed25519` by @JasonPowr
68

79
## v1.7.3

crypto/keys/pem/pem.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@ import (
3030
)
3131

3232
// ReadPrivateKeyFile reads a PEM-encoded private key from a file.
33-
// The key must be protected by a password.
33+
// The key may be protected by a password. If password is empty, the key is
34+
// assumed to be unencrypted.
3435
func ReadPrivateKeyFile(file, password string) (crypto.Signer, error) {
35-
if password == "" {
36-
return nil, fmt.Errorf("pemfile: empty password for file %q", file)
37-
}
38-
3936
keyPEM, err := os.ReadFile(file)
4037
if err != nil {
4138
return nil, fmt.Errorf("pemfile: error reading file %q: %v", file, err)

crypto/keys/pem/pem_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func TestLoadPrivateKeyAndSign(t *testing.T) {
7676
keyPath: "../../../testdata/log-rpc-server.privkey.pem",
7777
keyPass: "towel",
7878
},
79+
{
80+
desc: "ECDSA from file without password",
81+
keyPath: "../../../testdata/log-rpc-server-unencrypted.privkey.pem",
82+
},
7983
{
8084
desc: "Non-existent file",
8185
keyPath: "non-existent.pem",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MHcCAQEEIHG5m/q2sUSa4P8pRZgYt3K0ESFSKp1qp15VjJhpLle4oAoGCCqGSM49AwEHoUQDQgAEvuynpVdR+5xSNaVBb//1fqO6Nb/nC+WvRQ4bALzy4G+QbByvO1Qpm2eUzTdDUnsLN5hp3pIXYAmtjvjY1fFZEg==
3+
-----END PRIVATE KEY-----

0 commit comments

Comments
 (0)