46 |
* passwords before encrypting them. |
* passwords before encrypting them. |
47 |
*/ |
*/ |
48 |
int |
int |
49 |
encrypt_passwords(FILE * fd, account_t * accts[]) |
encrypt_passwords(FILE * fd, account_t ** accts) |
50 |
{ |
{ |
51 |
int i; |
int i; |
52 |
char *c; |
char *c; |
67 |
|
|
68 |
/* Initialization vector. */ |
/* Initialization vector. */ |
69 |
c = ultostr(1 + random() % 100000000, 10); |
c = ultostr(1 + random() % 100000000, 10); |
70 |
snprintf(iv, EVP_MAX_IV_LENGTH, "%.8s", c); |
snprintf(iv, EVP_MAX_IV_LENGTH, "%08s", c); |
71 |
fprintf(fd, "%s\n", iv); |
fprintf(fd, "%s\n", iv); |
72 |
|
|
73 |
EVP_CIPHER_CTX_init(&ctx); |
EVP_CIPHER_CTX_init(&ctx); |
82 |
for (i = 0; accts[i] != NULL; i++) { |
for (i = 0; accts[i] != NULL; i++) { |
83 |
snprintf(buf, ENCRYPTION_BUF, "%s %s %s\n", accts[i]->server, |
snprintf(buf, ENCRYPTION_BUF, "%s %s %s\n", accts[i]->server, |
84 |
accts[i]->username, accts[i]->password); |
accts[i]->username, accts[i]->password); |
|
|
|
85 |
EVP_DigestUpdate(&mdctx, buf, strlen(buf)); |
EVP_DigestUpdate(&mdctx, buf, strlen(buf)); |
86 |
EVP_EncryptUpdate(&ctx, ebuf, &ebufl, buf, strlen(buf)); |
EVP_EncryptUpdate(&ctx, ebuf, &ebufl, buf, strlen(buf)); |
87 |
EVP_EncodeUpdate(&bctx, bbuf, &bbufl, ebuf, ebufl); |
EVP_EncodeUpdate(&bctx, bbuf, &bbufl, ebuf, ebufl); |
217 |
void |
void |
218 |
password_editor(void) |
password_editor(void) |
219 |
{ |
{ |
220 |
int i, q, n; |
int i, q, n, pn; |
221 |
char buf[LINE_MAX]; |
char buf[LINE_MAX]; |
222 |
char *c; |
char *c; |
223 |
char *p[2]; |
char *p[2]; |
224 |
account_t *a, *accts[EDITOR_PASSWORDS_MAX + 1]; |
account_t *a, **accts; |
225 |
|
|
226 |
if (!(flags & FLAG_BLANK_PASSWORD)) { |
if (!(flags & FLAG_BLANK_PASSWORD)) { |
227 |
error("no candidate passwords for encryption found\n"); |
error("no candidate passwords for encryption found\n"); |
228 |
return; |
return; |
229 |
} |
} |
230 |
q = 0; |
q = pn = 0; |
231 |
|
|
232 |
|
for (a = accounts; a != NULL; a = a->next) |
233 |
|
if (a->passwdattr == PASSWORD_NONE || |
234 |
|
a->passwdattr == PASSWORD_ENCRYPTED) |
235 |
|
pn++; |
236 |
|
|
237 |
|
accts = (account_t **) xmalloc((pn + 1) * sizeof(account_t *)); |
238 |
|
|
239 |
memset(accts, 0, (EDITOR_PASSWORDS_MAX + 1) * sizeof(account_t *)); |
memset(accts, 0, (pn + 1) * sizeof(account_t *)); |
240 |
|
|
241 |
for (i = 0, a = accounts; i < EDITOR_PASSWORDS_MAX && a != NULL; |
for (i = 0, a = accounts; a != NULL; a = a->next) { |
|
a = a->next) { |
|
242 |
if (a->passwdattr == PASSWORD_NONE || |
if (a->passwdattr == PASSWORD_NONE || |
243 |
a->passwdattr == PASSWORD_ENCRYPTED) |
a->passwdattr == PASSWORD_ENCRYPTED) |
244 |
accts[i++] = a; |
accts[i++] = a; |
258 |
"l\tlist entries\n" |
"l\tlist entries\n" |
259 |
"p\tchange master password\n" |
"p\tchange master password\n" |
260 |
"q\tquit without saving\n" |
"q\tquit without saving\n" |
261 |
"s\tsave changes\n" |
"w\tsave changes\n" |
262 |
"x\tsave and exit\n"); |
"x\tsave and exit\n"); |
263 |
else if (*c == 'q') |
else if (*c == 'q') |
264 |
q = 1; |
q = 1; |
265 |
else if (*c == 'l') |
else if (*c == 'l') |
266 |
for (i = 0; accts[i] != NULL; i++) |
for (i = 0; i < pn; i++) |
267 |
printf("%d %s %s %s\n", i + 1, |
printf("%d %s %s %s\n", i + 1, |
268 |
accts[i]->server, |
accts[i]->server, |
269 |
accts[i]->username, |
accts[i]->username, |
271 |
else if (*c == 'e') { |
else if (*c == 'e') { |
272 |
n = atoi(++c); |
n = atoi(++c); |
273 |
if (n == 0 || n < 1 || |
if (n == 0 || n < 1 || |
274 |
n > EDITOR_PASSWORDS_MAX || |
n > pn || |
275 |
accts[n - 1] == NULL) |
accts[n - 1] == NULL) |
276 |
break; |
break; |
277 |
accts[n - 1]->password[0] = '\0'; |
accts[n - 1]->password[0] = '\0'; |
283 |
} else if (*c == 'c') { |
} else if (*c == 'c') { |
284 |
n = atoi(++c); |
n = atoi(++c); |
285 |
if (n == 0 || n < 1 || |
if (n == 0 || n < 1 || |
286 |
n > EDITOR_PASSWORDS_MAX || |
n > pn || |
287 |
accts[n - 1] == NULL) |
accts[n - 1] == NULL) |
288 |
break; |
break; |
289 |
accts[n - 1]->password[0] = '\0'; |
accts[n - 1]->password[0] = '\0'; |
302 |
xstrncpy(passphr, p[0], PASSPHRASE_LEN - 1); |
xstrncpy(passphr, p[0], PASSPHRASE_LEN - 1); |
303 |
sfree(p[0]); |
sfree(p[0]); |
304 |
sfree(p[1]); |
sfree(p[1]); |
305 |
} else if (*c == 's' || *c == 'w') { |
} else if (*c == 'w' || *c == 's') { |
306 |
store_passwords(accts); |
store_passwords(accts); |
307 |
} else if (*c == 'x') { |
} else if (*c == 'x') { |
308 |
store_passwords(accts); |
store_passwords(accts); |