protected boolean createDataSetKey() {
    XnatToolPanelController masterController = createDialog.getMasterController();

    String sourceId = masterController.getDataSetSourceID();
    DataSetConfig dataSetConfig = masterController.getDataSetConfig();
    if (dataSetConfig == null) {
      masterController.showError("No DataSet Configuration Created. Create one first!");
      return false;
    }

    String dataSetName = dataSetConfig.getDataSetName();

    Secret passP1 = createDialog.getPassphraseSecret();

    if ((passP1.getChars() == null) || (passP1.getChars().length < 8)) {
      masterController.showError("Passphrase is to short!");
      return false;
    }

    SecretHolder valueH = new SecretHolder();
    masterController.uiAskField(
        "Verify passphrase.", "Verify your passphrase Please for DataSet:" + dataSetName, valueH);

    if (valueH.value == null || valueH.value.isEmpty()) {
      masterController.logger.debugPrintf(
          "KeyCreateDialogController:doCreateNewKey(): Cancelled\n");
      return false;
    }

    Secret secret2 = valueH.value;
    if (!passP1.equals(secret2)) {
      masterController.showError("Passphrases do not match!");
      return false;
    }

    try {
      // Use passphrase both as key digest source and encryption password
      // for now.

      Secret keySourceText = secret2;
      Secret keyPassphrase = secret2;
      XnatTool xnatTool = masterController.getXnatTool();
      xnatTool.initializeEncryptionKeyFromSourceText(sourceId, keySourceText, keyPassphrase);
      // authenticate and initalize encryption:
      xnatTool.authenticateEncryptionKeys(sourceId, keyPassphrase, false);
      byte rawKey[] = xnatTool.getCurrentDataSetConfig().getEncryptionKey();
      this.createDialog.setKey(rawKey, this.createDialog.showRawKeyCB.isSelected());
      this.createDialog.setPassphrase(secret2);
      // / update main panel as well:
      this.createDialog.getMasterController().updatePassphrase(keyPassphrase);

      return true;
    } catch (Exception e) {
      this.handle("Could not initialize new Encryption Key.", e);
    }

    return false;
  }
Esempio n. 2
0
  public boolean askAuthentication(String message, SecretHolder secret) {
    //
    if (enabled == false) {
      return false;
    }
    // Thanks to Swing's serialization, we can send Swing Components !
    JTextField passwordField = new JPasswordField(20);
    Object[] inputFields = {message, passwordField};
    int result =
        JOptionPane.showConfirmDialog(
            null, inputFields, "Authentication Required", JOptionPane.WARNING_MESSAGE);

    if (result == JOptionPane.OK_OPTION) {
      secret.value = Secret.wrap(passwordField.getText().toCharArray());
      return true;
    }

    return false;
  }