Пример #1
0
 private boolean authenticateClient() throws IOException {
   String line = in.readLine();
   if (line == null || line.equals(secret) == false) {
     Log.warn(
         Thread.currentThread().getName()
             + ": failed authentication attempt with \""
             + line
             + "\".");
     out.println("Authentication failed");
     return false;
   }
   writeNewSecret();
   out.println("Authentication OK");
   return true;
 }
Пример #2
0
 private void handleRequest() throws IOException {
   String line = in.readLine();
   if (line == null || line.length() == 0) {
     Log.warn(Thread.currentThread().getName() + ": ignoring empty request.");
     return;
   }
   if (handleCommand(line, out) == false) {
     out.println(
         Thread.currentThread().getName() + ": didn't understand request \"" + line + "\".");
   }
 }
Пример #3
0
  public boolean handleCommand(String line, PrintWriter out) {
    String[] split = line.split("[\t ]");
    String commandName = split[0];

    try {
      Method[] methods = exportedInterface.getMethods();
      for (Method method : methods) {
        if (method.getName().equals(commandName) && method.getReturnType() == void.class) {
          return invokeMethod(line, out, method, split);
        }
      }
      throw new NoSuchMethodException();
    } catch (NoSuchMethodException nsmex) {
      out.println(fullName + ": didn't understand request \"" + line + "\".");
    } catch (Exception ex) {
      Log.warn(fullName + ": exception thrown while handling command \"" + line + "\".", ex);
      out.println(fullName + ": request denied \"" + line + "\" (" + ex.toString() + ").");
    } finally {
      out.flush();
      out.close();
    }
    return false;
  }
Пример #4
0
  public static void main(String args[]) throws Exception {
    MessageDigest m = MessageDigest.getInstance("MD5");
    PrintWriter out = new PrintWriter(new FileOutputStream("dict.txt"));

    for (int i1 = 'a'; i1 < 'z'; i1++) {
      System.out.println("Now Processing" + (char) i1);
      for (int i2 = 'a'; i2 < 'z'; i2++)
        for (int i3 = 'a'; i3 < 'z'; i3++)
          for (int i4 = 'a'; i4 < 'z'; i4++) {
            char[] ch = {(char) i1, (char) i2, (char) i3, (char) i4};
            String passwd = new String(ch);
            m.update(passwd.getBytes("UTF8"));
            byte s[] = m.digest();
            String result = "";
            for (int i = 0; i < s.length; i++) {
              result += Integer.toHexString((0x000000ff & s[i]) | 0xffffff00).substring(6);
            }
            out.print(passwd + "    ");
            out.println(result);
          }
    }
    out.close();
  }