Skip to content

Commit 65966ee

Browse files
authored
Upgrade to Go 1.18 and update dependencies (#239)
1 parent 22443bc commit 65966ee

File tree

183 files changed

+22937
-4660
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+22937
-4660
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
go: [1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x]
15+
go: [1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x]
1616
steps:
1717
- uses: actions/checkout@v2
1818

apns2/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"os"
88
"strings"
99

10+
"github.com/alecthomas/kingpin"
1011
"github.com/sideshow/apns2"
1112
"github.com/sideshow/apns2/certificate"
12-
"gopkg.in/alecthomas/kingpin.v2"
1313
)
1414

1515
var (

certificate/certificate.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
// Possible errors when parsing a certificate.
1818
var (
19-
ErrFailedToDecryptKey = errors.New("failed to decrypt private key")
2019
ErrFailedToParsePrivateKey = errors.New("failed to parse private key")
2120
ErrFailedToParseCertificate = errors.New("failed to parse certificate PEM data")
2221
ErrNoPrivateKey = errors.New("no private key")
@@ -56,11 +55,10 @@ func FromP12Bytes(bytes []byte, password string) (tls.Certificate, error) {
5655
// FromPemFile loads a PEM certificate from a local file and returns a
5756
// tls.Certificate. This function is similar to the crypto/tls LoadX509KeyPair
5857
// function, however it supports PEM files with the cert and key combined
59-
// in the same file, as well as password protected key files which are both
60-
// common with APNs certificates.
58+
// in the same file. It does not support password-protected key files due
59+
// to security concerns with the deprecated PEM encryption method.
6160
//
62-
// Use "" as the password argument if the PEM certificate is not password
63-
// protected.
61+
// The password argument is kept for backwards compatibility but is no longer used.
6462
func FromPemFile(filename string, password string) (tls.Certificate, error) {
6563
bytes, err := os.ReadFile(filename)
6664
if err != nil {
@@ -109,13 +107,6 @@ func FromPemBytes(bytes []byte, password string) (tls.Certificate, error) {
109107
}
110108

111109
func unencryptPrivateKey(block *pem.Block, password string) (crypto.PrivateKey, error) {
112-
if x509.IsEncryptedPEMBlock(block) {
113-
bytes, err := x509.DecryptPEMBlock(block, []byte(password))
114-
if err != nil {
115-
return nil, ErrFailedToDecryptKey
116-
}
117-
return parsePrivateKey(bytes)
118-
}
119110
return parsePrivateKey(block.Bytes)
120111
}
121112

certificate/certificate_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@ func TestValidCertificateFromPemBytesWithPKCS8PrivateKey(t *testing.T) {
7070
assert.NoError(t, err)
7171
assert.NotEqual(t, tls.Certificate{}, cer)
7272
}
73-
74-
func TestEncryptedValidCertificateFromPemFile(t *testing.T) {
75-
cer, err := certificate.FromPemFile("_fixtures/certificate-valid-encrypted.pem", "password")
76-
assert.NoError(t, err)
77-
assert.NotEqual(t, tls.Certificate{}, cer)
73+
func TestUnsupportedEncryptedCertificateFromPemFile(t *testing.T) {
74+
cer, err := certificate.FromPemFile("_fixtures/certificate-legacy-encrypted-unsupported.pem", "password")
75+
assert.Equal(t, tls.Certificate{}, cer)
76+
assert.Equal(t, certificate.ErrFailedToParsePrivateKey, err)
7877
}
7978

8079
func TestNoSuchFilePemFile(t *testing.T) {
@@ -83,12 +82,6 @@ func TestNoSuchFilePemFile(t *testing.T) {
8382
assert.Equal(t, errors.New("open : no such file or directory").Error(), err.Error())
8483
}
8584

86-
func TestBadPasswordPemFile(t *testing.T) {
87-
cer, err := certificate.FromPemFile("_fixtures/certificate-valid-encrypted.pem", "badpassword")
88-
assert.Equal(t, tls.Certificate{}, cer)
89-
assert.Equal(t, certificate.ErrFailedToDecryptKey, err)
90-
}
91-
9285
func TestBadKeyPemFile(t *testing.T) {
9386
cer, err := certificate.FromPemFile("_fixtures/certificate-bad-key.pem", "")
9487
assert.Equal(t, tls.Certificate{}, cer)

client.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ func NewClient(certificate tls.Certificate) *Client {
9292
tlsConfig := &tls.Config{
9393
Certificates: []tls.Certificate{certificate},
9494
}
95-
if len(certificate.Certificate) > 0 {
96-
tlsConfig.BuildNameToCertificate()
97-
}
9895
transport := &http2.Transport{
9996
TLSClientConfig: tlsConfig,
10097
DialTLS: DialTLS,

client_test.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"net"
1313
"net/http"
1414
"net/http/httptest"
15-
"strings"
1615
"testing"
1716
"time"
1817

@@ -116,33 +115,52 @@ func TestClientBadDeviceToken(t *testing.T) {
116115
func TestClientNameToCertificate(t *testing.T) {
117116
crt, _ := certificate.FromP12File("certificate/_fixtures/certificate-valid.p12", "")
118117
client := apns.NewClient(crt)
119-
name := client.HTTPClient.Transport.(*http2.Transport).TLSClientConfig.NameToCertificate
120-
assert.Len(t, name, 1)
121118

119+
// Check if the client's certificate is set correctly
120+
clientCerts := client.HTTPClient.Transport.(*http2.Transport).TLSClientConfig.Certificates
121+
assert.Len(t, clientCerts, 1)
122+
assert.Equal(t, crt, clientCerts[0])
123+
124+
// Test with an empty certificate
122125
certificate2 := tls.Certificate{}
123126
client2 := apns.NewClient(certificate2)
124-
name2 := client2.HTTPClient.Transport.(*http2.Transport).TLSClientConfig.NameToCertificate
125-
assert.Len(t, name2, 0)
127+
128+
// Check if the client's certificate is empty
129+
clientCerts2 := client2.HTTPClient.Transport.(*http2.Transport).TLSClientConfig.Certificates
130+
assert.Len(t, clientCerts2, 1)
131+
assert.Equal(t, certificate2, clientCerts2[0])
126132
}
127133

128134
func TestDialTLSTimeout(t *testing.T) {
129135
apns.TLSDialTimeout = 10 * time.Millisecond
130136
crt, _ := certificate.FromP12File("certificate/_fixtures/certificate-valid.p12", "")
131137
client := apns.NewClient(crt)
132-
dialTLS := client.HTTPClient.Transport.(*http2.Transport).DialTLS
138+
139+
// Replace the DialTLS with DialTLSContext
140+
transport := client.HTTPClient.Transport.(*http2.Transport)
141+
transport.DialTLSContext = func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) {
142+
dialer := &net.Dialer{
143+
Timeout: apns.TLSDialTimeout,
144+
}
145+
return tls.DialWithDialer(dialer, network, addr, nil)
146+
}
147+
133148
listener, err := net.Listen("tcp", "127.0.0.1:0")
134149
if err != nil {
135150
t.Fatal(err)
136151
}
137152
address := listener.Addr().String()
138153
defer listener.Close()
154+
155+
ctx, cancel := context.WithTimeout(context.Background(), apns.TLSDialTimeout)
156+
defer cancel()
157+
139158
var e error
140-
if _, e = dialTLS("tcp", address, nil); e == nil {
159+
if _, e = transport.DialTLSContext(ctx, "tcp", address, nil); e == nil {
141160
t.Fatal("Dial completed successfully")
142161
}
143-
// Go 1.7.x and later will return a context deadline exceeded error
144-
// Previous versions will return a time out
145-
if !strings.Contains(e.Error(), "timed out") && !errors.Is(e, context.DeadlineExceeded) {
162+
163+
if !errors.Is(e, context.DeadlineExceeded) {
146164
t.Errorf("Unexpected error: %s", e)
147165
}
148166
}

go.mod

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
module github.com/sideshow/apns2
22

3-
go 1.15
3+
go 1.18
4+
5+
require (
6+
github.com/alecthomas/kingpin v2.2.6+incompatible
7+
github.com/golang-jwt/jwt/v5 v5.2.1
8+
golang.org/x/crypto v0.31.0
9+
golang.org/x/net v0.33.0
10+
)
411

512
require (
613
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
7-
github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4 // indirect
8-
github.com/golang-jwt/jwt/v4 v4.4.1
9-
github.com/stretchr/testify v1.7.0
10-
golang.org/x/crypto v0.0.0-20170512130425-ab89591268e0
11-
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b
12-
gopkg.in/alecthomas/kingpin.v2 v2.2.6
14+
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect
15+
github.com/davecgh/go-spew v1.1.1 // indirect
16+
github.com/pmezard/go-difflib v1.0.0 // indirect
17+
github.com/stretchr/testify v1.10.0 // indirect
18+
golang.org/x/text v0.21.0 // indirect
19+
gopkg.in/yaml.v3 v3.0.1 // indirect
1320
)

go.sum

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1+
github.com/alecthomas/kingpin v2.2.6+incompatible h1:5svnBTFgJjZvGKyYBtMB0+m5wvrbUHiqye8wRJMlnYI=
2+
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
13
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
24
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3-
github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4 h1:EBTWhcAX7rNQ80RLwLCpHZBBrJuzallFHnF+yMXo928=
4-
github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
5-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
5+
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b h1:mimo19zliBX/vSQ6PWWSL9lK8qwHozUj03+zLoEB8O0=
6+
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b/go.mod h1:fvzegU4vN3H1qMT+8wDmzjAcDONcgo2/SZ/TyfdUOFs=
67
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7-
github.com/golang-jwt/jwt/v4 v4.4.1 h1:pC5DB52sCeK48Wlb9oPcdhnjkz1TKt1D/P7WKJ0kUcQ=
8-
github.com/golang-jwt/jwt/v4 v4.4.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
8+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10+
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
11+
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
912
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1013
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1114
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
12-
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
13-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
14-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
15-
golang.org/x/crypto v0.0.0-20170512130425-ab89591268e0 h1:Kv0JVjoWyBVkLETNHnV/PxoZcMP3J7+WTc6+QQnzZmY=
16-
golang.org/x/crypto v0.0.0-20170512130425-ab89591268e0/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
17-
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b h1:vI32FkLJNAWtGD4BwkThwEy6XS7ZLLMHkSkYfF8M0W0=
18-
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
19-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20-
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
21-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
22-
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
23-
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
24-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
25-
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
26-
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
27-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
15+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
16+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
17+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
18+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
19+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
20+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
21+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
22+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
23+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
24+
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
25+
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
26+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
27+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
28+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
29+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
2830
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
29-
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
30-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
3131
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
32+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
33+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

token/token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"sync"
1010
"time"
1111

12-
"github.com/golang-jwt/jwt/v4"
12+
"github.com/golang-jwt/jwt/v5"
1313
)
1414

1515
const (

0 commit comments

Comments
 (0)