github.com/miolini/go@v0.0.0-20160405192216-fca68c8cb408/src/crypto/tls/handshake_server_test.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package tls 6 7 import ( 8 "bytes" 9 "crypto/ecdsa" 10 "crypto/elliptic" 11 "crypto/rsa" 12 "encoding/hex" 13 "encoding/pem" 14 "errors" 15 "fmt" 16 "io" 17 "math/big" 18 "net" 19 "os" 20 "os/exec" 21 "path/filepath" 22 "strings" 23 "testing" 24 "time" 25 ) 26 27 // zeroSource is an io.Reader that returns an unlimited number of zero bytes. 28 type zeroSource struct{} 29 30 func (zeroSource) Read(b []byte) (n int, err error) { 31 for i := range b { 32 b[i] = 0 33 } 34 35 return len(b), nil 36 } 37 38 var testConfig *Config 39 40 func allCipherSuites() []uint16 { 41 ids := make([]uint16, len(cipherSuites)) 42 for i, suite := range cipherSuites { 43 ids[i] = suite.id 44 } 45 46 return ids 47 } 48 49 func init() { 50 testConfig = &Config{ 51 Time: func() time.Time { return time.Unix(0, 0) }, 52 Rand: zeroSource{}, 53 Certificates: make([]Certificate, 2), 54 InsecureSkipVerify: true, 55 MinVersion: VersionSSL30, 56 MaxVersion: VersionTLS12, 57 CipherSuites: allCipherSuites(), 58 } 59 testConfig.Certificates[0].Certificate = [][]byte{testRSACertificate} 60 testConfig.Certificates[0].PrivateKey = testRSAPrivateKey 61 testConfig.Certificates[1].Certificate = [][]byte{testSNICertificate} 62 testConfig.Certificates[1].PrivateKey = testRSAPrivateKey 63 testConfig.BuildNameToCertificate() 64 } 65 66 func testClientHello(t *testing.T, serverConfig *Config, m handshakeMessage) { 67 testClientHelloFailure(t, serverConfig, m, "") 68 } 69 70 func testClientHelloFailure(t *testing.T, serverConfig *Config, m handshakeMessage, expectedSubStr string) { 71 // Create in-memory network connection, 72 // send message to server. Should return 73 // expected error. 74 c, s := net.Pipe() 75 go func() { 76 cli := Client(c, testConfig) 77 if ch, ok := m.(*clientHelloMsg); ok { 78 cli.vers = ch.vers 79 } 80 cli.writeRecord(recordTypeHandshake, m.marshal()) 81 c.Close() 82 }() 83 hs := serverHandshakeState{ 84 c: Server(s, serverConfig), 85 } 86 _, err := hs.readClientHello() 87 s.Close() 88 if len(expectedSubStr) == 0 { 89 if err != nil && err != io.EOF { 90 t.Errorf("Got error: %s; expected to succeed", err) 91 } 92 } else if err == nil || !strings.Contains(err.Error(), expectedSubStr) { 93 t.Errorf("Got error: %s; expected to match substring '%s'", err, expectedSubStr) 94 } 95 } 96 97 func TestSimpleError(t *testing.T) { 98 testClientHelloFailure(t, testConfig, &serverHelloDoneMsg{}, "unexpected handshake message") 99 } 100 101 var badProtocolVersions = []uint16{0x0000, 0x0005, 0x0100, 0x0105, 0x0200, 0x0205} 102 103 func TestRejectBadProtocolVersion(t *testing.T) { 104 for _, v := range badProtocolVersions { 105 testClientHelloFailure(t, testConfig, &clientHelloMsg{vers: v}, "unsupported, maximum protocol version") 106 } 107 } 108 109 func TestNoSuiteOverlap(t *testing.T) { 110 clientHello := &clientHelloMsg{ 111 vers: VersionTLS10, 112 cipherSuites: []uint16{0xff00}, 113 compressionMethods: []uint8{compressionNone}, 114 } 115 testClientHelloFailure(t, testConfig, clientHello, "no cipher suite supported by both client and server") 116 } 117 118 func TestNoCompressionOverlap(t *testing.T) { 119 clientHello := &clientHelloMsg{ 120 vers: VersionTLS10, 121 cipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, 122 compressionMethods: []uint8{0xff}, 123 } 124 testClientHelloFailure(t, testConfig, clientHello, "client does not support uncompressed connections") 125 } 126 127 func TestNoRC4ByDefault(t *testing.T) { 128 clientHello := &clientHelloMsg{ 129 vers: VersionTLS10, 130 cipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, 131 compressionMethods: []uint8{compressionNone}, 132 } 133 serverConfig := *testConfig 134 // Reset the enabled cipher suites to nil in order to test the 135 // defaults. 136 serverConfig.CipherSuites = nil 137 testClientHelloFailure(t, &serverConfig, clientHello, "no cipher suite supported by both client and server") 138 } 139 140 func TestDontSelectECDSAWithRSAKey(t *testing.T) { 141 // Test that, even when both sides support an ECDSA cipher suite, it 142 // won't be selected if the server's private key doesn't support it. 143 clientHello := &clientHelloMsg{ 144 vers: VersionTLS10, 145 cipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA}, 146 compressionMethods: []uint8{compressionNone}, 147 supportedCurves: []CurveID{CurveP256}, 148 supportedPoints: []uint8{pointFormatUncompressed}, 149 } 150 serverConfig := *testConfig 151 serverConfig.CipherSuites = clientHello.cipherSuites 152 serverConfig.Certificates = make([]Certificate, 1) 153 serverConfig.Certificates[0].Certificate = [][]byte{testECDSACertificate} 154 serverConfig.Certificates[0].PrivateKey = testECDSAPrivateKey 155 serverConfig.BuildNameToCertificate() 156 // First test that it *does* work when the server's key is ECDSA. 157 testClientHello(t, &serverConfig, clientHello) 158 159 // Now test that switching to an RSA key causes the expected error (and 160 // not an internal error about a signing failure). 161 serverConfig.Certificates = testConfig.Certificates 162 testClientHelloFailure(t, &serverConfig, clientHello, "no cipher suite supported by both client and server") 163 } 164 165 func TestDontSelectRSAWithECDSAKey(t *testing.T) { 166 // Test that, even when both sides support an RSA cipher suite, it 167 // won't be selected if the server's private key doesn't support it. 168 clientHello := &clientHelloMsg{ 169 vers: VersionTLS10, 170 cipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, 171 compressionMethods: []uint8{compressionNone}, 172 supportedCurves: []CurveID{CurveP256}, 173 supportedPoints: []uint8{pointFormatUncompressed}, 174 } 175 serverConfig := *testConfig 176 serverConfig.CipherSuites = clientHello.cipherSuites 177 // First test that it *does* work when the server's key is RSA. 178 testClientHello(t, &serverConfig, clientHello) 179 180 // Now test that switching to an ECDSA key causes the expected error 181 // (and not an internal error about a signing failure). 182 serverConfig.Certificates = make([]Certificate, 1) 183 serverConfig.Certificates[0].Certificate = [][]byte{testECDSACertificate} 184 serverConfig.Certificates[0].PrivateKey = testECDSAPrivateKey 185 serverConfig.BuildNameToCertificate() 186 testClientHelloFailure(t, &serverConfig, clientHello, "no cipher suite supported by both client and server") 187 } 188 189 func TestRenegotiationExtension(t *testing.T) { 190 clientHello := &clientHelloMsg{ 191 vers: VersionTLS12, 192 compressionMethods: []uint8{compressionNone}, 193 random: make([]byte, 32), 194 secureRenegotiation: true, 195 cipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, 196 } 197 198 var buf []byte 199 c, s := net.Pipe() 200 201 go func() { 202 cli := Client(c, testConfig) 203 cli.vers = clientHello.vers 204 cli.writeRecord(recordTypeHandshake, clientHello.marshal()) 205 206 buf = make([]byte, 1024) 207 n, err := c.Read(buf) 208 if err != nil { 209 t.Fatalf("Server read returned error: %s", err) 210 } 211 buf = buf[:n] 212 c.Close() 213 }() 214 215 Server(s, testConfig).Handshake() 216 217 if len(buf) < 5+4 { 218 t.Fatalf("Server returned short message of length %d", len(buf)) 219 } 220 // buf contains a TLS record, with a 5 byte record header and a 4 byte 221 // handshake header. The length of the ServerHello is taken from the 222 // handshake header. 223 serverHelloLen := int(buf[6])<<16 | int(buf[7])<<8 | int(buf[8]) 224 225 var serverHello serverHelloMsg 226 // unmarshal expects to be given the handshake header, but 227 // serverHelloLen doesn't include it. 228 if !serverHello.unmarshal(buf[5 : 9+serverHelloLen]) { 229 t.Fatalf("Failed to parse ServerHello") 230 } 231 232 if !serverHello.secureRenegotiation { 233 t.Errorf("Secure renegotiation extension was not echoed.") 234 } 235 } 236 237 func TestTLS12OnlyCipherSuites(t *testing.T) { 238 // Test that a Server doesn't select a TLS 1.2-only cipher suite when 239 // the client negotiates TLS 1.1. 240 var zeros [32]byte 241 242 clientHello := &clientHelloMsg{ 243 vers: VersionTLS11, 244 random: zeros[:], 245 cipherSuites: []uint16{ 246 // The Server, by default, will use the client's 247 // preference order. So the GCM cipher suite 248 // will be selected unless it's excluded because 249 // of the version in this ClientHello. 250 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 251 TLS_RSA_WITH_RC4_128_SHA, 252 }, 253 compressionMethods: []uint8{compressionNone}, 254 supportedCurves: []CurveID{CurveP256, CurveP384, CurveP521}, 255 supportedPoints: []uint8{pointFormatUncompressed}, 256 } 257 258 c, s := net.Pipe() 259 var reply interface{} 260 var clientErr error 261 go func() { 262 cli := Client(c, testConfig) 263 cli.vers = clientHello.vers 264 cli.writeRecord(recordTypeHandshake, clientHello.marshal()) 265 reply, clientErr = cli.readHandshake() 266 c.Close() 267 }() 268 config := *testConfig 269 config.CipherSuites = clientHello.cipherSuites 270 Server(s, &config).Handshake() 271 s.Close() 272 if clientErr != nil { 273 t.Fatal(clientErr) 274 } 275 serverHello, ok := reply.(*serverHelloMsg) 276 if !ok { 277 t.Fatalf("didn't get ServerHello message in reply. Got %v\n", reply) 278 } 279 if s := serverHello.cipherSuite; s != TLS_RSA_WITH_RC4_128_SHA { 280 t.Fatalf("bad cipher suite from server: %x", s) 281 } 282 } 283 284 func TestAlertForwarding(t *testing.T) { 285 c, s := net.Pipe() 286 go func() { 287 Client(c, testConfig).sendAlert(alertUnknownCA) 288 c.Close() 289 }() 290 291 err := Server(s, testConfig).Handshake() 292 s.Close() 293 if e, ok := err.(*net.OpError); !ok || e.Err != error(alertUnknownCA) { 294 t.Errorf("Got error: %s; expected: %s", err, error(alertUnknownCA)) 295 } 296 } 297 298 func TestClose(t *testing.T) { 299 c, s := net.Pipe() 300 go c.Close() 301 302 err := Server(s, testConfig).Handshake() 303 s.Close() 304 if err != io.EOF { 305 t.Errorf("Got error: %s; expected: %s", err, io.EOF) 306 } 307 } 308 309 func testHandshake(clientConfig, serverConfig *Config) (serverState, clientState ConnectionState, err error) { 310 c, s := net.Pipe() 311 done := make(chan bool) 312 go func() { 313 cli := Client(c, clientConfig) 314 cli.Handshake() 315 clientState = cli.ConnectionState() 316 c.Close() 317 done <- true 318 }() 319 server := Server(s, serverConfig) 320 err = server.Handshake() 321 if err == nil { 322 serverState = server.ConnectionState() 323 } 324 s.Close() 325 <-done 326 return 327 } 328 329 func TestVersion(t *testing.T) { 330 serverConfig := &Config{ 331 Certificates: testConfig.Certificates, 332 MaxVersion: VersionTLS11, 333 } 334 clientConfig := &Config{ 335 InsecureSkipVerify: true, 336 } 337 state, _, err := testHandshake(clientConfig, serverConfig) 338 if err != nil { 339 t.Fatalf("handshake failed: %s", err) 340 } 341 if state.Version != VersionTLS11 { 342 t.Fatalf("Incorrect version %x, should be %x", state.Version, VersionTLS11) 343 } 344 } 345 346 func TestCipherSuitePreference(t *testing.T) { 347 serverConfig := &Config{ 348 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA}, 349 Certificates: testConfig.Certificates, 350 MaxVersion: VersionTLS11, 351 } 352 clientConfig := &Config{ 353 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_RC4_128_SHA}, 354 InsecureSkipVerify: true, 355 } 356 state, _, err := testHandshake(clientConfig, serverConfig) 357 if err != nil { 358 t.Fatalf("handshake failed: %s", err) 359 } 360 if state.CipherSuite != TLS_RSA_WITH_AES_128_CBC_SHA { 361 // By default the server should use the client's preference. 362 t.Fatalf("Client's preference was not used, got %x", state.CipherSuite) 363 } 364 365 serverConfig.PreferServerCipherSuites = true 366 state, _, err = testHandshake(clientConfig, serverConfig) 367 if err != nil { 368 t.Fatalf("handshake failed: %s", err) 369 } 370 if state.CipherSuite != TLS_RSA_WITH_RC4_128_SHA { 371 t.Fatalf("Server's preference was not used, got %x", state.CipherSuite) 372 } 373 } 374 375 func TestSCTHandshake(t *testing.T) { 376 expected := [][]byte{[]byte("certificate"), []byte("transparency")} 377 serverConfig := &Config{ 378 Certificates: []Certificate{{ 379 Certificate: [][]byte{testRSACertificate}, 380 PrivateKey: testRSAPrivateKey, 381 SignedCertificateTimestamps: expected, 382 }}, 383 } 384 clientConfig := &Config{ 385 InsecureSkipVerify: true, 386 } 387 _, state, err := testHandshake(clientConfig, serverConfig) 388 if err != nil { 389 t.Fatalf("handshake failed: %s", err) 390 } 391 actual := state.SignedCertificateTimestamps 392 if len(actual) != len(expected) { 393 t.Fatalf("got %d scts, want %d", len(actual), len(expected)) 394 } 395 for i, sct := range expected { 396 if !bytes.Equal(sct, actual[i]) { 397 t.Fatalf("SCT #%d was %x, but expected %x", i, actual[i], sct) 398 } 399 } 400 } 401 402 // Note: see comment in handshake_test.go for details of how the reference 403 // tests work. 404 405 // serverTest represents a test of the TLS server handshake against a reference 406 // implementation. 407 type serverTest struct { 408 // name is a freeform string identifying the test and the file in which 409 // the expected results will be stored. 410 name string 411 // command, if not empty, contains a series of arguments for the 412 // command to run for the reference server. 413 command []string 414 // expectedPeerCerts contains a list of PEM blocks of expected 415 // certificates from the client. 416 expectedPeerCerts []string 417 // config, if not nil, contains a custom Config to use for this test. 418 config *Config 419 // expectHandshakeErrorIncluding, when not empty, contains a string 420 // that must be a substring of the error resulting from the handshake. 421 expectHandshakeErrorIncluding string 422 // validate, if not nil, is a function that will be called with the 423 // ConnectionState of the resulting connection. It returns false if the 424 // ConnectionState is unacceptable. 425 validate func(ConnectionState) error 426 } 427 428 var defaultClientCommand = []string{"openssl", "s_client", "-no_ticket"} 429 430 // connFromCommand starts opens a listening socket and starts the reference 431 // client to connect to it. It returns a recordingConn that wraps the resulting 432 // connection. 433 func (test *serverTest) connFromCommand() (conn *recordingConn, child *exec.Cmd, err error) { 434 l, err := net.ListenTCP("tcp", &net.TCPAddr{ 435 IP: net.IPv4(127, 0, 0, 1), 436 Port: 0, 437 }) 438 if err != nil { 439 return nil, nil, err 440 } 441 defer l.Close() 442 443 port := l.Addr().(*net.TCPAddr).Port 444 445 var command []string 446 command = append(command, test.command...) 447 if len(command) == 0 { 448 command = defaultClientCommand 449 } 450 command = append(command, "-connect") 451 command = append(command, fmt.Sprintf("127.0.0.1:%d", port)) 452 cmd := exec.Command(command[0], command[1:]...) 453 cmd.Stdin = nil 454 var output bytes.Buffer 455 cmd.Stdout = &output 456 cmd.Stderr = &output 457 if err := cmd.Start(); err != nil { 458 return nil, nil, err 459 } 460 461 connChan := make(chan interface{}) 462 go func() { 463 tcpConn, err := l.Accept() 464 if err != nil { 465 connChan <- err 466 } 467 connChan <- tcpConn 468 }() 469 470 var tcpConn net.Conn 471 select { 472 case connOrError := <-connChan: 473 if err, ok := connOrError.(error); ok { 474 return nil, nil, err 475 } 476 tcpConn = connOrError.(net.Conn) 477 case <-time.After(2 * time.Second): 478 output.WriteTo(os.Stdout) 479 return nil, nil, errors.New("timed out waiting for connection from child process") 480 } 481 482 record := &recordingConn{ 483 Conn: tcpConn, 484 } 485 486 return record, cmd, nil 487 } 488 489 func (test *serverTest) dataPath() string { 490 return filepath.Join("testdata", "Server-"+test.name) 491 } 492 493 func (test *serverTest) loadData() (flows [][]byte, err error) { 494 in, err := os.Open(test.dataPath()) 495 if err != nil { 496 return nil, err 497 } 498 defer in.Close() 499 return parseTestData(in) 500 } 501 502 func (test *serverTest) run(t *testing.T, write bool) { 503 var clientConn, serverConn net.Conn 504 var recordingConn *recordingConn 505 var childProcess *exec.Cmd 506 507 if write { 508 var err error 509 recordingConn, childProcess, err = test.connFromCommand() 510 if err != nil { 511 t.Fatalf("Failed to start subcommand: %s", err) 512 } 513 serverConn = recordingConn 514 } else { 515 clientConn, serverConn = net.Pipe() 516 } 517 config := test.config 518 if config == nil { 519 config = testConfig 520 } 521 server := Server(serverConn, config) 522 connStateChan := make(chan ConnectionState, 1) 523 go func() { 524 _, err := server.Write([]byte("hello, world\n")) 525 if len(test.expectHandshakeErrorIncluding) > 0 { 526 if err == nil { 527 t.Errorf("Error expected, but no error returned") 528 } else if s := err.Error(); !strings.Contains(s, test.expectHandshakeErrorIncluding) { 529 t.Errorf("Error expected containing '%s' but got '%s'", test.expectHandshakeErrorIncluding, s) 530 } 531 } else { 532 if err != nil { 533 t.Logf("Error from Server.Write: '%s'", err) 534 } 535 } 536 server.Close() 537 serverConn.Close() 538 connStateChan <- server.ConnectionState() 539 }() 540 541 if !write { 542 flows, err := test.loadData() 543 if err != nil { 544 t.Fatalf("%s: failed to load data from %s", test.name, test.dataPath()) 545 } 546 for i, b := range flows { 547 if i%2 == 0 { 548 clientConn.Write(b) 549 continue 550 } 551 bb := make([]byte, len(b)) 552 n, err := io.ReadFull(clientConn, bb) 553 if err != nil { 554 t.Fatalf("%s #%d: %s\nRead %d, wanted %d, got %x, wanted %x\n", test.name, i+1, err, n, len(bb), bb[:n], b) 555 } 556 if !bytes.Equal(b, bb) { 557 t.Fatalf("%s #%d: mismatch on read: got:%x want:%x", test.name, i+1, bb, b) 558 } 559 } 560 clientConn.Close() 561 } 562 563 connState := <-connStateChan 564 peerCerts := connState.PeerCertificates 565 if len(peerCerts) == len(test.expectedPeerCerts) { 566 for i, peerCert := range peerCerts { 567 block, _ := pem.Decode([]byte(test.expectedPeerCerts[i])) 568 if !bytes.Equal(block.Bytes, peerCert.Raw) { 569 t.Fatalf("%s: mismatch on peer cert %d", test.name, i+1) 570 } 571 } 572 } else { 573 t.Fatalf("%s: mismatch on peer list length: %d (wanted) != %d (got)", test.name, len(test.expectedPeerCerts), len(peerCerts)) 574 } 575 576 if test.validate != nil { 577 if err := test.validate(connState); err != nil { 578 t.Fatalf("validate callback returned error: %s", err) 579 } 580 } 581 582 if write { 583 path := test.dataPath() 584 out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) 585 if err != nil { 586 t.Fatalf("Failed to create output file: %s", err) 587 } 588 defer out.Close() 589 recordingConn.Close() 590 if len(recordingConn.flows) < 3 { 591 childProcess.Stdout.(*bytes.Buffer).WriteTo(os.Stdout) 592 if len(test.expectHandshakeErrorIncluding) == 0 { 593 t.Fatalf("Handshake failed") 594 } 595 } 596 recordingConn.WriteTo(out) 597 fmt.Printf("Wrote %s\n", path) 598 childProcess.Wait() 599 } 600 } 601 602 func runServerTestForVersion(t *testing.T, template *serverTest, prefix, option string) { 603 test := *template 604 test.name = prefix + test.name 605 if len(test.command) == 0 { 606 test.command = defaultClientCommand 607 } 608 test.command = append([]string(nil), test.command...) 609 test.command = append(test.command, option) 610 test.run(t, *update) 611 } 612 613 func runServerTestSSLv3(t *testing.T, template *serverTest) { 614 runServerTestForVersion(t, template, "SSLv3-", "-ssl3") 615 } 616 617 func runServerTestTLS10(t *testing.T, template *serverTest) { 618 runServerTestForVersion(t, template, "TLSv10-", "-tls1") 619 } 620 621 func runServerTestTLS11(t *testing.T, template *serverTest) { 622 runServerTestForVersion(t, template, "TLSv11-", "-tls1_1") 623 } 624 625 func runServerTestTLS12(t *testing.T, template *serverTest) { 626 runServerTestForVersion(t, template, "TLSv12-", "-tls1_2") 627 } 628 629 func TestHandshakeServerRSARC4(t *testing.T) { 630 test := &serverTest{ 631 name: "RSA-RC4", 632 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "RC4-SHA"}, 633 } 634 runServerTestSSLv3(t, test) 635 runServerTestTLS10(t, test) 636 runServerTestTLS11(t, test) 637 runServerTestTLS12(t, test) 638 } 639 640 func TestHandshakeServerRSA3DES(t *testing.T) { 641 test := &serverTest{ 642 name: "RSA-3DES", 643 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "DES-CBC3-SHA"}, 644 } 645 runServerTestSSLv3(t, test) 646 runServerTestTLS10(t, test) 647 runServerTestTLS12(t, test) 648 } 649 650 func TestHandshakeServerRSAAES(t *testing.T) { 651 test := &serverTest{ 652 name: "RSA-AES", 653 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "AES128-SHA"}, 654 } 655 runServerTestSSLv3(t, test) 656 runServerTestTLS10(t, test) 657 runServerTestTLS12(t, test) 658 } 659 660 func TestHandshakeServerAESGCM(t *testing.T) { 661 test := &serverTest{ 662 name: "RSA-AES-GCM", 663 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "ECDHE-RSA-AES128-GCM-SHA256"}, 664 } 665 runServerTestTLS12(t, test) 666 } 667 668 func TestHandshakeServerAES256GCMSHA384(t *testing.T) { 669 test := &serverTest{ 670 name: "RSA-AES256-GCM-SHA384", 671 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "ECDHE-RSA-AES256-GCM-SHA384"}, 672 } 673 runServerTestTLS12(t, test) 674 } 675 676 func TestHandshakeServerECDHEECDSAAES(t *testing.T) { 677 config := *testConfig 678 config.Certificates = make([]Certificate, 1) 679 config.Certificates[0].Certificate = [][]byte{testECDSACertificate} 680 config.Certificates[0].PrivateKey = testECDSAPrivateKey 681 config.BuildNameToCertificate() 682 683 test := &serverTest{ 684 name: "ECDHE-ECDSA-AES", 685 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "ECDHE-ECDSA-AES256-SHA"}, 686 config: &config, 687 } 688 runServerTestTLS10(t, test) 689 runServerTestTLS12(t, test) 690 } 691 692 func TestHandshakeServerALPN(t *testing.T) { 693 config := *testConfig 694 config.NextProtos = []string{"proto1", "proto2"} 695 696 test := &serverTest{ 697 name: "ALPN", 698 // Note that this needs OpenSSL 1.0.2 because that is the first 699 // version that supports the -alpn flag. 700 command: []string{"openssl", "s_client", "-alpn", "proto2,proto1"}, 701 config: &config, 702 validate: func(state ConnectionState) error { 703 // The server's preferences should override the client. 704 if state.NegotiatedProtocol != "proto1" { 705 return fmt.Errorf("Got protocol %q, wanted proto1", state.NegotiatedProtocol) 706 } 707 return nil 708 }, 709 } 710 runServerTestTLS12(t, test) 711 } 712 713 func TestHandshakeServerALPNNoMatch(t *testing.T) { 714 config := *testConfig 715 config.NextProtos = []string{"proto3"} 716 717 test := &serverTest{ 718 name: "ALPN-NoMatch", 719 // Note that this needs OpenSSL 1.0.2 because that is the first 720 // version that supports the -alpn flag. 721 command: []string{"openssl", "s_client", "-alpn", "proto2,proto1"}, 722 config: &config, 723 validate: func(state ConnectionState) error { 724 // Rather than reject the connection, Go doesn't select 725 // a protocol when there is no overlap. 726 if state.NegotiatedProtocol != "" { 727 return fmt.Errorf("Got protocol %q, wanted ''", state.NegotiatedProtocol) 728 } 729 return nil 730 }, 731 } 732 runServerTestTLS12(t, test) 733 } 734 735 // TestHandshakeServerSNI involves a client sending an SNI extension of 736 // "snitest.com", which happens to match the CN of testSNICertificate. The test 737 // verifies that the server correctly selects that certificate. 738 func TestHandshakeServerSNI(t *testing.T) { 739 test := &serverTest{ 740 name: "SNI", 741 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "AES128-SHA", "-servername", "snitest.com"}, 742 } 743 runServerTestTLS12(t, test) 744 } 745 746 // TestHandshakeServerSNICertForName is similar to TestHandshakeServerSNI, but 747 // tests the dynamic GetCertificate method 748 func TestHandshakeServerSNIGetCertificate(t *testing.T) { 749 config := *testConfig 750 751 // Replace the NameToCertificate map with a GetCertificate function 752 nameToCert := config.NameToCertificate 753 config.NameToCertificate = nil 754 config.GetCertificate = func(clientHello *ClientHelloInfo) (*Certificate, error) { 755 cert, _ := nameToCert[clientHello.ServerName] 756 return cert, nil 757 } 758 test := &serverTest{ 759 name: "SNI-GetCertificate", 760 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "AES128-SHA", "-servername", "snitest.com"}, 761 config: &config, 762 } 763 runServerTestTLS12(t, test) 764 } 765 766 // TestHandshakeServerSNICertForNameNotFound is similar to 767 // TestHandshakeServerSNICertForName, but tests to make sure that when the 768 // GetCertificate method doesn't return a cert, we fall back to what's in 769 // the NameToCertificate map. 770 func TestHandshakeServerSNIGetCertificateNotFound(t *testing.T) { 771 config := *testConfig 772 773 config.GetCertificate = func(clientHello *ClientHelloInfo) (*Certificate, error) { 774 return nil, nil 775 } 776 test := &serverTest{ 777 name: "SNI-GetCertificateNotFound", 778 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "AES128-SHA", "-servername", "snitest.com"}, 779 config: &config, 780 } 781 runServerTestTLS12(t, test) 782 } 783 784 // TestHandshakeServerSNICertForNameError tests to make sure that errors in 785 // GetCertificate result in a tls alert. 786 func TestHandshakeServerSNIGetCertificateError(t *testing.T) { 787 const errMsg = "TestHandshakeServerSNIGetCertificateError error" 788 789 serverConfig := *testConfig 790 serverConfig.GetCertificate = func(clientHello *ClientHelloInfo) (*Certificate, error) { 791 return nil, errors.New(errMsg) 792 } 793 794 clientHello := &clientHelloMsg{ 795 vers: VersionTLS10, 796 cipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, 797 compressionMethods: []uint8{compressionNone}, 798 serverName: "test", 799 } 800 testClientHelloFailure(t, &serverConfig, clientHello, errMsg) 801 } 802 803 // TestHandshakeServerEmptyCertificates tests that GetCertificates is called in 804 // the case that Certificates is empty, even without SNI. 805 func TestHandshakeServerEmptyCertificates(t *testing.T) { 806 const errMsg = "TestHandshakeServerEmptyCertificates error" 807 808 serverConfig := *testConfig 809 serverConfig.GetCertificate = func(clientHello *ClientHelloInfo) (*Certificate, error) { 810 return nil, errors.New(errMsg) 811 } 812 serverConfig.Certificates = nil 813 814 clientHello := &clientHelloMsg{ 815 vers: VersionTLS10, 816 cipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, 817 compressionMethods: []uint8{compressionNone}, 818 } 819 testClientHelloFailure(t, &serverConfig, clientHello, errMsg) 820 821 // With an empty Certificates and a nil GetCertificate, the server 822 // should always return a “no certificates” error. 823 serverConfig.GetCertificate = nil 824 825 clientHello = &clientHelloMsg{ 826 vers: VersionTLS10, 827 cipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, 828 compressionMethods: []uint8{compressionNone}, 829 } 830 testClientHelloFailure(t, &serverConfig, clientHello, "no certificates") 831 } 832 833 // TestCipherSuiteCertPreferance ensures that we select an RSA ciphersuite with 834 // an RSA certificate and an ECDSA ciphersuite with an ECDSA certificate. 835 func TestCipherSuiteCertPreferenceECDSA(t *testing.T) { 836 config := *testConfig 837 config.CipherSuites = []uint16{TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA} 838 config.PreferServerCipherSuites = true 839 840 test := &serverTest{ 841 name: "CipherSuiteCertPreferenceRSA", 842 config: &config, 843 } 844 runServerTestTLS12(t, test) 845 846 config = *testConfig 847 config.CipherSuites = []uint16{TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA} 848 config.Certificates = []Certificate{ 849 { 850 Certificate: [][]byte{testECDSACertificate}, 851 PrivateKey: testECDSAPrivateKey, 852 }, 853 } 854 config.BuildNameToCertificate() 855 config.PreferServerCipherSuites = true 856 857 test = &serverTest{ 858 name: "CipherSuiteCertPreferenceECDSA", 859 config: &config, 860 } 861 runServerTestTLS12(t, test) 862 } 863 864 func TestResumption(t *testing.T) { 865 sessionFilePath := tempFile("") 866 defer os.Remove(sessionFilePath) 867 868 test := &serverTest{ 869 name: "IssueTicket", 870 command: []string{"openssl", "s_client", "-cipher", "RC4-SHA", "-sess_out", sessionFilePath}, 871 } 872 runServerTestTLS12(t, test) 873 874 test = &serverTest{ 875 name: "Resume", 876 command: []string{"openssl", "s_client", "-cipher", "RC4-SHA", "-sess_in", sessionFilePath}, 877 } 878 runServerTestTLS12(t, test) 879 } 880 881 func TestResumptionDisabled(t *testing.T) { 882 sessionFilePath := tempFile("") 883 defer os.Remove(sessionFilePath) 884 885 config := *testConfig 886 887 test := &serverTest{ 888 name: "IssueTicketPreDisable", 889 command: []string{"openssl", "s_client", "-cipher", "RC4-SHA", "-sess_out", sessionFilePath}, 890 config: &config, 891 } 892 runServerTestTLS12(t, test) 893 894 config.SessionTicketsDisabled = true 895 896 test = &serverTest{ 897 name: "ResumeDisabled", 898 command: []string{"openssl", "s_client", "-cipher", "RC4-SHA", "-sess_in", sessionFilePath}, 899 config: &config, 900 } 901 runServerTestTLS12(t, test) 902 903 // One needs to manually confirm that the handshake in the golden data 904 // file for ResumeDisabled does not include a resumption handshake. 905 } 906 907 func TestFallbackSCSV(t *testing.T) { 908 serverConfig := &Config{ 909 Certificates: testConfig.Certificates, 910 } 911 test := &serverTest{ 912 name: "FallbackSCSV", 913 config: serverConfig, 914 // OpenSSL 1.0.1j is needed for the -fallback_scsv option. 915 command: []string{"openssl", "s_client", "-fallback_scsv"}, 916 expectHandshakeErrorIncluding: "inappropriate protocol fallback", 917 } 918 runServerTestTLS11(t, test) 919 } 920 921 // cert.pem and key.pem were generated with generate_cert.go 922 // Thus, they have no ExtKeyUsage fields and trigger an error 923 // when verification is turned on. 924 925 const clientCertificatePEM = ` 926 -----BEGIN CERTIFICATE----- 927 MIIB7TCCAVigAwIBAgIBADALBgkqhkiG9w0BAQUwJjEQMA4GA1UEChMHQWNtZSBD 928 bzESMBAGA1UEAxMJMTI3LjAuMC4xMB4XDTExMTIwODA3NTUxMloXDTEyMTIwNzA4 929 MDAxMlowJjEQMA4GA1UEChMHQWNtZSBDbzESMBAGA1UEAxMJMTI3LjAuMC4xMIGc 930 MAsGCSqGSIb3DQEBAQOBjAAwgYgCgYBO0Hsx44Jk2VnAwoekXh6LczPHY1PfZpIG 931 hPZk1Y/kNqcdK+izIDZFI7Xjla7t4PUgnI2V339aEu+H5Fto5OkOdOwEin/ekyfE 932 ARl6vfLcPRSr0FTKIQzQTW6HLlzF0rtNS0/Otiz3fojsfNcCkXSmHgwa2uNKWi7e 933 E5xMQIhZkwIDAQABozIwMDAOBgNVHQ8BAf8EBAMCAKAwDQYDVR0OBAYEBAECAwQw 934 DwYDVR0jBAgwBoAEAQIDBDALBgkqhkiG9w0BAQUDgYEANh+zegx1yW43RmEr1b3A 935 p0vMRpqBWHyFeSnIyMZn3TJWRSt1tukkqVCavh9a+hoV2cxVlXIWg7nCto/9iIw4 936 hB2rXZIxE0/9gzvGnfERYraL7KtnvshksBFQRlgXa5kc0x38BvEO5ZaoDPl4ILdE 937 GFGNEH5PlGffo05wc46QkYU= 938 -----END CERTIFICATE-----` 939 940 const clientKeyPEM = ` 941 -----BEGIN RSA PRIVATE KEY----- 942 MIICWgIBAAKBgE7QezHjgmTZWcDCh6ReHotzM8djU99mkgaE9mTVj+Q2px0r6LMg 943 NkUjteOVru3g9SCcjZXff1oS74fkW2jk6Q507ASKf96TJ8QBGXq98tw9FKvQVMoh 944 DNBNbocuXMXSu01LT862LPd+iOx81wKRdKYeDBra40paLt4TnExAiFmTAgMBAAEC 945 gYBxvXd8yNteFTns8A/2yomEMC4yeosJJSpp1CsN3BJ7g8/qTnrVPxBy+RU+qr63 946 t2WquaOu/cr5P8iEsa6lk20tf8pjKLNXeX0b1RTzK8rJLbS7nGzP3tvOhL096VtQ 947 dAo4ROEaro0TzYpHmpciSvxVIeEIAAdFDObDJPKqcJAxyQJBAJizfYgK8Gzx9fsx 948 hxp+VteCbVPg2euASH5Yv3K5LukRdKoSzHE2grUVQgN/LafC0eZibRanxHegYSr7 949 7qaswKUCQQCEIWor/X4XTMdVj3Oj+vpiw75y/S9gh682+myZL+d/02IEkwnB098P 950 RkKVpenBHyrGg0oeN5La7URILWKj7CPXAkBKo6F+d+phNjwIFoN1Xb/RA32w/D1I 951 saG9sF+UEhRt9AxUfW/U/tIQ9V0ZHHcSg1XaCM5Nvp934brdKdvTOKnJAkBD5h/3 952 Rybatlvg/fzBEaJFyq09zhngkxlZOUtBVTqzl17RVvY2orgH02U4HbCHy4phxOn7 953 qTdQRYlHRftgnWK1AkANibn9PRYJ7mJyJ9Dyj2QeNcSkSTzrt0tPvUMf4+meJymN 954 1Ntu5+S1DLLzfxlaljWG6ylW6DNxujCyuXIV2rvA 955 -----END RSA PRIVATE KEY-----` 956 957 const clientECDSACertificatePEM = ` 958 -----BEGIN CERTIFICATE----- 959 MIIB/DCCAV4CCQCaMIRsJjXZFzAJBgcqhkjOPQQBMEUxCzAJBgNVBAYTAkFVMRMw 960 EQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0 961 eSBMdGQwHhcNMTIxMTE0MTMyNTUzWhcNMjIxMTEyMTMyNTUzWjBBMQswCQYDVQQG 962 EwJBVTEMMAoGA1UECBMDTlNXMRAwDgYDVQQHEwdQeXJtb250MRIwEAYDVQQDEwlK 963 b2VsIFNpbmcwgZswEAYHKoZIzj0CAQYFK4EEACMDgYYABACVjJF1FMBexFe01MNv 964 ja5oHt1vzobhfm6ySD6B5U7ixohLZNz1MLvT/2XMW/TdtWo+PtAd3kfDdq0Z9kUs 965 jLzYHQFMH3CQRnZIi4+DzEpcj0B22uCJ7B0rxE4wdihBsmKo+1vx+U56jb0JuK7q 966 ixgnTy5w/hOWusPTQBbNZU6sER7m8TAJBgcqhkjOPQQBA4GMADCBiAJCAOAUxGBg 967 C3JosDJdYUoCdFzCgbkWqD8pyDbHgf9stlvZcPE4O1BIKJTLCRpS8V3ujfK58PDa 968 2RU6+b0DeoeiIzXsAkIBo9SKeDUcSpoj0gq+KxAxnZxfvuiRs9oa9V2jI/Umi0Vw 969 jWVim34BmT0Y9hCaOGGbLlfk+syxis7iI6CH8OFnUes= 970 -----END CERTIFICATE-----` 971 972 const clientECDSAKeyPEM = ` 973 -----BEGIN EC PARAMETERS----- 974 BgUrgQQAIw== 975 -----END EC PARAMETERS----- 976 -----BEGIN EC PRIVATE KEY----- 977 MIHcAgEBBEIBkJN9X4IqZIguiEVKMqeBUP5xtRsEv4HJEtOpOGLELwO53SD78Ew8 978 k+wLWoqizS3NpQyMtrU8JFdWfj+C57UNkOugBwYFK4EEACOhgYkDgYYABACVjJF1 979 FMBexFe01MNvja5oHt1vzobhfm6ySD6B5U7ixohLZNz1MLvT/2XMW/TdtWo+PtAd 980 3kfDdq0Z9kUsjLzYHQFMH3CQRnZIi4+DzEpcj0B22uCJ7B0rxE4wdihBsmKo+1vx 981 +U56jb0JuK7qixgnTy5w/hOWusPTQBbNZU6sER7m8Q== 982 -----END EC PRIVATE KEY-----` 983 984 func TestClientAuth(t *testing.T) { 985 var certPath, keyPath, ecdsaCertPath, ecdsaKeyPath string 986 987 if *update { 988 certPath = tempFile(clientCertificatePEM) 989 defer os.Remove(certPath) 990 keyPath = tempFile(clientKeyPEM) 991 defer os.Remove(keyPath) 992 ecdsaCertPath = tempFile(clientECDSACertificatePEM) 993 defer os.Remove(ecdsaCertPath) 994 ecdsaKeyPath = tempFile(clientECDSAKeyPEM) 995 defer os.Remove(ecdsaKeyPath) 996 } 997 998 config := *testConfig 999 config.ClientAuth = RequestClientCert 1000 1001 test := &serverTest{ 1002 name: "ClientAuthRequestedNotGiven", 1003 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "RC4-SHA"}, 1004 config: &config, 1005 } 1006 runServerTestTLS12(t, test) 1007 1008 test = &serverTest{ 1009 name: "ClientAuthRequestedAndGiven", 1010 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "RC4-SHA", "-cert", certPath, "-key", keyPath}, 1011 config: &config, 1012 expectedPeerCerts: []string{clientCertificatePEM}, 1013 } 1014 runServerTestTLS12(t, test) 1015 1016 test = &serverTest{ 1017 name: "ClientAuthRequestedAndECDSAGiven", 1018 command: []string{"openssl", "s_client", "-no_ticket", "-cipher", "RC4-SHA", "-cert", ecdsaCertPath, "-key", ecdsaKeyPath}, 1019 config: &config, 1020 expectedPeerCerts: []string{clientECDSACertificatePEM}, 1021 } 1022 runServerTestTLS12(t, test) 1023 } 1024 1025 func bigFromString(s string) *big.Int { 1026 ret := new(big.Int) 1027 ret.SetString(s, 10) 1028 return ret 1029 } 1030 1031 func fromHex(s string) []byte { 1032 b, _ := hex.DecodeString(s) 1033 return b 1034 } 1035 1036 var testRSACertificate = fromHex("30820263308201cca003020102020900a273000c8100cbf3300d06092a864886f70d01010b0500302b31173015060355040a130e476f6f676c652054455354494e473110300e06035504031307476f20526f6f74301e170d3135303130313030303030305a170d3235303130313030303030305a302631173015060355040a130e476f6f676c652054455354494e47310b300906035504031302476f30819f300d06092a864886f70d010101050003818d0030818902818100af8788f6201b95656c14ab4405af3b4514e3b76dfd00634d957ffe6a623586c04af9187cf6aa255e7a64316600baf48e92afc76bd876d4f35f41cb6e5615971b97c13c123921663d2b16d1bcdb1cc0a7dab7caadbadacbd52150ecde8dabd16b814b8902f3c4bec16c89b14484bd21d1047d9d164df98215f6effad60947f2fb0203010001a38193308190300e0603551d0f0101ff0404030205a0301d0603551d250416301406082b0601050507030106082b06010505070302300c0603551d130101ff0402300030190603551d0e0412041012508d896f1bd1dc544d6ecb695e06f4301b0603551d23041430128010bf3db6a966f2b840cfeab40378481a4130190603551d1104123010820e6578616d706c652e676f6c616e67300d06092a864886f70d01010b050003818100927caf91551218965931a64840d52dd5eebb02a0f5c21e7c9bb3307d3cdc76da4f3dc0faae2d33246b037b1b67591121b511bc77b9d9e06ea82d2e35fa645f223e63106bbeff14866d0df01531a814381e3b84872ccb98ed5176b9b14fdddb9b84048640fa51ddbab48debe346de46b94f86c7f9a4c24134acccf6eab0ab3918") 1037 1038 var testRSACertificateIssuer = fromHex("3082024d308201b6a003020102020827326bd913b7c43d300d06092a864886f70d01010b0500302b31173015060355040a130e476f6f676c652054455354494e473110300e06035504031307476f20526f6f74301e170d3135303130313030303030305a170d3235303130313030303030305a302b31173015060355040a130e476f6f676c652054455354494e473110300e06035504031307476f20526f6f7430819f300d06092a864886f70d010101050003818d0030818902818100f0429a7b9f66a222c8453800452db355b34c4409fee09af2510a6589bfa35bdb4d453200d1de24338d6d5e5a91cc8301628445d6eb4e675927b9c1ea5c0f676acfb0f708ce4f19827e321c1898bf86df9823d5f0b05df2b6779888eff8abbc7f41c6e7d2667386a579b8cbaad3f6fd597cd7c4b187911a425aed1b555c1965190203010001a37a3078300e0603551d0f0101ff040403020204301d0603551d250416301406082b0601050507030106082b06010505070302300f0603551d130101ff040530030101ff30190603551d0e04120410bf3db6a966f2b840cfeab40378481a41301b0603551d23041430128010bf3db6a966f2b840cfeab40378481a41300d06092a864886f70d01010b050003818100586e68c1219ed4f5782b7cfd53cf1a55750a98781b2023f8694bb831fff6d7d4aad1f0ac782b1ec787f00a8956bdd06b4a1063444fcafe955c07d679163a730802c568886a2cf8a3c2ab41176957131c4b9e077ebd7ffbb91fdad8b08b932e9aeefac04923ffdc0aa145563f7f061995317400203578f350e3e566deb29dec5e") 1039 1040 var testECDSACertificate = fromHex("3082020030820162020900b8bf2d47a0d2ebf4300906072a8648ce3d04013045310b3009060355040613024155311330110603550408130a536f6d652d53746174653121301f060355040a1318496e7465726e6574205769646769747320507479204c7464301e170d3132313132323135303633325a170d3232313132303135303633325a3045310b3009060355040613024155311330110603550408130a536f6d652d53746174653121301f060355040a1318496e7465726e6574205769646769747320507479204c746430819b301006072a8648ce3d020106052b81040023038186000400c4a1edbe98f90b4873367ec316561122f23d53c33b4d213dcd6b75e6f6b0dc9adf26c1bcb287f072327cb3642f1c90bcea6823107efee325c0483a69e0286dd33700ef0462dd0da09c706283d881d36431aa9e9731bd96b068c09b23de76643f1a5c7fe9120e5858b65f70dd9bd8ead5d7f5d5ccb9b69f30665b669a20e227e5bffe3b300906072a8648ce3d040103818c0030818802420188a24febe245c5487d1bacf5ed989dae4770c05e1bb62fbdf1b64db76140d311a2ceee0b7e927eff769dc33b7ea53fcefa10e259ec472d7cacda4e970e15a06fd00242014dfcbe67139c2d050ebd3fa38c25c13313830d9406bbd4377af6ec7ac9862eddd711697f857c56defb31782be4c7780daecbbe9e4e3624317b6a0f399512078f2a") 1041 1042 var testSNICertificate = fromHex("308201f23082015da003020102020100300b06092a864886f70d01010530283110300e060355040a130741636d6520436f311430120603550403130b736e69746573742e636f6d301e170d3132303431313137343033355a170d3133303431313137343533355a30283110300e060355040a130741636d6520436f311430120603550403130b736e69746573742e636f6d30819d300b06092a864886f70d01010103818d0030818902818100bb79d6f517b5e5bf4610d0dc69bee62b07435ad0032d8a7a4385b71452e7a5654c2c78b8238cb5b482e5de1f953b7e62a52ca533d6fe125c7a56fcf506bffa587b263fb5cd04d3d0c921964ac7f4549f5abfef427100fe1899077f7e887d7df10439c4a22edb51c97ce3c04c3b326601cfafb11db8719a1ddbdb896baeda2d790203010001a3323030300e0603551d0f0101ff0404030200a0300d0603551d0e0406040401020304300f0603551d2304083006800401020304300b06092a864886f70d0101050381810089c6455f1c1f5ef8eb1ab174ee2439059f5c4259bb1a8d86cdb1d056f56a717da40e95ab90f59e8deaf627c157995094db0802266eb34fc6842dea8a4b68d9c1389103ab84fb9e1f85d9b5d23ff2312c8670fbb540148245a4ebafe264d90c8a4cf4f85b0fac12ac2fc4a3154bad52462868af96c62c6525d652b6e31845bdcc") 1043 1044 var testRSAPrivateKey = &rsa.PrivateKey{ 1045 PublicKey: rsa.PublicKey{ 1046 N: bigFromString("123260960069105588390096594560395120585636206567569540256061833976822892593755073841963170165000086278069699238754008398039246547214989242849418349143232951701395321381739566687846006911427966669790845430647688107009232778985142860108863460556510585049041936029324503323373417214453307648498561956908810892027L"), 1047 E: 65537, 1048 }, 1049 D: bigFromString("73196363031103823625826315929954946106043759818067219550565550066527203472294428548476778865091068522665312037075674791871635825938217363523103946045078950060973913307430314113074463630778799389010335923241901501086246276485964417618981733827707048660375428006201525399194575538037883519254056917253456403553L"), 1050 Primes: []*big.Int{ 1051 bigFromString("11157426355495284553529769521954035649776033703833034489026848970480272318436419662860715175517581249375929775774910501512841707465207184924996975125010787L"), 1052 bigFromString("11047436580963564307160117670964629323534448585520694947919342920137706075617545637058809770319843170934495909554506529982972972247390145716507031692656521L"), 1053 }, 1054 } 1055 1056 var testECDSAPrivateKey = &ecdsa.PrivateKey{ 1057 PublicKey: ecdsa.PublicKey{ 1058 Curve: elliptic.P521(), 1059 X: bigFromString("2636411247892461147287360222306590634450676461695221912739908880441342231985950069527906976759812296359387337367668045707086543273113073382714101597903639351"), 1060 Y: bigFromString("3204695818431246682253994090650952614555094516658732116404513121125038617915183037601737180082382202488628239201196033284060130040574800684774115478859677243"), 1061 }, 1062 D: bigFromString("5477294338614160138026852784385529180817726002953041720191098180813046231640184669647735805135001309477695746518160084669446643325196003346204701381388769751"), 1063 }