Skip to content

Commit 31ed926

Browse files
authored
add test for GOEXPERIMENT=boringcrypto (#861)
* add test for GOEXPERIMENT=boringcrypto * fix NebulaCertificate.Sign Set the PublicKey field in a more compatible way for the tests. The current method grabs the public key from the certificate, but the correct thing to do is to derive it from the private key. Either way doesn't really matter as I don't think the Sign method actually even uses the PublicKey field. * assert boring * cleanup tests
1 parent 48eb638 commit 31ed926

5 files changed

Lines changed: 49 additions & 10 deletions

File tree

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,36 @@ jobs:
5252
path: e2e/mermaid/
5353
if-no-files-found: warn
5454

55+
test-linux-boringcrypto:
56+
name: Build and test on linux with boringcrypto
57+
runs-on: ubuntu-latest
58+
steps:
59+
60+
- name: Set up Go 1.20
61+
uses: actions/setup-go@v2
62+
with:
63+
go-version: "1.20"
64+
id: go
65+
66+
- name: Check out code into the Go module directory
67+
uses: actions/checkout@v2
68+
69+
- uses: actions/cache@v2
70+
with:
71+
path: ~/go/pkg/mod
72+
key: ${{ runner.os }}-go1.20-${{ hashFiles('**/go.sum') }}
73+
restore-keys: |
74+
${{ runner.os }}-go1.20-
75+
76+
- name: Build
77+
run: make bin-boringcrypto
78+
79+
- name: Test
80+
run: make test-boringcrypto
81+
82+
- name: End 2 end
83+
run: make e2evv GOEXPERIMENT=boringcrypto CGO_ENABLED=1
84+
5585
test:
5686
name: Build and test on ${{ matrix.os }}
5787
runs-on: ${{ matrix.os }}

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ vet:
142142
test:
143143
go test -v ./...
144144

145+
test-boringcrypto:
146+
GOEXPERIMENT=boringcrypto CGO_ENABLED=1 go test -v ./...
147+
145148
test-cov-html:
146149
go test -coverprofile=coverage.out
147150
go tool cover -html=coverage.out

cert/cert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,15 @@ func (nc *NebulaCertificate) Sign(curve Curve, key []byte) error {
522522
signer := ed25519.PrivateKey(key)
523523
sig = ed25519.Sign(signer, b)
524524
case Curve_P256:
525-
x, y := elliptic.Unmarshal(elliptic.P256(), nc.Details.PublicKey)
526525
signer := &ecdsa.PrivateKey{
527526
PublicKey: ecdsa.PublicKey{
528527
Curve: elliptic.P256(),
529-
X: x, Y: y,
530528
},
531529
// ref: https://github.com/golang/go/blob/go1.19/src/crypto/x509/sec1.go#L95
532530
D: new(big.Int).SetBytes(key),
533531
}
532+
// ref: https://github.com/golang/go/blob/go1.19/src/crypto/x509/sec1.go#L119
533+
signer.X, signer.Y = signer.Curve.ScalarBaseMult(key)
534534

535535
// We need to hash first for ECDSA
536536
// - https://pkg.go.dev/crypto/ecdsa#SignASN1

noiseutil/boring_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44
package noiseutil
55

66
import (
7+
"crypto/boring"
78
"encoding/hex"
89
"testing"
910

1011
"github.com/stretchr/testify/assert"
1112
)
1213

14+
func TestEncryptLockNeeded(t *testing.T) {
15+
assert.True(t, EncryptLockNeeded)
16+
}
17+
1318
// Ensure NewGCMTLS validates the nonce is non-repeating
1419
func TestNewGCMTLS(t *testing.T) {
20+
assert.True(t, boring.Enabled())
21+
1522
// Test Case 16 from GCM Spec:
1623
// - (now dead link): http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf
1724
// - as listed in boringssl tests: https://github.com/google/boringssl/blob/fips-20220613/crypto/cipher_extra/test/cipher_tests.txt#L412-L418

noiseutil/notboring_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
package noiseutil
55

66
import (
7-
// NOTE: We have to force these imports here or boring_test.go fails to
8-
// compile correctly. This seems to be a Go bug:
9-
//
10-
// $ GOEXPERIMENT=boringcrypto go test ./noiseutil
11-
// # github.com/slackhq/nebula/noiseutil
12-
// boring_test.go:10:2: cannot find package
13-
14-
_ "github.com/stretchr/testify/assert"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
1510
)
11+
12+
func TestEncryptLockNeeded(t *testing.T) {
13+
assert.False(t, EncryptLockNeeded)
14+
}

0 commit comments

Comments
 (0)