[C# 2.0] Authentification HTTPS
Bonjour à tous,
Mon application doit se connecter à un serveur en mode HTTPS. L'authentification se fait sur la base des clés (au lieu d'un username/password).
A priori je ne peux utiliser WebRequest car Credentials ne gère que l'authentification profil / mot de passe.
J'ai donc essayé d'utiliser un TcpClient avec un SslStream mais j'obtiens à chaque fois l'erreur suivante :
Code:
1 2
|
System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted |
Je n'arrive pas à comprendre... même en ajoutant le callback pour vérification des certificats lors de l'appel à AuthenticateAsClient, même résultat.
Je précise que j'arrive à me connecter à un https (par ex, https://addons.mozilla.org/ sans pb avec un HttpWebRequest )
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
String host = "mon_serveur";
TcpClient tcp = new TcpClient( host, 443);
if (!tcp.Connected)
return;
SslStream ssl = new SslStream(tcp.GetStream(), false);
// même comportement si j'enlève les certificats
X509CertificateCollection certifs = new X509CertificateCollection();
certifs.Add(new X509Certificate("mon_certif.der", "123"));
certifs.Add(X509Certificate.CreateFromCertFile("ca.crt"));
try {
ssl.AuthenticateAsClient(host, certifs);
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
} |