35 |
{ |
{ |
36 |
char *c; |
char *c; |
37 |
|
|
38 |
tty_disable_echo(); |
tty_noecho(); |
39 |
|
|
40 |
if (fgets(passwd, pwlen, stdin)) |
if (fgets(passwd, pwlen, stdin)) |
41 |
if ((c = strchr(passwd, '\n'))) |
if ((c = strchr(passwd, '\n'))) |
58 |
int i, n; |
int i, n; |
59 |
unsigned char iv[EVP_MAX_IV_LENGTH]; |
unsigned char iv[EVP_MAX_IV_LENGTH]; |
60 |
unsigned char *key; |
unsigned char *key; |
61 |
unsigned char buf[ENCRYPTION_BUF]; |
unsigned char buf[ENCRYPT_BUF]; |
62 |
unsigned char ebuf[ENCRYPTION_BUF]; |
unsigned char ebuf[ENCRYPT_BUF]; |
63 |
unsigned char bbuf[ENCRYPTION_BUF]; |
unsigned char bbuf[ENCRYPT_BUF]; |
64 |
unsigned char mdv[EVP_MAX_MD_SIZE]; |
unsigned char mdv[EVP_MAX_MD_SIZE]; |
65 |
int mdl, ebufl, bbufl; |
int mdl, ebufl, bbufl; |
66 |
EVP_CIPHER_CTX ctx; |
EVP_CIPHER_CTX ctx; |
86 |
EVP_EncodeInit(&bctx); |
EVP_EncodeInit(&bctx); |
87 |
|
|
88 |
for (i = 0; accts[i] != NULL; i++) { |
for (i = 0; accts[i] != NULL; i++) { |
89 |
snprintf(buf, ENCRYPTION_BUF, "%s %s %s\n", accts[i]->server, |
snprintf(buf, ENCRYPT_BUF, "%s %s %s\n", accts[i]->server, |
90 |
accts[i]->username, accts[i]->password); |
accts[i]->user, accts[i]->pass); |
91 |
EVP_DigestUpdate(&mdctx, buf, strlen(buf)); |
EVP_DigestUpdate(&mdctx, buf, strlen(buf)); |
92 |
EVP_EncryptUpdate(&ctx, ebuf, &ebufl, buf, strlen(buf)); |
EVP_EncryptUpdate(&ctx, ebuf, &ebufl, buf, strlen(buf)); |
93 |
EVP_EncodeUpdate(&bctx, bbuf, &bbufl, ebuf, ebufl); |
EVP_EncodeUpdate(&bctx, bbuf, &bbufl, ebuf, ebufl); |
97 |
|
|
98 |
EVP_DigestFinal(&mdctx, mdv, &mdl); |
EVP_DigestFinal(&mdctx, mdv, &mdl); |
99 |
|
|
100 |
xstrncpy(buf, ".\n", ENCRYPTION_BUF - 1); |
xstrncpy(buf, ".\n", ENCRYPT_BUF - 1); |
101 |
|
|
102 |
/* MD5 checksum of data. */ |
/* MD5 checksum of data. */ |
103 |
for (i = 0; i < mdl; i++) |
for (i = 0; i < mdl; i++) |
104 |
snprintf(2 + buf + i * 2, ENCRYPTION_BUF - 3 - i * 2, "%02x", |
snprintf(2 + buf + i * 2, ENCRYPT_BUF - 3 - i * 2, "%02x", |
105 |
mdv[i]); |
mdv[i]); |
106 |
|
|
107 |
EVP_EncryptUpdate(&ctx, ebuf, &ebufl, buf, strlen(buf)); |
EVP_EncryptUpdate(&ctx, ebuf, &ebufl, buf, strlen(buf)); |
143 |
|
|
144 |
j = 1; |
j = 1; |
145 |
|
|
146 |
c = *buf = (unsigned char *)smalloc(DECRYPTION_BUF * sizeof(char)); |
c = *buf = (unsigned char *)smalloc(DECRYPT_BUF * sizeof(char)); |
147 |
key = (unsigned char *)smalloc(EVP_MAX_KEY_LENGTH); |
key = (unsigned char *)smalloc(EVP_MAX_KEY_LENGTH); |
148 |
ctx = (EVP_CIPHER_CTX *) smalloc(sizeof(EVP_CIPHER_CTX)); |
ctx = (EVP_CIPHER_CTX *) smalloc(sizeof(EVP_CIPHER_CTX)); |
149 |
|
|
167 |
c += bufl; |
c += bufl; |
168 |
*c = '\0'; |
*c = '\0'; |
169 |
|
|
170 |
if (c - *buf > DECRYPTION_BUF * j - 64) { |
if (c - *buf > DECRYPT_BUF * j - 64) { |
171 |
i = c - *buf; |
i = c - *buf; |
172 |
*buf = (char *)srealloc(*buf, DECRYPTION_BUF * ++j); |
*buf = (char *)srealloc(*buf, DECRYPT_BUF * ++j); |
173 |
c = *buf + i; |
c = *buf + i; |
174 |
*c = '\0'; |
*c = '\0'; |
175 |
} |
} |
226 |
char pwfile[PATH_MAX]; |
char pwfile[PATH_MAX]; |
227 |
FILE *fd; |
FILE *fd; |
228 |
|
|
229 |
snprintf(pwfile, PATH_MAX, "%s/%s", home, PATHNAME_PASSWORD_FILE); |
snprintf(pwfile, PATH_MAX, "%s/%s", home, PATHNAME_PASSWORDS); |
230 |
|
|
231 |
create_file(pwfile, S_IRUSR | S_IWUSR); |
create_file(pwfile, S_IRUSR | S_IWUSR); |
232 |
|
|
233 |
fd = fopen(pwfile, "w"); |
fd = fopen(pwfile, "w"); |
234 |
|
|
235 |
if (fd == NULL) |
if (fd == NULL) |
236 |
fatal(ERROR_FILE_OPEN, "opening passwords file %s; %s\n", |
fatal(ERROR_FILEOPEN, "opening passwords file %s; %s\n", |
237 |
pwfile, strerror(errno)); |
pwfile, strerror(errno)); |
238 |
|
|
239 |
encrypt_passwords(fd, accts); |
encrypt_passwords(fd, accts); |
256 |
char *p[2]; |
char *p[2]; |
257 |
account_t *a, **accts; |
account_t *a, **accts; |
258 |
|
|
259 |
if (!(flags & FLAG_BLANK_PASSWORD)) { |
if (!(flags & FLAG_BLANKPASS)) { |
260 |
error("no candidate passwords for encryption found\n"); |
error("no candidate passwords for encryption found\n"); |
261 |
return; |
return; |
262 |
} |
} |
263 |
q = pn = 0; |
q = pn = 0; |
264 |
|
|
265 |
for (a = accounts; a != NULL; a = a->next) |
for (a = accounts; a != NULL; a = a->next) |
266 |
if (a->passwdattr == PASSWORD_NONE || |
if (a->pass_attr != PASS_ATTR_PLAIN) |
|
a->passwdattr == PASSWORD_ENCRYPTED) |
|
267 |
pn++; |
pn++; |
268 |
|
|
269 |
accts = (account_t **) xmalloc((pn + 1) * sizeof(account_t *)); |
accts = (account_t **) xmalloc((pn + 1) * sizeof(account_t *)); |
271 |
memset(accts, 0, (pn + 1) * sizeof(account_t *)); |
memset(accts, 0, (pn + 1) * sizeof(account_t *)); |
272 |
|
|
273 |
for (i = 0, a = accounts; a != NULL; a = a->next) { |
for (i = 0, a = accounts; a != NULL; a = a->next) { |
274 |
if (a->passwdattr == PASSWORD_NONE || |
if (a->pass_attr != PASS_ATTR_PLAIN) |
|
a->passwdattr == PASSWORD_ENCRYPTED) |
|
275 |
accts[i++] = a; |
accts[i++] = a; |
276 |
} |
} |
277 |
|
|
297 |
for (i = 0; i < pn; i++) |
for (i = 0; i < pn; i++) |
298 |
printf("%d %s %s %s\n", i + 1, |
printf("%d %s %s %s\n", i + 1, |
299 |
accts[i]->server, |
accts[i]->server, |
300 |
accts[i]->username, |
accts[i]->user, |
301 |
accts[i]->password); |
accts[i]->pass); |
302 |
else if (*c == 'e') { |
else if (*c == 'e') { |
303 |
n = atoi(++c); |
n = atoi(++c); |
304 |
if (n == 0 || n < 1 || |
if (n == 0 || n < 1 || |
305 |
n > pn || |
n > pn || |
306 |
accts[n - 1] == NULL) |
accts[n - 1] == NULL) |
307 |
break; |
break; |
308 |
accts[n - 1]->password[0] = '\0'; |
accts[n - 1]->pass[0] = '\0'; |
309 |
printf("Enter new password: "); |
printf("Enter new password: "); |
310 |
if (fgets(accts[n - 1]->password, PASSWORD_LEN, |
if (fgets(accts[n - 1]->pass, PASS_LEN, |
311 |
stdin) && |
stdin) && |
312 |
(c = strchr(accts[n - 1]->password, '\n'))) |
(c = strchr(accts[n - 1]->pass, '\n'))) |
313 |
*c = '\0'; |
*c = '\0'; |
314 |
} else if (*c == 'c') { |
} else if (*c == 'c') { |
315 |
n = atoi(++c); |
n = atoi(++c); |
317 |
n > pn || |
n > pn || |
318 |
accts[n - 1] == NULL) |
accts[n - 1] == NULL) |
319 |
break; |
break; |
320 |
accts[n - 1]->password[0] = '\0'; |
accts[n - 1]->pass[0] = '\0'; |
321 |
} else if (*c == 'p') { |
} else if (*c == 'p') { |
322 |
p[0] = (char *)smalloc(PASSPHRASE_LEN); |
p[0] = (char *)smalloc(PASSPHRASE_LEN); |
323 |
p[1] = (char *)smalloc(PASSPHRASE_LEN); |
p[1] = (char *)smalloc(PASSPHRASE_LEN); |