Ejemplo n.º 1
0
  public static void main(String[] args) throws MalformedURLException {

    os = System.getProperty("os.name");

    boolean testMode = false;
    if (args.length > 0) {
      if (args[0] != null) {
        if (args[0].equals("-r")) {
          System.out.println("Rescue mode only works for PEAs, not for PeaFactory...");
        } else if (args[0].equals("-t")) {
          System.out.println("#####---TEST MODE---#####");
          testMode = true;
        } else {
          System.out.println("Unknown argument: " + args[0]);
        }
      }
    }
    if (testMode == true) {

      new TestMode().runInTestMode();
    }

    // i18n:
    language = defaultLocale.getLanguage(); // get default language
    currentLocale = new Locale(language); // set default language as language

    // File file = new File("src" + File.separator + "config" + File.separator + "i18n");
    File file = new File("config" + File.separator + "i18n");
    URL[] urls = {file.toURI().toURL()};
    ClassLoader loader = new URLClassLoader(urls);
    languageBundle = ResourceBundle.getBundle("LanguagesBundle", currentLocale, loader);

    // DEFAULT HASH FUNCTION:
    if (HashStuff.getHashAlgo() == null) { // needed for RandomPasswordDialog
      HashStuff.setHashAlgo(DEFAULT_HASH);
    }
    EventQueue.invokeLater(
        new Runnable() {
          public void run() {
            try {

              PswDialogView.setUI();

              // select the kind of pea
              ProjectSelection proj = new ProjectSelection();
              proj.setLocation(100, 100);
              proj.setVisible(true);

              frame = MainView.getInstance();

            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });
  }
Ejemplo n.º 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:
      //
    }
  }