2017-09-22 12 views
-1

J'ai vu plusieurs questions liées à ce problème, et j'ai essayé beaucoup d'idées présentées en eux sans succès.problèmes avec le certificat x.509 C#

Voici mes situations:

PREMIERES:

Quand j'écris dans app.config quelque chose comme ceci:

<behaviors> 
    <endpointBehaviors> 
    <behavior name="CustomBehavior"> 
     <clientCredentials> 
     <clientCertificate findValue="1234*********" 
      x509FindType="FindByThumbprint" 
      storeLocation="LocalMachine" storeName="Root" /> 
     </clientCredentials> 
    </behavior> 
    </endpointBehaviors> 
    </behaviors> 

Que j'ai vu ce genre de communiquer: « Le certificat à distance est invalide selon la procédure de validation. "

DEUXIÈME:

 <behaviors> 
    <endpointBehaviors> 
    <behavior name="CustomBehavior"> 
     <clientCredentials> 
     <clientCertificate findValue="test" 
      x509FindType="FindBySubjectName" 
      storeLocation="LocalMachine" storeName="Root" /> 
     </clientCredentials> 
    </behavior> 
    </endpointBehaviors> 
    </behaviors> 

Que je vois ce genre de communiquer: Il est à plusieurs certificats avec ce nom.

J'installe mon certificat par mmc dans l'ordinateur local et ce certificat est dans la racine de publication de confiance. Aussi je vérifie si IE a ce certificat et aussi.

J'ai essayé de rechercher mon certificat par empreinte digitale, par nom de sujet, nom d'émetteur, numéro de série, identificateur de clé de sujet et rien.

MISE À JOUR: J'ai trouvé la solution Tout ce que vous devez ajouter est:

BasicHttpBinding basicHttpBinding = new BasicHttpBinding();

 basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 

     basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; 

     EndpointAddress endpoint = new EndpointAddress("http://testasp.asmx"); 

     RemoteSetup.RemoteSetupServiceSoapClient client = new RemoteSetup.RemoteSetupServiceSoapClient(basicHttpBinding, endpoint); 

     client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; 

     client.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; 
+0

formatez votre code correctement dans votre question. –

Répondre

0

J'ai eu une sorte de problème similaire et fait quelque chose comme ceci: Première enregistré à ServerCertificateValidationCallback événement:

System.Net.ServicePointManager.ServerCertificateValidationCallback += 
       new RemoteCertificateValidationCallback(ValidateRemoteCertificate); 

ensuite vérifié manuellement persistant et retourné true:

private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, 
           X509Chain chain, SslPolicyErrors policyErrors) 
{ 
    bool result = false; 
    if (cert.Subject.ToUpper().Contains("MY_CERT_ISSUER_NAME")) 
    { 
     result = true; 
    } 
    return result; 
} 

Je n'ai trouvé aucune solution "correcte", celle-ci n'est pas silencieuse, mais peut aider.