Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RequestAuthLogin extends L2LoginClientPacket
- {
- private static Logger _log = Logger.getLogger(RequestAuthLogin.class.getName());
- private static final byte[] STATIC_BLOWFISH_KEY =
- {
- (byte) 0x47, (byte) 0x9b, (byte) 0xed, (byte) 0x4d,
- (byte) 0x08, (byte) 0x3b, (byte) 0xbb, (byte) 0xac,
- (byte) 0xa2, (byte) 0x0f, (byte) 0xe9, (byte) 0x93,
- (byte) 0xf8, (byte) 0xe8, (byte) 0xc8, (byte) 0x8d
- };
- private byte[] _raw = new byte[128];
- private String _user;
- private String _password;
- private int _ncotp;
- /**
- * @return
- */
- public String getPassword()
- {
- return _password;
- }
- /**
- * @return
- */
- public String getUser()
- {
- return _user;
- }
- public int getOneTimePassword()
- {
- return _ncotp;
- }
- @Override
- public boolean readImpl()
- {
- if (super._buf.remaining() >= 128)
- {
- readB(_raw);
- return true;
- }
- else
- {
- return false;
- }
- }
- @Override
- public void run()
- {
- byte[] decrypted = null;
- try
- {
- Cipher rsaCipher = Cipher.getInstance("RSA/ECB/nopadding");
- rsaCipher.init(Cipher.DECRYPT_MODE, getClient().getRSAPrivateKey());
- decrypted = rsaCipher.doFinal(_raw, 0x00, 0x80 );
- }
- catch (GeneralSecurityException e)
- {
- e.printStackTrace();
- return;
- }
- _user = new String(decrypted, 0x5E, 14 ).trim();
- _user = _user.toLowerCase();
- _password = new String(decrypted, 0x6C, 16).trim();
- _ncotp = decrypted[0x7c];
- _ncotp |= decrypted[0x7d] << 8;
- _ncotp |= decrypted[0x7e] << 16;
- _ncotp |= decrypted[0x7f] << 24;
- LoginController lc = LoginController.getInstance();
- L2LoginClient client = getClient();
- try
- {
- if (getClient().getBlowfishKey() == STATIC_BLOWFISH_KEY)
- {
- AuthLoginResult result = lc.tryAuthLogin(_user, _password, getClient());
- switch (result)
- {
- case AUTH_SUCCESS:
- client.setAccount(_user);
- client.setState(LoginClientState.AUTHED_LOGIN);
- client.setSessionKey(lc.assignSessionKeyToClient(_user, client));
- if (Config.SHOW_LICENCE)
- {
- client.sendPacket(new LoginOk(getClient().getSessionKey()));
- }
- else
- {
- getClient().sendPacket(new ServerList(getClient()));
- }
- break;
- case INVALID_PASSWORD:
- client.close(LoginFailReason.REASON_USER_OR_PASS_WRONG);
- break;
- case ACCOUNT_BANNED:
- client.close(new AccountKicked(AccountKickedReason.REASON_PERMANENTLY_BANNED));
- break;
- case ALREADY_ON_LS:
- L2LoginClient oldClient;
- if ((oldClient = lc.getAuthedClient(_user)) != null)
- {
- // kick the other client
- oldClient.close(LoginFailReason.REASON_ACCOUNT_IN_USE);
- lc.removeAuthedLoginClient(_user);
- }
- // kick also current client
- client.close(LoginFailReason.REASON_ACCOUNT_IN_USE);
- break;
- case ALREADY_ON_GS:
- GameServerInfo gsi;
- if ((gsi = lc.getAccountOnGameServer(_user)) != null)
- {
- client.close(LoginFailReason.REASON_ACCOUNT_IN_USE);
- // kick from there
- if (gsi.isAuthed())
- {
- gsi.getGameServerThread().kickPlayer(_user);
- }
- }
- break;
- }
- }
- else
- {
- InetAddress address = getClient().getConnection().getInetAddress();
- _log.info("Warning: Not BlowFish key ! IP: "+address+"");
- }
- }
- catch (HackingException e)
- {
- InetAddress address = getClient().getConnection().getInetAddress();
- lc.addBanForAddress(address, Config.LOGIN_BLOCK_AFTER_BAN*1000);
- _log.info("Banned ("+address+") for "+Config.LOGIN_BLOCK_AFTER_BAN+" seconds, due to "+e.getConnects()+" incorrect login attempts.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement