Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.59 KB | None | 0 0
  1. public class RequestAuthLogin extends L2LoginClientPacket
  2. {
  3.     private static Logger _log = Logger.getLogger(RequestAuthLogin.class.getName());
  4.     private static final byte[] STATIC_BLOWFISH_KEY =
  5.     {
  6.         (byte) 0x47, (byte) 0x9b, (byte) 0xed, (byte) 0x4d,
  7.         (byte) 0x08, (byte) 0x3b, (byte) 0xbb, (byte) 0xac,
  8.         (byte) 0xa2, (byte) 0x0f, (byte) 0xe9, (byte) 0x93,
  9.         (byte) 0xf8, (byte) 0xe8, (byte) 0xc8, (byte) 0x8d
  10.     };
  11.    
  12.     private byte[] _raw = new byte[128];
  13.  
  14.     private String _user;
  15.     private String _password;
  16.     private int _ncotp;
  17.  
  18.     /**
  19.      * @return
  20.      */
  21.     public String getPassword()
  22.     {
  23.         return _password;
  24.     }
  25.  
  26.     /**
  27.      * @return
  28.      */
  29.     public String getUser()
  30.     {
  31.         return _user;
  32.     }
  33.  
  34.     public int getOneTimePassword()
  35.     {
  36.         return _ncotp;
  37.     }
  38.  
  39.     @Override
  40.     public boolean readImpl()
  41.     {
  42.         if (super._buf.remaining() >= 128)
  43.         {
  44.             readB(_raw);
  45.             return true;
  46.         }
  47.         else
  48.         {
  49.             return false;
  50.         }
  51.     }
  52.    
  53.     @Override
  54.     public void run()
  55.     {
  56.         byte[] decrypted = null;
  57.         try
  58.         {
  59.             Cipher rsaCipher = Cipher.getInstance("RSA/ECB/nopadding");
  60.             rsaCipher.init(Cipher.DECRYPT_MODE, getClient().getRSAPrivateKey());
  61.             decrypted = rsaCipher.doFinal(_raw, 0x00, 0x80 );
  62.         }
  63.         catch (GeneralSecurityException e)
  64.         {
  65.             e.printStackTrace();
  66.             return;
  67.         }
  68.  
  69.         _user = new String(decrypted, 0x5E, 14 ).trim();
  70.         _user = _user.toLowerCase();
  71.         _password = new String(decrypted, 0x6C, 16).trim();
  72.         _ncotp = decrypted[0x7c];
  73.         _ncotp |= decrypted[0x7d] << 8;
  74.         _ncotp |= decrypted[0x7e] << 16;
  75.         _ncotp |= decrypted[0x7f] << 24;
  76.  
  77.         LoginController lc = LoginController.getInstance();
  78.         L2LoginClient client = getClient();
  79.         try
  80.         {
  81.             if (getClient().getBlowfishKey() == STATIC_BLOWFISH_KEY)
  82.             {
  83.             AuthLoginResult result = lc.tryAuthLogin(_user, _password, getClient());
  84.  
  85.             switch (result)
  86.             {
  87.                 case AUTH_SUCCESS:
  88.                     client.setAccount(_user);
  89.                     client.setState(LoginClientState.AUTHED_LOGIN);
  90.                     client.setSessionKey(lc.assignSessionKeyToClient(_user, client));
  91.                     if (Config.SHOW_LICENCE)
  92.                     {
  93.                         client.sendPacket(new LoginOk(getClient().getSessionKey()));
  94.                     }
  95.                     else
  96.                     {
  97.                         getClient().sendPacket(new ServerList(getClient()));
  98.                     }
  99.                     break;
  100.                 case INVALID_PASSWORD:
  101.                     client.close(LoginFailReason.REASON_USER_OR_PASS_WRONG);
  102.                     break;
  103.                 case ACCOUNT_BANNED:
  104.                     client.close(new AccountKicked(AccountKickedReason.REASON_PERMANENTLY_BANNED));
  105.                     break;
  106.                 case ALREADY_ON_LS:
  107.                     L2LoginClient oldClient;
  108.                     if ((oldClient = lc.getAuthedClient(_user)) != null)
  109.                     {
  110.                         // kick the other client
  111.                         oldClient.close(LoginFailReason.REASON_ACCOUNT_IN_USE);
  112.                         lc.removeAuthedLoginClient(_user);
  113.                     }
  114.                     // kick also current client
  115.                     client.close(LoginFailReason.REASON_ACCOUNT_IN_USE);
  116.                     break;
  117.                 case ALREADY_ON_GS:
  118.                     GameServerInfo gsi;
  119.                     if ((gsi = lc.getAccountOnGameServer(_user)) != null)
  120.                     {
  121.                         client.close(LoginFailReason.REASON_ACCOUNT_IN_USE);
  122.                         // kick from there
  123.                         if (gsi.isAuthed())
  124.                         {
  125.                             gsi.getGameServerThread().kickPlayer(_user);
  126.                         }
  127.                     }
  128.                     break;
  129.             }
  130.             }
  131.             else
  132.             {
  133.                 InetAddress address = getClient().getConnection().getInetAddress();
  134.                 _log.info("Warning: Not BlowFish key ! IP: "+address+"");
  135.             }
  136.         }
  137.         catch (HackingException e)
  138.         {
  139.             InetAddress address = getClient().getConnection().getInetAddress();
  140.             lc.addBanForAddress(address, Config.LOGIN_BLOCK_AFTER_BAN*1000);
  141.             _log.info("Banned ("+address+") for "+Config.LOGIN_BLOCK_AFTER_BAN+" seconds, due to "+e.getConnects()+" incorrect login attempts.");
  142.         }
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement