Can I determine if the HTTPS proxy is used only when viewing the certificate?

Since the HTTPS proxy will replace the SSL certificate with its own, what are my settings to determine if this HTTPS connection has a proxy in the middle?

I will use this information to determine my application policy, as there are cases when I want a 100% pass-through encrypted tunnel without decryption by a third party.

Even better, if you can tell me how to define this through C # in a .NET application or Silverlight.

For starters, here is an example method for verifying a certificate using .NET, but I'm still not sure how to use this to determine which part of the certificate to verify. In addition, I believe that ServicePointManger is more of a "global" class of connections. Using this can be too wide when I test a single HTTP connection, and I'm not sure if the ServicePointManager is available in Silverlight.

http://msdn.microsoft.com/en-us/library/bb408523.aspx

+3
source share
1 answer

. - ServicePointManager. , , "" :

void SomeMethod()
{
    ServicePointManager.ServerCertificateValidationCallback += 
        ValidateServerCertificate;

    var url = "https://mail.google.com/mail/?shva=1#inbox";
    var request = (HttpWebRequest)WebRequest.Create(url);
    request.GetResponse();
}

private static bool ValidateServerCertificate(object sender, 
        X509Certificate certificate, X509Chain chain, 
        SslPolicyErrors sslpolicyerrors)
{
    if(sender is HttpWebRequest)
    {
        var request = (HttpWebRequest) sender;
        if(request.RequestUri.ToString() == "https://mail.google.com/mail/?shva=1#inbox")
        {
            return (certificate.GetPublicKeyString() == "The public key string you expect");
        }
    }
    return true;
}

HttpWebRequest WCF, "" HttpWebRequest . , "" - , HttpWebRequest.

- :

void SomeMethod()
{
    ServicePointManager.ServerCertificateValidationCallback += 
        ValidateServerCertificate;

    var url = "https://mail.google.com/mail/?shva=1#inbox";
    var request = (HttpWebRequest)WebRequest.Create(url);
    request.GetResponse();

    var serverCert = request.ServicePoint.Certificate;
    // Validate the certificate.
}

, ServicePoint, - WCF. , WCF. , , , , , .

, -:

var httpRequest = (HttpWebRequest)WebRequest.Create("someurl");
var isUsingProxy = DoesRequstUseProxy(request);

bool DoesRequestUseProxy(HttpWebRequest request)
{
    if(request.Proxy == null)
    {
        return false;
    }

    return request.Proxy.GetProxy(request.RequestUri) != request.RequestUri;
}
+4

Source: https://habr.com/ru/post/1760564/


All Articles