您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Password.cxx 2.1KB

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