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