title: Oracle PL/SQL LDAP - Unable to open wallet
body: <p>I'm trying to authenticate against an SSL secured LDAP server internally for my application running on Oracle 11g on Windows server using PL/SQL. I've got the certificate loaded into a wallet and stored in d:\wallets\ and can verify that it's valid / loads in oracle wallet manager (ewallet.p12 opens with the password I configured correctly). However, no matter what I do I cannot get it working using the PL/SQL functions. Here is the code:</p>
  
  <pre><code>create or replace FUNCTION ldap_auth(
      p_username IN VARCHAR2,
      p_password IN VARCHAR2
  )
  RETURN varchar2 IS
      l_ldap_host         VARCHAR2(256) := 'ldapserver.internal.net';
      l_ldap_port         number := 636;
      l_dn                        VARCHAR2(512);
  
      l_retval                PLS_INTEGER;
      l_session               DBMS_LDAP.session;
  
      l_wallet_loc        varchar2(256) := 'file:D:\wallets';
      l_wallet_pwd        varchar2(256) := 'pa55w0rd';
      l_wallet_ssl        number := 3;
  
  BEGIN
      DBMS_LDAP.USE_EXCEPTION := TRUE;
      l_dn := 'cn='||p_username||',ou=People,dc=internal,dc=net';
  
      BEGIN
          l_session := DBMS_LDAP.init(l_ldap_host, l_ldap_port);
      EXCEPTION
          when others then
          raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
          RETURN 'exception1';
      END;
  
      BEGIN
          l_retval := DBMS_LDAP.open_ssl (l_session, l_wallet_loc, l_wallet_pwd, l_wallet_ssl);
      EXCEPTION
          when others then
          raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
          RETURN 'exception2';
      END;
  
      BEGIN
          l_retval := DBMS_LDAP.simple_bind_s(l_session, l_dn, p_password);
    EXCEPTION
      when others then
      raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
      RETURN 'exception3';
    END;
  
      return 'pass';
  END;
  </code></pre>
  
  <p>And here's what happens when I run it:</p>
  
  <pre><code>select ldap_auth('userID','userPassword') as results1 from dual
  </code></pre>
  
  <p>ORA-20001: An error was encountered - -31202 -ERROR- ORA-31202: DBMS_LDAP: LDAP client/server error: Unable to open wallet
  ORA-06512: at "DBUSERNAME.LDAP_AUTH", line 33</p>
  
  <p>I'm stuck at this point, I can't find any reference online as to how to make this work. </p>