public void testIsAuthorizedForMirroring() throws Exception {
    MockMartusServer nobodyAuthorizedCore = new MockMartusServer(this);
    ServerForMirroring nobodyAuthorized = new ServerForMirroring(nobodyAuthorizedCore, logger);
    nobodyAuthorized.loadConfigurationFiles();
    assertFalse(
        "client already authorized?",
        nobodyAuthorized.isAuthorizedForMirroring(clientSecurity1.getPublicKeyString()));
    nobodyAuthorizedCore.deleteAllFiles();

    MockMartusServer twoAuthorizedCore = new MockMartusServer(this);
    twoAuthorizedCore.enterSecureMode();
    File mirrorsWhoCallUs =
        new File(twoAuthorizedCore.getStartupConfigDirectory(), "mirrorsWhoCallUs");
    mirrorsWhoCallUs.mkdirs();
    File pubKeyFile1 = new File(mirrorsWhoCallUs, "code=1.2.3.4.5-ip=1.2.3.4.txt");
    MartusUtilities.exportServerPublicKey(clientSecurity1, pubKeyFile1);
    File pubKeyFile2 = new File(mirrorsWhoCallUs, "code=2.3.4.5.6-ip=2.3.4.5.txt");
    MartusUtilities.exportServerPublicKey(clientSecurity2, pubKeyFile2);
    ServerForMirroring twoAuthorized = new ServerForMirroring(twoAuthorizedCore, logger);
    twoAuthorized.loadConfigurationFiles();
    assertTrue(
        "client1 not authorized?",
        twoAuthorized.isAuthorizedForMirroring(clientSecurity1.getPublicKeyString()));
    assertTrue(
        "client2 not authorized?",
        twoAuthorized.isAuthorizedForMirroring(clientSecurity2.getPublicKeyString()));
    assertFalse(
        "ourselves authorized?", twoAuthorized.isAuthorizedForMirroring(coreServer.getAccountId()));
    mirrorsWhoCallUs.delete();
    twoAuthorizedCore.deleteAllFiles();
  }
  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());
  }
 MirroringRetriever createRetrieverToCall(File publicKeyFile)
     throws IOException, InvalidPublicKeyFileException, PublicInformationInvalidException,
         SSLSocketSetupException {
   String ip = MartusUtilities.extractIpFromFileName(publicKeyFile.getName());
   CallerSideMirroringGateway gateway = createGatewayToCall(ip, publicKeyFile);
   return new MirroringRetriever(getStore(), gateway, ip, logger);
 }
  public void testExtractIpFromFileName() throws Exception {
    try {
      MartusUtilities.extractIpFromFileName("code=x.y.z");
      fail("Should have thrown missing ip=");
    } catch (InvalidPublicKeyFileException ignoreExpectedException) {
    }

    try {
      MartusUtilities.extractIpFromFileName("ip=1.2.3");
      fail("Should have thrown not enough dots");
    } catch (InvalidPublicKeyFileException ignoreExpectedException) {
    }

    assertEquals("1.2.3.4", MartusUtilities.extractIpFromFileName("ip=1.2.3.4"));
    assertEquals("2.3.4.5", MartusUtilities.extractIpFromFileName("ip=2.3.4.5.txt"));
    assertEquals("3.4.5.6", MartusUtilities.extractIpFromFileName("code=x.y.z-ip=3.4.5.6.txt"));
  }
 public void testGetPublicInfo() throws Exception {
   Vector publicInfo = server.getPublicInfo();
   assertEquals(2, publicInfo.size());
   String publicKey = (String) publicInfo.get(0);
   String gotSig = (String) publicInfo.get(1);
   String serverPublicKeyString = server.getSecurity().getPublicKeyString();
   MartusUtilities.validatePublicInfo(publicKey, gotSig, clientSecurity1);
   assertEquals(serverPublicKeyString, publicInfo.get(0));
 }
  CallerSideMirroringGateway createGatewayToCall(String ip, File publicKeyFile)
      throws IOException, InvalidPublicKeyFileException, PublicInformationInvalidException,
          SSLSocketSetupException {
    int port = getPort();

    Vector publicInfo = MartusUtilities.importServerPublicKeyFromFile(publicKeyFile, getSecurity());
    String publicKey = (String) publicInfo.get(0);

    CallerSideMirroringGatewayForXmlRpc xmlRpcGateway =
        new CallerSideMirroringGatewayForXmlRpc(ip, port);
    xmlRpcGateway.setExpectedPublicKey(publicKey);
    return new CallerSideMirroringGateway(xmlRpcGateway);
  }
 public void testAnonymousPing() throws Exception {
   String accountId = "";
   Vector parameters = new Vector();
   parameters.add(MirroringInterface.CMD_MIRRORING_PING);
   String sig = "";
   Vector result = handler.request(accountId, parameters, sig);
   assertEquals(2, result.size());
   assertEquals(NetworkInterfaceConstants.OK, result.get(0));
   Vector publicInfo = (Vector) result.get(1);
   String publicKey = (String) publicInfo.get(0);
   String gotSig = (String) publicInfo.get(1);
   MartusUtilities.validatePublicInfo(publicKey, gotSig, callerSecurity);
   assertEquals(supplierSecurity.getPublicKeyString(), publicInfo.get(0));
 }
 void writePublicInfo(Vector publicInfo) {
   String publicKey = (String) publicInfo.get(0);
   String sig = (String) publicInfo.get(1);
   verifyPublicInfo(publicKey, sig);
   File outputFile = new File(outputFileName);
   try {
     UnicodeWriter writer = new UnicodeWriter(outputFile);
     MartusUtilities.writeServerPublicKey(writer, publicKey, sig);
     writer.close();
   } catch (IOException e) {
     e.printStackTrace();
     System.out.println("Error writing output file");
     System.exit(3);
   }
 }
Esempio n. 9
0
 public String toFileName() {
   String bulletinTitle = get(Bulletin.TAGTITLE);
   return MartusUtilities.toFileName(bulletinTitle, MartusUtilities.DEFAULT_FILE_NAME);
 }
 public void deleteStartupFiles() {
   DirectoryUtils.deleteEntireDirectoryTree(getDeleteOnStartupFolders());
   MartusUtilities.deleteAllFiles(getDeleteOnStartupFiles());
 }