【发布时间】:2011-01-12 16:42:34
【问题描述】:
我想使用 .p12 证书而不是使用用户名和密码连接到 LDAP 服务器。 Java 解决方案看起来像
String ldapURL = "ldaps://"+host+":"+port;
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12" );
System.setProperty("javax.net.ssl.keyStore",keystore);
System.setProperty("javax.net.ssl.keyStorePassword", keystorePassword);
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapURL);
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.REFERRAL, "follow");
try
{
// Create initial context
LdapContext ctx = new InitialLdapContext(env, null);
// Perform client authentication using TLS credentials
ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, "EXTERNAL");
SearchControls ctls = new SearchControls();
// Specify the search filter to match
String filter = "(objectClass=*)";
// Search for objects using the filter
NamingEnumeration answer = ctx.search("ou="+elemType[i]+","+siteSpecificBaseDN, filter, ctls);
...
我可以用 python 做同样的事情吗?我只能找到显示如何使用用户名和密码使用 python-ldap 连接到 LDAP 服务器的示例,但这不是我需要的。如果无法使用 .p12 证书,如果有使用 x509 证书(.pem 格式)的解决方案,它也会对我有所帮助。
【问题讨论】:
标签: python ldap certificate pkcs#12