WebRequest nicht sendet client-Zertifikat

Ich Schreibe ein client für eine REST-API und zur Authentifizierung an der API, die ich verwenden muss ein cert, das bereitgestellt wurde, zu mir.

dieser code ist wie folgt:

public string GetCustomer(int custId)
{
X509Certificate2 Cert = new X509Certificate2();
    Cert.Import(@"C:\users\foo\desktop\api\pubAndPrivateCert.pkcs12", "", X509KeyStorageFlags.PersistKeySet);

    ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://api.foo.net/api/customer/v1/" + custId);
    req.ClientCertificates.Add(Cert);

    req.UserAgent = "LOL API Client";
    req.Accept = "application/json";
    req.Method = WebRequestMethods.Http.Get;

    string result = null;
    using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
{
StreamReader reader = new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
}
return result;
}

Jedes mal, wenn ich den Antrag bekomme ich die Fehlermeldung: 400 und bei der Verwendung von Fiddler Blick auf die Antwort, die ich bekomme folgende

<html>
<head><title>400 No required SSL certificate was sent</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>No required SSL certificate was sent</center>
<hr><center>nginx/0.6.32</center>
</body>
</html>

Sehe ich keinen Grund, es nicht zu senden, das cert aber Fehlerbehebung SSL ist nicht gerade einfach. Ich habe noch einige debug-Anweisungen zum hinzufügen von detail und beendet mit fiddler und er ist, was ich habe

Diese Fehler sind von ValidateServerCertificate()

Certificate error: RemoteCertificateChainErrors
NotSignatureValid
The signature of the certificate cannot be verified.
1048576
Unknown error.

Diese sind die Fehler aus der WebExecption geworfen wird.

Cought Exception ProtocolError
The remote server returned an error: (400) Bad Request.
BadRequest
<html>
<head><title>400 No required SSL certificate was sent</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>No required SSL certificate was sent</center>
<hr><center>nginx/0.6.32</center>
</body>
</html>

Dies ist die ValidateServerCertificate() code..es gibt immer true zurück, zu ignorieren cert Fehler.

    public static bool ValidateServerCertificate(object sender, X509Certificate certificate,X509Chain chain,SslPolicyErrors sslPolicyErrors)
    {
        if (sslPolicyErrors == SslPolicyErrors.None)
            return true;

        if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateChainErrors)
        {
            Console.WriteLine("Certificate error: {0}", sslPolicyErrors);
            foreach (var chainstat in chain.ChainStatus)
            {
                Console.WriteLine("{0}", chainstat.Status);
                Console.WriteLine("{0}", chainstat.StatusInformation);
            }
            return true;
        }

        Console.WriteLine("Certificate error: {0}", sslPolicyErrors);

        //allow this client to communicate with unauthenticated servers. 
        return true;
    }
  • Debugging-client-Zertifikate mit Fiddler ist nicht wirklich möglich, da Fiddler gesendet werden müssen, seine eigenen cert... Prüfen Sie, ob Sie irgendwelche Ausnahmen (einschließlich behandelt sind) in Ihrem Prozess...
  • Fiddler kann Beantwortung der Anfragen Erfordert ein Client-Zertifikat.
InformationsquelleAutor user961346 | 2014-05-03
Schreibe einen Kommentar