github.com/mtsmfm/go/src@v0.0.0-20221020090648-44bdcb9f8fde/crypto/tls/handshake_client_tls13.go (about) 1 // Copyright 2018 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 "context" 10 "crypto" 11 "crypto/ecdh" 12 "crypto/hmac" 13 "crypto/rsa" 14 "errors" 15 "hash" 16 "time" 17 ) 18 19 type clientHandshakeStateTLS13 struct { 20 c *Conn 21 ctx context.Context 22 serverHello *serverHelloMsg 23 hello *clientHelloMsg 24 ecdheKey *ecdh.PrivateKey 25 26 session *ClientSessionState 27 earlySecret []byte 28 binderKey []byte 29 30 certReq *certificateRequestMsgTLS13 31 usingPSK bool 32 sentDummyCCS bool 33 suite *cipherSuiteTLS13 34 transcript hash.Hash 35 masterSecret []byte 36 trafficSecret []byte // client_application_traffic_secret_0 37 } 38 39 // handshake requires hs.c, hs.hello, hs.serverHello, hs.ecdheKey, and, 40 // optionally, hs.session, hs.earlySecret and hs.binderKey to be set. 41 func (hs *clientHandshakeStateTLS13) handshake() error { 42 c := hs.c 43 44 if needFIPS() { 45 return errors.New("tls: internal error: TLS 1.3 reached in FIPS mode") 46 } 47 48 // The server must not select TLS 1.3 in a renegotiation. See RFC 8446, 49 // sections 4.1.2 and 4.1.3. 50 if c.handshakes > 0 { 51 c.sendAlert(alertProtocolVersion) 52 return errors.New("tls: server selected TLS 1.3 in a renegotiation") 53 } 54 55 // Consistency check on the presence of a keyShare and its parameters. 56 if hs.ecdheKey == nil || len(hs.hello.keyShares) != 1 { 57 return c.sendAlert(alertInternalError) 58 } 59 60 if err := hs.checkServerHelloOrHRR(); err != nil { 61 return err 62 } 63 64 hs.transcript = hs.suite.hash.New() 65 hs.transcript.Write(hs.hello.marshal()) 66 67 if bytes.Equal(hs.serverHello.random, helloRetryRequestRandom) { 68 if err := hs.sendDummyChangeCipherSpec(); err != nil { 69 return err 70 } 71 if err := hs.processHelloRetryRequest(); err != nil { 72 return err 73 } 74 } 75 76 hs.transcript.Write(hs.serverHello.marshal()) 77 78 c.buffering = true 79 if err := hs.processServerHello(); err != nil { 80 return err 81 } 82 if err := hs.sendDummyChangeCipherSpec(); err != nil { 83 return err 84 } 85 if err := hs.establishHandshakeKeys(); err != nil { 86 return err 87 } 88 if err := hs.readServerParameters(); err != nil { 89 return err 90 } 91 if err := hs.readServerCertificate(); err != nil { 92 return err 93 } 94 if err := hs.readServerFinished(); err != nil { 95 return err 96 } 97 if err := hs.sendClientCertificate(); err != nil { 98 return err 99 } 100 if err := hs.sendClientFinished(); err != nil { 101 return err 102 } 103 if _, err := c.flush(); err != nil { 104 return err 105 } 106 107 c.isHandshakeComplete.Store(true) 108 109 return nil 110 } 111 112 // checkServerHelloOrHRR does validity checks that apply to both ServerHello and 113 // HelloRetryRequest messages. It sets hs.suite. 114 func (hs *clientHandshakeStateTLS13) checkServerHelloOrHRR() error { 115 c := hs.c 116 117 if hs.serverHello.supportedVersion == 0 { 118 c.sendAlert(alertMissingExtension) 119 return errors.New("tls: server selected TLS 1.3 using the legacy version field") 120 } 121 122 if hs.serverHello.supportedVersion != VersionTLS13 { 123 c.sendAlert(alertIllegalParameter) 124 return errors.New("tls: server selected an invalid version after a HelloRetryRequest") 125 } 126 127 if hs.serverHello.vers != VersionTLS12 { 128 c.sendAlert(alertIllegalParameter) 129 return errors.New("tls: server sent an incorrect legacy version") 130 } 131 132 if hs.serverHello.ocspStapling || 133 hs.serverHello.ticketSupported || 134 hs.serverHello.secureRenegotiationSupported || 135 len(hs.serverHello.secureRenegotiation) != 0 || 136 len(hs.serverHello.alpnProtocol) != 0 || 137 len(hs.serverHello.scts) != 0 { 138 c.sendAlert(alertUnsupportedExtension) 139 return errors.New("tls: server sent a ServerHello extension forbidden in TLS 1.3") 140 } 141 142 if !bytes.Equal(hs.hello.sessionId, hs.serverHello.sessionId) { 143 c.sendAlert(alertIllegalParameter) 144 return errors.New("tls: server did not echo the legacy session ID") 145 } 146 147 if hs.serverHello.compressionMethod != compressionNone { 148 c.sendAlert(alertIllegalParameter) 149 return errors.New("tls: server selected unsupported compression format") 150 } 151 152 selectedSuite := mutualCipherSuiteTLS13(hs.hello.cipherSuites, hs.serverHello.cipherSuite) 153 if hs.suite != nil && selectedSuite != hs.suite { 154 c.sendAlert(alertIllegalParameter) 155 return errors.New("tls: server changed cipher suite after a HelloRetryRequest") 156 } 157 if selectedSuite == nil { 158 c.sendAlert(alertIllegalParameter) 159 return errors.New("tls: server chose an unconfigured cipher suite") 160 } 161 hs.suite = selectedSuite 162 c.cipherSuite = hs.suite.id 163 164 return nil 165 } 166 167 // sendDummyChangeCipherSpec sends a ChangeCipherSpec record for compatibility 168 // with middleboxes that didn't implement TLS correctly. See RFC 8446, Appendix D.4. 169 func (hs *clientHandshakeStateTLS13) sendDummyChangeCipherSpec() error { 170 if hs.sentDummyCCS { 171 return nil 172 } 173 hs.sentDummyCCS = true 174 175 _, err := hs.c.writeRecord(recordTypeChangeCipherSpec, []byte{1}) 176 return err 177 } 178 179 // processHelloRetryRequest handles the HRR in hs.serverHello, modifies and 180 // resends hs.hello, and reads the new ServerHello into hs.serverHello. 181 func (hs *clientHandshakeStateTLS13) processHelloRetryRequest() error { 182 c := hs.c 183 184 // The first ClientHello gets double-hashed into the transcript upon a 185 // HelloRetryRequest. (The idea is that the server might offload transcript 186 // storage to the client in the cookie.) See RFC 8446, Section 4.4.1. 187 chHash := hs.transcript.Sum(nil) 188 hs.transcript.Reset() 189 hs.transcript.Write([]byte{typeMessageHash, 0, 0, uint8(len(chHash))}) 190 hs.transcript.Write(chHash) 191 hs.transcript.Write(hs.serverHello.marshal()) 192 193 // The only HelloRetryRequest extensions we support are key_share and 194 // cookie, and clients must abort the handshake if the HRR would not result 195 // in any change in the ClientHello. 196 if hs.serverHello.selectedGroup == 0 && hs.serverHello.cookie == nil { 197 c.sendAlert(alertIllegalParameter) 198 return errors.New("tls: server sent an unnecessary HelloRetryRequest message") 199 } 200 201 if hs.serverHello.cookie != nil { 202 hs.hello.cookie = hs.serverHello.cookie 203 } 204 205 if hs.serverHello.serverShare.group != 0 { 206 c.sendAlert(alertDecodeError) 207 return errors.New("tls: received malformed key_share extension") 208 } 209 210 // If the server sent a key_share extension selecting a group, ensure it's 211 // a group we advertised but did not send a key share for, and send a key 212 // share for it this time. 213 if curveID := hs.serverHello.selectedGroup; curveID != 0 { 214 curveOK := false 215 for _, id := range hs.hello.supportedCurves { 216 if id == curveID { 217 curveOK = true 218 break 219 } 220 } 221 if !curveOK { 222 c.sendAlert(alertIllegalParameter) 223 return errors.New("tls: server selected unsupported group") 224 } 225 if sentID, _ := curveIDForCurve(hs.ecdheKey.Curve()); sentID == curveID { 226 c.sendAlert(alertIllegalParameter) 227 return errors.New("tls: server sent an unnecessary HelloRetryRequest key_share") 228 } 229 if _, ok := curveForCurveID(curveID); !ok { 230 c.sendAlert(alertInternalError) 231 return errors.New("tls: CurvePreferences includes unsupported curve") 232 } 233 key, err := generateECDHEKey(c.config.rand(), curveID) 234 if err != nil { 235 c.sendAlert(alertInternalError) 236 return err 237 } 238 hs.ecdheKey = key 239 hs.hello.keyShares = []keyShare{{group: curveID, data: key.PublicKey().Bytes()}} 240 } 241 242 hs.hello.raw = nil 243 if len(hs.hello.pskIdentities) > 0 { 244 pskSuite := cipherSuiteTLS13ByID(hs.session.cipherSuite) 245 if pskSuite == nil { 246 return c.sendAlert(alertInternalError) 247 } 248 if pskSuite.hash == hs.suite.hash { 249 // Update binders and obfuscated_ticket_age. 250 ticketAge := uint32(c.config.time().Sub(hs.session.receivedAt) / time.Millisecond) 251 hs.hello.pskIdentities[0].obfuscatedTicketAge = ticketAge + hs.session.ageAdd 252 253 transcript := hs.suite.hash.New() 254 transcript.Write([]byte{typeMessageHash, 0, 0, uint8(len(chHash))}) 255 transcript.Write(chHash) 256 transcript.Write(hs.serverHello.marshal()) 257 transcript.Write(hs.hello.marshalWithoutBinders()) 258 pskBinders := [][]byte{hs.suite.finishedHash(hs.binderKey, transcript)} 259 hs.hello.updateBinders(pskBinders) 260 } else { 261 // Server selected a cipher suite incompatible with the PSK. 262 hs.hello.pskIdentities = nil 263 hs.hello.pskBinders = nil 264 } 265 } 266 267 hs.transcript.Write(hs.hello.marshal()) 268 if _, err := c.writeRecord(recordTypeHandshake, hs.hello.marshal()); err != nil { 269 return err 270 } 271 272 msg, err := c.readHandshake() 273 if err != nil { 274 return err 275 } 276 277 serverHello, ok := msg.(*serverHelloMsg) 278 if !ok { 279 c.sendAlert(alertUnexpectedMessage) 280 return unexpectedMessageError(serverHello, msg) 281 } 282 hs.serverHello = serverHello 283 284 if err := hs.checkServerHelloOrHRR(); err != nil { 285 return err 286 } 287 288 return nil 289 } 290 291 func (hs *clientHandshakeStateTLS13) processServerHello() error { 292 c := hs.c 293 294 if bytes.Equal(hs.serverHello.random, helloRetryRequestRandom) { 295 c.sendAlert(alertUnexpectedMessage) 296 return errors.New("tls: server sent two HelloRetryRequest messages") 297 } 298 299 if len(hs.serverHello.cookie) != 0 { 300 c.sendAlert(alertUnsupportedExtension) 301 return errors.New("tls: server sent a cookie in a normal ServerHello") 302 } 303 304 if hs.serverHello.selectedGroup != 0 { 305 c.sendAlert(alertDecodeError) 306 return errors.New("tls: malformed key_share extension") 307 } 308 309 if hs.serverHello.serverShare.group == 0 { 310 c.sendAlert(alertIllegalParameter) 311 return errors.New("tls: server did not send a key share") 312 } 313 if sentID, _ := curveIDForCurve(hs.ecdheKey.Curve()); hs.serverHello.serverShare.group != sentID { 314 c.sendAlert(alertIllegalParameter) 315 return errors.New("tls: server selected unsupported group") 316 } 317 318 if !hs.serverHello.selectedIdentityPresent { 319 return nil 320 } 321 322 if int(hs.serverHello.selectedIdentity) >= len(hs.hello.pskIdentities) { 323 c.sendAlert(alertIllegalParameter) 324 return errors.New("tls: server selected an invalid PSK") 325 } 326 327 if len(hs.hello.pskIdentities) != 1 || hs.session == nil { 328 return c.sendAlert(alertInternalError) 329 } 330 pskSuite := cipherSuiteTLS13ByID(hs.session.cipherSuite) 331 if pskSuite == nil { 332 return c.sendAlert(alertInternalError) 333 } 334 if pskSuite.hash != hs.suite.hash { 335 c.sendAlert(alertIllegalParameter) 336 return errors.New("tls: server selected an invalid PSK and cipher suite pair") 337 } 338 339 hs.usingPSK = true 340 c.didResume = true 341 c.peerCertificates = hs.session.serverCertificates 342 c.verifiedChains = hs.session.verifiedChains 343 c.ocspResponse = hs.session.ocspResponse 344 c.scts = hs.session.scts 345 return nil 346 } 347 348 func (hs *clientHandshakeStateTLS13) establishHandshakeKeys() error { 349 c := hs.c 350 351 peerKey, err := hs.ecdheKey.Curve().NewPublicKey(hs.serverHello.serverShare.data) 352 if err != nil { 353 c.sendAlert(alertIllegalParameter) 354 return errors.New("tls: invalid server key share") 355 } 356 sharedKey, err := hs.ecdheKey.Curve().ECDH(hs.ecdheKey, peerKey) 357 if err != nil { 358 c.sendAlert(alertIllegalParameter) 359 return errors.New("tls: invalid server key share") 360 } 361 362 earlySecret := hs.earlySecret 363 if !hs.usingPSK { 364 earlySecret = hs.suite.extract(nil, nil) 365 } 366 handshakeSecret := hs.suite.extract(sharedKey, 367 hs.suite.deriveSecret(earlySecret, "derived", nil)) 368 369 clientSecret := hs.suite.deriveSecret(handshakeSecret, 370 clientHandshakeTrafficLabel, hs.transcript) 371 c.out.setTrafficSecret(hs.suite, clientSecret) 372 serverSecret := hs.suite.deriveSecret(handshakeSecret, 373 serverHandshakeTrafficLabel, hs.transcript) 374 c.in.setTrafficSecret(hs.suite, serverSecret) 375 376 err = c.config.writeKeyLog(keyLogLabelClientHandshake, hs.hello.random, clientSecret) 377 if err != nil { 378 c.sendAlert(alertInternalError) 379 return err 380 } 381 err = c.config.writeKeyLog(keyLogLabelServerHandshake, hs.hello.random, serverSecret) 382 if err != nil { 383 c.sendAlert(alertInternalError) 384 return err 385 } 386 387 hs.masterSecret = hs.suite.extract(nil, 388 hs.suite.deriveSecret(handshakeSecret, "derived", nil)) 389 390 return nil 391 } 392 393 func (hs *clientHandshakeStateTLS13) readServerParameters() error { 394 c := hs.c 395 396 msg, err := c.readHandshake() 397 if err != nil { 398 return err 399 } 400 401 encryptedExtensions, ok := msg.(*encryptedExtensionsMsg) 402 if !ok { 403 c.sendAlert(alertUnexpectedMessage) 404 return unexpectedMessageError(encryptedExtensions, msg) 405 } 406 hs.transcript.Write(encryptedExtensions.marshal()) 407 408 if err := checkALPN(hs.hello.alpnProtocols, encryptedExtensions.alpnProtocol); err != nil { 409 c.sendAlert(alertUnsupportedExtension) 410 return err 411 } 412 c.clientProtocol = encryptedExtensions.alpnProtocol 413 414 return nil 415 } 416 417 func (hs *clientHandshakeStateTLS13) readServerCertificate() error { 418 c := hs.c 419 420 // Either a PSK or a certificate is always used, but not both. 421 // See RFC 8446, Section 4.1.1. 422 if hs.usingPSK { 423 // Make sure the connection is still being verified whether or not this 424 // is a resumption. Resumptions currently don't reverify certificates so 425 // they don't call verifyServerCertificate. See Issue 31641. 426 if c.config.VerifyConnection != nil { 427 if err := c.config.VerifyConnection(c.connectionStateLocked()); err != nil { 428 c.sendAlert(alertBadCertificate) 429 return err 430 } 431 } 432 return nil 433 } 434 435 msg, err := c.readHandshake() 436 if err != nil { 437 return err 438 } 439 440 certReq, ok := msg.(*certificateRequestMsgTLS13) 441 if ok { 442 hs.transcript.Write(certReq.marshal()) 443 444 hs.certReq = certReq 445 446 msg, err = c.readHandshake() 447 if err != nil { 448 return err 449 } 450 } 451 452 certMsg, ok := msg.(*certificateMsgTLS13) 453 if !ok { 454 c.sendAlert(alertUnexpectedMessage) 455 return unexpectedMessageError(certMsg, msg) 456 } 457 if len(certMsg.certificate.Certificate) == 0 { 458 c.sendAlert(alertDecodeError) 459 return errors.New("tls: received empty certificates message") 460 } 461 hs.transcript.Write(certMsg.marshal()) 462 463 c.scts = certMsg.certificate.SignedCertificateTimestamps 464 c.ocspResponse = certMsg.certificate.OCSPStaple 465 466 if err := c.verifyServerCertificate(certMsg.certificate.Certificate); err != nil { 467 return err 468 } 469 470 msg, err = c.readHandshake() 471 if err != nil { 472 return err 473 } 474 475 certVerify, ok := msg.(*certificateVerifyMsg) 476 if !ok { 477 c.sendAlert(alertUnexpectedMessage) 478 return unexpectedMessageError(certVerify, msg) 479 } 480 481 // See RFC 8446, Section 4.4.3. 482 if !isSupportedSignatureAlgorithm(certVerify.signatureAlgorithm, supportedSignatureAlgorithms()) { 483 c.sendAlert(alertIllegalParameter) 484 return errors.New("tls: certificate used with invalid signature algorithm") 485 } 486 sigType, sigHash, err := typeAndHashFromSignatureScheme(certVerify.signatureAlgorithm) 487 if err != nil { 488 return c.sendAlert(alertInternalError) 489 } 490 if sigType == signaturePKCS1v15 || sigHash == crypto.SHA1 { 491 c.sendAlert(alertIllegalParameter) 492 return errors.New("tls: certificate used with invalid signature algorithm") 493 } 494 signed := signedMessage(sigHash, serverSignatureContext, hs.transcript) 495 if err := verifyHandshakeSignature(sigType, c.peerCertificates[0].PublicKey, 496 sigHash, signed, certVerify.signature); err != nil { 497 c.sendAlert(alertDecryptError) 498 return errors.New("tls: invalid signature by the server certificate: " + err.Error()) 499 } 500 501 hs.transcript.Write(certVerify.marshal()) 502 503 return nil 504 } 505 506 func (hs *clientHandshakeStateTLS13) readServerFinished() error { 507 c := hs.c 508 509 msg, err := c.readHandshake() 510 if err != nil { 511 return err 512 } 513 514 finished, ok := msg.(*finishedMsg) 515 if !ok { 516 c.sendAlert(alertUnexpectedMessage) 517 return unexpectedMessageError(finished, msg) 518 } 519 520 expectedMAC := hs.suite.finishedHash(c.in.trafficSecret, hs.transcript) 521 if !hmac.Equal(expectedMAC, finished.verifyData) { 522 c.sendAlert(alertDecryptError) 523 return errors.New("tls: invalid server finished hash") 524 } 525 526 hs.transcript.Write(finished.marshal()) 527 528 // Derive secrets that take context through the server Finished. 529 530 hs.trafficSecret = hs.suite.deriveSecret(hs.masterSecret, 531 clientApplicationTrafficLabel, hs.transcript) 532 serverSecret := hs.suite.deriveSecret(hs.masterSecret, 533 serverApplicationTrafficLabel, hs.transcript) 534 c.in.setTrafficSecret(hs.suite, serverSecret) 535 536 err = c.config.writeKeyLog(keyLogLabelClientTraffic, hs.hello.random, hs.trafficSecret) 537 if err != nil { 538 c.sendAlert(alertInternalError) 539 return err 540 } 541 err = c.config.writeKeyLog(keyLogLabelServerTraffic, hs.hello.random, serverSecret) 542 if err != nil { 543 c.sendAlert(alertInternalError) 544 return err 545 } 546 547 c.ekm = hs.suite.exportKeyingMaterial(hs.masterSecret, hs.transcript) 548 549 return nil 550 } 551 552 func (hs *clientHandshakeStateTLS13) sendClientCertificate() error { 553 c := hs.c 554 555 if hs.certReq == nil { 556 return nil 557 } 558 559 cert, err := c.getClientCertificate(&CertificateRequestInfo{ 560 AcceptableCAs: hs.certReq.certificateAuthorities, 561 SignatureSchemes: hs.certReq.supportedSignatureAlgorithms, 562 Version: c.vers, 563 ctx: hs.ctx, 564 }) 565 if err != nil { 566 return err 567 } 568 569 certMsg := new(certificateMsgTLS13) 570 571 certMsg.certificate = *cert 572 certMsg.scts = hs.certReq.scts && len(cert.SignedCertificateTimestamps) > 0 573 certMsg.ocspStapling = hs.certReq.ocspStapling && len(cert.OCSPStaple) > 0 574 575 hs.transcript.Write(certMsg.marshal()) 576 if _, err := c.writeRecord(recordTypeHandshake, certMsg.marshal()); err != nil { 577 return err 578 } 579 580 // If we sent an empty certificate message, skip the CertificateVerify. 581 if len(cert.Certificate) == 0 { 582 return nil 583 } 584 585 certVerifyMsg := new(certificateVerifyMsg) 586 certVerifyMsg.hasSignatureAlgorithm = true 587 588 certVerifyMsg.signatureAlgorithm, err = selectSignatureScheme(c.vers, cert, hs.certReq.supportedSignatureAlgorithms) 589 if err != nil { 590 // getClientCertificate returned a certificate incompatible with the 591 // CertificateRequestInfo supported signature algorithms. 592 c.sendAlert(alertHandshakeFailure) 593 return err 594 } 595 596 sigType, sigHash, err := typeAndHashFromSignatureScheme(certVerifyMsg.signatureAlgorithm) 597 if err != nil { 598 return c.sendAlert(alertInternalError) 599 } 600 601 signed := signedMessage(sigHash, clientSignatureContext, hs.transcript) 602 signOpts := crypto.SignerOpts(sigHash) 603 if sigType == signatureRSAPSS { 604 signOpts = &rsa.PSSOptions{SaltLength: rsa.PSSSaltLengthEqualsHash, Hash: sigHash} 605 } 606 sig, err := cert.PrivateKey.(crypto.Signer).Sign(c.config.rand(), signed, signOpts) 607 if err != nil { 608 c.sendAlert(alertInternalError) 609 return errors.New("tls: failed to sign handshake: " + err.Error()) 610 } 611 certVerifyMsg.signature = sig 612 613 hs.transcript.Write(certVerifyMsg.marshal()) 614 if _, err := c.writeRecord(recordTypeHandshake, certVerifyMsg.marshal()); err != nil { 615 return err 616 } 617 618 return nil 619 } 620 621 func (hs *clientHandshakeStateTLS13) sendClientFinished() error { 622 c := hs.c 623 624 finished := &finishedMsg{ 625 verifyData: hs.suite.finishedHash(c.out.trafficSecret, hs.transcript), 626 } 627 628 hs.transcript.Write(finished.marshal()) 629 if _, err := c.writeRecord(recordTypeHandshake, finished.marshal()); err != nil { 630 return err 631 } 632 633 c.out.setTrafficSecret(hs.suite, hs.trafficSecret) 634 635 if !c.config.SessionTicketsDisabled && c.config.ClientSessionCache != nil { 636 c.resumptionSecret = hs.suite.deriveSecret(hs.masterSecret, 637 resumptionLabel, hs.transcript) 638 } 639 640 return nil 641 } 642 643 func (c *Conn) handleNewSessionTicket(msg *newSessionTicketMsgTLS13) error { 644 if !c.isClient { 645 c.sendAlert(alertUnexpectedMessage) 646 return errors.New("tls: received new session ticket from a client") 647 } 648 649 if c.config.SessionTicketsDisabled || c.config.ClientSessionCache == nil { 650 return nil 651 } 652 653 // See RFC 8446, Section 4.6.1. 654 if msg.lifetime == 0 { 655 return nil 656 } 657 lifetime := time.Duration(msg.lifetime) * time.Second 658 if lifetime > maxSessionTicketLifetime { 659 c.sendAlert(alertIllegalParameter) 660 return errors.New("tls: received a session ticket with invalid lifetime") 661 } 662 663 cipherSuite := cipherSuiteTLS13ByID(c.cipherSuite) 664 if cipherSuite == nil || c.resumptionSecret == nil { 665 return c.sendAlert(alertInternalError) 666 } 667 668 // Save the resumption_master_secret and nonce instead of deriving the PSK 669 // to do the least amount of work on NewSessionTicket messages before we 670 // know if the ticket will be used. Forward secrecy of resumed connections 671 // is guaranteed by the requirement for pskModeDHE. 672 session := &ClientSessionState{ 673 sessionTicket: msg.label, 674 vers: c.vers, 675 cipherSuite: c.cipherSuite, 676 masterSecret: c.resumptionSecret, 677 serverCertificates: c.peerCertificates, 678 verifiedChains: c.verifiedChains, 679 receivedAt: c.config.time(), 680 nonce: msg.nonce, 681 useBy: c.config.time().Add(lifetime), 682 ageAdd: msg.ageAdd, 683 ocspResponse: c.ocspResponse, 684 scts: c.scts, 685 } 686 687 cacheKey := clientSessionCacheKey(c.conn.RemoteAddr(), c.config) 688 c.config.ClientSessionCache.Put(cacheKey, session) 689 690 return nil 691 }