Skip to content

Commit e45ead2

Browse files
cpuDaniel
andauthored
deps: update /x/crypto, fix Go 1.13 test breakage. (#1081)
* deps: update /x/crypto to 8b5121be2f68 * helpers/derhelpers: split Go 1.12/1.13 impls. When using modern `golang.org/x/crypto/ed25519` on Go 1.13 the `x` library is a small wrapper around the stdlib version. The helper function needs to match on the stdlib type in this case. To maintain backwards compat with Go 1.12 the helper code is split by a build tag. The legacy code can use the `golang.org/x/crypto/ed25519` import while the new code can use the `crypto/ed25519` import. Co-authored-by: Daniel <cpu@letsencrypt.org>
1 parent 10ed8da commit e45ead2

File tree

9 files changed

+61
-89
lines changed

9 files changed

+61
-89
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/ziutek/mymysql v1.5.4 // indirect
2626
github.com/zmap/zcrypto v0.0.0-20190729165852-9051775e6a2e
2727
github.com/zmap/zlint v0.0.0-20190806154020-fd021b4cfbeb
28-
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
28+
golang.org/x/crypto v0.0.0-20200124225646-8b5121be2f68
2929
golang.org/x/lint v0.0.0-20190930215403-16217165b5de
3030
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
3131
golang.org/x/text v0.3.2 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
8282
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
8383
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
8484
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
85+
golang.org/x/crypto v0.0.0-20200124225646-8b5121be2f68 h1:WPLCzSEbawp58wezcvLvLnvhiDJAai54ESbc41NdXS0=
86+
golang.org/x/crypto v0.0.0-20200124225646-8b5121be2f68/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
8587
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
8688
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
8789
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// +build !go1.13
2+
3+
// Package derhelpers implements common functionality
4+
// on DER encoded data
5+
package derhelpers
6+
7+
import (
8+
"crypto"
9+
"crypto/ecdsa"
10+
"crypto/rsa"
11+
"crypto/x509"
12+
13+
cferr "github.com/cloudflare/cfssl/errors"
14+
"golang.org/x/crypto/ed25519"
15+
)
16+
17+
// ParsePrivateKeyDER parses a PKCS #1, PKCS #8, ECDSA, or Ed25519 DER-encoded
18+
// private key. The key must not be in PEM format.
19+
func ParsePrivateKeyDER(keyDER []byte) (key crypto.Signer, err error) {
20+
generalKey, err := x509.ParsePKCS8PrivateKey(keyDER)
21+
if err != nil {
22+
generalKey, err = x509.ParsePKCS1PrivateKey(keyDER)
23+
if err != nil {
24+
generalKey, err = x509.ParseECPrivateKey(keyDER)
25+
if err != nil {
26+
generalKey, err = ParseEd25519PrivateKey(keyDER)
27+
if err != nil {
28+
// We don't include the actual error into
29+
// the final error. The reason might be
30+
// we don't want to leak any info about
31+
// the private key.
32+
return nil, cferr.New(cferr.PrivateKeyError,
33+
cferr.ParseFailed)
34+
}
35+
}
36+
}
37+
}
38+
39+
switch generalKey.(type) {
40+
case *rsa.PrivateKey:
41+
return generalKey.(*rsa.PrivateKey), nil
42+
case *ecdsa.PrivateKey:
43+
return generalKey.(*ecdsa.PrivateKey), nil
44+
case ed25519.PrivateKey:
45+
return generalKey.(ed25519.PrivateKey), nil
46+
}
47+
48+
// should never reach here
49+
return nil, cferr.New(cferr.PrivateKeyError, cferr.ParseFailed)
50+
}

helpers/derhelpers/derhelpers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
// +build go1.13
2+
13
// Package derhelpers implements common functionality
24
// on DER encoded data
35
package derhelpers
46

57
import (
68
"crypto"
79
"crypto/ecdsa"
10+
"crypto/ed25519"
811
"crypto/rsa"
912
"crypto/x509"
1013

1114
cferr "github.com/cloudflare/cfssl/errors"
12-
"golang.org/x/crypto/ed25519"
1315
)
1416

1517
// ParsePrivateKeyDER parses a PKCS #1, PKCS #8, ECDSA, or Ed25519 DER-encoded

vendor/golang.org/x/crypto/cryptobyte/asn1.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/cryptobyte/string.go

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/ed25519/ed25519.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/ed25519/ed25519_go113.go

Lines changed: 0 additions & 73 deletions
This file was deleted.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ github.com/zmap/zcrypto/x509/pkix
9494
github.com/zmap/zlint
9595
github.com/zmap/zlint/lints
9696
github.com/zmap/zlint/util
97-
# golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
97+
# golang.org/x/crypto v0.0.0-20200124225646-8b5121be2f68
9898
golang.org/x/crypto/cryptobyte
9999
golang.org/x/crypto/cryptobyte/asn1
100100
golang.org/x/crypto/ed25519

0 commit comments

Comments
 (0)