Guest User

Untitled

a guest
Dec 9th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. package net.openproto.net;
  2.  
  3. import java.nio.ByteBuffer;
  4. import java.nio.channels.SocketChannel;
  5. import java.security.SecureRandom;
  6. import net.burtleburtle.bob.rand.IsaacRandom;
  7.  
  8. /**
  9.  * This class is used for logging the player into the server. It is basically a
  10.  * utility class for doing so. This currently only supports the 317 revision.
  11.  * @author Andrew
  12.  */
  13. public class LoginHandler {
  14.    
  15.     /**
  16.      * This will attempt to log a player into the server. If the buffer does not
  17.      * contain 17 bytes (the amount of bytes needed), this method will return.
  18.      * @param session The DeadSession attempting the log into the server.
  19.      * @param buf The buffer containing the login block (must be size of 17).
  20.      * @throws Exception If there is a problem sending the response.
  21.      */
  22.     public static void handle(DeadSession session, SocketChannel channel, ByteBuffer buf) throws Exception {
  23.         if (buf.position() < 17 || session == null) return;
  24.         long ignoredBytes = buf.getLong(); // first 8 bytes ignored
  25.         int responseCode = buf.get(); // response code = 0 for logging in
  26.         long ssk = buf.getLong(); // the server session key
  27.         ByteBuffer out = ByteBuffer.allocate(512); // output buffer
  28.         out.put((byte) 16).put((byte) (85)); // block size TODO: TUNE SIZE
  29.         out.put((byte) (255)).putShort((short) 317); // magic id and revision
  30.         out.put((byte) 0); // memory version. generally ignored
  31.         for (int i = 0; i < 9; i++) out.putInt(0); // crc keys
  32.         out.put((byte) 0); // RSA block length. TODO: FIX - APOLLO READS THIS LMAO
  33.         out.put((byte) 10); // RSA key value (confirming RSA works). should be 10 when unencrypted.
  34.         SecureRandom random = new SecureRandom(); // secure random
  35.         long clientHalf = random.nextLong(); // client half
  36.         out.putLong(clientHalf).putLong(ssk); // for ISAAC
  37.         int[] isaacSeed = {(int) (clientHalf >> 32), (int) clientHalf, (int) (ssk >> 32), (int) ssk};
  38.         IsaacRandom encryptor = new IsaacRandom(isaacSeed);
  39.         session.setEncryptor(encryptor); // set the encryptor
  40.         for (int i = 0; i < isaacSeed.length; i++) isaacSeed[i] += 50;
  41.         IsaacRandom decryptor = new IsaacRandom(isaacSeed);
  42.         out.putInt(32); // the users identification number
  43.         out.put(("usernamelol" + session.id).getBytes()).put((byte) 10); //username
  44.         out.put("passwords".getBytes()).put((byte) 10); //password
  45.         out.flip(); // flip the buffer to prepair for writing
  46.         session.loggedIn = true;
  47.         session.queue(out); // queue the data for writing
  48.     }
  49. }
Add Comment
Please, Sign In to add comment