MCPcopy Create free account
hub / github.com/XTLS/Go / readClientCertificate

Method readClientCertificate

handshake_server_tls13.go:765–848  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

763}
764
765func (hs *serverHandshakeStateTLS13) readClientCertificate() error {
766 c := hs.c
767
768 if !hs.requestClientCert() {
769 // Make sure the connection is still being verified whether or not
770 // the server requested a client certificate.
771 if c.config.VerifyConnection != nil {
772 if err := c.config.VerifyConnection(c.connectionStateLocked()); err != nil {
773 c.sendAlert(alertBadCertificate)
774 return err
775 }
776 }
777 return nil
778 }
779
780 // If we requested a client certificate, then the client must send a
781 // certificate message. If it's empty, no CertificateVerify is sent.
782
783 msg, err := c.readHandshake()
784 if err != nil {
785 return err
786 }
787
788 certMsg, ok := msg.(*certificateMsgTLS13)
789 if !ok {
790 c.sendAlert(alertUnexpectedMessage)
791 return unexpectedMessageError(certMsg, msg)
792 }
793 hs.transcript.Write(certMsg.marshal())
794
795 if err := c.processCertsFromClient(certMsg.certificate); err != nil {
796 return err
797 }
798
799 if c.config.VerifyConnection != nil {
800 if err := c.config.VerifyConnection(c.connectionStateLocked()); err != nil {
801 c.sendAlert(alertBadCertificate)
802 return err
803 }
804 }
805
806 if len(certMsg.certificate.Certificate) != 0 {
807 msg, err = c.readHandshake()
808 if err != nil {
809 return err
810 }
811
812 certVerify, ok := msg.(*certificateVerifyMsg)
813 if !ok {
814 c.sendAlert(alertUnexpectedMessage)
815 return unexpectedMessageError(certVerify, msg)
816 }
817
818 // See RFC 8446, Section 4.4.3.
819 if !isSupportedSignatureAlgorithm(certVerify.signatureAlgorithm, supportedSignatureAlgorithms) {
820 c.sendAlert(alertIllegalParameter)
821 return errors.New("tls: client certificate used with invalid signature algorithm")
822 }

Callers 1

handshakeMethod · 0.95

Calls 14

requestClientCertMethod · 0.95
sendSessionTicketsMethod · 0.95
unexpectedMessageErrorFunction · 0.85
signedMessageFunction · 0.85
verifyHandshakeSignatureFunction · 0.85
connectionStateLockedMethod · 0.80
sendAlertMethod · 0.80
readHandshakeMethod · 0.80
marshalMethod · 0.65

Tested by

no test coverage detected