summaryrefslogtreecommitdiff
path: root/noncore/comm/keypebble/vncauth.c
Unidiff
Diffstat (limited to 'noncore/comm/keypebble/vncauth.c') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/comm/keypebble/vncauth.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/noncore/comm/keypebble/vncauth.c b/noncore/comm/keypebble/vncauth.c
index 277d145..7de837a 100644
--- a/noncore/comm/keypebble/vncauth.c
+++ b/noncore/comm/keypebble/vncauth.c
@@ -49,102 +49,106 @@ int
49vncEncryptAndStorePasswd(char *passwd, char *fname) 49vncEncryptAndStorePasswd(char *passwd, char *fname)
50{ 50{
51 FILE *fp; 51 FILE *fp;
52 uint i; 52 uint i;
53 unsigned char encryptedPasswd[8]; 53 unsigned char encryptedPasswd[8];
54 54
55 if ((fp = fopen(fname,"w")) == NULL) return 1; 55 if ((fp = fopen(fname,"w")) == NULL) return 1;
56 56
57 chmod(fname, S_IRUSR|S_IWUSR); 57 chmod(fname, S_IRUSR|S_IWUSR);
58 58
59 /* pad password with nulls */ 59 /* pad password with nulls */
60 60
61 for (i = 0; i < 8; i++) { 61 for (i = 0; i < 8; i++) {
62 if (i < strlen(passwd)) { 62 if (i < strlen(passwd)) {
63 encryptedPasswd[i] = passwd[i]; 63 encryptedPasswd[i] = passwd[i];
64 } else { 64 } else {
65 encryptedPasswd[i] = 0; 65 encryptedPasswd[i] = 0;
66 } 66 }
67 } 67 }
68 68
69 /* Do encryption in-place - this way we overwrite our copy of the plaintext 69 /* Do encryption in-place - this way we overwrite our copy of the plaintext
70 password */ 70 password */
71 71
72 deskey(fixedkey, EN0); 72 deskey(fixedkey, EN0);
73 des(encryptedPasswd, encryptedPasswd); 73 des(encryptedPasswd, encryptedPasswd);
74 74
75 for (i = 0; i < 8; i++) { 75 for (i = 0; i < 8; i++) {
76 putc(encryptedPasswd[i], fp); 76 putc(encryptedPasswd[i], fp);
77 } 77 }
78 78
79 fclose(fp); 79 fclose(fp);
80 return 0; 80 return 0;
81} 81}
82 82
83 83
84/* 84/*
85 * Decrypt a password from a file. Returns a pointer to a newly allocated 85 * Decrypt a password from a file. Returns a pointer to a newly allocated
86 * string containing the password or a null pointer if the password could 86 * string containing the password or a null pointer if the password could
87 * not be retrieved for some reason. 87 * not be retrieved for some reason.
88 */ 88 */
89 89
90char * 90char *
91vncDecryptPasswdFromFile(char *fname) 91vncDecryptPasswdFromFile(char *fname)
92{ 92{
93 FILE *fp; 93 FILE *fp;
94 int i, ch; 94 int i, ch;
95 unsigned char *passwd = (unsigned char *)malloc(9); 95 unsigned char *passwd = (unsigned char *)malloc(9);
96 96
97 if ((fp = fopen(fname,"r")) == NULL) return NULL; 97 if ((fp = fopen(fname,"r")) == NULL) {
98 free(passwd);
99 return NULL;
100 }
98 101
99 for (i = 0; i < 8; i++) { 102 for (i = 0; i < 8; i++) {
100 ch = getc(fp); 103 ch = getc(fp);
101 if (ch == EOF) { 104 if (ch == EOF) {
102 fclose(fp); 105 fclose(fp);
106 free(passwd);
103 return NULL; 107 return NULL;
104 } 108 }
105 passwd[i] = ch; 109 passwd[i] = ch;
106 } 110 }
107 111
108 deskey(fixedkey, DE1); 112 deskey(fixedkey, DE1);
109 des(passwd, passwd); 113 des(passwd, passwd);
110 114
111 passwd[8] = 0; 115 passwd[8] = 0;
112 116
113 return (char *)passwd; 117 return (char *)passwd;
114} 118}
115 119
116 120
117/* 121/*
118 * Generate CHALLENGESIZE random bytes for use in challenge-response 122 * Generate CHALLENGESIZE random bytes for use in challenge-response
119 * authentication. 123 * authentication.
120 */ 124 */
121 125
122void 126void
123vncRandomBytes(unsigned char *bytes) 127vncRandomBytes(unsigned char *bytes)
124{ 128{
125 int i; 129 int i;
126 unsigned int seed = (unsigned int) time(0); 130 unsigned int seed = (unsigned int) time(0);
127 131
128 srandom(seed); 132 srandom(seed);
129 for (i = 0; i < CHALLENGESIZE; i++) { 133 for (i = 0; i < CHALLENGESIZE; i++) {
130 bytes[i] = (unsigned char)(random() & 255); 134 bytes[i] = (unsigned char)(random() & 255);
131 } 135 }
132} 136}
133 137
134 138
135/* 139/*
136 * Encrypt CHALLENGESIZE bytes in memory using a password. 140 * Encrypt CHALLENGESIZE bytes in memory using a password.
137 */ 141 */
138 142
139void 143void
140vncEncryptBytes(unsigned char *bytes, char *passwd) 144vncEncryptBytes(unsigned char *bytes, char *passwd)
141{ 145{
142 unsigned char key[8]; 146 unsigned char key[8];
143 int i; 147 int i;
144 148
145 /* key is simply password padded with nulls */ 149 /* key is simply password padded with nulls */
146 150
147 for (i = 0; i < 8; i++) { 151 for (i = 0; i < 8; i++) {
148 if (i < strlen(passwd)) { 152 if (i < strlen(passwd)) {
149 key[i] = passwd[i]; 153 key[i] = passwd[i];
150 } else { 154 } else {