GEODE-1958: Working on removing PasswordUtil and all related commands, classes, etc. Keeping decrypt() method to maintain backwards compatibility.
* this closes #578 Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/43b00bd8 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/43b00bd8 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/43b00bd8 Branch: refs/heads/feature/GEODE-2804v3 Commit: 43b00bd84984a7c9c28536cf4a13dc104834bf0b Parents: 5039e62 Author: YehEmily <emilyyeh1...@gmail.com> Authored: Mon Jun 12 11:42:15 2017 -0700 Committer: Jinmei Liao <jil...@pivotal.io> Committed: Wed Jun 21 11:35:47 2017 -0700 ---------------------------------------------------------------------- .../org/apache/geode/internal/SystemAdmin.java | 167 ++++++++++--------- .../geode/internal/i18n/LocalizedStrings.java | 3 - .../geode/internal/net/SocketCreator.java | 72 ++++---- .../geode/internal/util/PasswordUtil.java | 76 ++------- .../geode/management/internal/cli/Launcher.java | 19 +-- .../internal/cli/commands/ShellCommands.java | 67 ++++---- .../internal/cli/i18n/CliStrings.java | 11 +- .../geode/cache/util/PasswordUtilJUnitTest.java | 42 ----- .../internal/util/PasswordUtilJUnitTest.java | 41 +++++ .../internal/security/TestCommand.java | 3 +- 10 files changed, 224 insertions(+), 277 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/43b00bd8/geode-core/src/main/java/org/apache/geode/internal/SystemAdmin.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/SystemAdmin.java b/geode-core/src/main/java/org/apache/geode/internal/SystemAdmin.java index ceae486..ccc64e3 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/SystemAdmin.java +++ b/geode-core/src/main/java/org/apache/geode/internal/SystemAdmin.java @@ -14,42 +14,80 @@ */ package org.apache.geode.internal; -import static org.apache.geode.distributed.ConfigurationProperties.*; +import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL; +import static org.apache.geode.distributed.ConfigurationProperties.START_LOCATOR; -import org.apache.geode.*; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.RandomAccessFile; +import java.io.StringWriter; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.URL; +import java.net.URLDecoder; +import java.net.UnknownHostException; +import java.text.DateFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.zip.GZIPInputStream; + +import org.apache.geode.GemFireException; +import org.apache.geode.GemFireIOException; +import org.apache.geode.InternalGemFireException; +import org.apache.geode.NoSystemException; +import org.apache.geode.SystemFailure; +import org.apache.geode.UncreatedSystemException; +import org.apache.geode.UnstartedSystemException; import org.apache.geode.admin.AdminException; import org.apache.geode.admin.BackupStatus; import org.apache.geode.admin.internal.AdminDistributedSystemImpl; import org.apache.geode.cache.persistence.PersistentID; import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.internal.*; +import org.apache.geode.distributed.internal.DistributionConfig; +import org.apache.geode.distributed.internal.DistributionConfigImpl; +import org.apache.geode.distributed.internal.HighPriorityAckedMessage; +import org.apache.geode.distributed.internal.InternalDistributedSystem; import org.apache.geode.distributed.internal.membership.InternalDistributedMember; -import org.apache.geode.distributed.internal.tcpserver.*; -import org.apache.geode.internal.statistics.StatArchiveReader; -import org.apache.geode.internal.statistics.StatArchiveReader.ResourceInst; -import org.apache.geode.internal.statistics.StatArchiveReader.StatValue; +import org.apache.geode.distributed.internal.tcpserver.TcpClient; import org.apache.geode.internal.admin.remote.TailLogResponse; import org.apache.geode.internal.cache.DiskStoreImpl; import org.apache.geode.internal.i18n.LocalizedStrings; import org.apache.geode.internal.logging.DateFormatter; import org.apache.geode.internal.logging.MergeLogFiles; import org.apache.geode.internal.net.SocketCreator; +import org.apache.geode.internal.statistics.StatArchiveReader; +import org.apache.geode.internal.statistics.StatArchiveReader.ResourceInst; +import org.apache.geode.internal.statistics.StatArchiveReader.StatValue; import org.apache.geode.internal.util.JavaCommandBuilder; -import org.apache.geode.internal.util.PasswordUtil; import org.apache.geode.internal.util.PluckStacks; import org.apache.geode.internal.util.PluckStacks.ThreadStack; -import java.io.*; -import java.net.*; -import java.text.DateFormat; -import java.text.ParseException; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.zip.GZIPInputStream; - -import static org.apache.geode.distributed.ConfigurationProperties.START_LOCATOR; - /** * Provides static methods for various system administation tasks. */ @@ -163,7 +201,7 @@ public class SystemAdmin { String msg = tailFile(logFile, false); throw new GemFireIOException( LocalizedStrings.SystemAdmin_START_OF_LOCATOR_FAILED_THE_END_OF_0_CONTAINED_THIS_MESSAGE_1 - .toLocalizedString(new Object[] {logFile, msg}), + .toLocalizedString(logFile, msg), null); } catch (IOException ignore) { throw new GemFireIOException( @@ -335,13 +373,11 @@ public class SystemAdmin { ManagerInfo mi = ManagerInfo.loadLocatorInfo(directory); if (statusCode == ManagerInfo.KILLED_STATUS_CODE) { return LocalizedStrings.SystemAdmin_LOCATOR_IN_0_WAS_KILLED_WHILE_IT_WAS_1_LOCATOR_PROCESS_ID_WAS_2 - .toLocalizedString( - new Object[] {directory, ManagerInfo.statusToString(mi.getManagerStatus()), - Integer.valueOf(mi.getManagerProcessId())}); + .toLocalizedString(directory, ManagerInfo.statusToString(mi.getManagerStatus()), + Integer.valueOf(mi.getManagerProcessId())); } else { return LocalizedStrings.SystemAdmin_LOCATOR_IN_0_IS_1_LOCATOR_PROCESS_ID_IS_2 - .toLocalizedString( - new Object[] {directory, statusString, Integer.valueOf(mi.getManagerProcessId())}); + .toLocalizedString(directory, statusString, Integer.valueOf(mi.getManagerProcessId())); } } catch (UnstartedSystemException ex) { return LocalizedStrings.SystemAdmin_LOCATOR_IN_0_IS_STOPPED.toLocalizedString(directory); @@ -535,7 +571,7 @@ public class SystemAdmin { File outputFile = null; if (cmdLine.size() > 0) { - outputFile = new File((String) cmdLine.get(0)); + outputFile = new File(cmdLine.get(0)); os = new FileOutputStream(outputFile); ps = new PrintWriter(os); } else { @@ -627,7 +663,7 @@ public class SystemAdmin { } public static void showDiskStoreMetadata(ArrayList<String> args) { - String dsName = (String) args.get(0); + String dsName = args.get(0); File[] dirs = argsToFile(args.subList(1, args.size())); try { @@ -643,7 +679,7 @@ public class SystemAdmin { out.mkdirs(); } - String dsName = (String) args.get(0); + String dsName = args.get(0); File[] dirs = argsToFile(args.subList(1, args.size())); try { @@ -757,7 +793,7 @@ public class SystemAdmin { } catch (FileNotFoundException ex) { throw new GemFireIOException( LocalizedStrings.SystemAdmin_COULD_NOT_CREATE_FILE_0_FOR_OUTPUT_BECAUSE_1 - .toLocalizedString(new Object[] {outOption, getExceptionMessage(ex)})); + .toLocalizedString(outOption, getExceptionMessage(ex))); } } else { ps = System.out; @@ -778,7 +814,7 @@ public class SystemAdmin { } catch (FileNotFoundException ex) { throw new GemFireIOException( LocalizedStrings.SystemAdmin_COULD_NOT_OPEN_TO_0_FOR_READING_BECAUSE_1 - .toLocalizedString(new Object[] {fileName, getExceptionMessage(ex)})); + .toLocalizedString(fileName, getExceptionMessage(ex))); } if (!quiet) { ps.println(" " + fileName); @@ -1312,7 +1348,7 @@ public class SystemAdmin { .toLocalizedString( new Object[] {"commands", "options", "usage", "configuration", "-h"})); } else if (topic.equalsIgnoreCase("commands")) { - pw.println((String) usageMap.get("gemfire") + " <command> ..."); + pw.println(usageMap.get("gemfire") + " <command> ..."); format(pw, (String) helpMap.get("gemfire"), " ", 0); for (int i = 0; i < validCommands.length; i++) { pw.println((String) usageMap.get(validCommands[i])); @@ -1385,10 +1421,10 @@ public class SystemAdmin { private final static String[] validCommands = new String[] {"version", "stats", START_LOCATOR, "stop-locator", "status-locator", "info-locator", "tail-locator-log", "merge-logs", - "encrypt-password", "revoke-missing-disk-store", "list-missing-disk-stores", - "validate-disk-store", "upgrade-disk-store", "compact-disk-store", "compact-all-disk-stores", - "modify-disk-store", "show-disk-store-metadata", "export-disk-store", "shut-down-all", - "backup", "print-stacks", "help"}; + "revoke-missing-disk-store", "list-missing-disk-stores", "validate-disk-store", + "upgrade-disk-store", "compact-disk-store", "compact-all-disk-stores", "modify-disk-store", + "show-disk-store-metadata", "export-disk-store", "shut-down-all", "backup", "print-stacks", + "help"}; protected static String[] getValidCommands() { return validCommands.clone(); @@ -1475,28 +1511,23 @@ public class SystemAdmin { protected final Map helpMap = new HashMap(); protected void initHelpMap() { - helpMap.put("gemfire", LocalizedStrings.SystemAdmin_GEMFIRE_HELP.toLocalizedString( - new Object[] {join(validCommands), "-h", "-debug", "-help", "-q", "-J<vmOpt>"})); + helpMap.put("gemfire", LocalizedStrings.SystemAdmin_GEMFIRE_HELP + .toLocalizedString(join(validCommands), "-h", "-debug", "-help", "-q", "-J<vmOpt>")); helpMap.put("version", LocalizedStrings.SystemAdmin_VERSION_HELP.toLocalizedString()); helpMap.put("help", LocalizedStrings.SystemAdmin_HELP_HELP.toLocalizedString()); helpMap.put("stats", - LocalizedStrings.SystemAdmin_STATS_HELP_PART_A.toLocalizedString(new Object[] {"+", - "++", ":", ".", "-details", "-nofilter", "-archive=", "-persec", "-persample", - "-prunezeros"}) + "\n" - + LocalizedStrings.SystemAdmin_STATS_HELP_PART_B.toLocalizedString(new Object[] { - "-starttime", "-archive=", DateFormatter.FORMAT_STRING, "-endtime",})); - helpMap.put("encrypt-password", - LocalizedStrings.SystemAdmin_ENCRYPTS_A_PASSWORD_FOR_USE_IN_CACHE_XML_DATA_SOURCE_CONFIGURATION - .toLocalizedString()); + LocalizedStrings.SystemAdmin_STATS_HELP_PART_A.toLocalizedString("+", "++", ":", ".", + "-details", "-nofilter", "-archive=", "-persec", "-persample", "-prunezeros") + "\n" + + LocalizedStrings.SystemAdmin_STATS_HELP_PART_B.toLocalizedString("-starttime", + "-archive=", DateFormatter.FORMAT_STRING, "-endtime")); helpMap.put(START_LOCATOR, - LocalizedStrings.SystemAdmin_START_LOCATOR_HELP.toLocalizedString(new Object[] {"-port=", + LocalizedStrings.SystemAdmin_START_LOCATOR_HELP.toLocalizedString("-port=", Integer.valueOf(DistributionLocator.DEFAULT_LOCATOR_PORT), "-address=", "-dir=", - "-properties=", "-peer=", "-server=", "-hostname-for-clients=", "-D", "-X"})); - helpMap.put("stop-locator", - LocalizedStrings.SystemAdmin_STOP_LOCATOR_HELP.toLocalizedString(new Object[] {"-port=", - Integer.valueOf(DistributionLocator.DEFAULT_LOCATOR_PORT), "-address=", "-dir="})); + "-properties=", "-peer=", "-server=", "-hostname-for-clients=", "-D", "-X")); + helpMap.put("stop-locator", LocalizedStrings.SystemAdmin_STOP_LOCATOR_HELP.toLocalizedString( + "-port=", Integer.valueOf(DistributionLocator.DEFAULT_LOCATOR_PORT), "-address=", "-dir=")); helpMap.put("status-locator", LocalizedStrings.SystemAdmin_STATUS_LOCATOR_HELP - .toLocalizedString(new Object[] {join(ManagerInfo.statusNames), "-dir="})); + .toLocalizedString(join(ManagerInfo.statusNames), "-dir=")); helpMap.put("info-locator", LocalizedStrings.SystemAdmin_INFO_LOCATOR_HELP.toLocalizedString("-dir=")); helpMap.put("tail-locator-log", @@ -1593,15 +1624,15 @@ public class SystemAdmin { .toLocalizedString()); helpMap.put("-starttime=", LocalizedStrings.SystemAdmin_CAUSES_THE_0_COMMAND_TO_IGNORE_STATISTICS_SAMPLES_TAKEN_BEFORE_THIS_TIME_THE_ARGUMENT_FORMAT_MUST_MATCH_1 - .toLocalizedString(new Object[] {"stats", DateFormatter.FORMAT_STRING})); + .toLocalizedString("stats", DateFormatter.FORMAT_STRING)); helpMap.put("-endtime=", LocalizedStrings.SystemAdmin_CAUSES_THE_0_COMMAND_TO_IGNORE_STATISTICS_SAMPLES_TAKEN_AFTER_THIS_TIME_THE_ARGUMENT_FORMAT_MUST_MATCH_1 - .toLocalizedString(new Object[] {"stats", DateFormatter.FORMAT_STRING})); + .toLocalizedString("stats", DateFormatter.FORMAT_STRING)); helpMap.put("-dir=", - LocalizedStrings.SystemAdmin_DIR_ARGUMENT_HELP - .toLocalizedString(new Object[] {DistributionConfig.GEMFIRE_PREFIX + "properties", - DistributionConfig.GEMFIRE_PREFIX + "systemDirectory", "GEMFIRE", "defaultSystem", - "version"})); + LocalizedStrings.SystemAdmin_DIR_ARGUMENT_HELP.toLocalizedString( + DistributionConfig.GEMFIRE_PREFIX + "properties", + DistributionConfig.GEMFIRE_PREFIX + "systemDirectory", "GEMFIRE", "defaultSystem", + "version")); helpMap.put("-D", LocalizedStrings.SystemAdmin_SETS_A_JAVA_SYSTEM_PROPERTY_IN_THE_LOCATOR_VM_USED_MOST_OFTEN_FOR_CONFIGURING_SSL_COMMUNICATION .toLocalizedString()); @@ -1649,7 +1680,6 @@ public class SystemAdmin { usageMap.put("info-locator", "info-locator [-dir=<locatorDir>]"); usageMap.put("tail-locator-log", "tail-locator-log [-dir=<locatorDir>]"); usageMap.put("merge-logs", "merge-logs <logFile>+ [-out=<outFile>]"); - usageMap.put("encrypt-password", "encrypt-password <passwordString>"); usageMap.put("validate-disk-store", "validate-disk-store <diskStoreName> <directory>+"); usageMap.put("upgrade-disk-store", "upgrade-disk-store <diskStoreName> <directory>+ [-maxOplogSize=<int>]"); @@ -1733,7 +1763,6 @@ public class SystemAdmin { cmdOptionsMap.put("export-disk-store", new String[] {"-outputDir="}); cmdOptionsMap.put("shut-down-all", new String[] {}); cmdOptionsMap.put("backup", new String[] {"-baseline="}); - cmdOptionsMap.put("encrypt-password", new String[] {}); cmdOptionsMap.put("print-stacks", new String[] {"-all-threads"}); } @@ -1900,19 +1929,8 @@ public class SystemAdmin { } private static boolean needsSysDir(String cmd) { - if (cmd.equalsIgnoreCase("stats")) { - return false; - } - if (cmd.equalsIgnoreCase("merge-logs")) { - return false; - } - if (cmd.equalsIgnoreCase("version")) { - return false; - } - if (cmd.equalsIgnoreCase("help")) { - return false; - } - return true; + return !(cmd.equalsIgnoreCase("stats") || cmd.equalsIgnoreCase("merge-logs") + || cmd.equalsIgnoreCase("version") || cmd.equalsIgnoreCase("help")); } public static File getProductDir() { @@ -2206,11 +2224,6 @@ public class SystemAdmin { usage(cmd); } backup((String) cmdLine.get(0)); - } else if (cmd.equalsIgnoreCase("encrypt-password")) { - if (cmdLine.size() != 1) { - usage(cmd); - } - PasswordUtil.encrypt((String) cmdLine.get(0)); } else if (cmd.equalsIgnoreCase("print-stacks")) { printStacks(cmdLine, printStacksOption != null); } else { http://git-wip-us.apache.org/repos/asf/geode/blob/43b00bd8/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java index ae1c005..baad039 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java +++ b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java @@ -4514,8 +4514,6 @@ public class LocalizedStrings { "Prints statistic values from a statistic archive\nBy default all statistics are printed.\nThe statSpec arguments can be used to print individual resources or a specific statistic.\nThe format of a statSpec is: an optional combine operator, followed by an optional instanceId, followed by an optional typeId, followed by an optional statId.\nA combine operator can be \"{0}\" to combine all matches in the same file, or \"{1}\" to combine all matches across all files.\nAn instanceId must be the name or id of a resource.\nA typeId is a \"{2}\" followed by the name of a resource type.\nA statId is a \"{3}\" followed by the name of a statistic.\nA typeId or instanceId with no statId prints out all the matching resources and all their statistics.\nA typeId or instanceId with a statId prints out just the named statistic on the matching resources.\nA statId with no typeId or instanceId matches all statistics with that name.\nThe \"{4}\" option causes statistic descriptions to also be pr inted.\nThe \"{5}\" option, in conjunction with \"{6}\", causes the printed statistics to all be raw, unfiltered, values.\nThe \"{7}\" option, in conjunction with \"{6}\", causes the printed statistics to be the rate of change, per second, of the raw values.\nThe \"{8}\" option, in conjunction with \"{6}\", causes the printed statistics to be the rate of change, per sample, of the raw values.\nThe \"{9}\" option, in conjunction with \"{6}\", causes statistics whose values are all zero to not be printed."); public static final StringId SystemAdmin_STATS_HELP_PART_B = new StringId(3751, "The \"{0}\" option, in conjunction with \"{1}\", causes statistics samples taken before this time to be ignored. The argument format must match \"{2}\".\nThe \"{3}\" option, in conjunction with \"{1}\", causes statistics samples taken after this time to be ignored. The argument format must match \"{2}\".\nThe \"{1}\" option causes the data to come from an archive file."); - public static final StringId SystemAdmin_ENCRYPTS_A_PASSWORD_FOR_USE_IN_CACHE_XML_DATA_SOURCE_CONFIGURATION = - new StringId(3752, "Encrypts a password for use in cache.xml data source configuration."); public static final StringId SystemAdmin_START_LOCATOR_HELP = new StringId(3753, "Starts a locator.\nThe \"{0}\" option specifies the port the locator will listen on. It defaults to \"{1}\"\nThe \"{2}\" option specifies the address the locator will listen on. It defaults to listening on all local addresses.\nThe \"{3}\" option can be used to specify the directory the locator will run in.\nThe \"{4}\" option can be used to specify the gemfire.properties file for configuring the locator''s distributed system. The file''s path should be absolute, or relative to the locator''s directory ({3})\nThe \"{5}\" option can be used to specify whether peer locator service should be enabled. True (the default) will enable the service.\nThe \"{6}\" option can be used to specify whether server locator service should be enabled. True (the default) will enable the service.\nThe \"{7}\" option can be used to specify a host name or ip address that will be sent to clients so they can connect to this locator. The default is to use the address the locator is listening on.\nThe \"{8}\" option can be used to set system properties for the locator VM\nThe \"{9}\" option can be used to set vendor-specific VM options and is usually used to increase the size of the locator VM when using multicast.\n"); public static final StringId SystemAdmin_STOP_LOCATOR_HELP = new StringId(3754, @@ -4960,7 +4958,6 @@ public class LocalizedStrings { new StringId(3979, "Pooled High Priority Message Processor "); public static final StringId DistributionManager_POOLED_WAITING_MESSAGE_PROCESSOR = new StringId(3980, "Pooled Waiting Message Processor "); - public static final StringId PasswordUtil_ENCRYPTED_TO_0 = new StringId(3981, "Encrypted to {0}"); public static final StringId DistributionManager_SHUTDOWN_MESSAGE_THREAD_FOR_0 = new StringId(3982, "Shutdown Message Thread for {0}"); public static final StringId HealthMonitorImpl_HEALTH_MONITOR_OWNED_BY_0 = http://git-wip-us.apache.org/repos/asf/geode/blob/43b00bd8/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java b/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java index fec81ca..844b484 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java +++ b/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java @@ -14,32 +14,6 @@ */ package org.apache.geode.internal.net; -import org.apache.commons.lang.StringUtils; -import org.apache.geode.GemFireConfigException; -import org.apache.geode.SystemConnectException; -import org.apache.geode.SystemFailure; -import org.apache.geode.admin.internal.InetAddressUtil; -import org.apache.geode.cache.wan.GatewaySender; -import org.apache.geode.cache.wan.GatewayTransportFilter; -import org.apache.geode.distributed.ClientSocketFactory; -import org.apache.geode.distributed.internal.DistributionConfig; -import org.apache.geode.distributed.internal.DistributionConfigImpl; -import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.internal.ClassPathLoader; -import org.apache.geode.internal.ConnectionWatcher; -import org.apache.geode.internal.GfeConsoleReaderFactory; -import org.apache.geode.internal.GfeConsoleReaderFactory.GfeConsoleReader; -import org.apache.geode.internal.admin.SSLConfig; -import org.apache.geode.internal.cache.wan.TransportFilterServerSocket; -import org.apache.geode.internal.cache.wan.TransportFilterSocketFactory; -import org.apache.geode.internal.i18n.LocalizedStrings; -import org.apache.geode.internal.logging.LogService; -import org.apache.geode.internal.logging.log4j.LocalizedMessage; -import org.apache.geode.internal.security.SecurableCommunicationChannel; -import org.apache.geode.internal.util.ArgumentRedactor; -import org.apache.geode.internal.util.PasswordUtil; -import org.apache.logging.log4j.Logger; - import java.io.FileInputStream; import java.io.IOException; import java.net.BindException; @@ -75,6 +49,7 @@ import java.util.Map; import java.util.Properties; import java.util.Random; import java.util.Set; + import javax.naming.Context; import javax.naming.NamingEnumeration; import javax.naming.directory.Attribute; @@ -97,6 +72,33 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509ExtendedKeyManager; +import org.apache.commons.lang.StringUtils; +import org.apache.logging.log4j.Logger; + +import org.apache.geode.GemFireConfigException; +import org.apache.geode.SystemConnectException; +import org.apache.geode.SystemFailure; +import org.apache.geode.admin.internal.InetAddressUtil; +import org.apache.geode.cache.wan.GatewaySender; +import org.apache.geode.cache.wan.GatewayTransportFilter; +import org.apache.geode.distributed.ClientSocketFactory; +import org.apache.geode.distributed.internal.DistributionConfig; +import org.apache.geode.distributed.internal.DistributionConfigImpl; +import org.apache.geode.distributed.internal.InternalDistributedSystem; +import org.apache.geode.internal.ClassPathLoader; +import org.apache.geode.internal.ConnectionWatcher; +import org.apache.geode.internal.GfeConsoleReaderFactory; +import org.apache.geode.internal.GfeConsoleReaderFactory.GfeConsoleReader; +import org.apache.geode.internal.admin.SSLConfig; +import org.apache.geode.internal.cache.wan.TransportFilterServerSocket; +import org.apache.geode.internal.cache.wan.TransportFilterSocketFactory; +import org.apache.geode.internal.i18n.LocalizedStrings; +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.internal.logging.log4j.LocalizedMessage; +import org.apache.geode.internal.security.SecurableCommunicationChannel; +import org.apache.geode.internal.util.ArgumentRedactor; +import org.apache.geode.internal.util.PasswordUtil; + /** * Analyze configuration data (gemfire.properties) and configure sockets accordingly for SSL. * <p> @@ -294,7 +296,7 @@ public class SocketCreator { * hits and duplicate strings */ public static synchronized String getHostName(InetAddress addr) { - String result = (String) hostNames.get(addr); + String result = hostNames.get(addr); if (result == null) { result = addr.getHostName(); hostNames.put(addr, result); @@ -307,7 +309,7 @@ public class SocketCreator { * hits and duplicate strings */ public static synchronized String getCanonicalHostName(InetAddress addr, String hostName) { - String result = (String) hostNames.get(addr); + String result = hostNames.get(addr); if (result == null) { hostNames.put(addr, hostName); return hostName; @@ -434,14 +436,8 @@ public class SocketCreator { throw new GemFireConfigException( "SSL properties are empty, but a console is not available"); } - if (key.toLowerCase().contains("password")) { - char[] password = consoleReader.readPassword("Please enter " + key + ": "); - env.put(key, PasswordUtil.encrypt(new String(password), false)); - } else { - String val = consoleReader.readLine("Please enter " + key + ": "); - env.put(key, val); - } - + String val = consoleReader.readLine("Please enter " + key + ": "); + env.put(key, val); } } } @@ -727,7 +723,7 @@ public class SocketCreator { } catch (BindException e) { BindException throwMe = new BindException(LocalizedStrings.SocketCreator_FAILED_TO_CREATE_SERVER_SOCKET_ON_0_1 - .toLocalizedString(new Object[] {bindAddr, Integer.valueOf(nport)})); + .toLocalizedString(bindAddr, Integer.valueOf(nport))); throwMe.initCause(e); throw throwMe; } @@ -784,7 +780,7 @@ public class SocketCreator { } catch (BindException e) { BindException throwMe = new BindException(LocalizedStrings.SocketCreator_FAILED_TO_CREATE_SERVER_SOCKET_ON_0_1 - .toLocalizedString(new Object[] {bindAddr, Integer.valueOf(nport)})); + .toLocalizedString(bindAddr, Integer.valueOf(nport))); throwMe.initCause(e); throw throwMe; } http://git-wip-us.apache.org/repos/asf/geode/blob/43b00bd8/geode-core/src/main/java/org/apache/geode/internal/util/PasswordUtil.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/util/PasswordUtil.java b/geode-core/src/main/java/org/apache/geode/internal/util/PasswordUtil.java index b3472c7..5cc3bcd 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/util/PasswordUtil.java +++ b/geode-core/src/main/java/org/apache/geode/internal/util/PasswordUtil.java @@ -14,8 +14,6 @@ */ package org.apache.geode.internal.util; -import org.apache.geode.internal.i18n.LocalizedStrings; - import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; @@ -44,72 +42,30 @@ public class PasswordUtil { private static byte[] init = "string".getBytes(); /** - * Encrypts a password string - * - * @param password String to be encrypted. - * @return String encrypted String - */ - public static String encrypt(String password) { - return encrypt(password, true); - } - - /** - * - * @param password String to be encrypted - * @param echo if true prints result to system.out - * @return String encrypted String - */ - public static String encrypt(String password, boolean echo) { - String encryptedString = null; - try { - SecretKeySpec key = new SecretKeySpec(init, "Blowfish"); - Cipher cipher = Cipher.getInstance("Blowfish"); - cipher.init(Cipher.ENCRYPT_MODE, key); - byte[] encrypted = cipher.doFinal(password.getBytes()); - encryptedString = byteArrayToHexString(encrypted); - if (echo) { - System.out.println( - LocalizedStrings.PasswordUtil_ENCRYPTED_TO_0.toLocalizedString(encryptedString)); - } - } catch (Exception e) { - e.printStackTrace(); - } - return encryptedString; - } - - /** * Decrypts an encrypted password string. - * + * * @param password String to be decrypted * @return String decrypted String */ + @Deprecated public static String decrypt(String password) { + String toDecrypt; if (password.startsWith("encrypted(") && password.endsWith(")")) { - byte[] decrypted = null; - try { - String toDecrypt = password.substring(10, password.length() - 1); - SecretKeySpec key = new SecretKeySpec(init, "Blowfish"); - Cipher cipher = Cipher.getInstance("Blowfish"); - cipher.init(Cipher.DECRYPT_MODE, key); - decrypted = cipher.doFinal(hexStringToByteArray(toDecrypt)); - return new String(decrypted); - } catch (Exception e) { - e.printStackTrace(); - } + toDecrypt = password.substring(10, password.length() - 1); + } else { + toDecrypt = password; } - return password; - } - - private static String byteArrayToHexString(byte[] b) { - StringBuilder sb = new StringBuilder(b.length * 2); - for (int i = 0; i < b.length; i++) { - int v = b[i] & 0xff; - if (v < 16) { - sb.append('0'); - } - sb.append(Integer.toHexString(v)); + byte[] decrypted; + try { + SecretKeySpec key = new SecretKeySpec(init, "Blowfish"); + Cipher cipher = Cipher.getInstance("Blowfish"); + cipher.init(Cipher.DECRYPT_MODE, key); + decrypted = cipher.doFinal(hexStringToByteArray(toDecrypt)); + return new String(decrypted); + } catch (Exception e) { + e.printStackTrace(); } - return sb.toString().toUpperCase(); + return toDecrypt; } private static byte[] hexStringToByteArray(String s) { http://git-wip-us.apache.org/repos/asf/geode/blob/43b00bd8/geode-core/src/main/java/org/apache/geode/management/internal/cli/Launcher.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/Launcher.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/Launcher.java index e4e00da..a5986f5 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/Launcher.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/Launcher.java @@ -14,22 +14,23 @@ */ package org.apache.geode.management.internal.cli; -import org.apache.geode.internal.GemFireVersion; -import org.apache.geode.internal.PureJavaMode; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.shell.Gfsh; -import org.apache.geode.management.internal.cli.shell.GfshConfig; -import org.apache.geode.management.internal.cli.shell.jline.GfshHistory; -import org.springframework.shell.core.ExitShellRequest; - import java.io.IOException; import java.io.PrintStream; import java.util.HashSet; import java.util.List; import java.util.Set; + import joptsimple.OptionException; import joptsimple.OptionParser; import joptsimple.OptionSet; +import org.springframework.shell.core.ExitShellRequest; + +import org.apache.geode.internal.GemFireVersion; +import org.apache.geode.internal.PureJavaMode; +import org.apache.geode.management.internal.cli.i18n.CliStrings; +import org.apache.geode.management.internal.cli.shell.Gfsh; +import org.apache.geode.management.internal.cli.shell.GfshConfig; +import org.apache.geode.management.internal.cli.shell.jline.GfshHistory; /** * Launcher class for : @@ -93,8 +94,6 @@ public class Launcher { protected Launcher() { this.startupTimeLogHelper = new StartupTimeLogHelper(); this.allowedCommandLineCommands = new HashSet<String>(); - - this.allowedCommandLineCommands.add(CliStrings.ENCRYPT); this.allowedCommandLineCommands.add(CliStrings.RUN); this.allowedCommandLineCommands.add(CliStrings.START_PULSE); this.allowedCommandLineCommands.add(CliStrings.START_JCONSOLE); http://git-wip-us.apache.org/repos/asf/geode/blob/43b00bd8/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ShellCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ShellCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ShellCommands.java index e37d1ba..2da95a7 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ShellCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ShellCommands.java @@ -20,7 +20,38 @@ import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_SSL_P import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Writer; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.KeyStore; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManagerFactory; + import org.apache.commons.lang.StringUtils; +import org.springframework.shell.core.ExitShellRequest; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + import org.apache.geode.distributed.internal.DistributionConfig; import org.apache.geode.internal.ClassPathLoader; import org.apache.geode.internal.DSFIDFactory; @@ -54,35 +85,6 @@ import org.apache.geode.management.internal.web.http.support.SimpleHttpRequester import org.apache.geode.management.internal.web.shell.HttpOperationInvoker; import org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker; import org.apache.geode.security.AuthenticationFailedException; -import org.springframework.shell.core.ExitShellRequest; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Writer; -import java.net.MalformedURLException; -import java.net.URL; -import java.security.KeyStore; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManagerFactory; /** * @@ -985,13 +987,6 @@ public class ShellCommands implements GfshCommand { return result; } - @CliCommand(value = CliStrings.ENCRYPT, help = CliStrings.ENCRYPT__HELP) - @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_DEBUG_UTIL}) - public Result encryptPassword(@CliOption(key = CliStrings.ENCRYPT_STRING, - help = CliStrings.ENCRYPT_STRING__HELP, mandatory = true) String stringToEncrypt) { - return ResultBuilder.createInfoResult(PasswordUtil.encrypt(stringToEncrypt, false/* echo */)); - } - @CliCommand(value = {CliStrings.VERSION}, help = CliStrings.VERSION__HELP) @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GFSH}) public Result version(@CliOption(key = {CliStrings.VERSION__FULL}, specifiedDefaultValue = "true", http://git-wip-us.apache.org/repos/asf/geode/blob/43b00bd8/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java index bdf5cff..0f74edd 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java @@ -36,6 +36,8 @@ import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_ARC import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_SAMPLE_RATE; import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION; +import java.text.MessageFormat; + import org.apache.geode.cache.PartitionAttributesFactory; import org.apache.geode.cache.server.CacheServer; import org.apache.geode.distributed.ConfigurationProperties; @@ -44,8 +46,6 @@ import org.apache.geode.distributed.internal.DistributionConfig; import org.apache.geode.internal.cache.xmlcache.CacheXml; import org.apache.geode.management.internal.cli.shell.Gfsh; -import java.text.MessageFormat; - /** * - * Contains 'String' constants used as key to the Localized strings to be used in classes under * <code>org.apache.geode.management.internal.cli</code> for Command Line Interface (CLI). NOTES: 1. @@ -1265,13 +1265,6 @@ public class CliStrings { "String to be echoed. For example, \"SYS_USER variable is set to ${SYS_USER}\"."; public static final String ECHO__MSG__NO_GFSH_INSTANCE = "Could not get GFSH Instance"; - /* 'encrypt password' command */ - public static final String ENCRYPT = "encrypt password"; - public static final String ENCRYPT__HELP = - "Encrypt a password for use in data source configuration."; - public static final String ENCRYPT_STRING = "password"; - public static final String ENCRYPT_STRING__HELP = "Password to be encrypted."; - /* 'execute function' command */ public static final String EXECUTE_FUNCTION = "execute function"; public static final String EXECUTE_FUNCTION__HELP = http://git-wip-us.apache.org/repos/asf/geode/blob/43b00bd8/geode-core/src/test/java/org/apache/geode/cache/util/PasswordUtilJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache/util/PasswordUtilJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/util/PasswordUtilJUnitTest.java deleted file mode 100644 index 06e8666..0000000 --- a/geode-core/src/test/java/org/apache/geode/cache/util/PasswordUtilJUnitTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.cache.util; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import org.apache.geode.internal.util.PasswordUtil; -import org.apache.geode.test.junit.categories.SecurityTest; -import org.apache.geode.test.junit.categories.UnitTest; - -@Category({UnitTest.class, SecurityTest.class}) -public class PasswordUtilJUnitTest { - - @Test - public void testPasswordUtil() { - String x = "password"; - String z = null; - - // System.out.println(x); - String y = PasswordUtil.encrypt(x); - // System.out.println(y); - y = "encrypted(" + y + ")"; - z = PasswordUtil.decrypt(y); - // System.out.println(z); - assertEquals(x, z); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/43b00bd8/geode-core/src/test/java/org/apache/geode/internal/util/PasswordUtilJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/internal/util/PasswordUtilJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/util/PasswordUtilJUnitTest.java new file mode 100644 index 0000000..8051c56 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/internal/util/PasswordUtilJUnitTest.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.geode.internal.util; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import org.apache.geode.test.junit.categories.SecurityTest; +import org.apache.geode.test.junit.categories.UnitTest; + +@Category({UnitTest.class, SecurityTest.class}) +public class PasswordUtilJUnitTest { + + /** + * Tests PasswordUtil's decrypt method (which is now deprecated) and verifies that backwards + * compatibility has not been broken with the removal of PasswordUtil's encryption methods. + * Previously encrypted passwords may still be used and decrypted. + */ + @Test + public void testPasswordUtil() { + String password = "password"; + String encrypted = "encrypted(C3CDC3485F7FF64381841CD344CBDF8A)"; + String decrypted = PasswordUtil.decrypt(encrypted); + assertEquals(password, decrypted); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/43b00bd8/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java index 800d0da..7ce0438 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java @@ -224,7 +224,6 @@ public class TestCommand { createTestCommand("debug --state=on", null); createTestCommand("describe connection", null); createTestCommand("echo --string=\"Hello World!\"", null); - createTestCommand("encrypt password --password=value", null); createTestCommand("version", null); createTestCommand("sleep", null); createTestCommand("sh ls", null); @@ -249,5 +248,5 @@ public class TestCommand { // Misc commands // createTestCommand("shutdown", clusterManage); - }; + } }