julplemet59
Messages postés3Date d'inscriptionjeudi 29 mars 2007StatutMembreDernière intervention14 avril 2010
-
14 avril 2010 à 10:06
julplemet59
Messages postés3Date d'inscriptionjeudi 29 mars 2007StatutMembreDernière intervention14 avril 2010
-
14 avril 2010 à 16:11
Bonjour,
Je ne parviens pas à me connecter à un serveur ldap sécurisé en SSL. En utilisant des browsers LDAP (codés en java), j'y parviens (Point particulier: Ils me proposent de valider manuellement le certificat)
Quand je code en C#, je tombe sur différents messages d'erreur selon mes tests (erreur inconnue, serveur non opétationnel...)
A noter que je n'ai aucun problème quand ce n'est pas sécurisé SSL pour me connecter et parcourir le serveur.
Si quelqu'un pouvait m'aidait, ce serveur est joignable pour les tests (ldapv3):
serveur: ldapclient.com
port: 389
authentification: anonyme
ou en SSL
serveur: ldapclient.com
port: 636
authentification: anonyme
Voici un des nombreux codes que j'ai utilise pour tester (le dernier en fait):
Sachant que le code en gras est celui qui permet la connexion est que celui ci qui ne passe pas en SSL.
public byte[] GetRecipientCertificateFromLDAPStore()
{
[b]SearchResultCollection col;
DirectorySearcher searcher = new DirectorySearcher();
string[] resultsFields = new string[] { "cn", "mail", "usercertificate;binary" };
//Pass the IPAddress and the Port of the LDAP Server.
string[] textArray1 = new string[] { "LDAP://", "ldapclient.com", ":", "636", "" };
searcher.SearchRoot = new DirectoryEntry(string.Concat(textArray1), null, null, AuthenticationTypes.SecureSocketsLayer);
searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;
searcher.PropertiesToLoad.AddRange(resultsFields);
searcher.Filter = string.Format("(&(cn={0})(mail={1}))", "* *", "* *");
col = searcher.FindAll();/b
X509Certificate2 certificate1 = new X509Certificate2();
foreach (SearchResult result1 in col)
{
IEnumerator enumerator2;
try
{
enumerator2 = result1.GetDirectoryEntry().Properties["usercertificate;binary"].GetEnumerator();
while (enumerator2.MoveNext())
{
object obj1 = RuntimeHelpers.GetObjectValue(enumerator2.Current);
certificate1.Import((byte[])obj1);
//Can access different Properties for example:
//certificate1.Subject;
//certificate1.SerialNumber;
//certificate1.Version;
//certificate1.NotBefore;
//certificate1.NotAfter;
//certificate1.Issuer;
return certificate1.Export(X509ContentType.Cert);
}
}
catch { }
}
return null;
}
public byte[] GetRecipientCertificateFromLDAPStore()
{
SearchResultCollection col;
DirectorySearcher searcher = new DirectorySearcher();
string[] resultsFields = new string[] { "cn", "mail", "usercertificate;binary" };
//Pass the IPAddress and the Port of the LDAP Server.
string[] textArray1 = new string[] { "LDAP://", "ldapclient.com", ":", "636", "" };
searcher.SearchRoot = new DirectoryEntry(string.Concat(textArray1), null, null, AuthenticationTypes.SecureSocketsLayer);
searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;
searcher.PropertiesToLoad.AddRange(resultsFields);
searcher.Filter = string.Format("(&(cn={0})(mail={1}))", "* *", "* *");
col = searcher.FindAll();
X509Certificate2 certificate1 = new X509Certificate2();
foreach (SearchResult result1 in col)
{
IEnumerator enumerator2;
try
{
enumerator2 = result1.GetDirectoryEntry().Properties["usercertificate;binary"].GetEnumerator();
while (enumerator2.MoveNext())
{
object obj1 = RuntimeHelpers.GetObjectValue(enumerator2.Current);
certificate1.Import((byte[])obj1);
//Can access different Properties for example:
//certificate1.Subject;
//certificate1.SerialNumber;
//certificate1.Version;
//certificate1.NotBefore;
//certificate1.NotAfter;
//certificate1.Issuer;
return certificate1.Export(X509ContentType.Cert);
}
}
catch { }
}
return null;
}