Skip to content

Commit 1ea5f77

Browse files
authored
update to go 1.25, use the cool new ECDSA key marshalling functions (#1483)
* update to go 1.25, use the cool new ECDSA key marshalling functions * bonk the runners * actually bump go.mod * bump golangci-lint
1 parent 4cdeb28 commit 1ea5f77

8 files changed

Lines changed: 23 additions & 27 deletions

File tree

.github/workflows/gofmt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
- uses: actions/setup-go@v5
2020
with:
21-
go-version: '1.24'
21+
go-version: '1.25'
2222
check-latest: true
2323

2424
- name: Install goimports

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
- uses: actions/setup-go@v5
1616
with:
17-
go-version: '1.24'
17+
go-version: '1.25'
1818
check-latest: true
1919

2020
- name: Build
@@ -37,7 +37,7 @@ jobs:
3737

3838
- uses: actions/setup-go@v5
3939
with:
40-
go-version: '1.24'
40+
go-version: '1.25'
4141
check-latest: true
4242

4343
- name: Build
@@ -70,7 +70,7 @@ jobs:
7070

7171
- uses: actions/setup-go@v5
7272
with:
73-
go-version: '1.24'
73+
go-version: '1.25'
7474
check-latest: true
7575

7676
- name: Import certificates

.github/workflows/smoke.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
- uses: actions/setup-go@v5
2424
with:
25-
go-version: '1.24'
25+
go-version: '1.25'
2626
check-latest: true
2727

2828
- name: build

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
- uses: actions/setup-go@v5
2424
with:
25-
go-version: '1.24'
25+
go-version: '1.25'
2626
check-latest: true
2727

2828
- name: Build
@@ -34,7 +34,7 @@ jobs:
3434
- name: golangci-lint
3535
uses: golangci/golangci-lint-action@v8
3636
with:
37-
version: v2.1
37+
version: v2.5
3838

3939
- name: Test
4040
run: make test
@@ -60,7 +60,7 @@ jobs:
6060

6161
- uses: actions/setup-go@v5
6262
with:
63-
go-version: '1.24'
63+
go-version: '1.25'
6464
check-latest: true
6565

6666
- name: Build
@@ -81,7 +81,7 @@ jobs:
8181

8282
- uses: actions/setup-go@v5
8383
with:
84-
go-version: '1.22'
84+
go-version: '1.25'
8585
check-latest: true
8686

8787
- name: Build
@@ -102,7 +102,7 @@ jobs:
102102

103103
- uses: actions/setup-go@v5
104104
with:
105-
go-version: '1.24'
105+
go-version: '1.25'
106106
check-latest: true
107107

108108
- name: Build nebula
@@ -117,7 +117,7 @@ jobs:
117117
- name: golangci-lint
118118
uses: golangci/golangci-lint-action@v8
119119
with:
120-
version: v2.1
120+
version: v2.5
121121

122122
- name: Test
123123
run: make test

cert/cert_v1.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ func (c *certificateV1) CheckSignature(key []byte) bool {
110110
case Curve_CURVE25519:
111111
return ed25519.Verify(key, b, c.signature)
112112
case Curve_P256:
113-
x, y := elliptic.Unmarshal(elliptic.P256(), key)
114-
pubKey := &ecdsa.PublicKey{Curve: elliptic.P256(), X: x, Y: y}
113+
pubKey, err := ecdsa.ParseUncompressedPublicKey(elliptic.P256(), key)
114+
if err != nil {
115+
return false
116+
}
115117
hashed := sha256.Sum256(b)
116118
return ecdsa.VerifyASN1(pubKey, hashed[:], c.signature)
117119
default:

cert/cert_v2.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ func (c *certificateV2) CheckSignature(key []byte) bool {
149149
case Curve_CURVE25519:
150150
return ed25519.Verify(key, b, c.signature)
151151
case Curve_P256:
152-
x, y := elliptic.Unmarshal(elliptic.P256(), key)
153-
pubKey := &ecdsa.PublicKey{Curve: elliptic.P256(), X: x, Y: y}
152+
pubKey, err := ecdsa.ParseUncompressedPublicKey(elliptic.P256(), key)
153+
if err != nil {
154+
return false
155+
}
154156
hashed := sha256.Sum256(b)
155157
return ecdsa.VerifyASN1(pubKey, hashed[:], c.signature)
156158
default:

cert/sign.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"crypto/rand"
88
"crypto/sha256"
99
"fmt"
10-
"math/big"
1110
"net/netip"
1211
"time"
1312
)
@@ -55,15 +54,10 @@ func (t *TBSCertificate) Sign(signer Certificate, curve Curve, key []byte) (Cert
5554
}
5655
return t.SignWith(signer, curve, sp)
5756
case Curve_P256:
58-
pk := &ecdsa.PrivateKey{
59-
PublicKey: ecdsa.PublicKey{
60-
Curve: elliptic.P256(),
61-
},
62-
// ref: https://github.com/golang/go/blob/go1.19/src/crypto/x509/sec1.go#L95
63-
D: new(big.Int).SetBytes(key),
57+
pk, err := ecdsa.ParseRawPrivateKey(elliptic.P256(), key)
58+
if err != nil {
59+
return nil, err
6460
}
65-
// ref: https://github.com/golang/go/blob/go1.19/src/crypto/x509/sec1.go#L119
66-
pk.X, pk.Y = pk.Curve.ScalarBaseMult(key)
6761
sp := func(certBytes []byte) ([]byte, error) {
6862
// We need to hash first for ECDSA
6963
// - https://pkg.go.dev/crypto/ecdsa#SignASN1

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/slackhq/nebula
22

3-
go 1.23.0
4-
5-
toolchain go1.24.1
3+
go 1.25
64

75
require (
86
dario.cat/mergo v1.0.2

0 commit comments

Comments
 (0)