mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
22.06.2007 8cab3e223d3f3ea4529f47cefb102d8bb2f0065e
Fix for issues  2495: setup : nullpointer exception for null value on key store pin
and 2496: setup : should not asking for key Store PIN in loop

Update the code to avoid the NullPointerException and limit the number of times we ask for the Key Store PIN to 7. Once this limit is reached the setup is canceled.
2 files modified
80 ■■■■ changed files
opends/src/messages/messages/tools.properties 2 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/InstallDS.java 78 ●●●● patch | view | raw | blame | history
opends/src/messages/messages/tools.properties
@@ -2199,3 +2199,5 @@
MILD_ERR_INSTALLDS_CANNOT_WRITE_SKIPPED_1483=Cannot write to skipped entries \
 file %s.  Verify that you have enough write rights on the file
INFO_INSTALLDS_PROMPT_SKIPPED_FILE_1484=Write skipped entries to file:
SEVERE_ERR_INSTALLDS_TOO_MANY_KEYSTORE_PASSWORD_TRIES_1485=The maximum number \
 of tries to provide the certificate key store PIN is %s.  Install canceled.
opends/src/server/org/opends/server/tools/InstallDS.java
@@ -122,7 +122,11 @@
    /**
     * Error initializing server.
     */
    ERROR_INITIALIZING_SERVER(4);
    ERROR_INITIALIZING_SERVER(4),
    /**
     * The user failed providing password (for the keystore for instance).
     */
    ERROR_PASSWORD_LIMIT(5);
    private int returnCode;
    private ErrorReturnCode(int returnCode)
@@ -141,6 +145,8 @@
    }
  };
  private static final int LIMIT_KEYSTORE_PASSWORD_PROMPT = 7;
  /**
   * The Logger.
   */
@@ -355,19 +361,26 @@
    UserData uData = new UserData();
    if (isInteractive())
    try
    {
      promptIfRequired(uData);
    }
    else
    {
      try
      if (isInteractive())
      {
        promptIfRequired(uData);
      }
      else
      {
        initializeUserDataWithParser(uData);
      }
      catch (UserDataException ude)
    }
    catch (UserDataException ude)
    {
      printErrorMessage(ude.getMessageObject());
      if (isPasswordTriesError(ude.getMessageObject()))
      {
        printErrorMessage(ude.getMessageObject());
        return ErrorReturnCode.ERROR_PASSWORD_LIMIT.getReturnCode();
      }
      else
      {
        return ErrorReturnCode.ERROR_USER_DATA.getReturnCode();
      }
    }
@@ -772,8 +785,10 @@
   * data or if the provided data is not valid, it prompts the user to provide
   * it.
   * @param uData the UserData object to be updated.
   * @throws UserDataException if the user did not manage to provide the
   * keystore password after a certain number of tries.
   */
  private void promptIfRequired(UserData uData)
  private void promptIfRequired(UserData uData) throws UserDataException
  {
    uData.setConfigurationClassName(argParser.configClassArg.getValue());
    uData.setConfigurationFile(argParser.configFileArg.getValue());
@@ -1221,8 +1236,11 @@
   * If the user did not provide explicitly some data or if the provided data is
   * not valid, it prompts the user to provide it.
   * @param uData the UserData object to be updated.
   * @throws UserDataException if the user did not manage to provide the
   * keystore password after a certain number of tries.
   */
  private void promptIfRequiredForSecurityData(UserData uData)
  throws UserDataException
  {
    // Check that the security data provided is valid.
    boolean enableSSL = false;
@@ -1550,15 +1568,24 @@
   * @param ldapsPort the LDAPS port to use.
   * @return a SecurityOptions object that corresponds to the provided
   * parameters (or to what the user provided after being prompted).
   * @throws UserDataException if the user did not manage to provide the
   * keystore password after a certain number of tries.
   */
  private SecurityOptions createSecurityOptionsPrompting(
      SecurityOptions.CertificateType type, boolean enableSSL,
      boolean enableStartTLS, int ldapsPort)
      boolean enableStartTLS, int ldapsPort) throws UserDataException
  {
    SecurityOptions securityOptions;
    String path;
    String certNickname = argParser.certNicknameArg.getValue();
    String pwd = argParser.getKeyStorePassword();
    if (pwd != null)
    {
      if (pwd.length() == 0)
      {
        pwd = null;
      }
    }
    Message pathPrompt;
    String defaultPathValue;
@@ -1586,6 +1613,7 @@
    LinkedList<Message> errorMessages = new LinkedList<Message>();
    LinkedList<String> keystoreAliases = new LinkedList<String>();
    boolean firstTry = true;
    int nPasswordPrompts = 0;
    while ((errorMessages.size() > 0) || firstTry)
    {
@@ -1625,8 +1653,19 @@
        {
          printLineBreak();
        }
        pwd = promptForPassword(
            INFO_INSTALLDS_PROMPT_KEYSTORE_PASSWORD.get());
        pwd = null;
        while (pwd == null)
        {
          if (nPasswordPrompts > LIMIT_KEYSTORE_PASSWORD_PROMPT)
          {
            throw new UserDataException(null,
                ERR_INSTALLDS_TOO_MANY_KEYSTORE_PASSWORD_TRIES.get(
                    String.valueOf(LIMIT_KEYSTORE_PASSWORD_PROMPT)));
          }
          pwd = promptForPassword(
              INFO_INSTALLDS_PROMPT_KEYSTORE_PASSWORD.get());
          nPasswordPrompts ++;
        }
      }
      if (containsCertNicknameErrorMessage(errorMessages))
      {
@@ -1745,6 +1784,19 @@
  }
  /**
   * Tells if the error messages provided corresponds to a problem with the
   * password tries.
   * @param msg the message to analyze.
   * @return <CODE>true</CODE> if the error message provided corresponds to a
   * problem with the password tries and <CODE>false</CODE> otherwise.
   */
  private boolean isPasswordTriesError(Message msg)
  {
    return msg.getDescriptor().equals(
        ERR_INSTALLDS_TOO_MANY_KEYSTORE_PASSWORD_TRIES);
  }
  /**
   * Interactively prompts (on standard output) the user to provide an integer
   * value.  The answer provided must be parseable as an integer, and may be
   * required to be within a given set of bounds.  It will keep prompting until