@Test public void testHideOpenSslPassword(){ String command_pass = "openssl ca -config ca.config -in agent_hostname1.csr -out "+ "agent_hostname1.crt -batch -passin pass:1234 -keyfile ca.key -cert ca.crt"; String command_key = "openssl ca -create_serial -out /var/lib/ambari-server/keys/ca.crt -days 365 -keyfile /var/lib/ambari-server/keys/ca.key " + "-key 1234 -selfsign -extensions jdk7_ca " + "-config /var/lib/ambari-server/keys/ca.config -batch " + "-infiles /var/lib/ambari-server/keys/ca.csr"; Assert.assertFalse(ShellCommandUtil.hideOpenSslPassword(command_pass).contains("1234")); Assert.assertFalse(ShellCommandUtil.hideOpenSslPassword(command_key).contains("1234")); }
public static String hideOpenSslPassword(String command) { int start; if (command.contains(PASS_TOKEN)) { start = command.indexOf(PASS_TOKEN) + PASS_TOKEN.length(); } else if (command.contains(KEY_TOKEN)) { start = command.indexOf(KEY_TOKEN) + KEY_TOKEN.length(); } else { return command; } CharSequence cs = command.subSequence(start, command.indexOf(" ", start)); return command.replace(cs, "****"); }
ShellCommandUtil { public static String hideOpenSslPassword(String command) { int start; if (command.contains(PASS_TOKEN)) { start = command.indexOf(PASS_TOKEN) + PASS_TOKEN.length(); } else if (command.contains(KEY_TOKEN)) { start = command.indexOf(KEY_TOKEN) + KEY_TOKEN.length(); } else { return command; } CharSequence cs = command.subSequence(start, command.indexOf(" ", start)); return command.replace(cs, "****"); } }
ShellCommandUtil { public static String hideOpenSslPassword(String command) { int start; if (command.contains(PASS_TOKEN)) { start = command.indexOf(PASS_TOKEN) + PASS_TOKEN.length(); } else if (command.contains(KEY_TOKEN)) { start = command.indexOf(KEY_TOKEN) + KEY_TOKEN.length(); } else { return command; } CharSequence cs = command.subSequence(start, command.indexOf(" ", start)); return command.replace(cs, "****"); }  }
ShellCommandUtil { public static String hideOpenSslPassword(String command) { int start; if (command.contains(PASS_TOKEN)) { start = command.indexOf(PASS_TOKEN) + PASS_TOKEN.length(); } else if (command.contains(KEY_TOKEN)) { start = command.indexOf(KEY_TOKEN) + KEY_TOKEN.length(); } else { return command; } CharSequence cs = command.subSequence(start, command.indexOf(" ", start)); return command.replace(cs, "****"); }  static void logOpenSslExitCode(String command, int exitCode); static String hideOpenSslPassword(String command); static String getOpenSslCommandResult(String command, int exitCode); static String getUnixFilePermissions(String path); static void setUnixFilePermissions(String mode, String path); static Result setFileOwner(String path, String ownerName); static Result setFileGroup(String path,  String groupName); static Result setFileMode(String path,
                                   boolean ownerReadable, boolean ownerWritable, boolean ownerExecutable,
                                   boolean groupReadable, boolean groupWritable, boolean groupExecutable,
                                   boolean otherReadable, boolean otherWritable, boolean otherExecutable); static Result pathExists(String path, boolean sudo); static Result mkdir(String directoryPath, boolean sudo); static Result copyFile(String srcFile, String destFile, boolean force, boolean sudo); static Result delete(String file, boolean force, boolean sudo); static Result runCommand(List<String> args, Map<String, String> vars, InteractiveHandler interactiveHandler, boolean sudo); static Result runCommand(String[] args, Map<String, String> vars, InteractiveHandler interactiveHandler, boolean sudo); static Result runCommand(String[] args, Map<String, String> vars); static Result runCommand(String[] args); }
ShellCommandUtil { public static String hideOpenSslPassword(String command) { int start; if (command.contains(PASS_TOKEN)) { start = command.indexOf(PASS_TOKEN) + PASS_TOKEN.length(); } else if (command.contains(KEY_TOKEN)) { start = command.indexOf(KEY_TOKEN) + KEY_TOKEN.length(); } else { return command; } CharSequence cs = command.subSequence(start, command.indexOf(" ", start)); return command.replace(cs, "****"); }  static void logOpenSslExitCode(String command, int exitCode); static String hideOpenSslPassword(String command); static String getOpenSslCommandResult(String command, int exitCode); static String getUnixFilePermissions(String path); static void setUnixFilePermissions(String mode, String path); static Result setFileOwner(String path, String ownerName); static Result setFileGroup(String path,  String groupName); static Result setFileMode(String path,
                                   boolean ownerReadable, boolean ownerWritable, boolean ownerExecutable,
                                   boolean groupReadable, boolean groupWritable, boolean groupExecutable,
                                   boolean otherReadable, boolean otherWritable, boolean otherExecutable); static Result pathExists(String path, boolean sudo); static Result mkdir(String directoryPath, boolean sudo); static Result copyFile(String srcFile, String destFile, boolean force, boolean sudo); static Result delete(String file, boolean force, boolean sudo); static Result runCommand(List<String> args, Map<String, String> vars, InteractiveHandler interactiveHandler, boolean sudo); static Result runCommand(String[] args, Map<String, String> vars, InteractiveHandler interactiveHandler, boolean sudo); static Result runCommand(String[] args, Map<String, String> vars); static Result runCommand(String[] args); static final boolean WINDOWS; static final boolean LINUX; static final boolean MAC; static final boolean UNIX_LIKE; static final String MASK_OWNER_ONLY_RW; static final String MASK_OWNER_ONLY_RWX; static final String MASK_EVERYBODY_RWX; }