Created
August 16, 2016 20:51
-
-
Save madhusudancs/6c248769481e10ab7f2e9f002b007bcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sP, cP := net.Pipe() | |
sCfg := &tls.Config{ | |
Certificates: []tls.Certificate{serverCert}, | |
RootCAs: roots, | |
ClientAuth: tls.RequireAndVerifyClientCert, | |
ClientCAs: roots, | |
InsecureSkipVerify: false, | |
} | |
cCfg := &tls.Config{ | |
ServerName: "1.2.3.4", | |
Certificates: []tls.Certificate{}, | |
RootCAs: roots, | |
} | |
cCfg.BuildNameToCertificate() | |
done := make(chan bool) | |
go func() { | |
fmt.Println("Setting up server") | |
s := tls.Server(sP, sCfg) | |
fmt.Println("Beginning server handshake") | |
err := s.Handshake() | |
fmt.Println("Server handshake done") | |
if err != nil { | |
t.Errorf("server handshake error: %v", err) | |
} else { | |
sState := s.ConnectionState() | |
t.Logf("server state: %+v", sState) | |
} | |
sP.Close() | |
done <- true | |
}() | |
go func() { | |
fmt.Println("Setting up client") | |
c := tls.Client(cP, cCfg) | |
fmt.Println("Beginning client handshake") | |
err = c.Handshake() | |
fmt.Println("Client handshake done") | |
if err != nil { | |
t.Errorf("client handshake error: %v", err) | |
return | |
} | |
cState := c.ConnectionState() | |
cP.Close() | |
t.Logf("client state: %+v", cState) | |
done <- true | |
}() | |
timeout := make(chan bool, 1) | |
go func() { | |
time.Sleep(5 * time.Second) | |
timeout <- true | |
}() | |
select { | |
case <-done: | |
// a read from ch has occurred | |
case <-timeout: | |
bufS := make([]byte, 256) | |
n, err := sP.Read(bufS) | |
fmt.Printf("Server remaining: %d %v\n%v\n", n, bufS[:n], err) | |
bufC := make([]byte, 256) | |
n, err = cP.Read(bufC) | |
fmt.Printf("Client remaining: %d %v\n\n%v", n, bufC[:n], err) | |
// the read from ch has timed out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment