You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CSecurityVncAuth.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  16. * USA.
  17. */
  18. package com.tigervnc.rfb;
  19. import java.nio.*;
  20. import com.tigervnc.rdr.*;
  21. import com.tigervnc.vncviewer.*;
  22. public class CSecurityVncAuth extends CSecurity {
  23. public CSecurityVncAuth() { }
  24. private static final int vncAuthChallengeSize = 16;
  25. public boolean processMsg(CConnection cc)
  26. {
  27. InStream is = cc.getInStream();
  28. OutStream os = cc.getOutStream();
  29. // Read the challenge & obtain the user's password
  30. ByteBuffer challenge = ByteBuffer.allocate(vncAuthChallengeSize);
  31. is.readBytes(challenge, vncAuthChallengeSize);
  32. StringBuffer passwd = new StringBuffer();
  33. upg.getUserPasswd(cc.isSecure(), null, passwd);
  34. // Calculate the correct response
  35. byte[] key = new byte[8];
  36. int pwdLen = passwd.length();
  37. byte[] utf8str = new byte[pwdLen];
  38. try {
  39. utf8str = passwd.toString().getBytes("UTF8");
  40. } catch(java.io.UnsupportedEncodingException e) {
  41. e.printStackTrace();
  42. }
  43. for (int i=0; i<8; i++)
  44. key[i] = i<pwdLen ? utf8str[i] : 0;
  45. DesCipher des = new DesCipher(key);
  46. for (int j = 0; j < vncAuthChallengeSize; j += 8)
  47. des.encrypt(challenge.array(),j,challenge.array(),j);
  48. // Return the response to the server
  49. os.writeBytes(challenge.array(), 0, vncAuthChallengeSize);
  50. os.flush();
  51. return true;
  52. }
  53. public int getType() { return Security.secTypeVncAuth; }
  54. public String description() { return "No Encryption"; }
  55. static LogWriter vlog = new LogWriter("VncAuth");
  56. }