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.

Password.cxx 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // XXX not thread-safe, because d3des isn't - do we need to worry about this?
  20. //
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <string.h>
  25. extern "C" {
  26. #include <rfb/d3des.h>
  27. }
  28. #include <rdr/types.h>
  29. #include <rdr/Exception.h>
  30. #include <rfb/Password.h>
  31. using namespace rfb;
  32. static unsigned char d3desObfuscationKey[] = {23,82,107,6,35,78,88,7};
  33. PlainPasswd::PlainPasswd() {}
  34. PlainPasswd::PlainPasswd(char* pwd) : CharArray(pwd) {
  35. }
  36. PlainPasswd::PlainPasswd(size_t len) : CharArray(len) {
  37. }
  38. PlainPasswd::PlainPasswd(const ObfuscatedPasswd& obfPwd) : CharArray(9) {
  39. if (obfPwd.length < 8)
  40. throw rdr::Exception("bad obfuscated password length");
  41. deskey(d3desObfuscationKey, DE1);
  42. des((rdr::U8*)obfPwd.buf, (rdr::U8*)buf);
  43. buf[8] = 0;
  44. }
  45. PlainPasswd::~PlainPasswd() {
  46. replaceBuf(0);
  47. }
  48. void PlainPasswd::replaceBuf(char* b) {
  49. if (buf)
  50. memset(buf, 0, strlen(buf));
  51. CharArray::replaceBuf(b);
  52. }
  53. ObfuscatedPasswd::ObfuscatedPasswd() : length(0) {
  54. }
  55. ObfuscatedPasswd::ObfuscatedPasswd(size_t len) : CharArray(len), length(len) {
  56. }
  57. ObfuscatedPasswd::ObfuscatedPasswd(const PlainPasswd& plainPwd) : CharArray(8), length(8) {
  58. size_t l = strlen(plainPwd.buf), i;
  59. for (i=0; i<8; i++)
  60. buf[i] = i<l ? plainPwd.buf[i] : 0;
  61. deskey(d3desObfuscationKey, EN0);
  62. des((rdr::U8*)buf, (rdr::U8*)buf);
  63. }
  64. ObfuscatedPasswd::~ObfuscatedPasswd() {
  65. if (buf)
  66. memset(buf, 0, length);
  67. }