public void deleteAllFiles() throws IOException {
    File allowUploadFile = serverForClients.getAllowUploadFile();
    allowUploadFile.delete();
    if (allowUploadFile.exists()) throw new IOException("allowUploadFile");
    MartusServerUtilities.deleteSignaturesForFile(allowUploadFile);

    File authorizeLogFile = serverForClients.getAuthorizeLogFile();
    authorizeLogFile.delete();
    if (authorizeLogFile.exists()) throw new IOException("authorizeLogFile");
    MartusServerUtilities.deleteSignaturesForFile(authorizeLogFile);

    File magicWordsFile = serverForClients.getMagicWordsFile();
    magicWordsFile.delete();
    if (magicWordsFile.exists()) throw new IOException("magicWordsFile");
    getKeyPairFile().delete();
    if (getKeyPairFile().exists()) throw new IOException("keyPairFile");

    File magicSig = MartusUtilities.getSignatureFileFromFile(magicWordsFile);
    if (magicSig.exists()) magicSig.delete();

    File triggerDirectory = getTriggerDirectory();
    if (triggerDirectory.exists()) triggerDirectory.delete();

    File startupDirectory = getStartupConfigDirectory();
    if (startupDirectory.exists()) startupDirectory.delete();

    getDataDirectory().delete();
    if (getDataDirectory().exists())
      throw new IOException("dataDirectory: " + getDataDirectory().getPath());
  }
  public static void main(String[] args) throws Exception {
    System.out.println(
        "ChangeServerPassphrase:\nThis program will replace your keypair.dat file."
            + "\nWe strongly recommend that you make sure you have a backup copy before running this program. "
            + "\nAlso, after successfully changing the password, we strongly recommend that you create a backup of the new keypair.dat file.\n");

    if (args.length == 0 || !args[0].startsWith("--keypair")) {
      System.err.println(
          "Error: Incorrect argument.\nChangeServerPassphrase --keypair=/path/keypair.dat");
      System.err.flush();
      System.exit(2);
    }
    File keyPairFile = new File(args[0].substring(args[0].indexOf("=") + 1));

    if (!keyPairFile.exists()) {
      System.err.println(
          "Error: There is no keypair file at location " + keyPairFile.getAbsolutePath() + ".");
      System.err.flush();
      System.exit(3);
    }

    System.out.print("Enter current passphrase:");
    System.out.flush();

    UnicodeReader rawReader = new UnicodeReader(System.in);
    BufferedReader reader = new BufferedReader(rawReader);
    try {
      // TODO security issue here password is a string
      String oldPassphrase = reader.readLine();

      MartusCrypto security =
          MartusServerUtilities.loadCurrentMartusSecurity(keyPairFile, oldPassphrase.toCharArray());

      System.out.print("Enter new passphrase:");
      System.out.flush();
      // TODO security issue here password is a string
      String newPassphrase1 = reader.readLine();
      System.out.print("Re-enter the new passphrase:");
      System.out.flush();
      String newPassphrase2 = reader.readLine();

      if (newPassphrase1.equals(newPassphrase2)) {
        System.out.println("Updating passphrase...");
        System.out.flush();
        updateKeypairPassphrase(keyPairFile, newPassphrase1.toCharArray(), security);
      } else {
        System.err.println("Passwords not the same");
        System.exit(3);
      }
    } catch (Exception e) {
      System.err.println("ChangeServerPassphrase.main: " + e);
      System.exit(3);
    } finally {
      reader.close();
    }

    System.out.println("Server passphrase updated.");
    System.out.flush();
    System.exit(0);
  }
  private void writeAccountDirectoryIdentificationFile(File accountDirectory, String accountId)
      throws Exception {
    String publicCode = MartusSecurity.computeFormattedPublicCode(accountId);
    File metadataDirectory = new File(accountDirectory, "metadata");
    metadataDirectory.mkdirs();
    File identificationFile = new File(metadataDirectory, "acct-" + publicCode + ".txt");
    UnicodeWriter writer = new UnicodeWriter(identificationFile);
    try {
      writer.writeln(accountId);
    } finally {
      writer.close();
    }

    MartusServerUtilities.createSignatureFileFromFileOnServer(identificationFile, security);
  }
  private void createAccountMap(String[] args) throws Exception {
    processArgs(args);
    if (prompt) System.out.println("CreateAccountMap");

    File packetsDirectory = new File(packetDirName);
    if (noisy) MartusLogger.log("Packets directory: " + packetsDirectory);

    security = MartusServerUtilities.loadKeyPair(keyPairFileName, prompt);
    db = new ServerFileDatabase(packetsDirectory, security);
    File mapFile = db.getAccountMapFile();

    if (noisy) MartusLogger.log("Account map file: " + mapFile.getAbsolutePath());
    if (mapFile.exists()) {
      System.err.println("Cannot create account map because it already exists");
      System.exit(1);
    }

    processPacketsDirectory(packetsDirectory);
    if (prompt) MartusLogger.log("Finished");
  }