| | |
| | | import org.opends.server.admin.client.cli.SecureConnectionCliArgs; |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ClientException; |
| | | import com.forgerock.opendj.cli.CommandBuilder; |
| | | import com.forgerock.opendj.cli.ConsoleApplication; |
| | | import com.forgerock.opendj.cli.Menu; |
| | | import com.forgerock.opendj.cli.MenuBuilder; |
| | | import com.forgerock.opendj.cli.MenuResult; |
| | | import com.forgerock.opendj.cli.ValidationCallback; |
| | | |
| | | import org.opends.server.util.SelectableCertificateKeyManager; |
| | | import org.opends.admin.ads.ADSContext; |
| | | import org.opends.admin.ads.util.ApplicationTrustManager; |
| | |
| | | private String providedBindDN; |
| | | private String adminUID; |
| | | private String providedAdminUID; |
| | | private String bindPassword; |
| | | private char[] bindPassword; |
| | | private KeyManager keyManager; |
| | | private ApplicationTrustManager trustManager; |
| | | // Boolean that tells if we ask for bind DN or admin UID in the same prompt. |
| | |
| | | |
| | | private String keystorePath; |
| | | |
| | | private String keystorePassword; |
| | | private char[] keystorePassword; |
| | | |
| | | private String certifNickname; |
| | | |
| | | private String truststorePath; |
| | | |
| | | private String truststorePassword; |
| | | private char[] truststorePassword; |
| | | |
| | | // The timeout to be used to connect |
| | | private int connectTimeout; |
| | |
| | | SecureConnectionCliArgs secureArgs) { |
| | | this.app = app; |
| | | this.secureArgsList = secureArgs; |
| | | this.commandBuilder = new CommandBuilder(null); |
| | | this.commandBuilder = new CommandBuilder(null, null); |
| | | this.useSSL = secureArgs.useSSL(); |
| | | this.useStartTLS = secureArgs.useStartTLS(); |
| | | this.trustAll = secureArgs.trustAllArg.isPresent(); |
| | |
| | | } |
| | | |
| | | boolean addedPasswordFileArgument = false; |
| | | bindPassword = secureArgsList.bindPasswordArg.getValue(); |
| | | if (secureArgsList.bindPasswordArg.isPresent()) |
| | | { |
| | | bindPassword = secureArgsList.bindPasswordArg.getValue().toCharArray(); |
| | | } |
| | | if (keyManager == null) |
| | | { |
| | | if (secureArgsList.bindPasswordFileArg.isPresent()) |
| | | { |
| | | // Read from file if it exists. |
| | | bindPassword = secureArgsList.bindPasswordFileArg.getValue(); |
| | | bindPassword = secureArgsList.bindPasswordFileArg.getValue().toCharArray(); |
| | | |
| | | if (bindPassword == null) |
| | | { |
| | |
| | | } |
| | | } |
| | | copySecureArgsList.bindPasswordArg.clearValues(); |
| | | copySecureArgsList.bindPasswordArg.addValue(bindPassword); |
| | | copySecureArgsList.bindPasswordArg.addValue(String.valueOf(bindPassword)); |
| | | if (!addedPasswordFileArgument) |
| | | { |
| | | commandBuilder.addObfuscatedArgument( |
| | |
| | | // Then the truststore password. |
| | | // As the most common case is to have no password for truststore, |
| | | // we don't ask it in the interactive mode. |
| | | truststorePassword = secureArgsList.trustStorePasswordArg |
| | | .getValue(); |
| | | |
| | | if (secureArgsList.trustStorePasswordArg.isPresent()) |
| | | { |
| | | truststorePassword = |
| | | secureArgsList.trustStorePasswordArg.getValue().toCharArray(); |
| | | } |
| | | if (secureArgsList.trustStorePasswordFileArg.isPresent()) |
| | | { |
| | | // Read from file if it exists. |
| | | truststorePassword = secureArgsList.trustStorePasswordFileArg |
| | | .getValue(); |
| | | .getValue().toCharArray(); |
| | | } |
| | | if ((truststorePassword != null) && (truststorePassword.equals("-"))) |
| | | { |
| | |
| | | FileInputStream fos = new FileInputStream(truststorePath); |
| | | if (truststorePassword != null) |
| | | { |
| | | truststore.load(fos, truststorePassword.toCharArray()); |
| | | truststore.load(fos, truststorePassword); |
| | | } |
| | | else |
| | | { |
| | |
| | | // Only add the trust store password if there is one AND if the user |
| | | // specified a trust store path. |
| | | copySecureArgsList.trustStorePasswordArg.clearValues(); |
| | | copySecureArgsList.trustStorePasswordArg.addValue(truststorePassword); |
| | | copySecureArgsList.trustStorePasswordArg.addValue(String.valueOf(truststorePassword)); |
| | | commandBuilder.addObfuscatedArgument( |
| | | copySecureArgsList.trustStorePasswordArg); |
| | | } |
| | |
| | | } |
| | | |
| | | // Then the keystore password. |
| | | keystorePassword = secureArgsList.keyStorePasswordArg.getValue(); |
| | | keystorePassword = secureArgsList.keyStorePasswordArg.getValue().toCharArray(); |
| | | |
| | | if (secureArgsList.keyStorePasswordFileArg.isPresent()) |
| | | { |
| | | // Read from file if it exists. |
| | | keystorePassword = secureArgsList.keyStorePasswordFileArg.getValue(); |
| | | keystorePassword = secureArgsList.keyStorePasswordFileArg.getValue().toCharArray(); |
| | | |
| | | if (keystorePassword == null) |
| | | { |
| | |
| | | { |
| | | FileInputStream fos = new FileInputStream(keystorePath); |
| | | keystore = KeyStore.getInstance(KeyStore.getDefaultType()); |
| | | keystore.load(fos, keystorePassword.toCharArray()); |
| | | keystore.load(fos, keystorePassword); |
| | | fos.close(); |
| | | aliasesEnum = keystore.aliases(); |
| | | } |
| | |
| | | |
| | | // We'we got all the information to get the keys manager |
| | | ApplicationKeyManager akm = new ApplicationKeyManager(keystore, |
| | | keystorePassword.toCharArray()); |
| | | keystorePassword); |
| | | |
| | | |
| | | if (secureArgsList.keyStorePasswordFileArg.isPresent()) |
| | |
| | | else if (keystorePassword != null) |
| | | { |
| | | copySecureArgsList.keyStorePasswordArg.clearValues(); |
| | | copySecureArgsList.keyStorePasswordArg.addValue(keystorePassword); |
| | | copySecureArgsList.keyStorePasswordArg.addValue(String.valueOf(keystorePassword)); |
| | | commandBuilder.addObfuscatedArgument( |
| | | copySecureArgsList.keyStorePasswordArg); |
| | | } |
| | |
| | | * @return bind password for connections |
| | | */ |
| | | public String getBindPassword() { |
| | | return this.bindPassword; |
| | | return String.valueOf(this.bindPassword); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | // Read the password from the stdin. |
| | | String truststorePassword; |
| | | char[] truststorePassword; |
| | | try |
| | | { |
| | | app.println(); |
| | |
| | | { |
| | | fis = null; |
| | | } |
| | | ts.load(fis, truststorePassword.toCharArray()); |
| | | ts.load(fis, truststorePassword); |
| | | if (fis != null) |
| | | { |
| | | fis.close(); |
| | |
| | | ts.setCertificateEntry(alias, chain[i]); |
| | | } |
| | | FileOutputStream fos = new FileOutputStream(truststorePath); |
| | | ts.store(fos, truststorePassword.toCharArray()); |
| | | ts.store(fos, truststorePassword); |
| | | if (fos != null) |
| | | { |
| | | fos.close(); |
| | |
| | | if (this.useSSL) { |
| | | options.setUseSSL(true); |
| | | SSLConnectionFactory sslConnectionFactory = new SSLConnectionFactory(); |
| | | sslConnectionFactory.init(getTrustManager() == null, keystorePath, |
| | | keystorePassword, certifNickname, |
| | | truststorePath, truststorePassword); |
| | | sslConnectionFactory.init(getTrustManager() == null, String |
| | | .valueOf(keystorePath), String.valueOf(keystorePassword), String |
| | | .valueOf(certifNickname), String.valueOf(truststorePath), String |
| | | .valueOf(truststorePassword)); |
| | | options.setSSLConnectionFactory(sslConnectionFactory); |
| | | } else { |
| | | options.setUseSSL(false); |