Skip to content

Commit 15d5926

Browse files
authored
Lower required Go version, add CI test for specific version (#1717)
### Description of changes: Add back support for Go 1.17.13 which is used by NetOS. Fix a few language compatibility issues for interface{} and cmd struct. ### Testing: This change adds a new CI test which uses Go 1.17.13. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license. --------- Co-authored-by: Sean McGrail <[email protected]> --------- Revert "Replace interface{} with any" This reverts commit 6a90c15.
1 parent fc14c55 commit 15d5926

33 files changed

+157
-119
lines changed

.github/workflows/go.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Go Compatability
2+
on:
3+
push:
4+
branches: [ '*' ]
5+
pull_request:
6+
branches: [ '*' ]
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref_name }}
9+
cancel-in-progress: true
10+
env:
11+
DOCKER_BUILDKIT: 1
12+
GOPROXY: https://proxy.golang.org,direct
13+
jobs:
14+
go-version-1_17_13:
15+
if: github.repository_owner == 'aws'
16+
env:
17+
GOROOT: "/usr/local/go"
18+
GO_ARCHIVE: "go1.17.13.linux-amd64.tar.gz"
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Install OS Dependencies
22+
run: |
23+
which go
24+
sudo apt-get update
25+
sudo apt-get -y --no-install-recommends install cmake gcc ninja-build make
26+
sudo rm -rf /usr/local/go
27+
sudo rm /usr/bin/go
28+
wget -q "https://dl.google.com/go/${GO_ARCHIVE}"
29+
sudo tar -C /usr/local -xf $GO_ARCHIVE
30+
echo "${GOROOT}/bin" >> $GITHUB_PATH
31+
- uses: actions/checkout@v3
32+
- name: Run integration build
33+
run: |
34+
./tests/ci/run_fips_tests.sh

BUILDING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If in doubt, use the most recent stable version of each build tool.
2020
`PERL_EXECUTABLE`.
2121
* To build without Perl (not recommended) see [this section.](#using-pre-generated-build-files)
2222

23-
* [Go](https://golang.org/dl/) 1.18 or later is required. If not found by
23+
* [Go](https://golang.org/dl/) 1.17.13 or later is required. If not found by
2424
CMake, the go executable may be configured explicitly by setting
2525
`GO_EXECUTABLE`.
2626
* To build without Go (not recommended) see [this section.](#using-pre-generated-build-files)

cmake/go.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ elseif(NOT DISABLE_GO)
2222
string(REGEX MATCH "([0-9]+\\.)*[0-9]+" go_version ${go_version_output})
2323

2424
# This should track /go.mod and /BUILDING.md
25-
set(minimum_go_version "1.18")
25+
set(minimum_go_version "1.17.13")
2626
if(go_version VERSION_LESS minimum_go_version)
2727
message(FATAL_ERROR "Go compiler version must be at least ${minimum_go_version}. Found version ${go_version}")
2828
else()

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module boringssl.googlesource.com/boringssl
22

33
// When this changes update /cmake/go.cmake minimum_go_version and /BUILDING.md
4-
go 1.18
4+
go 1.17
55

66
require (
77
golang.org/x/crypto v0.10.0

ssl/test/runner/cipher_suites.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type cipherSuite struct {
8484
ka func(version uint16) keyAgreement
8585
// flags is a bitmask of the suite* values, above.
8686
flags int
87-
cipher func(key, iv []byte, isRead bool) any
87+
cipher func(key, iv []byte, isRead bool) interface{}
8888
mac func(version uint16, macKey []byte) macFunction
8989
aead func(version uint16, key, fixedNonce []byte) *tlsAead
9090
}
@@ -155,19 +155,19 @@ func ivLen3DES(vers uint16) int {
155155

156156
type nullCipher struct{}
157157

158-
func cipherNull(key, iv []byte, isRead bool) any {
158+
func cipherNull(key, iv []byte, isRead bool) interface{} {
159159
return nullCipher{}
160160
}
161161

162-
func cipher3DES(key, iv []byte, isRead bool) any {
162+
func cipher3DES(key, iv []byte, isRead bool) interface{} {
163163
block, _ := des.NewTripleDESCipher(key)
164164
if isRead {
165165
return cipher.NewCBCDecrypter(block, iv)
166166
}
167167
return cipher.NewCBCEncrypter(block, iv)
168168
}
169169

170-
func cipherAES(key, iv []byte, isRead bool) any {
170+
func cipherAES(key, iv []byte, isRead bool) interface{} {
171171
block, _ := aes.NewCipher(key)
172172
if isRead {
173173
return cipher.NewCBCDecrypter(block, iv)

ssl/test/runner/common.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2234,11 +2234,11 @@ type lruSessionCache struct {
22342234

22352235
type lruSessionCacheEntry struct {
22362236
sessionKey string
2237-
state any
2237+
state interface{}
22382238
}
22392239

22402240
// Put adds the provided (sessionKey, cs) pair to the cache.
2241-
func (c *lruSessionCache) Put(sessionKey string, cs any) {
2241+
func (c *lruSessionCache) Put(sessionKey string, cs interface{}) {
22422242
c.Lock()
22432243
defer c.Unlock()
22442244

@@ -2266,7 +2266,7 @@ func (c *lruSessionCache) Put(sessionKey string, cs any) {
22662266

22672267
// Get returns the value associated with a given key. It returns (nil,
22682268
// false) if no value is found.
2269-
func (c *lruSessionCache) Get(sessionKey string) (any, bool) {
2269+
func (c *lruSessionCache) Get(sessionKey string) (interface{}, bool) {
22702270
c.Lock()
22712271
defer c.Unlock()
22722272

@@ -2380,7 +2380,7 @@ func initDefaultCipherSuites() {
23802380
}
23812381
}
23822382

2383-
func unexpectedMessageError(wanted, got any) error {
2383+
func unexpectedMessageError(wanted, got interface{}) error {
23842384
return fmt.Errorf("tls: received unexpected handshake message of type %T when waiting for %T", got, wanted)
23852385
}
23862386

ssl/test/runner/conn.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ type halfConn struct {
176176
version uint16 // protocol version
177177
wireVersion uint16 // wire version
178178
isDTLS bool
179-
cipher any // cipher algorithm
179+
cipher interface{} // cipher algorithm
180180
mac macFunction
181181
seq [8]byte // 64-bit sequence number
182182
outSeq [8]byte // Mapped sequence number
183183
bfree *block // list of free blocks
184184

185-
nextCipher any // next encryption state
185+
nextCipher interface{} // next encryption state
186186
nextMac macFunction // next MAC algorithm
187187
nextSeq [6]byte // next epoch's starting sequence number in DTLS
188188

@@ -209,7 +209,7 @@ func (hc *halfConn) error() error {
209209

210210
// prepareCipherSpec sets the encryption and MAC states
211211
// that a subsequent changeCipherSpec will use.
212-
func (hc *halfConn) prepareCipherSpec(version uint16, cipher any, mac macFunction) {
212+
func (hc *halfConn) prepareCipherSpec(version uint16, cipher interface{}, mac macFunction) {
213213
hc.wireVersion = version
214214
protocolVersion, ok := wireToVersion(version, hc.isDTLS)
215215
if !ok {
@@ -1343,7 +1343,7 @@ func (c *Conn) doReadHandshake() ([]byte, error) {
13431343
// readHandshake reads the next handshake message from
13441344
// the record layer.
13451345
// c.in.Mutex < L; c.out.Mutex < L.
1346-
func (c *Conn) readHandshake() (any, error) {
1346+
func (c *Conn) readHandshake() (interface{}, error) {
13471347
data, err := c.doReadHandshake()
13481348
if err != nil {
13491349
return nil, err

ssl/test/runner/handshake_client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ func (hs *clientHandshakeState) encryptClientHello(hello, innerHello *clientHell
936936
return nil
937937
}
938938

939-
func (hs *clientHandshakeState) checkECHConfirmation(msg any, hello *clientHelloMsg, finishedHash *finishedHash) bool {
939+
func (hs *clientHandshakeState) checkECHConfirmation(msg interface{}, hello *clientHelloMsg, finishedHash *finishedHash) bool {
940940
var offset int
941941
var raw, label []byte
942942
if hrr, ok := msg.(*helloRetryRequestMsg); ok {
@@ -961,7 +961,7 @@ func (hs *clientHandshakeState) checkECHConfirmation(msg any, hello *clientHello
961961
return bytes.Equal(confirmation, raw[offset:offset+echAcceptConfirmationLength])
962962
}
963963

964-
func (hs *clientHandshakeState) doTLS13Handshake(msg any) error {
964+
func (hs *clientHandshakeState) doTLS13Handshake(msg interface{}) error {
965965
c := hs.c
966966

967967
// The first message may be a ServerHello or HelloRetryRequest.
@@ -1919,7 +1919,7 @@ func (hs *clientHandshakeState) establishKeys() error {
19191919

19201920
clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV :=
19211921
keysFromMasterSecret(c.vers, hs.suite, hs.masterSecret, hs.hello.random, hs.serverHello.random, hs.suite.macLen, hs.suite.keyLen, hs.suite.ivLen(c.vers))
1922-
var clientCipher, serverCipher any
1922+
var clientCipher, serverCipher interface{}
19231923
var clientHash, serverHash macFunction
19241924
if hs.suite.cipher != nil {
19251925
clientCipher = hs.suite.cipher(clientKey, clientIV, false /* not for reading */)

ssl/test/runner/handshake_server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ func (hs *serverHandshakeState) establishKeys() error {
21152115
clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV :=
21162116
keysFromMasterSecret(c.vers, hs.suite, hs.masterSecret, hs.clientHello.random, hs.hello.random, hs.suite.macLen, hs.suite.keyLen, hs.suite.ivLen(c.vers))
21172117

2118-
var clientCipher, serverCipher any
2118+
var clientCipher, serverCipher interface{}
21192119
var clientHash, serverHash macFunction
21202120

21212121
if hs.suite.aead == nil {

ssl/test/runner/prf.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ var (
452452

453453
// deriveTrafficAEAD derives traffic keys and constructs an AEAD given a traffic
454454
// secret.
455-
func deriveTrafficAEAD(version uint16, suite *cipherSuite, secret []byte, side trafficDirection) any {
455+
func deriveTrafficAEAD(version uint16, suite *cipherSuite, secret []byte, side trafficDirection) interface{} {
456456
key := hkdfExpandLabel(suite.hash(), secret, keyTLS13, nil, suite.keyLen)
457457
iv := hkdfExpandLabel(suite.hash(), secret, ivTLS13, nil, suite.ivLen(version))
458458

ssl/test/runner/sign.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (e *ed25519Signer) verifyMessage(key crypto.PublicKey, msg, sig []byte) err
272272
return nil
273273
}
274274

275-
func getSigner(version uint16, key any, config *Config, sigAlg signatureAlgorithm, isVerify bool) (signer, error) {
275+
func getSigner(version uint16, key interface{}, config *Config, sigAlg signatureAlgorithm, isVerify bool) (signer, error) {
276276
// TLS 1.1 and below use legacy signature algorithms.
277277
if version < VersionTLS12 || (!isVerify && config.Bugs.AlwaysSignAsLegacyVersion) {
278278
if config.Bugs.SigningAlgorithmForLegacyVersions == 0 || isVerify {

util/all_tests.go

+30-26
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ var sdeCPUs = []string{
100100

101101
func targetArchMatchesRuntime(target string) bool {
102102
if (target == "") ||
103-
(target == "x86" && runtime.GOARCH == "amd64") ||
104-
(target == "arm" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64")) {
103+
(target == "x86" && runtime.GOARCH == "amd64") ||
104+
(target == "arm" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64")) {
105105
return true
106106
}
107107
return false
108108
}
109109

110-
func valgrindOf(dbAttach bool, supps []string, path string, args ...string) *exec.Cmd {
110+
func valgrindOf(ctx context.Context, dbAttach bool, supps []string, path string, args ...string) (context.Context, *exec.Cmd) {
111111
valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--trace-children=yes", "--quiet"}
112112
for _, supp := range supps {
113113
valgrindArgs = append(valgrindArgs, "--suppressions="+*valgrindSuppDir+"/"+supp)
@@ -118,26 +118,26 @@ func valgrindOf(dbAttach bool, supps []string, path string, args ...string) *exe
118118
valgrindArgs = append(valgrindArgs, path)
119119
valgrindArgs = append(valgrindArgs, args...)
120120

121-
return exec.Command("valgrind", valgrindArgs...)
121+
return ctx, exec.CommandContext(ctx, "valgrind", valgrindArgs...)
122122
}
123123

124-
func callgrindOf(path string, args ...string) *exec.Cmd {
124+
func callgrindOf(ctx context.Context, path string, args ...string) (context.Context, *exec.Cmd) {
125125
valgrindArgs := []string{"-q", "--tool=callgrind", "--dump-instr=yes", "--collect-jumps=yes", "--callgrind-out-file=" + *buildDir + "/callgrind/callgrind.out.%p"}
126126
valgrindArgs = append(valgrindArgs, path)
127127
valgrindArgs = append(valgrindArgs, args...)
128128

129-
return exec.Command("valgrind", valgrindArgs...)
129+
return ctx, exec.CommandContext(ctx, "valgrind", valgrindArgs...)
130130
}
131131

132-
func gdbOf(path string, args ...string) *exec.Cmd {
132+
func gdbOf(ctx context.Context, path string, args ...string) (context.Context, *exec.Cmd) {
133133
xtermArgs := []string{"-e", "gdb", "--args"}
134134
xtermArgs = append(xtermArgs, path)
135135
xtermArgs = append(xtermArgs, args...)
136136

137-
return exec.Command("xterm", xtermArgs...)
137+
return ctx, exec.CommandContext(ctx, "xterm", xtermArgs...)
138138
}
139139

140-
func sdeOf(cpu, path string, args ...string) (*exec.Cmd, context.CancelFunc) {
140+
func sdeOf(ctx context.Context, cpu, path string, args ...string) (context.Context, context.CancelFunc, *exec.Cmd) {
141141
sdeArgs := []string{"-" + cpu}
142142
// The kernel's vdso code for gettimeofday sometimes uses the RDTSCP
143143
// instruction. Although SDE has a -chip_check_vsyscall flag that
@@ -152,9 +152,9 @@ func sdeOf(cpu, path string, args ...string) (*exec.Cmd, context.CancelFunc) {
152152

153153
// TODO(CryptoAlg-2154):SDE+ASAN tests will hang without exiting if tests pass for an unknown reason.
154154
// Current workaround is to manually cancel the run after 20 minutes and check the output.
155-
ctx, cancel := context.WithTimeout(context.Background(), 1200*time.Second)
155+
ctx, cancel := context.WithTimeout(ctx, 1200*time.Second)
156156

157-
return exec.CommandContext(ctx, *sdePath, sdeArgs...), cancel
157+
return ctx, cancel, exec.CommandContext(ctx, *sdePath, sdeArgs...)
158158
}
159159

160160
var (
@@ -173,23 +173,20 @@ func runTestOnce(test test, mallocNumToFail int64) (passed bool, err error) {
173173
}
174174
var cmd *exec.Cmd
175175
var cancel context.CancelFunc
176-
cancelled := false
176+
177+
ctx := context.Background()
178+
177179
if *useValgrind {
178-
cmd = valgrindOf(false, test.ValgrindSupp, prog, args...)
180+
ctx, cmd = valgrindOf(ctx, false, test.ValgrindSupp, prog, args...)
179181
} else if *useCallgrind {
180-
cmd = callgrindOf(prog, args...)
182+
ctx, cmd = callgrindOf(ctx, prog, args...)
181183
} else if *useGDB {
182-
cmd = gdbOf(prog, args...)
184+
ctx, cmd = gdbOf(ctx, prog, args...)
183185
} else if *useSDE {
184-
cmd, cancel = sdeOf(test.cpu, prog, args...)
186+
ctx, cancel, cmd = sdeOf(ctx, test.cpu, prog, args...)
185187
defer cancel()
186-
187-
cmd.Cancel = func() error {
188-
cancelled = true
189-
return cmd.Process.Kill()
190-
}
191188
} else {
192-
cmd = exec.Command(prog, args...)
189+
cmd = exec.CommandContext(ctx, prog, args...)
193190
}
194191
if test.Env != nil || test.numShards != 0 {
195192
cmd.Env = make([]string, len(os.Environ()))
@@ -219,23 +216,30 @@ func runTestOnce(test test, mallocNumToFail int64) (passed bool, err error) {
219216
}
220217

221218
if err := cmd.Wait(); err != nil {
222-
if exitError, ok := err.(*exec.ExitError); ok {
219+
var exitError *exec.ExitError
220+
if errors.As(err, &exitError) {
223221
switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
224222
case 88:
225223
return false, errMoreMallocs
226224
case 89:
227225
fmt.Print(string(outBuf.Bytes()))
228226
return false, errTestSkipped
229227
}
230-
if cancelled {
231-
return testPass(outBuf), errTestHanging
228+
select {
229+
case <-ctx.Done():
230+
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
231+
return testPass(outBuf), errTestHanging
232+
} else if ctx.Err() != nil {
233+
return false, ctx.Err()
234+
}
235+
default:
236+
// Nothing
232237
}
233238
}
234239
fmt.Print(string(outBuf.Bytes()))
235240
return false, err
236241
}
237242

238-
239243
return testPass(outBuf), nil
240244
}
241245

0 commit comments

Comments
 (0)