67 |
|
|
68 |
/* Initialization vector. */ |
/* Initialization vector. */ |
69 |
c = ultostr(1 + random() % 100000000, 10); |
c = ultostr(1 + random() % 100000000, 10); |
70 |
memset(iv, '0', EVP_MAX_IV_LENGTH); |
snprintf(iv, EVP_MAX_IV_LENGTH, "%.8s", c); |
71 |
memcpy(iv + 8 - strlen(c), c, min(8, strlen(c))); |
fprintf(fd, "%s\n", iv); |
|
fprintf(fd, "%.8s\n", iv); |
|
72 |
|
|
73 |
EVP_CIPHER_CTX_init(&ctx); |
EVP_CIPHER_CTX_init(&ctx); |
74 |
|
|
96 |
|
|
97 |
/* MD5 checksum of data. */ |
/* MD5 checksum of data. */ |
98 |
for (i = 0; i < mdl; i++) |
for (i = 0; i < mdl; i++) |
99 |
snprintf(2 + buf + i * 2, ENCRYPTION_BUF - i * 2, "%02x", |
snprintf(2 + buf + i * 2, ENCRYPTION_BUF - 3 - i * 2, "%02x", |
100 |
mdv[i]); |
mdv[i]); |
101 |
|
|
102 |
EVP_EncryptUpdate(&ctx, ebuf, &ebufl, buf, strlen(buf)); |
EVP_EncryptUpdate(&ctx, ebuf, &ebufl, buf, strlen(buf)); |
104 |
fwrite(bbuf, sizeof(char), bbufl, fd); |
fwrite(bbuf, sizeof(char), bbufl, fd); |
105 |
|
|
106 |
EVP_EncryptFinal(&ctx, ebuf, &ebufl); |
EVP_EncryptFinal(&ctx, ebuf, &ebufl); |
107 |
|
|
108 |
EVP_EncodeUpdate(&bctx, bbuf, &bbufl, ebuf, ebufl); |
EVP_EncodeUpdate(&bctx, bbuf, &bbufl, ebuf, ebufl); |
109 |
EVP_EncodeFinal(&bctx, bbuf, &bbufl); |
fwrite(bbuf, sizeof(char), bbufl, fd); |
110 |
|
|
111 |
|
EVP_EncodeFinal(&bctx, bbuf, &bbufl); |
112 |
fwrite(bbuf, sizeof(char), bbufl, fd); |
fwrite(bbuf, sizeof(char), bbufl, fd); |
113 |
|
|
114 |
EVP_CIPHER_CTX_cleanup(&ctx); |
EVP_CIPHER_CTX_cleanup(&ctx); |
222 |
char buf[LINE_MAX]; |
char buf[LINE_MAX]; |
223 |
char *c; |
char *c; |
224 |
char *p[2]; |
char *p[2]; |
225 |
account_t *a, *accts[EDITOR_PASSWORDS_MAX]; |
account_t *a, *accts[EDITOR_PASSWORDS_MAX + 1]; |
226 |
|
|
227 |
if (!(flags & FLAG_BLANK_PASSWORD)) { |
if (!(flags & FLAG_BLANK_PASSWORD)) { |
228 |
error("no candidate passwords for encryption found\n"); |
error("no candidate passwords for encryption found\n"); |
230 |
} |
} |
231 |
q = 0; |
q = 0; |
232 |
|
|
233 |
memset(accts, 0, EDITOR_PASSWORDS_MAX); |
memset(accts, 0, (EDITOR_PASSWORDS_MAX + 1) * sizeof(account_t *)); |
234 |
|
|
235 |
for (i = 0, a = accounts; i < EDITOR_PASSWORDS_MAX - 1 && a != NULL; |
for (i = 0, a = accounts; i < EDITOR_PASSWORDS_MAX && a != NULL; |
236 |
a = a->next) { |
a = a->next) { |
237 |
if (a->passwdattr == PASSWORD_NONE || |
if (a->passwdattr == PASSWORD_NONE || |
238 |
a->passwdattr == PASSWORD_ENCRYPTED) |
a->passwdattr == PASSWORD_ENCRYPTED) |
265 |
accts[i]->password); |
accts[i]->password); |
266 |
else if (*c == 'e') { |
else if (*c == 'e') { |
267 |
n = atoi(++c); |
n = atoi(++c); |
268 |
if (n == 0 || n < 1 || n > 128 || |
if (n == 0 || n < 1 || |
269 |
|
n > EDITOR_PASSWORDS_MAX || |
270 |
accts[n - 1] == NULL) |
accts[n - 1] == NULL) |
271 |
break; |
break; |
272 |
accts[n - 1]->password[0] = '\0'; |
accts[n - 1]->password[0] = '\0'; |
277 |
*c = '\0'; |
*c = '\0'; |
278 |
} else if (*c == 'c') { |
} else if (*c == 'c') { |
279 |
n = atoi(++c); |
n = atoi(++c); |
280 |
if (n == 0 || n < 1 || n > 128 || |
if (n == 0 || n < 1 || |
281 |
|
n > EDITOR_PASSWORDS_MAX || |
282 |
accts[n - 1] == NULL) |
accts[n - 1] == NULL) |
283 |
break; |
break; |
284 |
accts[n - 1]->password[0] = '\0'; |
accts[n - 1]->password[0] = '\0'; |