示例#1
0
  //
  // This should probably be a separate tool and not be baked into Maven.
  //
  private void encryption(CliRequest cliRequest) throws Exception {
    if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_MASTER_PASSWORD)) {
      String passwd = cliRequest.commandLine.getOptionValue(CLIManager.ENCRYPT_MASTER_PASSWORD);

      DefaultPlexusCipher cipher = new DefaultPlexusCipher();

      cliRequest.stdout.println(
          cipher.encryptAndDecorate(passwd, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION));

      throw new ExitException(0);
    } else if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_PASSWORD)) {
      String passwd = cliRequest.commandLine.getOptionValue(CLIManager.ENCRYPT_PASSWORD);

      String configurationFile = dispatcher.getConfigurationFile();

      if (configurationFile.startsWith("~")) {
        configurationFile = System.getProperty("user.home") + configurationFile.substring(1);
      }

      String file =
          System.getProperty(DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, configurationFile);

      String master = null;

      SettingsSecurity sec = SecUtil.read(file, true);
      if (sec != null) {
        master = sec.getMaster();
      }

      if (master == null) {
        throw new IllegalStateException(
            "Master password is not set in the setting security file: " + file);
      }

      DefaultPlexusCipher cipher = new DefaultPlexusCipher();
      String masterPasswd =
          cipher.decryptDecorated(master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION);
      cliRequest.stdout.println(cipher.encryptAndDecorate(passwd, masterPasswd));

      throw new ExitException(0);
    }
  }
示例#2
0
文件: MavenCli.java 项目: nerro/maven
  //
  // This should probably be a separate tool and not be baked into Maven.
  //
  private void encryption(CliRequest cliRequest) throws Exception {
    if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_MASTER_PASSWORD)) {
      String passwd = cliRequest.commandLine.getOptionValue(CLIManager.ENCRYPT_MASTER_PASSWORD);

      if (passwd == null) {
        Console cons = System.console();
        char[] password = (cons == null) ? null : cons.readPassword("Master password: "******"Password: "******"~")) {
        configurationFile = System.getProperty("user.home") + configurationFile.substring(1);
      }

      String file =
          System.getProperty(DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, configurationFile);

      String master = null;

      SettingsSecurity sec = SecUtil.read(file, true);
      if (sec != null) {
        master = sec.getMaster();
      }

      if (master == null) {
        throw new IllegalStateException(
            "Master password is not set in the setting security file: " + file);
      }

      DefaultPlexusCipher cipher = new DefaultPlexusCipher();
      String masterPasswd =
          cipher.decryptDecorated(master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION);
      System.out.println(cipher.encryptAndDecorate(passwd, masterPasswd));

      throw new ExitException(0);
    }
  }