| | |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | | import javax.net.ssl.KeyManager; |
| | | |
| | | import org.opends.admin.ads.ADSContext; |
| | | import org.opends.admin.ads.ADSContextException; |
| | | import org.opends.admin.ads.util.ApplicationKeyManager; |
| | |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.util.PasswordReader; |
| | | import org.opends.server.util.SelectableCertificateKeyManager; |
| | | import org.opends.server.util.args.ArgumentException; |
| | | import org.opends.server.util.args.BooleanArgument; |
| | | import org.opends.server.util.args.FileBasedArgument; |
| | |
| | | private BooleanArgument useSSLArg = null; |
| | | |
| | | /** |
| | | * The 'startTLSArg' global argument. |
| | | */ |
| | | private BooleanArgument startTLSArg = null; |
| | | |
| | | /** |
| | | * The 'hostName' global argument. |
| | | */ |
| | | private StringArgument hostNameArg = null; |
| | |
| | | private BooleanArgument verboseArg = null; |
| | | |
| | | /** |
| | | * The 'trustAllArg' global argument. |
| | | */ |
| | | private BooleanArgument trustAllArg = null; |
| | | |
| | | /** |
| | | * The 'trustStore' global argument. |
| | | */ |
| | | private StringArgument trustStorePathArg = null; |
| | |
| | | private FileBasedArgument keyStorePasswordFileArg = null; |
| | | |
| | | /** |
| | | * The 'keyStorePasswordFile' global argument. |
| | | */ |
| | | private StringArgument certNicknameArg = null; |
| | | |
| | | /** |
| | | * The Logger. |
| | | */ |
| | | static private final Logger LOG = |
| | |
| | | OPTION_LONG_USE_SSL, MSGID_DESCRIPTION_USE_SSL); |
| | | addGlobalArgument(useSSLArg); |
| | | |
| | | startTLSArg = new BooleanArgument("startTLS", OPTION_SHORT_START_TLS, |
| | | OPTION_LONG_START_TLS, |
| | | MSGID_DESCRIPTION_START_TLS); |
| | | addGlobalArgument(startTLSArg); |
| | | |
| | | hostNameArg = new StringArgument("host", OPTION_SHORT_HOST, |
| | | OPTION_LONG_HOST, false, false, true, OPTION_VALUE_HOST, "localhost", |
| | | null, MSGID_DESCRIPTION_HOST); |
| | |
| | | MSGID_DESCRIPTION_BINDPASSWORDFILE); |
| | | addGlobalArgument(bindPasswordFileArg); |
| | | |
| | | trustAllArg = new BooleanArgument("trustAll", 'X', "trustAll", |
| | | MSGID_DESCRIPTION_TRUSTALL); |
| | | addGlobalArgument(trustAllArg); |
| | | |
| | | trustStorePathArg = new StringArgument("trustStorePath", |
| | | OPTION_SHORT_TRUSTSTOREPATH, OPTION_LONG_TRUSTSTOREPATH, false, |
| | | false, true, OPTION_VALUE_TRUSTSTOREPATH, null, null, |
| | |
| | | MSGID_DESCRIPTION_KEYSTOREPASSWORD_FILE); |
| | | addGlobalArgument(keyStorePasswordFileArg); |
| | | |
| | | certNicknameArg = new StringArgument("certnickname", 'N', "certNickname", |
| | | false, false, true, "{nickname}", null, null, |
| | | MSGID_DESCRIPTION_CERT_NICKNAME); |
| | | addGlobalArgument(certNicknameArg); |
| | | |
| | | verboseArg = new BooleanArgument("verbose", 'v', "verbose", |
| | | MSGID_DESCRIPTION_VERBOSE); |
| | | addGlobalArgument(verboseArg); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Indicate if the startTLS mode is required. |
| | | * |
| | | * @return True if startTLS mode is required |
| | | */ |
| | | public boolean startTLS() |
| | | { |
| | | if (startTLSArg.isPresent()) |
| | | { |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | return false ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Handle TrustStore. |
| | | * |
| | | * @return The trustStore manager to be used for the command. |
| | |
| | | { |
| | | ApplicationTrustManager truststoreManager = null ; |
| | | KeyStore truststore = null ; |
| | | if (trustAllArg.isPresent()) |
| | | { |
| | | // Running a null TrustManager will force createLdapsContext and |
| | | // createStartTLSContext to use a bindTrustManager. |
| | | return null ; |
| | | } |
| | | else |
| | | if (trustStorePathArg.isPresent()) |
| | | { |
| | | try |
| | |
| | | * |
| | | * @return The keyStore manager to be used for the command. |
| | | */ |
| | | public ApplicationKeyManager getKeyManager() |
| | | public KeyManager getKeyManager() |
| | | { |
| | | KeyStore keyStore = null; |
| | | String keyStorePasswordValue = null; |
| | |
| | | LOG.log(Level.WARNING, "Error with the keystore", e); |
| | | } |
| | | } |
| | | return new ApplicationKeyManager(keyStore, keyStorePasswordValue |
| | | .toCharArray()); |
| | | ApplicationKeyManager akm = new ApplicationKeyManager(keyStore, |
| | | keyStorePasswordValue.toCharArray()); |
| | | if (certNicknameArg.isPresent()) |
| | | { |
| | | return new SelectableCertificateKeyManager(akm, certNicknameArg |
| | | .getValue()); |
| | | } |
| | | else |
| | | { |
| | | return akm; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | return returnCode.CONFLICTING_ARGS.getReturnCode(); |
| | | } |
| | | |
| | | // Couldn't have at the same time trustAll and |
| | | // trustStore related arg |
| | | if (trustAllArg.isPresent() && trustStorePathArg.isPresent()) |
| | | { |
| | | int msgID = MSGID_TOOL_CONFLICTING_ARGS; |
| | | String message = getMessage(msgID, trustAllArg.getLongIdentifier(), |
| | | trustStorePathArg.getLongIdentifier()); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return returnCode.CONFLICTING_ARGS.getReturnCode(); |
| | | } |
| | | if (trustAllArg.isPresent() && trustStorePasswordArg.isPresent()) |
| | | { |
| | | int msgID = MSGID_TOOL_CONFLICTING_ARGS; |
| | | String message = getMessage(msgID, trustAllArg.getLongIdentifier(), |
| | | trustStorePasswordArg.getLongIdentifier()); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return returnCode.CONFLICTING_ARGS.getReturnCode(); |
| | | } |
| | | if (trustAllArg.isPresent() && trustStorePasswordFileArg.isPresent()) |
| | | { |
| | | int msgID = MSGID_TOOL_CONFLICTING_ARGS; |
| | | String message = getMessage(msgID, trustAllArg.getLongIdentifier(), |
| | | trustStorePasswordFileArg.getLongIdentifier()); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return returnCode.CONFLICTING_ARGS.getReturnCode(); |
| | | } |
| | | |
| | | // Couldn't have at the same time trustStorePasswordArg and |
| | | // trustStorePasswordFileArg |
| | | if (trustStorePasswordArg.isPresent() |
| | |
| | | return returnCode.CONFLICTING_ARGS.getReturnCode(); |
| | | } |
| | | |
| | | // Couldn't have at the same time startTLSArg and |
| | | // useSSLArg |
| | | if (startTLSArg.isPresent() |
| | | && useSSLArg.isPresent()) |
| | | { |
| | | int msgID = MSGID_TOOL_CONFLICTING_ARGS; |
| | | String message = getMessage(msgID, startTLSArg |
| | | .getLongIdentifier(), useSSLArg.getLongIdentifier()); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return returnCode.CONFLICTING_ARGS.getReturnCode(); |
| | | } |
| | | |
| | | return ReturnCode.SUCCESSFUL_NOP.getReturnCode(); |
| | | } |
| | | |