예제 #1
0
  @Override
  public void actionPerformed(ActionEvent ape) {

    String command = ape.getActionCommand();

    if (command.equals("newSetting")) {
      // check parameters
      int garlic = Integer.parseInt(memoryField.getText());
      int lambda = Integer.parseInt(timeField.getText());
      if (garlic > 63) {
        errorLabel.setText("invalid memory cost parameter: must be < 64");
        pack();
        return;
      }
      if (garlic == 0 || lambda == 0) {
        errorLabel.setText("invalid cost parameters");
        pack();
        return;
      }
      if (instance.equals("Dragonfly-Full") || instance.equals("Dragonfly")) {
        CatenaKDF.setVersionID(instance);
        CatenaKDF.setGarlicDragonfly(garlic);
        CatenaKDF.setLambdaDragonfly(lambda);
      } else if (instance.equals("Butterfly-Full") || instance.equals("Butterfly")) {
        CatenaKDF.setVersionID(instance);
        CatenaKDF.setGarlicButterfly(garlic);
        CatenaKDF.setLambdaButterfly(lambda);
      }
      KeyDerivation.setKdf(new CatenaKDF());

      setting.dispose();

    } else { // RadioButton for instance
      instance = ape.getActionCommand();
      int garlic = Integer.parseInt(memoryField.getText());
      int lambda = Integer.parseInt(timeField.getText());
      if (garlic > 22 || lambda > 4) {
        errorLabel.setText("Warning: Long execution time");
      } else {
        errorLabel.setText("");
      }

      if (instance.equals("Dragonfly")) {
        timeRecommendedLabel.setText("recommended 2"); // lambda: 2
        memoryRecommendedLabel.setText("recommended >= 18"); // garlic
        timeField.setText("2");
        memoryField.setText("18");
      } else if (instance.equals("Dragonfly-Full")) {
        timeRecommendedLabel.setText("recommended 2"); // lambda: 2
        memoryRecommendedLabel.setText("recommended >= 18"); // garlic
        timeField.setText("2");
        memoryField.setText("18");
      } else if (instance.equals("Butterfly")) {
        timeRecommendedLabel.setText("recommended 4"); // lambda: 4
        memoryRecommendedLabel.setText("recommended >= 14"); // garlic
        timeField.setText("4");
        memoryField.setText("14");
      } else if (instance.equals("Butterfly-Full")) {
        timeRecommendedLabel.setText("recommended 4"); // lambda: 4
        memoryRecommendedLabel.setText("recommended >= 14"); // garlic
        timeField.setText("4");
        memoryField.setText("14");
      }
    }
  }
예제 #2
0
  public static final void createFile() {

    // =====================
    // initialize (order!)
    //
    if (HashStuff.getHashAlgo() == null) {
      HashStuff.setHashAlgo(DEFAULT_HASH); // default
    }
    if (CipherStuff.isBound() == true) {
      Attachments.generateAndSetProgramRandomBytes();
      Attachments.generateAndSetFileIdentifier();
      KeyDerivation.setSalt(Attachments.getProgramRandomBytes());
    } else {
      // use default values for fileIdentifier and programRandomBytes
      // calculate default salt and update via setAttachedSalt:
      // xor the salt with attachedSalt (will be attached to the content)
      Attachments.setFileIdentifier("PFACTORY".getBytes(UTF_8)); // 8 byte
      // 129 byte string to initialize the salt:
      String fixedSaltString =
          "PEAFACTORY - PRODUCTION OF PASSWORD ENCRYPTED ARCHIVES - FIXED STRING USED TO INITIALIZE THE SALT FOR THE KEY DERIVATION FUNCTION";
      String saltString = fixedSaltString.substring(0, KeyDerivation.getSaltSize());
      Attachments.setProgramRandomBytes(saltString.getBytes(UTF_8));
      KeyDerivation.setSalt(saltString.getBytes(UTF_8));

      byte[] attachedSalt =
          new RandomStuff().createRandomBytes(Attachments.getProgramRandomBytesSize());
      KeyDerivation.setAttachedAndUpdateSalt(attachedSalt);
    }

    // DEFAULT CIPHER ALGO:
    if (CipherStuff.getCipherAlgo() == null) {
      CipherStuff.setCipherAlgo(DEFAULT_CIPHER);
    }
    // DEFAULT KEY DERIVATION FUNCTION
    if (KeyDerivation.getKdf() == null) {
      KeyDerivation.setKdf(DEFAULT_KDF);
    }

    // ======================================
    // get password from pswField and check:
    //
    char[] pswInputChars = MainView.getPsw();
    MainView.resetPsw();
    char[] pswInputChars2 = MainView.getPsw2();
    MainView.resetPsw2();

    if ((pswInputChars2.length == 0) && (pswInputChars.length != 0)) {
      JOptionPane.showMessageDialog(
          null, languageBundle.getString("password2_is_null"), null, JOptionPane.PLAIN_MESSAGE);
      return;
    } else if (pswInputChars.length != pswInputChars2.length) {
      JOptionPane.showMessageDialog(
          null, languageBundle.getString("different_password"), null, JOptionPane.PLAIN_MESSAGE);
      return;
    }
    boolean pswEqual = true;
    // prevent timing attacks:
    for (int i = 0; i < pswInputChars.length; i++) {
      if (pswInputChars[i] != pswInputChars2[i]) {
        pswEqual = false;
      }
    }
    if (pswEqual == false) {
      JOptionPane.showMessageDialog(
          null, languageBundle.getString("different_password"), null, JOptionPane.PLAIN_MESSAGE);
      return;
    }

    int inputLength = pswInputChars.length;

    Arrays.fill(pswInputChars2, '\0');
    // Warning for insecure password
    if ((inputLength == 0) && (MainView.isBlankPea() == false)) {
      // allow null-passwords with warning
      JOptionPane.showMessageDialog(
          frame,
          languageBundle.getString("no_password_warning"),
          "Warning",
          JOptionPane.WARNING_MESSAGE);
      pswInputChars = "no password".toCharArray();

    } else if (inputLength < 12 && MainView.isBlankPea() == false) {
      JOptionPane.showMessageDialog(
          null,
          languageBundle.getString("short_password_warning"),
          null,
          JOptionPane.PLAIN_MESSAGE);
    }

    // =============
    //  derive key:
    //
    byte[] keyMaterial = null;

    if (MainView.isBlankPea() == false) { // if true: no need to derive key
      keyMaterial = PswDialogBase.deriveKeyFromPsw(pswInputChars);

      if (keyMaterial == null) {
        JOptionPane.showMessageDialog(
            frame,
            languageBundle.getString("program_bug") + ": \n  (keyMaterial is null)",
            "Error",
            JOptionPane.ERROR_MESSAGE);
        return;
      }
    }
    MainView.progressBar.setValue(35);
    MainView.progressBar.paint(MainView.progressBar.getGraphics());

    // =================
    // generate jar file:
    //
    // long start = System.currentTimeMillis(); // Startpunkt

    new JarStuff().generateJarFile(keyMaterial);

    // System.out.println("generateJarFile - Zeit in ms: \n" + (System.currentTimeMillis() -
    // start));//Messpunkt

    String fileOrDirectory =
        (MainView.getOpenedFileName() == null)
            ? languageBundle.getString("directory")
            : languageBundle.getString("file");
    if (MainView.isBlankPea() == true) {
      fileOrDirectory = languageBundle.getString("directory"); // for all peas
    }
    if (DataType.getCurrentType() instanceof FileType) {
      fileOrDirectory = languageBundle.getString("file");
    }
    String peaFileName =
        JarStuff.getJarFileName()
            .substring(0, (JarStuff.getJarFileName().length() - 4)); // extract ".jar"
    String peaPath = System.getProperty("user.dir") + File.separator + "peas";

    // show informations about created pea:
    int input =
        JOptionPane.showConfirmDialog(
            frame,
            languageBundle.getString("new_pea_info")
                + "\n"
                + DataType.getCurrentType().getDescription()
                + "\n\n"
                + languageBundle.getString("new_pea_type_info")
                + " "
                + fileOrDirectory
                + " \n "
                + "    - "
                + peaFileName
                + " -\n"
                + languageBundle.getString("new_pea_location_info")
                + "\n "
                + "   "
                + peaPath
                + "\n\n"
                + languageBundle.getString("open_directory")
                + "\n ",
            "Pea info",
            JOptionPane.YES_NO_OPTION);

    if (input == JOptionPane.YES_OPTION) { // 0

      String error = OperatingSystemStuff.openFileManager(peaPath);

      if (error != null) {
        JOptionPane.showMessageDialog(
            frame,
            languageBundle.getString("desktop_error") + "\n\n  " + error,
            languageBundle.getString("error"),
            JOptionPane.ERROR_MESSAGE);
      }
    } else { // do not open folder peas:
      //
    }
  }