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.cxx 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. //
  19. // CSecurityVncAuth
  20. //
  21. // XXX not thread-safe, because d3des isn't - do we need to worry about this?
  22. //
  23. #ifdef HAVE_CONFIG_H
  24. #include <config.h>
  25. #endif
  26. #include <string.h>
  27. #include <stdio.h>
  28. #include <rfb/CConnection.h>
  29. #include <rfb/Password.h>
  30. #include <rfb/CSecurityVncAuth.h>
  31. #include <rfb/util.h>
  32. #include <rfb/Security.h>
  33. extern "C" {
  34. #include <rfb/d3des.h>
  35. }
  36. #include <rdr/InStream.h>
  37. #include <rdr/OutStream.h>
  38. using namespace rfb;
  39. static const int vncAuthChallengeSize = 16;
  40. bool CSecurityVncAuth::processMsg()
  41. {
  42. rdr::InStream* is = cc->getInStream();
  43. rdr::OutStream* os = cc->getOutStream();
  44. if (!is->hasData(vncAuthChallengeSize))
  45. return false;
  46. // Read the challenge & obtain the user's password
  47. rdr::U8 challenge[vncAuthChallengeSize];
  48. is->readBytes(challenge, vncAuthChallengeSize);
  49. PlainPasswd passwd;
  50. (CSecurity::upg)->getUserPasswd(cc->isSecure(), 0, &passwd.buf);
  51. // Calculate the correct response
  52. rdr::U8 key[8];
  53. int pwdLen = strlen(passwd.buf);
  54. for (int i=0; i<8; i++)
  55. key[i] = i<pwdLen ? passwd.buf[i] : 0;
  56. deskey(key, EN0);
  57. for (int j = 0; j < vncAuthChallengeSize; j += 8)
  58. des(challenge+j, challenge+j);
  59. // Return the response to the server
  60. os->writeBytes(challenge, vncAuthChallengeSize);
  61. os->flush();
  62. return true;
  63. }