Alternative TLS implementation in Go
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

1060 lignes
38 KiB

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