mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-12-01 14:18:36 +00:00
Fix public key verification with empty certificate chain
This commit is contained in:
@@ -276,6 +276,9 @@ func verifyConnection(rootCAs *x509.CertPool, timeFunc func() time.Time, serverN
|
||||
}
|
||||
|
||||
func VerifyPublicKeySHA256(knownHashValues [][]byte, rawCerts [][]byte) error {
|
||||
if len(rawCerts) == 0 {
|
||||
return E.New("missing remote certificate")
|
||||
}
|
||||
leafCertificate, err := x509.ParseCertificate(rawCerts[0])
|
||||
if err != nil {
|
||||
return E.Cause(err, "failed to parse leaf certificate")
|
||||
|
||||
@@ -473,6 +473,7 @@ func NewSTDServer(ctx context.Context, logger log.ContextLogger, options option.
|
||||
}
|
||||
tlsConfig.ClientCAs = clientCertificateCA
|
||||
} else if len(options.ClientCertificatePublicKeySHA256) > 0 {
|
||||
verifyIfGiven := tlsConfig.ClientAuth == tls.VerifyClientCertIfGiven
|
||||
switch tlsConfig.ClientAuth {
|
||||
case tls.RequireAndVerifyClientCert:
|
||||
tlsConfig.ClientAuth = tls.RequireAnyClientCert
|
||||
@@ -480,6 +481,9 @@ func NewSTDServer(ctx context.Context, logger log.ContextLogger, options option.
|
||||
tlsConfig.ClientAuth = tls.RequestClientCert
|
||||
}
|
||||
tlsConfig.VerifyPeerCertificate = func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
|
||||
if verifyIfGiven && len(rawCerts) == 0 {
|
||||
return nil
|
||||
}
|
||||
return VerifyPublicKeySHA256(options.ClientCertificatePublicKeySHA256, rawCerts)
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user