()
| 611 | } |
| 612 | |
| 613 | func (hs *clientHandshakeStateTLS13) readServerCertificate() error { |
| 614 | c := hs.c |
| 615 | |
| 616 | // Either a PSK or a certificate is always used, but not both. |
| 617 | // See RFC 8446, Section 4.1.1. |
| 618 | if hs.usingPSK { |
| 619 | // Make sure the connection is still being verified whether or not this |
| 620 | // is a resumption. Resumptions currently don't reverify certificates so |
| 621 | // they don't call verifyServerCertificate. See Issue 31641. |
| 622 | if c.config.VerifyConnection != nil { |
| 623 | if err := c.config.VerifyConnection(c.connectionStateLocked()); err != nil { |
| 624 | c.sendAlert(alertBadCertificate) |
| 625 | return err |
| 626 | } |
| 627 | } |
| 628 | return nil |
| 629 | } |
| 630 | |
| 631 | msg, err := c.readHandshake(hs.transcript) |
| 632 | if err != nil { |
| 633 | return err |
| 634 | } |
| 635 | |
| 636 | certReq, ok := msg.(*certificateRequestMsgTLS13) |
| 637 | if ok { |
| 638 | hs.certReq = certReq |
| 639 | |
| 640 | msg, err = c.readHandshake(hs.transcript) |
| 641 | if err != nil { |
| 642 | return err |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | certMsg, ok := msg.(*certificateMsgTLS13) |
| 647 | if !ok { |
| 648 | c.sendAlert(alertUnexpectedMessage) |
| 649 | return unexpectedMessageError(certMsg, msg) |
| 650 | } |
| 651 | if len(certMsg.certificate.Certificate) == 0 { |
| 652 | c.sendAlert(alertDecodeError) |
| 653 | return errors.New("tls: received empty certificates message") |
| 654 | } |
| 655 | |
| 656 | c.scts = certMsg.certificate.SignedCertificateTimestamps |
| 657 | c.ocspResponse = certMsg.certificate.OCSPStaple |
| 658 | |
| 659 | if err := c.verifyServerCertificate(certMsg.certificate.Certificate); err != nil { |
| 660 | return err |
| 661 | } |
| 662 | |
| 663 | // certificateVerifyMsg is included in the transcript, but not until |
| 664 | // after we verify the handshake signature, since the state before |
| 665 | // this message was sent is used. |
| 666 | msg, err = c.readHandshake(nil) |
| 667 | if err != nil { |
| 668 | return err |
| 669 | } |
| 670 |
no test coverage detected