【问题标题】:ssl certificate to the AD password changessl证书到AD密码修改
【发布时间】:2013-05-25 23:30:27
【问题描述】:

我正在使用 Java 并尝试更改 AD 中的密码。我已将证书导入服务器,但证书中出现错误。

进口有效:

keytool -import -keystore "C:\Program Files\Java\jre6\lib\security\cacerts" -trustcacerts -alias openldap -file "C:\certnew.cer"

列表有效:

keytool -list -keystore "C:\Program Files\Java\jre6\lib\security\cacerts"

我的代码:

public class PassChange
{
    public static void main (String[] args) {

    Hashtable env = new Hashtable();
    String userName = "CN=optimus,DC=ad,DC=euclid,DC=com";

    String oldPassword = "euclid!23";
    String newPassword = "kcube!23";

    //Could also do this via command line java -Djavax.net.ssl.trustStore....

    String keystore = "C:\\Program Files\\Java\\jre6\\lib\\security\\cacerts";

    // 1    String keystore = "C:\\Program Files\\Java\\jre6\\lib\\security\\cacerts";
    // 2    String keystore = "C:\\Program Files\\Java\\jre6\\lib\\security\\cacerts.jks";
    // 3    String keystore = "c:\\";
    // 1,2,3 all error

    System.setProperty("javax.net.ssl.trustStore", keystore);

    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
    //set security credentials, note using simple cleartext authentication
    env.put(Context.SECURITY_AUTHENTICATION,"simple");
    env.put(Context.SECURITY_PRINCIPAL,userName);
    env.put(Context.SECURITY_CREDENTIALS,oldPassword);

    //specify use of ssl
    env.put(Context.SECURITY_PROTOCOL,"ssl");

    //connect to my domain controller
    String ldapURL = "ldaps://xxx.xxx.xxx.xxx:636";
    env.put(Context.PROVIDER_URL,ldapURL);

    try {

        // Create the initial directory context
        LdapContext ctx = new InitialLdapContext(env,null);

        //change password is a single ldap modify operation
        //that deletes the old password and adds the new password
        ModificationItem[] mods = new ModificationItem[2];
        String oldQuotedPassword = "\"" + oldPassword + "\"";
        byte[] oldUnicodePassword = oldQuotedPassword.getBytes("UTF-16LE");
        String newQuotedPassword = "\"" + newPassword + "\"";
        byte[] newUnicodePassword = newQuotedPassword.getBytes("UTF-16LE");

        mods[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("unicodePwd", oldUnicodePassword));
        mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("unicodePwd", newUnicodePassword));

        ctx.modifyAttributes(userName, mods);

        System.out.println("Changed Password for: " + userName);    
        ctx.close();

    } 
    catch (NamingException e) {
        System.err.println("Problem changing password: " + e);
    }
    catch (UnsupportedEncodingException e) {
        System.err.println("Problem encoding password: " + e);
    }
}
} 

错误信息:

问题更改密码:javax.naming.CommunicationException:简单绑定失败:xxx.xxx.xxx.xxx:636 [根异常是 javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX 路径构建失败: sun.security.provider.certpath.SunCertPathBuilderException: 无法找到请求目标的有效证书路径]

【问题讨论】:

  • 要分析,SSL证书有什么问题,尝试运行带有附加属性javax.net.debug=all的程序。然后使用调试输出更新您的帖子。参见docs.oracle.com/javase/1.5.0/docs/guide/security/jsse/…
  • javax.net.debug=all mode ......最后一行错误------ -------------------> Thread-0,调用 closeSocket() Thread-0,处理异常:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException : PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException: 无法找到请求目标的有效证书路径

标签: ssl ldap certificate


【解决方案1】:

您导入了哪个证书?您不想要服务器证书。相反,您需要证书颁发机构的公钥。具体来说,开关-trustcacerts 表示这是一个CA 公钥。

猜名字,不知道你是不是抢了服务器的证书。

【讨论】:

  • Answer 谢谢 ^ ^ 我有服务器证书。从服务器向客户端颁发证书时使用的是副本。如果是这样,我需要证书颁发机构的公钥吗?
  • @user2436284 用于通过 SSL 访问的 LDAP 的客户端应该在 JRE 的 cacerts 文件中为您的 CA 提供受信任的 CA 证书。重要的导入期间的 keytool 开关是 -trustcacerts
猜你喜欢
  • 2014-10-04
  • 1970-01-01
  • 2010-09-16
  • 2013-10-01
  • 1970-01-01
  • 2020-11-08
  • 1970-01-01
  • 2012-07-03
  • 1970-01-01
相关资源
最近更新 更多