import (
"bytes"
- "context"
"crypto"
"crypto/elliptic"
"crypto/x509"
"os"
"os/exec"
"path/filepath"
- "runtime"
"strings"
"testing"
"time"
cli.writeRecord(recordTypeHandshake, m.marshal())
c.Close()
}()
- ctx := context.Background()
conn := Server(s, serverConfig)
- ch, err := conn.readClientHello(ctx)
+ ch, err := conn.readClientHello()
hs := serverHandshakeState{
c: conn,
- ctx: ctx,
clientHello: ch,
}
if err == nil {
c.Close()
}()
conn := Server(s, serverConfig)
- ctx := context.Background()
- ch, err := conn.readClientHello(ctx)
+ ch, err := conn.readClientHello()
hs := serverHandshakeState{
c: conn,
- ctx: ctx,
clientHello: ch,
}
if err == nil {
}
}
-func TestServerHandshakeContextCancellation(t *testing.T) {
- c, s := localPipe(t)
- clientConfig := testConfig.Clone()
- clientErr := make(chan error, 1)
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel()
- go func() {
- defer close(clientErr)
- defer c.Close()
- clientHello := &clientHelloMsg{
- vers: VersionTLS10,
- random: make([]byte, 32),
- cipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
- compressionMethods: []uint8{compressionNone},
- }
- cli := Client(c, clientConfig)
- _, err := cli.writeRecord(recordTypeHandshake, clientHello.marshal())
- cancel()
- clientErr <- err
- }()
- conn := Server(s, testConfig)
- err := conn.HandshakeContext(ctx)
- if err == nil {
- t.Fatal("Server handshake did not error when the context was canceled")
- }
- if err != context.Canceled {
- t.Errorf("Unexpected server handshake error: %v", err)
- }
- if err := <-clientErr; err != nil {
- t.Errorf("Unexpected client error: %v", err)
- }
- if runtime.GOARCH == "wasm" {
- t.Skip("conn.Close does not error as expected when called multiple times on WASM")
- }
- err = conn.Close()
- if err == nil {
- t.Error("Server connection was not closed when the context was canceled")
- }
-}
-
func TestAESCipherReordering(t *testing.T) {
currentAESSupport := hasAESGCMHardwareSupport
defer func() { hasAESGCMHardwareSupport = currentAESSupport; initDefaultCipherSuites() }()