增加远程证书验证
This commit is contained in:
parent
994099a7d2
commit
f5698ef1e1
@ -2,6 +2,7 @@
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -51,9 +52,15 @@ namespace FastGithub.ReverseProxy
|
|||||||
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
|
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
|
||||||
{
|
{
|
||||||
TargetHost = tlsSniContext.TlsSniPattern.Value,
|
TargetHost = tlsSniContext.TlsSniPattern.Value,
|
||||||
RemoteCertificateValidationCallback = delegate { return true; }
|
RemoteCertificateValidationCallback = ValidateServerCertificate
|
||||||
}, cancellationToken);
|
}, cancellationToken);
|
||||||
return sslStream;
|
return sslStream;
|
||||||
|
|
||||||
|
// 这里最好需要验证证书的使用者和所有使用者可选名称
|
||||||
|
static bool ValidateServerCertificate(object sender, X509Certificate? cert, X509Chain? chain, SslPolicyErrors errors)
|
||||||
|
{
|
||||||
|
return errors == SslPolicyErrors.None || errors == SslPolicyErrors.RemoteCertificateNameMismatch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user