Skip to content

Commit 7247dca

Browse files
committed
crypto/tls: update how we create testing scripts.
crypto/tls is tested, in part, by replaying recorded TLS connections and checking that the bytes sent by the Go code haven't changed. Previously we used GnuTLS's debug output and extracted the bytes of the TLS connection using a Python script. That wasn't great, and I think GnuTLS removed that level of debugging in a more current release. This change records the connection with Go code and adds a test for ECDHE-AES clients generating using this method. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5988048
1 parent 98aa496 commit 7247dca

File tree

3 files changed

+301
-100
lines changed

3 files changed

+301
-100
lines changed

src/pkg/crypto/tls/handshake_client_test.go

Lines changed: 199 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"flag"
1010
"io"
1111
"net"
12+
"os"
1213
"testing"
1314
)
1415

@@ -39,7 +40,15 @@ func testClientScript(t *testing.T, name string, clientScript [][]byte, config *
3940
}
4041

4142
func TestHandshakeClientRC4(t *testing.T) {
42-
testClientScript(t, "RC4", rc4ClientScript, testConfig)
43+
var config = *testConfig
44+
config.CipherSuites = []uint16{TLS_RSA_WITH_RC4_128_SHA}
45+
testClientScript(t, "RC4", rc4ClientScript, &config)
46+
}
47+
48+
func TestHandshakeClientECDHEAES(t *testing.T) {
49+
var config = *testConfig
50+
config.CipherSuites = []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}
51+
testClientScript(t, "ECDHE-AES", ecdheAESClientScript, &config)
4352
}
4453

4554
var connect = flag.Bool("connect", false, "connect to a TLS server on :10443")
@@ -49,25 +58,33 @@ func TestRunClient(t *testing.T) {
4958
return
5059
}
5160

52-
testConfig.CipherSuites = []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA}
53-
54-
conn, err := Dial("tcp", "127.0.0.1:10443", testConfig)
61+
tcpConn, err := net.Dial("tcp", "127.0.0.1:10443")
5562
if err != nil {
5663
t.Fatal(err)
5764
}
5865

66+
record := &recordingConn{
67+
Conn: tcpConn,
68+
}
69+
70+
config := GetTestConfig()
71+
conn := Client(record, config)
72+
if err := conn.Handshake(); err != nil {
73+
t.Fatalf("error from TLS handshake: %s", err)
74+
}
75+
5976
conn.Write([]byte("hello\n"))
6077
conn.Close()
78+
79+
record.WriteTo(os.Stdout)
6180
}
6281

6382
// Script of interaction with gnutls implementation.
6483
// The values for this test are obtained by building and running in client mode:
65-
// % go test -run "TestRunClient" -connect
66-
// and then:
67-
// % gnutls-serv -p 10443 --debug 100 --x509keyfile key.pem --x509certfile cert.pem -a > /tmp/log 2>&1
68-
// % python parse-gnutls-cli-debug-log.py < /tmp/log
84+
// % go test -test.run "TestRunClient" -connect
85+
// The recorded bytes are written to stdout.
6986
//
70-
// Where key.pem is:
87+
// The server private key is:
7188
// -----BEGIN RSA PRIVATE KEY-----
7289
// MIIBPAIBAAJBAJ+zw4Qnlf8SMVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVD
7390
// TGiXav6ooKXfX3j/7tdkuD8Ey2//Kv7+ue0CAwEAAQJAN6W31vDEP2DjdqhzCDDu
@@ -78,17 +95,20 @@ func TestRunClient(t *testing.T) {
7895
// vnlEGo8K85u+KwIOimM48ZG8oTk7iFdkqLJR1utT3aU=
7996
// -----END RSA PRIVATE KEY-----
8097
//
81-
// and cert.pem is:
98+
// and certificate is:
8299
// -----BEGIN CERTIFICATE-----
83-
// MIIBoDCCAUoCAQAwDQYJKoZIhvcNAQEEBQAwYzELMAkGA1UEBhMCQVUxEzARBgNV
84-
// BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMSMwIQYD
85-
// VQQDExpTZXJ2ZXIgdGVzdCBjZXJ0ICg1MTIgYml0KTAeFw05NzA5MDkwMzQxMjZa
86-
// Fw05NzEwMDkwMzQxMjZaMF4xCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0
87-
// YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxFzAVBgNVBAMT
88-
// DkVyaWMgdGhlIFlvdW5nMFEwCQYFKw4DAgwFAANEAAJBALVEqPODnpI4rShlY8S7
89-
// tB713JNvabvn6Gned7zylwLLiXQAo/PAT6mfdWPTyCX9RlId/Aroh1ou893BA32Q
90-
// sggwDQYJKoZIhvcNAQEEBQADQQCU5SSgapJSdRXJoX+CpCvFy+JVh9HpSjCpSNKO
91-
// 19raHv98hKAUJuP9HyM+SUsffO6mAIgitUaqW8/wDMePhEC3
100+
// MIICKzCCAdWgAwIBAgIJALE1E2URIMWSMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
101+
// BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
102+
// aWRnaXRzIFB0eSBMdGQwHhcNMTIwNDA2MTcxMDEzWhcNMTUwNDA2MTcxMDEzWjBF
103+
// MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50
104+
// ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ+z
105+
// w4Qnlf8SMVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVDTGiXav6ooKXfX3j/
106+
// 7tdkuD8Ey2//Kv7+ue0CAwEAAaOBpzCBpDAdBgNVHQ4EFgQUeKaXmmO1xaGlM7oi
107+
// fCNuWxt6zCswdQYDVR0jBG4wbIAUeKaXmmO1xaGlM7oifCNuWxt6zCuhSaRHMEUx
108+
// CzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRl
109+
// cm5ldCBXaWRnaXRzIFB0eSBMdGSCCQCxNRNlESDFkjAMBgNVHRMEBTADAQH/MA0G
110+
// CSqGSIb3DQEBBQUAA0EAhTZAc8G7GtrUWZ8tonAxRnTsg26oyDxRrzms7EC86CJG
111+
// HZnWRiok1IsFCEv7NRFukrt3uuQSu/TIXpyBqJdgTA==
92112
// -----END CERTIFICATE-----
93113
var rc4ClientScript = [][]byte{
94114
{
@@ -210,3 +230,163 @@ var rc4ClientScript = [][]byte{
210230
0x59, 0xac, 0xc6, 0xb5, 0x56, 0x55, 0x96,
211231
},
212232
}
233+
234+
var ecdheAESClientScript = [][]byte{
235+
{
236+
0x16, 0x03, 0x01, 0x00, 0x4a, 0x01, 0x00, 0x00,
237+
0x46, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
238+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241+
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xc0, 0x13,
242+
0x01, 0x00, 0x00, 0x1b, 0x00, 0x05, 0x00, 0x05,
243+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
244+
0x08, 0x00, 0x06, 0x00, 0x17, 0x00, 0x18, 0x00,
245+
0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00,
246+
},
247+
{
248+
0x16, 0x03, 0x01, 0x00, 0x54, 0x02, 0x00, 0x00,
249+
0x50, 0x03, 0x01, 0x4f, 0x7f, 0x24, 0x25, 0x10,
250+
0xa8, 0x9d, 0xb1, 0x33, 0xd6, 0x53, 0x81, 0xce,
251+
0xb0, 0x69, 0xed, 0x1b, 0x9c, 0x5e, 0x40, 0x3a,
252+
0x4d, 0x06, 0xbc, 0xc7, 0x84, 0x51, 0x5a, 0x30,
253+
0x40, 0x50, 0x48, 0x20, 0xcd, 0x91, 0x80, 0x08,
254+
0xff, 0x82, 0x38, 0xc6, 0x03, 0x2d, 0x45, 0x4c,
255+
0x91, 0xbb, 0xcc, 0x27, 0x3d, 0x58, 0xff, 0x0d,
256+
0x26, 0x34, 0x7b, 0x48, 0x7a, 0xce, 0x25, 0x20,
257+
0x90, 0x0f, 0x35, 0x9f, 0xc0, 0x13, 0x00, 0x00,
258+
0x08, 0x00, 0x0b, 0x00, 0x04, 0x03, 0x00, 0x01,
259+
0x02, 0x16, 0x03, 0x01, 0x02, 0x39, 0x0b, 0x00,
260+
0x02, 0x35, 0x00, 0x02, 0x32, 0x00, 0x02, 0x2f,
261+
0x30, 0x82, 0x02, 0x2b, 0x30, 0x82, 0x01, 0xd5,
262+
0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
263+
0xb1, 0x35, 0x13, 0x65, 0x11, 0x20, 0xc5, 0x92,
264+
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
265+
0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30,
266+
0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
267+
0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13,
268+
0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13,
269+
0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74,
270+
0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06,
271+
0x03, 0x55, 0x04, 0x0a, 0x13, 0x18, 0x49, 0x6e,
272+
0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57,
273+
0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50,
274+
0x74, 0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, 0x1e,
275+
0x17, 0x0d, 0x31, 0x32, 0x30, 0x34, 0x30, 0x36,
276+
0x31, 0x37, 0x31, 0x30, 0x31, 0x33, 0x5a, 0x17,
277+
0x0d, 0x31, 0x35, 0x30, 0x34, 0x30, 0x36, 0x31,
278+
0x37, 0x31, 0x30, 0x31, 0x33, 0x5a, 0x30, 0x45,
279+
0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
280+
0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30,
281+
0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a,
282+
0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61,
283+
0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03,
284+
0x55, 0x04, 0x0a, 0x13, 0x18, 0x49, 0x6e, 0x74,
285+
0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69,
286+
0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74,
287+
0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, 0x5c, 0x30,
288+
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
289+
0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b,
290+
0x00, 0x30, 0x48, 0x02, 0x41, 0x00, 0x9f, 0xb3,
291+
0xc3, 0x84, 0x27, 0x95, 0xff, 0x12, 0x31, 0x52,
292+
0x0f, 0x15, 0xef, 0x46, 0x11, 0xc4, 0xad, 0x80,
293+
0xe6, 0x36, 0x5b, 0x0f, 0xdd, 0x80, 0xd7, 0x61,
294+
0x8d, 0xe0, 0xfc, 0x72, 0x45, 0x09, 0x34, 0xfe,
295+
0x55, 0x66, 0x45, 0x43, 0x4c, 0x68, 0x97, 0x6a,
296+
0xfe, 0xa8, 0xa0, 0xa5, 0xdf, 0x5f, 0x78, 0xff,
297+
0xee, 0xd7, 0x64, 0xb8, 0x3f, 0x04, 0xcb, 0x6f,
298+
0xff, 0x2a, 0xfe, 0xfe, 0xb9, 0xed, 0x02, 0x03,
299+
0x01, 0x00, 0x01, 0xa3, 0x81, 0xa7, 0x30, 0x81,
300+
0xa4, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e,
301+
0x04, 0x16, 0x04, 0x14, 0x78, 0xa6, 0x97, 0x9a,
302+
0x63, 0xb5, 0xc5, 0xa1, 0xa5, 0x33, 0xba, 0x22,
303+
0x7c, 0x23, 0x6e, 0x5b, 0x1b, 0x7a, 0xcc, 0x2b,
304+
0x30, 0x75, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04,
305+
0x6e, 0x30, 0x6c, 0x80, 0x14, 0x78, 0xa6, 0x97,
306+
0x9a, 0x63, 0xb5, 0xc5, 0xa1, 0xa5, 0x33, 0xba,
307+
0x22, 0x7c, 0x23, 0x6e, 0x5b, 0x1b, 0x7a, 0xcc,
308+
0x2b, 0xa1, 0x49, 0xa4, 0x47, 0x30, 0x45, 0x31,
309+
0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06,
310+
0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11,
311+
0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a, 0x53,
312+
0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74,
313+
0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55,
314+
0x04, 0x0a, 0x13, 0x18, 0x49, 0x6e, 0x74, 0x65,
315+
0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64,
316+
0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79,
317+
0x20, 0x4c, 0x74, 0x64, 0x82, 0x09, 0x00, 0xb1,
318+
0x35, 0x13, 0x65, 0x11, 0x20, 0xc5, 0x92, 0x30,
319+
0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05,
320+
0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06,
321+
0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
322+
0x01, 0x05, 0x05, 0x00, 0x03, 0x41, 0x00, 0x85,
323+
0x36, 0x40, 0x73, 0xc1, 0xbb, 0x1a, 0xda, 0xd4,
324+
0x59, 0x9f, 0x2d, 0xa2, 0x70, 0x31, 0x46, 0x74,
325+
0xec, 0x83, 0x6e, 0xa8, 0xc8, 0x3c, 0x51, 0xaf,
326+
0x39, 0xac, 0xec, 0x40, 0xbc, 0xe8, 0x22, 0x46,
327+
0x1d, 0x99, 0xd6, 0x46, 0x2a, 0x24, 0xd4, 0x8b,
328+
0x05, 0x08, 0x4b, 0xfb, 0x35, 0x11, 0x6e, 0x92,
329+
0xbb, 0x77, 0xba, 0xe4, 0x12, 0xbb, 0xf4, 0xc8,
330+
0x5e, 0x9c, 0x81, 0xa8, 0x97, 0x60, 0x4c, 0x16,
331+
0x03, 0x01, 0x00, 0x8b, 0x0c, 0x00, 0x00, 0x87,
332+
0x03, 0x00, 0x17, 0x41, 0x04, 0x0b, 0xe5, 0x39,
333+
0xde, 0x17, 0x7a, 0xaf, 0x96, 0xd5, 0x16, 0x01,
334+
0xa8, 0x06, 0x80, 0x98, 0x75, 0x52, 0x56, 0x92,
335+
0x15, 0xf9, 0x8d, 0xc0, 0x98, 0x62, 0xed, 0x54,
336+
0xb7, 0xef, 0x03, 0x11, 0x34, 0x82, 0x65, 0xd1,
337+
0xde, 0x25, 0x15, 0x4c, 0xf3, 0xdf, 0x4d, 0xbd,
338+
0x6c, 0xed, 0x3d, 0xd6, 0x04, 0xcc, 0xd1, 0xf7,
339+
0x6d, 0x32, 0xb1, 0x1c, 0x59, 0xca, 0xfb, 0xbc,
340+
0x61, 0xeb, 0x4b, 0xe6, 0x00, 0x00, 0x40, 0x3e,
341+
0xe6, 0x23, 0x54, 0x61, 0x3f, 0x63, 0x16, 0xeb,
342+
0x5c, 0xc3, 0xba, 0x8a, 0x19, 0x13, 0x60, 0x9f,
343+
0x23, 0xbf, 0x36, 0x1a, 0x32, 0x7a, 0xae, 0x34,
344+
0x7f, 0x2f, 0x89, 0x85, 0xe1, 0x0e, 0x93, 0xd7,
345+
0xf0, 0xab, 0xa1, 0x0d, 0x54, 0x95, 0x79, 0x0b,
346+
0xb4, 0xf1, 0x1c, 0x1d, 0x0f, 0x8c, 0x16, 0xec,
347+
0x82, 0x60, 0xee, 0xa3, 0x71, 0x2f, 0xaf, 0x3e,
348+
0xf1, 0xbd, 0xb5, 0x1b, 0x7f, 0xe0, 0xd2, 0x16,
349+
0x03, 0x01, 0x00, 0x04, 0x0e, 0x00, 0x00, 0x00,
350+
},
351+
{
352+
0x16, 0x03, 0x01, 0x00, 0x46, 0x10, 0x00, 0x00,
353+
0x42, 0x41, 0x04, 0x1e, 0x18, 0x37, 0xef, 0x0d,
354+
0x19, 0x51, 0x88, 0x35, 0x75, 0x71, 0xb5, 0xe5,
355+
0x54, 0x5b, 0x12, 0x2e, 0x8f, 0x09, 0x67, 0xfd,
356+
0xa7, 0x24, 0x20, 0x3e, 0xb2, 0x56, 0x1c, 0xce,
357+
0x97, 0x28, 0x5e, 0xf8, 0x2b, 0x2d, 0x4f, 0x9e,
358+
0xf1, 0x07, 0x9f, 0x6c, 0x4b, 0x5b, 0x83, 0x56,
359+
0xe2, 0x32, 0x42, 0xe9, 0x58, 0xb6, 0xd7, 0x49,
360+
0xa6, 0xb5, 0x68, 0x1a, 0x41, 0x03, 0x56, 0x6b,
361+
0xdc, 0x5a, 0x89, 0x14, 0x03, 0x01, 0x00, 0x01,
362+
0x01, 0x16, 0x03, 0x01, 0x00, 0x30, 0x09, 0xac,
363+
0xbe, 0x94, 0x75, 0x4d, 0x73, 0x45, 0xbd, 0xa8,
364+
0x0c, 0xe3, 0x5f, 0x72, 0x0b, 0x40, 0x4f, 0xd0,
365+
0xd2, 0xcb, 0x16, 0x50, 0xfe, 0xdd, 0x1a, 0x33,
366+
0x5c, 0x18, 0x37, 0x98, 0x42, 0xfc, 0x25, 0x42,
367+
0x33, 0xce, 0x60, 0xcf, 0x8e, 0x95, 0x6e, 0x48,
368+
0xed, 0x00, 0x35, 0x50, 0x26, 0x7f,
369+
},
370+
{
371+
0x14, 0x03, 0x01, 0x00, 0x01, 0x01, 0x16, 0x03,
372+
0x01, 0x00, 0x30, 0xf6, 0x6a, 0xdb, 0x83, 0xd4,
373+
0x3c, 0x77, 0x52, 0xad, 0xc0, 0x0f, 0x3a, 0x2c,
374+
0x42, 0xb9, 0x60, 0x4b, 0xb2, 0xf6, 0x84, 0xfd,
375+
0x4e, 0x96, 0xfc, 0x15, 0xe7, 0x94, 0x25, 0xb0,
376+
0x59, 0x9f, 0xdd, 0xb6, 0x58, 0x03, 0x13, 0x8d,
377+
0xeb, 0xb0, 0xad, 0x30, 0x31, 0x58, 0x6c, 0xa0,
378+
0x8f, 0x57, 0x50,
379+
},
380+
{
381+
0x17, 0x03, 0x01, 0x00, 0x20, 0xab, 0x64, 0x3d,
382+
0x79, 0x69, 0x3e, 0xba, 0xc4, 0x24, 0x7b, 0xe5,
383+
0xe5, 0x23, 0x66, 0x6f, 0x32, 0xdf, 0x50, 0x7c,
384+
0x06, 0x2a, 0x02, 0x82, 0x79, 0x40, 0xdb, 0xb1,
385+
0x04, 0xc0, 0x2b, 0xdc, 0x3a, 0x15, 0x03, 0x01,
386+
0x00, 0x20, 0xf8, 0xad, 0xca, 0xd7, 0x96, 0xf0,
387+
0xd6, 0xa3, 0x62, 0xe1, 0x03, 0x44, 0xdb, 0xd0,
388+
0xc9, 0x63, 0x3e, 0x1b, 0x70, 0x41, 0x57, 0x0c,
389+
0xd8, 0x8e, 0x71, 0x49, 0x68, 0xe3, 0x04, 0x53,
390+
0x5a, 0xbe,
391+
},
392+
}

0 commit comments

Comments
 (0)