예제 #1
2
  /**
   * Sets the java.security.policy system property to point at the location of the security policy
   * file, which is assumed to be at "provided\rmiUtils\server.policy" (file separators adjusted to
   * match operating system). the security manager is then started. This method must be called
   * before starting the class server.
   */
  private void configSecurityManager() {
    // file.separator is "\" in Windows and "/" in Unix/Linux/Mac.
    String sep = System.getProperty("file.separator");

    System.setProperty(
        "java.security.policy", "provided" + sep + "rmiUtils" + sep + "server.policy");
    outputCmd.apply("java.security.policy: " + System.getProperty("java.security.policy"));

    // Start the security manager
    if (System.getSecurityManager() == null) {
      outputCmd.apply("Installing new Security Manager...\n");
      System.setSecurityManager(new SecurityManager());
      outputCmd.apply("Security Manager = " + System.getSecurityManager());
    }
  }
예제 #2
1
  /**
   * Sets the java.rmi.server.hostname and java.rmi.server.codebase system properties which control
   * the automatic remote dynamic class loading. This must be called before starting the class
   * server.
   *
   * @param classServerPort The port the class server will use.
   */
  private void configRMIProperties(int classServerPort) {
    // Logs all RMI activity to System.err
    System.setProperty("java.rmi.server.logCalls", "true");

    try {
      // Try to get figure out this server's IP address and save it as the
      // RMI server hostname.
      System.setProperty("java.rmi.server.hostname", getLocalAddress());

      System.setProperty(
          "java.rmi.server.codebase",
          "http://" + System.getProperty("java.rmi.server.hostname") + ":" + classServerPort + "/");
      System.setProperty(
          "java.rmi.server.useCodebaseOnly",
          "false"); // Must be false to allow remote class dynamic loading (defaults to true for JDK
                    // 1.7+)
      outputCmd.apply(
          "java.rmi.server.hostname: " + System.getProperty("java.rmi.server.hostname") + "\n",
          "java.rmi.server.codebase: " + System.getProperty("java.rmi.server.codebase") + "\n",
          "java.rmi.server.useCodebaseOnly: "
              + System.getProperty("java.rmi.server.useCodebaseOnly")
              + "\n");

    } catch (Exception e) {
      outputCmd.apply("Error getting local host address: " + e + "\n");
    }
  }
예제 #3
0
  public SetupDataClient() throws RemoteException {

    try {
      // get the registry
      registry = LocateRegistry.getRegistry(serverAddress, (new Integer(serverPort)).intValue());
      // look up the remote object
      rmiServer = (databaseinter) registry.lookup("Database");

      rmiServer.receiveMessage("abc");
      // starting time
      long time1 = System.currentTimeMillis();
      // call the remote method

      System.out.println("sending " + text + " to " + serverAddress + ":" + serverPort);
      // receiving time
      long time2 = System.currentTimeMillis();
      long timedelay = time2 - time1;
      System.out.println("RMI delay time: " + timedelay);
      // converting process

      // finish converting
      long time3 = System.currentTimeMillis();
      long timefinish = time3 - time1;
      System.out.println("Total time: " + timefinish);
    } catch (NotBoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      System.out.println("File not found");
      System.out.println(e.getMessage());
      e.printStackTrace();
    }
  }
예제 #4
0
  public VINDecoderServer() {
    try {
      // Start the RMI Server
      // Registry registry = LocateRegistry.createRegistry(1099);

      // Assign a security manager, in the event that dynamic
      // classes are loaded
      if (System.getSecurityManager() == null)
        System.setSecurityManager(
            new RMISecurityManager() {
              public void checkConnect(String host, int port) {}

              public void checkConnect(String host, int port, Object context) {}

              public void checkAccept(String host, int port) {}
            });
      System.out.println("Set the security manager");
      // Create an instance of our power service server ...
      VINDecoderImpl vd = new VINDecoderImpl();
      vd.setDB("/usr/local/vendor/bea/user_projects/matson/lib/jato_matson.jar");
      System.out.println("Decoding vin...");
      System.out.println(vd.decode("1GTDL19W5YB530809", null));
      System.out.println("End Decoding vin...");

      // ... and bind it with the RMI Registry
      // Naming.bind ("VINDecoderService", vd);

      System.out.println("VINDecoderService bound....");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #5
0
  /**
   * Start the class file server to support remote dynamic class loading. This method must be called
   * after configSecurityManager() and configRMIProperties(). If the reference to the class file
   * server, "classFileServer" is null, it is assumed that the class file server is not runnng.
   *
   * @param classServerPort the port the class file server will use.
   */
  private void startClassFileServer(int classServerPort) {
    if (null != classFileServer) stopClassFileServer();

    String userDir = System.getProperty("user.dir");
    outputCmd.apply("user.dir: " + userDir);
    try {
      classFileServer = new ClassFileServer(classServerPort, System.getProperty("user.dir"));
    } catch (java.io.IOException e) {
      outputCmd.apply("Unable to start ClassServer: " + e.getMessage());
      e.printStackTrace();
    }
  }
  private static Echo[] spawnAndTest() {

    System.err.println("\nCreate Test-->");

    Echo[] echo = new Echo[protocol.length];

    for (int i = 0; i < protocol.length; i++) {

      JavaVM serverVM =
          new JavaVM("EchoImpl", "-Djava.security.policy=" + TestParams.defaultPolicy, protocol[i]);

      System.err.println("\nusing protocol: " + (protocol[i] == "" ? "none" : protocol[i]));

      try {
        /* spawn VM for EchoServer */
        serverVM.start();

        /* lookup server */
        int tries = 12; // need enough tries for slow machine.
        echo[i] = null;
        do {
          try {
            echo[i] = (Echo) Naming.lookup("//:" + REGISTRY_PORT + "/EchoServer");
            break;
          } catch (NotBoundException e) {
            try {
              Thread.sleep(2000);
            } catch (Exception ignore) {
            }
            continue;
          }
        } while (--tries > 0);

        if (echo[i] == null) TestLibrary.bomb("server not bound in 12 tries", null);

        /* invoke remote method and print result*/
        System.err.println("Bound to " + echo[i]);
        byte[] data = ("Greetings, citizen " + System.getProperty("user.name") + "!").getBytes();
        byte[] result = echo[i].echoNot(data);
        for (int j = 0; j < result.length; j++) result[j] = (byte) ~result[j];
        System.err.println("Result: " + new String(result));
        echo[i].shutdown();

      } catch (Exception e) {
        TestLibrary.bomb("test failed", e);

      } finally {
        serverVM.destroy();
        try {
          Naming.unbind("//:" + REGISTRY_PORT + "/EchoServer");
        } catch (Exception e) {
          TestLibrary.bomb("unbinding EchoServer", e);
        }
      }
    }
    return echo;
  }
  public static void main(String args[]) {
    try {
      // ReceiveMessageInterface rmiclient;
      RmiServer server = new RmiServer();
      // rmiclient=(ReceiveMessageInterface)(registry.lookup("rmiclient"));
      // rmiclient.generateKeys(publicKey);
      KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
      keyGen.initialize(1024);
      KeyPair keypair = keyGen.genKeyPair();
      publicKey = keypair.getPublic();
      privateKey = keypair.getPrivate();

      BufferedImage image = ImageIO.read(new File("/home/subba/Desktop/test/iris1.bmp"));

      // write it to byte array in-memory (jpg format)
      ByteArrayOutputStream b = new ByteArrayOutputStream();
      ImageIO.write(image, "bmp", b);

      // do whatever with the array...
      byte[] jpgByteArray = b.toByteArray();

      // convert it to a String with 0s and 1s
      StringBuilder sb = new StringBuilder();
      int i = 0;
      for (byte by : jpgByteArray) {
        i++;
        if (i > 366) break;
        sb.append(Integer.toBinaryString(by & 0xFF));
      }
      sb.append("0000000000000000000000000000000000000000000");
      System.out.println(sb.toString().length());
      System.out.println(sb.toString());
      int token = 170;
      StringBuilder sb1 = new StringBuilder();
      sb1.append(Integer.toBinaryString(token));
      for (int j = 0; j < 102; j++) {
        sb1.append("00000000000000000000");
      }
      System.out.println("Binary is " + sb1.length());
      for (i = 0; i < sb.length(); i++) {
        bioTemplate.append(sb.charAt(i) ^ sb1.charAt(i));
      }

      /*MessageDigest digest = MessageDigest.getInstance("SHA-256");
      byte[] hashvalue=serviceProviderKey.getBytes();
      digest.update(hashvalue);
      Phashdigest=digest.digest();
      */

      securePassword = getSecurePassword(serviceProviderKey, "200");
      System.out.println(securePassword);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
  public static void main(String args[]) {

    /*
     * Create and install a security manager
     */
    if (System.getSecurityManager() == null) {
      System.setSecurityManager(new SecurityManager());
    }

    try {
      Registry registry = LocateRegistry.getRegistry(2002);
      Hello obj = (Hello) registry.lookup("Hello");
      String message = obj.sayHello();
      System.out.println(message);

    } catch (Exception e) {
      System.out.println("HelloClient exception: " + e.getMessage());
      e.printStackTrace();
    }
  }
  public String sendDetails(String password, byte[] phash, String transactionID, byte[] spdata)
      throws RemoteException, NotBoundException, NoSuchAlgorithmException, NoSuchPaddingException,
          InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
    Cipher cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.DECRYPT_MODE, privateKey);
    byte[] cipherData = cipher.doFinal(spdata);
    String x = new String(cipherData);
    String sp[] = new String[10];
    StringTokenizer st = new StringTokenizer(x.toString(), "|");
    int count = 0;
    StringBuilder message = new StringBuilder();
    while (st.hasMoreTokens()) {
      sp[count] = st.nextToken();
      count++;
    }

    String decodemessgae = new String();
    if (securePassword.equals(sp[1]) && serviceProviderId.equals(sp[0].toString().trim())) {
      System.out.println("hellosubba");
      if (transactionID.equals(transactionDetails[0].toString())) {
        int qrData[] = new int[16];

        for (int i = 0; i < password.length(); i++) {
          message.append(password.charAt(i) ^ bioTemplate.charAt(i));
        }
        for (int i = 0; i < message.length(); i++) {
          if (message.charAt(i) == '1') {
            decodemessgae += '0';
          } else decodemessgae += '1';
        }
        int start = 56, end = 63;
        for (int i = 0; i < 16; i++) {
          qrData[i] = Integer.parseInt(decodemessgae.substring(start, end), 2);
          start += 64;
          end += 64;
        }
        RsDecode dec = new RsDecode(16);
        int r = dec.decode(qrData);
        System.out.println("r=" + r);
        System.out.println("qrData=" + java.util.Arrays.toString(qrData));

        int[] MM = new int[qrData.length + 16];
        System.arraycopy(qrData, 0, MM, 0, qrData.length);
        RsEncode enc = new RsEncode(16);
        enc.encode(MM);
        System.out.println("qrData=" + java.util.Arrays.toString(MM));
      }
    } else {
      message.append("unkonw third party user");
    }
    return message.toString();
  }
  private static void reactivateAndTest(Echo[] echo) {

    System.err.println("\nReactivate Test-->");

    for (int i = 0; i < echo.length; i++) {
      try {
        System.err.println("\nusing protocol: " + (protocol[i] == "" ? "none" : protocol[i]));
        byte[] data = ("Greetings, citizen " + System.getProperty("user.name") + "!").getBytes();
        byte[] result = echo[i].echoNot(data);
        for (int j = 0; j < result.length; j++) result[j] = (byte) ~result[j];
        System.err.println("Result: " + new String(result));
        echo[i].shutdown();
      } catch (Exception e) {
        TestLibrary.bomb("activating EchoServer for protocol " + protocol[i], e);
      }
    }
  }
예제 #11
0
파일: Client.java 프로젝트: Eneru/l3s6
  public static void main(String[] args) {
    if (args.length != 1) {
      System.out.println("Usage : java Client <machine du Serveur:port du rmiregistry>");
      System.exit(0);
    }
    try {
      int[][] a = {{1, 0, 0}, {0, 2, 0}, {0, 0, 3}};
      int[][] b = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};

      int[][] res;

      OpMatrice op = (OpMatrice) Naming.lookup("rmi://" + args[0] + "/Matrice");
      res = op.multiplicationMatrice(a, b);
      op.AffichageMatrice(res);
    } catch (NotBoundException re) {
      System.out.println(re);
    } catch (RemoteException re) {
      System.out.println(re);
    } catch (MalformedURLException e) {
      System.out.println(e);
    }
  }
 public void crash() {
   System.exit(0);
 }