MCPcopy Index your code
hub / github.com/XTLS/Go / verifyHandshakeSignature

Function verifyHandshakeSignature

auth.go:22–61  ·  view source on GitHub ↗

verifyHandshakeSignature verifies a signature against pre-hashed (if required) handshake contents.

(sigType uint8, pubkey crypto.PublicKey, hashFunc crypto.Hash, signed, sig []byte)

Source from the content-addressed store, hash-verified

20// verifyHandshakeSignature verifies a signature against pre-hashed
21// (if required) handshake contents.
22func verifyHandshakeSignature(sigType uint8, pubkey crypto.PublicKey, hashFunc crypto.Hash, signed, sig []byte) error {
23 switch sigType {
24 case signatureECDSA:
25 pubKey, ok := pubkey.(*ecdsa.PublicKey)
26 if !ok {
27 return fmt.Errorf("expected an ECDSA public key, got %T", pubkey)
28 }
29 if !ecdsa.VerifyASN1(pubKey, signed, sig) {
30 return errors.New("ECDSA verification failure")
31 }
32 case signatureEd25519:
33 pubKey, ok := pubkey.(ed25519.PublicKey)
34 if !ok {
35 return fmt.Errorf("expected an Ed25519 public key, got %T", pubkey)
36 }
37 if !ed25519.Verify(pubKey, signed, sig) {
38 return errors.New("Ed25519 verification failure")
39 }
40 case signaturePKCS1v15:
41 pubKey, ok := pubkey.(*rsa.PublicKey)
42 if !ok {
43 return fmt.Errorf("expected an RSA public key, got %T", pubkey)
44 }
45 if err := rsa.VerifyPKCS1v15(pubKey, hashFunc, signed, sig); err != nil {
46 return err
47 }
48 case signatureRSAPSS:
49 pubKey, ok := pubkey.(*rsa.PublicKey)
50 if !ok {
51 return fmt.Errorf("expected an RSA public key, got %T", pubkey)
52 }
53 signOpts := &rsa.PSSOptions{SaltLength: rsa.PSSSaltLengthEqualsHash}
54 if err := rsa.VerifyPSS(pubKey, hashFunc, signed, sig, signOpts); err != nil {
55 return err
56 }
57 default:
58 return errors.New("internal error: unknown signature type")
59 }
60 return nil
61}
62
63const (
64 serverSignatureContext = "TLS 1.3, server CertificateVerify\x00"

Callers 4

readServerCertificateMethod · 0.85
readClientCertificateMethod · 0.85
doFullHandshakeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…