PageRenderTime 63ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/java/com/l2jserver/loginserver/network/gameserverpackets/BlowFishKey.java

https://github.com/ichiro101/l2adena-l2j-core
Java | 74 lines | 46 code | 6 blank | 22 comment | 4 complexity | 04a0883e456c579b97923e08c913e95a MD5 | raw file
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.loginserver.network.gameserverpackets;
  16. import java.security.GeneralSecurityException;
  17. import java.util.logging.Level;
  18. import java.util.logging.Logger;
  19. import javax.crypto.Cipher;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.loginserver.GameServerThread;
  22. import com.l2jserver.loginserver.network.L2JGameServerPacketHandler.GameServerState;
  23. import com.l2jserver.util.crypt.NewCrypt;
  24. import com.l2jserver.util.network.BaseRecievePacket;
  25. /**
  26. * @author -Wooden-
  27. *
  28. */
  29. public class BlowFishKey extends BaseRecievePacket
  30. {
  31. protected static final Logger _log = Logger.getLogger(BlowFishKey.class.getName());
  32. /**
  33. * @param decrypt
  34. */
  35. public BlowFishKey(byte[] decrypt, GameServerThread server)
  36. {
  37. super(decrypt);
  38. int size = readD();
  39. byte[] tempKey = readB(size);
  40. try
  41. {
  42. byte [] tempDecryptKey;
  43. Cipher rsaCipher = Cipher.getInstance("RSA/ECB/nopadding");
  44. rsaCipher.init(Cipher.DECRYPT_MODE, server.getPrivateKey());
  45. tempDecryptKey = rsaCipher.doFinal(tempKey);
  46. // there are nulls before the key we must remove them
  47. int i = 0;
  48. int len = tempDecryptKey.length;
  49. for(; i < len; i++)
  50. {
  51. if(tempDecryptKey[i] != 0)
  52. break;
  53. }
  54. byte[] key = new byte[len-i];
  55. System.arraycopy(tempDecryptKey,i,key,0,len-i);
  56. server.SetBlowFish(new NewCrypt(key));
  57. if (Config.DEBUG)
  58. {
  59. _log.info("New BlowFish key received, Blowfih Engine initialized:");
  60. }
  61. server.setLoginConnectionState(GameServerState.BF_CONNECTED);
  62. }
  63. catch(GeneralSecurityException e)
  64. {
  65. _log.log(Level.SEVERE, "Error While decrypting blowfish key (RSA): " + e.getMessage(), e);
  66. }
  67. }
  68. }