mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 03:50:57 +01:00
unfortunately my tab/spc config was wrong for a couple of years. fixed all tabs=>spaces+re-indent
This commit is contained in:
112
src/encryption.c
112
src/encryption.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of Pretty Curved Privacy (pcp1).
|
||||
|
||||
Copyright (C) 2013-2015 T.v.Dein.
|
||||
Copyright (C) 2013-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -66,12 +66,12 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
||||
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase for symetric decryption", NULL, 1, NULL);
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase for symetric decryption", NULL, 1, NULL);
|
||||
}
|
||||
else {
|
||||
passphrase = smalloc(strlen(passwd)+1);
|
||||
memcpy(passphrase, passwd, strlen(passwd) + 1);
|
||||
passphrase = smalloc(strlen(passwd)+1);
|
||||
memcpy(passphrase, passwd, strlen(passwd) + 1);
|
||||
}
|
||||
|
||||
symkey = pcp_scrypt(ptx, passphrase, strlen(passphrase), salt, 90);
|
||||
@@ -79,48 +79,48 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
||||
free(salt);
|
||||
}
|
||||
else if(head == PCP_ASYM_CIPHER || head == PCP_ASYM_CIPHER_SIG
|
||||
|| head == PCP_ASYM_CIPHER_ANON || head == PCP_ASYM_CIPHER_ANON_SIG) {
|
||||
|| head == PCP_ASYM_CIPHER_ANON || head == PCP_ASYM_CIPHER_ANON_SIG) {
|
||||
/* asymetric mode */
|
||||
if(useid) {
|
||||
secret = pcphash_keyexists(ptx, id);
|
||||
if(secret == NULL) {
|
||||
fatal(ptx, "Could not find a secret key with id 0x%s in vault %s!\n",
|
||||
id, vault->filename);
|
||||
goto errde3;
|
||||
}
|
||||
secret = pcphash_keyexists(ptx, id);
|
||||
if(secret == NULL) {
|
||||
fatal(ptx, "Could not find a secret key with id 0x%s in vault %s!\n",
|
||||
id, vault->filename);
|
||||
goto errde3;
|
||||
}
|
||||
}
|
||||
else {
|
||||
secret = pcp_find_primary_secret();
|
||||
if(secret == NULL) {
|
||||
fatal(ptx, "Could not find a secret key in vault %s!\n", id, vault->filename);
|
||||
goto errde3;
|
||||
}
|
||||
secret = pcp_find_primary_secret();
|
||||
if(secret == NULL) {
|
||||
fatal(ptx, "Could not find a secret key in vault %s!\n", id, vault->filename);
|
||||
goto errde3;
|
||||
}
|
||||
}
|
||||
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1, NULL);
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1, NULL);
|
||||
}
|
||||
else {
|
||||
passphrase = smalloc(strlen(passwd)+1);
|
||||
memcpy(passphrase, passwd, strlen(passwd)+1);
|
||||
passphrase = smalloc(strlen(passwd)+1);
|
||||
memcpy(passphrase, passwd, strlen(passwd)+1);
|
||||
}
|
||||
|
||||
secret = pcpkey_decrypt(ptx, secret, passphrase);
|
||||
sfree(passphrase);
|
||||
if(secret == NULL)
|
||||
goto errde3;
|
||||
goto errde3;
|
||||
|
||||
if(head == PCP_ASYM_CIPHER_ANON)
|
||||
anon = 1;
|
||||
anon = 1;
|
||||
|
||||
if(head == PCP_ASYM_CIPHER_SIG)
|
||||
verify = 1;
|
||||
verify = 1;
|
||||
|
||||
if(head == PCP_ASYM_CIPHER_ANON_SIG) {
|
||||
anon = 1;
|
||||
verify = 1;
|
||||
anon = 1;
|
||||
verify = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -164,7 +164,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
||||
|
||||
|
||||
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
|
||||
plist_t *recipient, int signcrypt, int armor, int anon) {
|
||||
plist_t *recipient, int signcrypt, int armor, int anon) {
|
||||
FILE *in = NULL;
|
||||
FILE *out = NULL;
|
||||
pcp_pubkey_t *pubhash = NULL; /* FIXME: add free() */
|
||||
@@ -201,15 +201,15 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
|
||||
/* self-encryption: look if its a secret one */
|
||||
pcp_key_t *s = pcphash_keyexists(ptx, id);
|
||||
if(s != NULL) {
|
||||
tmp = pcpkey_pub_from_secret(s);
|
||||
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
||||
memcpy(pub, tmp, sizeof(pcp_pubkey_t));
|
||||
HASH_ADD_STR( pubhash, id, pub);
|
||||
tmp = pcpkey_pub_from_secret(s);
|
||||
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
||||
memcpy(pub, tmp, sizeof(pcp_pubkey_t));
|
||||
HASH_ADD_STR( pubhash, id, pub);
|
||||
}
|
||||
else {
|
||||
fatal(ptx, "Could not find a public key with id 0x%s in vault %s!\n",
|
||||
id, vault->filename);
|
||||
goto erren3;
|
||||
fatal(ptx, "Could not find a public key with id 0x%s in vault %s!\n",
|
||||
id, vault->filename);
|
||||
goto erren3;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -227,15 +227,15 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
|
||||
pcphash_iteratepub(ptx, tmp) {
|
||||
rec = recipient->first;
|
||||
while (rec != NULL) {
|
||||
_lc(rec->value);
|
||||
if(strnstr(tmp->mail, rec->value, 255) != NULL
|
||||
|| strnstr(tmp->owner, rec->value, 255) != NULL) {
|
||||
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
||||
memcpy(pub, tmp, sizeof(pcp_pubkey_t));
|
||||
HASH_ADD_STR( pubhash, id, pub);
|
||||
/* fprintf(stderr, " => found a matching key %s\n", tmp->id); */
|
||||
}
|
||||
rec = rec->next;
|
||||
_lc(rec->value);
|
||||
if(strnstr(tmp->mail, rec->value, 255) != NULL
|
||||
|| strnstr(tmp->owner, rec->value, 255) != NULL) {
|
||||
pub = ucmalloc(sizeof(pcp_pubkey_t));
|
||||
memcpy(pub, tmp, sizeof(pcp_pubkey_t));
|
||||
HASH_ADD_STR( pubhash, id, pub);
|
||||
/* fprintf(stderr, " => found a matching key %s\n", tmp->id); */
|
||||
}
|
||||
rec = rec->next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,10 +243,10 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
|
||||
rec = recipient->first;
|
||||
while (rec != NULL) {
|
||||
if(strnstr("__self__", rec->value, 13) != NULL) {
|
||||
pcp_key_t *s = pcp_find_primary_secret();
|
||||
pcp_pubkey_t *p = pcpkey_pub_from_secret(s);
|
||||
HASH_ADD_STR( pubhash, id, p);
|
||||
break;
|
||||
pcp_key_t *s = pcp_find_primary_secret();
|
||||
pcp_pubkey_t *p = pcpkey_pub_from_secret(s);
|
||||
HASH_ADD_STR( pubhash, id, p);
|
||||
break;
|
||||
}
|
||||
rec = rec->next;
|
||||
}
|
||||
@@ -264,22 +264,22 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
|
||||
secret = pcp_find_primary_secret();
|
||||
if(secret == NULL) {
|
||||
fatal(ptx, "Could not find a secret key in vault %s!\n", id, vault->filename);
|
||||
goto erren2;
|
||||
goto erren2;
|
||||
}
|
||||
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1, NULL);
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1, NULL);
|
||||
}
|
||||
else {
|
||||
passphrase = smalloc(strlen(passwd)+1);
|
||||
memcpy(passphrase, passwd, strlen(passwd)+1);
|
||||
passphrase = smalloc(strlen(passwd)+1);
|
||||
memcpy(passphrase, passwd, strlen(passwd)+1);
|
||||
}
|
||||
secret = pcpkey_decrypt(ptx, secret, passphrase);
|
||||
sfree(passphrase);
|
||||
if(secret == NULL)
|
||||
goto erren2;
|
||||
goto erren2;
|
||||
|
||||
signsecret = secret;
|
||||
}
|
||||
@@ -341,7 +341,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd,
|
||||
fprintf(stderr, "Encrypted %"FMT_SIZE_T" bytes for:\n", (SIZE_T_CAST)clen);
|
||||
pcp_pubkey_t *cur, *t;
|
||||
HASH_ITER(hh, pubhash, cur, t) {
|
||||
fprintf(stderr, " 0x%s - %s <%s>\n", cur->id, cur->owner, cur->mail);
|
||||
fprintf(stderr, " 0x%s - %s <%s>\n", cur->id, cur->owner, cur->mail);
|
||||
}
|
||||
}
|
||||
if(signcrypt)
|
||||
@@ -381,8 +381,8 @@ void pcpchecksum(char **files, int filenum, char *key) {
|
||||
}
|
||||
else {
|
||||
if((in = fopen(files[i], "rb")) == NULL) {
|
||||
fatal(ptx, "Could not open input file %s\n", files[i]);
|
||||
break;
|
||||
fatal(ptx, "Could not open input file %s\n", files[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Pcpstream *pin = ps_new_file(in);
|
||||
|
||||
202
src/keymgmt.c
202
src/keymgmt.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of Pretty Curved Privacy (pcp1).
|
||||
|
||||
Copyright (C) 2013-2015 T.v.Dein.
|
||||
Copyright (C) 2013-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -78,8 +78,8 @@ void pcp_keygen(char *passwd) {
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase for key encryption",
|
||||
"Enter the passphrase again", 1, NULL);
|
||||
"Enter passphrase for key encryption",
|
||||
"Enter the passphrase again", 1, NULL);
|
||||
}
|
||||
else {
|
||||
passphrase = passwd;
|
||||
@@ -91,7 +91,7 @@ void pcp_keygen(char *passwd) {
|
||||
fprintf(stderr, "WARNING: you are using a weak passphrase (entropy: %lf)!\n", ent);
|
||||
char *yes = pcp_getstdin("Are you sure to use it [yes|NO]?");
|
||||
if(strncmp(yes, "yes", 1024) != 0) {
|
||||
goto errkg1;
|
||||
goto errkg1;
|
||||
}
|
||||
}
|
||||
key = pcpkey_encrypt(ptx, k, passphrase);
|
||||
@@ -167,7 +167,7 @@ char *pcp_normalize_id(char *keyid) {
|
||||
if(keyid[0] == '0' && keyid[1] == 'x' && len == 18) {
|
||||
int i;
|
||||
for(i=0; i<16; ++i) {
|
||||
id[i] = keyid[i+2];
|
||||
id[i] = keyid[i+2];
|
||||
}
|
||||
id[16] = 0;
|
||||
}
|
||||
@@ -238,18 +238,18 @@ void pcp_exportsecret(char *keyid, int useid, char *outfile, int armor, char *pa
|
||||
if(passwd == NULL) {
|
||||
char *passphrase;
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1, NULL);
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1, NULL);
|
||||
key = pcpkey_decrypt(ptx, key, passphrase);
|
||||
if(key == NULL) {
|
||||
sfree(passphrase);
|
||||
goto errexpse1;
|
||||
sfree(passphrase);
|
||||
goto errexpse1;
|
||||
}
|
||||
sfree(passphrase);
|
||||
}
|
||||
else {
|
||||
key = pcpkey_decrypt(ptx, key, passwd);
|
||||
if(key == NULL) {
|
||||
goto errexpse1;
|
||||
goto errexpse1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,20 +262,20 @@ void pcp_exportsecret(char *keyid, int useid, char *outfile, int armor, char *pa
|
||||
char *passphrase;
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase to encrypt the exported secret key",
|
||||
"Repeat passphrase", 1, NULL);
|
||||
"Repeat passphrase", 1, NULL);
|
||||
exported_sk = pcp_export_secret(ptx, key, passphrase);
|
||||
sfree(passphrase);
|
||||
}
|
||||
|
||||
if(exported_sk != NULL) {
|
||||
if(armor == 1) {
|
||||
size_t zlen;
|
||||
char *z85 = pcp_z85_encode(buffer_get(exported_sk), buffer_size(exported_sk), &zlen, 1);
|
||||
fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_SK_HEADER, z85, EXP_SK_FOOTER);
|
||||
free(z85);
|
||||
size_t zlen;
|
||||
char *z85 = pcp_z85_encode(buffer_get(exported_sk), buffer_size(exported_sk), &zlen, 1);
|
||||
fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_SK_HEADER, z85, EXP_SK_FOOTER);
|
||||
free(z85);
|
||||
}
|
||||
else {
|
||||
fwrite(buffer_get(exported_sk), 1, buffer_size(exported_sk), out);
|
||||
fwrite(buffer_get(exported_sk), 1, buffer_size(exported_sk), out);
|
||||
}
|
||||
buffer_free(exported_sk);
|
||||
fprintf(stderr, "secret key exported.\n");
|
||||
@@ -318,13 +318,13 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int
|
||||
/* ok, so, then look for a secret key with that id */
|
||||
sk = pcphash_keyexists(ptx, keyid);
|
||||
if(sk == NULL) {
|
||||
fatal(ptx, "Could not find a key with id 0x%s in vault %s!\n",
|
||||
keyid, vault->filename);
|
||||
goto errpcpexpu1;
|
||||
fatal(ptx, "Could not find a key with id 0x%s in vault %s!\n",
|
||||
keyid, vault->filename);
|
||||
goto errpcpexpu1;
|
||||
}
|
||||
else {
|
||||
/* ok, so it's our own key */
|
||||
is_foreign = 0;
|
||||
/* ok, so it's our own key */
|
||||
is_foreign = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -351,7 +351,7 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int
|
||||
else {
|
||||
char *passphrase;
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1, NULL);
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1, NULL);
|
||||
sk = pcpkey_decrypt(ptx, sk, passphrase);
|
||||
sfree(passphrase);
|
||||
}
|
||||
@@ -365,16 +365,16 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int
|
||||
if(is_foreign == 0) {
|
||||
exported_pk = pcp_export_rfc_pub(ptx, sk);
|
||||
if(exported_pk != NULL) {
|
||||
if(armor == 1) {
|
||||
size_t zlen;
|
||||
char *z85 = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1);
|
||||
fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_PK_HEADER, z85, EXP_PK_FOOTER);
|
||||
free(z85);
|
||||
}
|
||||
else
|
||||
fwrite(buffer_get(exported_pk), 1, buffer_size(exported_pk), out);
|
||||
buffer_free(exported_pk);
|
||||
fprintf(stderr, "public key exported.\n");
|
||||
if(armor == 1) {
|
||||
size_t zlen;
|
||||
char *z85 = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1);
|
||||
fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_PK_HEADER, z85, EXP_PK_FOOTER);
|
||||
free(z85);
|
||||
}
|
||||
else
|
||||
fwrite(buffer_get(exported_pk), 1, buffer_size(exported_pk), out);
|
||||
buffer_free(exported_pk);
|
||||
fprintf(stderr, "public key exported.\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -387,13 +387,13 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int
|
||||
if(is_foreign == 0) {
|
||||
exported_pk = pcp_export_pbp_pub(sk);
|
||||
if(exported_pk != NULL) {
|
||||
/* PBP format requires armoring always */
|
||||
size_t zlen;
|
||||
char *z85pbp = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1);
|
||||
fprintf(out, "%s", z85pbp);
|
||||
free(z85pbp);
|
||||
buffer_free(exported_pk);
|
||||
fprintf(stderr, "public key exported in PBP format.\n");
|
||||
/* PBP format requires armoring always */
|
||||
size_t zlen;
|
||||
char *z85pbp = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1);
|
||||
fprintf(out, "%s", z85pbp);
|
||||
free(z85pbp);
|
||||
buffer_free(exported_pk);
|
||||
fprintf(stderr, "public key exported in PBP format.\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -446,63 +446,63 @@ void pcpedit_key(char *keyid) {
|
||||
fprintf(stderr, "Current owner: %s\n", key->owner);
|
||||
char *owner = pcp_getstdin(" enter new name or press enter to keep current");
|
||||
if(strlen(owner) > 0)
|
||||
memcpy(key->owner, owner, strlen(owner) + 1);
|
||||
memcpy(key->owner, owner, strlen(owner) + 1);
|
||||
|
||||
fprintf(stderr, "Current mail: %s\n", key->mail);
|
||||
char *mail = pcp_getstdin(" enter new email or press enter to keep current");
|
||||
if(strlen(mail) > 0)
|
||||
memcpy(key->mail, mail, strlen(mail) + 1);
|
||||
memcpy(key->mail, mail, strlen(mail) + 1);
|
||||
|
||||
free(owner);
|
||||
free(mail);
|
||||
|
||||
if(key->type != PCP_KEY_TYPE_MAINSECRET) {
|
||||
pcp_key_t *other = NULL;
|
||||
uint8_t haveprimary = 0;
|
||||
pcphash_iterate(ptx, other) {
|
||||
if(other->type == PCP_KEY_TYPE_MAINSECRET) {
|
||||
haveprimary = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pcp_key_t *other = NULL;
|
||||
uint8_t haveprimary = 0;
|
||||
pcphash_iterate(ptx, other) {
|
||||
if(other->type == PCP_KEY_TYPE_MAINSECRET) {
|
||||
haveprimary = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char *yes = NULL;
|
||||
char *yes = NULL;
|
||||
if(! haveprimary) {
|
||||
fprintf(stderr, "There is currently no primary secret in your vault,\n");
|
||||
yes = pcp_getstdin("want to make this one the primary [yes|NO]?");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "The key %s is currently the primary secret,\n", other->id);
|
||||
yes = pcp_getstdin("want to make this one the primary instead [yes|NO]?");
|
||||
}
|
||||
fprintf(stderr, "There is currently no primary secret in your vault,\n");
|
||||
yes = pcp_getstdin("want to make this one the primary [yes|NO]?");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "The key %s is currently the primary secret,\n", other->id);
|
||||
yes = pcp_getstdin("want to make this one the primary instead [yes|NO]?");
|
||||
}
|
||||
|
||||
if(strncmp(yes, "yes", 1024) == 0) {
|
||||
key->type = PCP_KEY_TYPE_MAINSECRET;
|
||||
if(haveprimary) {
|
||||
fprintf(stderr, "other type: %d\n", other->type);
|
||||
other->type = PCP_KEY_TYPE_SECRET;
|
||||
fprintf(stderr, " new type: %d\n", other->type);
|
||||
}
|
||||
}
|
||||
free(yes);
|
||||
if(strncmp(yes, "yes", 1024) == 0) {
|
||||
key->type = PCP_KEY_TYPE_MAINSECRET;
|
||||
if(haveprimary) {
|
||||
fprintf(stderr, "other type: %d\n", other->type);
|
||||
other->type = PCP_KEY_TYPE_SECRET;
|
||||
fprintf(stderr, " new type: %d\n", other->type);
|
||||
}
|
||||
}
|
||||
free(yes);
|
||||
}
|
||||
|
||||
char *passphrase;
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter new passphrase for key encryption (press enter to keep current)",
|
||||
"Enter the passphrase again", 1, NULL);
|
||||
"Enter new passphrase for key encryption (press enter to keep current)",
|
||||
"Enter the passphrase again", 1, NULL);
|
||||
|
||||
if(strnlen(passphrase, 1024) > 0) {
|
||||
key = pcpkey_encrypt(ptx, key, passphrase);
|
||||
sfree(passphrase);
|
||||
key = pcpkey_encrypt(ptx, key, passphrase);
|
||||
sfree(passphrase);
|
||||
}
|
||||
|
||||
if(key != NULL) {
|
||||
if(debug)
|
||||
pcp_dumpkey(key);
|
||||
if(debug)
|
||||
pcp_dumpkey(key);
|
||||
|
||||
vault->unsafed = 1; /* will be safed automatically */
|
||||
fprintf(stderr, "Key %s changed.\n", key->id);
|
||||
vault->unsafed = 1; /* will be safed automatically */
|
||||
fprintf(stderr, "Key %s changed.\n", key->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -564,26 +564,26 @@ int pcp_import (vault_t *vault, FILE *in, char *passwd) {
|
||||
fatals_ifany(ptx);
|
||||
char *yes = pcp_getstdin("WARNING: signature doesn't verify, import anyway [yes|NO]?");
|
||||
if(strncmp(yes, "yes", 1024) != 0) {
|
||||
free(yes);
|
||||
goto errimp2;
|
||||
free(yes);
|
||||
goto errimp2;
|
||||
}
|
||||
free(yes);
|
||||
}
|
||||
|
||||
if(pcp_sanitycheck_pub(ptx, pub) == 0) {
|
||||
if(pcpvault_addkey(ptx, vault, (void *)pub, PCP_KEY_TYPE_PUBLIC) == 0) {
|
||||
fprintf(stderr, "key 0x%s added to %s.\n", pub->id, vault->filename);
|
||||
/* avoid double free */
|
||||
success = 0;
|
||||
fprintf(stderr, "key 0x%s added to %s.\n", pub->id, vault->filename);
|
||||
/* avoid double free */
|
||||
success = 0;
|
||||
}
|
||||
else
|
||||
goto errimp2;
|
||||
goto errimp2;
|
||||
|
||||
if(keysig != NULL) {
|
||||
if(pcpvault_addkey(ptx, vault, keysig, keysig->type) != 0) {
|
||||
/* FIXME: remove pubkey if storing the keysig failed */
|
||||
goto errimp2;
|
||||
}
|
||||
if(pcpvault_addkey(ptx, vault, keysig, keysig->type) != 0) {
|
||||
/* FIXME: remove pubkey if storing the keysig failed */
|
||||
goto errimp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -599,7 +599,7 @@ int pcp_import (vault_t *vault, FILE *in, char *passwd) {
|
||||
else {
|
||||
char *passphrase;
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase to decrypt the secret key file", NULL, 1, NULL);
|
||||
"Enter passphrase to decrypt the secret key file", NULL, 1, NULL);
|
||||
sk = pcp_import_secret(ptx, buf, bufsize, passphrase);
|
||||
sfree(passphrase);
|
||||
}
|
||||
@@ -624,33 +624,33 @@ int pcp_import (vault_t *vault, FILE *in, char *passwd) {
|
||||
else {
|
||||
char *passphrase;
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase for key encryption",
|
||||
"Enter the passphrase again", 1, NULL);
|
||||
"Enter passphrase for key encryption",
|
||||
"Enter the passphrase again", 1, NULL);
|
||||
|
||||
if(strnlen(passphrase, 1024) > 0) {
|
||||
/* encrypt the key */
|
||||
sk = pcpkey_encrypt(ptx, sk, passphrase);
|
||||
sfree(passphrase);
|
||||
/* encrypt the key */
|
||||
sk = pcpkey_encrypt(ptx, sk, passphrase);
|
||||
sfree(passphrase);
|
||||
}
|
||||
else {
|
||||
/* ask for confirmation if we shall store it in the clear */
|
||||
char *yes = pcp_getstdin(
|
||||
"WARNING: secret key will be stored unencrypted. Are you sure [yes|NO]?");
|
||||
if(strncmp(yes, "yes", 1024) != 0) {
|
||||
free(yes);
|
||||
goto errimp1;
|
||||
}
|
||||
free(yes);
|
||||
/* ask for confirmation if we shall store it in the clear */
|
||||
char *yes = pcp_getstdin(
|
||||
"WARNING: secret key will be stored unencrypted. Are you sure [yes|NO]?");
|
||||
if(strncmp(yes, "yes", 1024) != 0) {
|
||||
free(yes);
|
||||
goto errimp1;
|
||||
}
|
||||
free(yes);
|
||||
}
|
||||
}
|
||||
|
||||
if(sk != NULL) {
|
||||
/* store it to the vault if we got it til here */
|
||||
if(pcp_sanitycheck_key(ptx, sk) == 0) {
|
||||
if(pcp_storekey(sk) == 0) {
|
||||
pcpkey_printshortinfo(sk);
|
||||
success = 0;
|
||||
}
|
||||
if(pcp_storekey(sk) == 0) {
|
||||
pcpkey_printshortinfo(sk);
|
||||
success = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of Pretty Curved Privacy (pcp1).
|
||||
|
||||
Copyright (C) 2013 T.Linden.
|
||||
Copyright (C) 2013-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -92,13 +92,13 @@ void pcptext_key(char *keyid) {
|
||||
pcp_pubkey_t *p = pcphash_pubkeyexists(ptx, keyid);
|
||||
if(p != NULL) {
|
||||
if(debug) {
|
||||
pcp_dumppubkey(p);
|
||||
pcp_keysig_t *s = pcphash_keysigexists(ptx, keyid);
|
||||
if(s != NULL) {
|
||||
printf("\n");
|
||||
pcp_dumpkeysig(s);
|
||||
}
|
||||
printf("\n");
|
||||
pcp_dumppubkey(p);
|
||||
pcp_keysig_t *s = pcphash_keysigexists(ptx, keyid);
|
||||
if(s != NULL) {
|
||||
printf("\n");
|
||||
pcp_dumpkeysig(s);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
pcppubkey_print(p, stdout);
|
||||
}
|
||||
@@ -119,11 +119,11 @@ void pcptext_vault(vault_t *vault) {
|
||||
|
||||
checksum = _bin2hex(vault->checksum, LSHA);
|
||||
jout = json_pack("{sssisssisi}",
|
||||
"keyvaultfile", vault->filename,
|
||||
"version", vault->version,
|
||||
"checksum", checksum,
|
||||
"secretkeys", pcphash_count(ptx),
|
||||
"publickey", pcphash_countpub(ptx));
|
||||
"keyvaultfile" , vault->filename,
|
||||
"version" , vault->version,
|
||||
"checksum" , checksum,
|
||||
"secretkeys" , pcphash_count(ptx),
|
||||
"publickey" , pcphash_countpub(ptx));
|
||||
|
||||
jkeys = json_array();
|
||||
|
||||
@@ -174,11 +174,11 @@ void pcpkey_printlineinfo(pcp_key_t *key) {
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
printf("0x%s %s %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n",
|
||||
key->id,
|
||||
(key->type == PCP_KEY_TYPE_MAINSECRET) ? "primary secret" : "secret ",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec,
|
||||
key->owner, key->mail);
|
||||
key->id,
|
||||
(key->type == PCP_KEY_TYPE_MAINSECRET) ? "primary secret" : "secret ",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec,
|
||||
key->owner, key->mail);
|
||||
|
||||
if(ptx->verbose) {
|
||||
printf(" ");
|
||||
@@ -186,14 +186,14 @@ void pcpkey_printlineinfo(pcp_key_t *key) {
|
||||
int i, y;
|
||||
for(i=0; i<LSHA; i+=4) {
|
||||
for(y=0; y<4; y++) {
|
||||
printf("%02x", hash[i+y]);
|
||||
printf("%02x", hash[i+y]);
|
||||
}
|
||||
printf(" ");
|
||||
}
|
||||
free(hash);
|
||||
printf("\n encrypted: %s, serial: %08x, version: %d\n",
|
||||
(key->secret[0] == '\0') ? "yes" : " no",
|
||||
key->serial, (int)key->version);
|
||||
(key->secret[0] == '\0') ? "yes" : " no",
|
||||
key->serial, (int)key->version);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
@@ -203,11 +203,11 @@ void pcppubkey_printlineinfo(pcp_pubkey_t *key) {
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
printf("0x%s %s %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n",
|
||||
key->id,
|
||||
(key->valid == 1) ? "valid public " : "public ",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec,
|
||||
key->owner, key->mail);
|
||||
key->id,
|
||||
(key->valid == 1) ? "valid public " : "public ",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec,
|
||||
key->owner, key->mail);
|
||||
|
||||
if(ptx->verbose) {
|
||||
printf(" ");
|
||||
@@ -215,23 +215,23 @@ void pcppubkey_printlineinfo(pcp_pubkey_t *key) {
|
||||
int i, y;
|
||||
for(i=0; i<LSHA; i+=4) {
|
||||
for(y=0; y<4; y++) {
|
||||
printf("%02x", hash[i+y]);
|
||||
printf("%02x", hash[i+y]);
|
||||
}
|
||||
printf(" ");
|
||||
}
|
||||
free(hash);
|
||||
printf("\n signed: %s, serial: %08x, version: %d, ",
|
||||
(key->valid == 1) ? "yes" : " no",
|
||||
key->serial, (int)key->version);
|
||||
(key->valid == 1) ? "yes" : " no",
|
||||
key->serial, (int)key->version);
|
||||
pcp_keysig_t *sig = pcphash_keysigexists(ptx, key->id);
|
||||
if(sig != NULL) {
|
||||
printf("signature fingerprint:\n ");
|
||||
byte *checksum = sig->checksum;
|
||||
for(i=0; i<LSHA; i+=4) {
|
||||
for(y=0; y<4; y++) {
|
||||
printf("%02x", checksum[i+y]);
|
||||
}
|
||||
printf(" ");
|
||||
for(y=0; y<4; y++) {
|
||||
printf("%02x", checksum[i+y]);
|
||||
}
|
||||
printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
@@ -253,7 +253,7 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
|
||||
|
||||
jout = pcp_pk2json(key);
|
||||
json_object_set(jout, "random-art-id", json_string(r));
|
||||
|
||||
|
||||
jdump = json_dumps(jout, JSON_INDENT(4) | JSON_PRESERVE_ORDER);
|
||||
fprintf(out, "%s\n", jdump);
|
||||
json_decref(jout);
|
||||
@@ -278,8 +278,8 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
|
||||
|
||||
/* 2004-06-14T23:34:30. */
|
||||
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec);
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec);
|
||||
|
||||
byte *hash = pcppubkey_getchecksum(key);
|
||||
fprintf(out, " Checksum: ");
|
||||
@@ -298,10 +298,10 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
|
||||
size_t rlen = strlen(r);
|
||||
for (i=0; i<rlen; ++i) {
|
||||
if(r[i] == '\n') {
|
||||
fprintf(out, "\n ");
|
||||
fprintf(out, "\n ");
|
||||
}
|
||||
else {
|
||||
fprintf(out, "%c", r[i]);
|
||||
fprintf(out, "%c", r[i]);
|
||||
}
|
||||
}
|
||||
fprintf(out, "\n");
|
||||
@@ -327,7 +327,7 @@ void pcpkey_print(pcp_key_t *key, FILE* out) {
|
||||
jout = pcp_sk2json(key, NULL, 0);
|
||||
json_object_set(jout, "type", json_string("secret"));
|
||||
json_object_set(jout, "random-art-id", json_string(r));
|
||||
|
||||
|
||||
jdump = json_dumps(jout, JSON_INDENT(4) | JSON_PRESERVE_ORDER);
|
||||
fprintf(out, "%s\n", jdump);
|
||||
json_decref(jout);
|
||||
@@ -349,8 +349,8 @@ void pcpkey_print(pcp_key_t *key, FILE* out) {
|
||||
|
||||
/* 2004-06-14T23:34:30. */
|
||||
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec);
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec);
|
||||
|
||||
fprintf(out, " Serial Number: 0x%08X\n", key->serial);
|
||||
fprintf(out, " Key Version: 0x%08X\n", key->version);
|
||||
@@ -359,10 +359,10 @@ void pcpkey_print(pcp_key_t *key, FILE* out) {
|
||||
size_t rlen = strlen(r);
|
||||
for (i=0; i<rlen; ++i) {
|
||||
if(r[i] == '\n') {
|
||||
fprintf(out, "\n ");
|
||||
fprintf(out, "\n ");
|
||||
}
|
||||
else {
|
||||
fprintf(out, "%c", r[i]);
|
||||
fprintf(out, "%c", r[i]);
|
||||
}
|
||||
}
|
||||
fprintf(out, "\n");
|
||||
|
||||
515
src/pcp.c
515
src/pcp.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of Pretty Curved Privacy (pcp1).
|
||||
|
||||
Copyright (C) 2013-2015 T.Linden.
|
||||
Copyright (C) 2013-2016 T.Linden.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -34,7 +34,7 @@ void usage(int error) {
|
||||
|
||||
void version() {
|
||||
fprintf(stderr, "pcp version %d.%d.%d, use --help to learn how to use.\n",
|
||||
PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
|
||||
PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -139,163 +139,162 @@ int main (int argc, char **argv) {
|
||||
};
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcmf:b1F:0KAMX:jC",
|
||||
longopts, NULL)) != -1) {
|
||||
longopts, NULL)) != -1) {
|
||||
|
||||
switch (opt) {
|
||||
case 0:
|
||||
switch(lo) {
|
||||
case 's':
|
||||
printf("sign\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
switch(lo) {
|
||||
case 's':
|
||||
printf("sign\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
mode += PCP_MODE_KEYGEN;
|
||||
usevault = 1;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'L':
|
||||
ptx->verbose = 1; /* no break by purpose, turn on -l */
|
||||
case 'l':
|
||||
mode += PCP_MODE_LISTKEYS;
|
||||
usevault = 1;
|
||||
break;
|
||||
mode += PCP_MODE_LISTKEYS;
|
||||
usevault = 1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
mode += PCP_MODE_EXPORT_SECRET;
|
||||
usevault = 1;
|
||||
break;
|
||||
mode += PCP_MODE_EXPORT_SECRET;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'p':
|
||||
mode += PCP_MODE_EXPORT_PUBLIC;
|
||||
usevault = 1;
|
||||
break;
|
||||
mode += PCP_MODE_EXPORT_PUBLIC;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'K':
|
||||
mode += PCP_MODE_IMPORT;
|
||||
usevault = 1;
|
||||
break;
|
||||
mode += PCP_MODE_IMPORT;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'R':
|
||||
mode += PCP_MODE_DELETE_KEY;
|
||||
usevault = 1;
|
||||
break;
|
||||
mode += PCP_MODE_DELETE_KEY;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 't':
|
||||
mode += PCP_MODE_TEXT;
|
||||
usevault = 0;
|
||||
break;
|
||||
mode += PCP_MODE_TEXT;
|
||||
usevault = 0;
|
||||
break;
|
||||
case 'E':
|
||||
mode += PCP_MODE_EDIT;
|
||||
usevault = 1;
|
||||
break;
|
||||
mode += PCP_MODE_EDIT;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'e':
|
||||
mode += PCP_MODE_ENCRYPT;
|
||||
usevault = 1;
|
||||
break;
|
||||
mode += PCP_MODE_ENCRYPT;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'm':
|
||||
mode += PCP_MODE_ENCRYPT_ME;
|
||||
break;
|
||||
mode += PCP_MODE_ENCRYPT_ME;
|
||||
break;
|
||||
case 'd':
|
||||
mode += PCP_MODE_DECRYPT;
|
||||
usevault = 1;
|
||||
break;
|
||||
mode += PCP_MODE_DECRYPT;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'z':
|
||||
case 'a':
|
||||
armor = 1;
|
||||
break;
|
||||
armor = 1;
|
||||
break;
|
||||
case 'Z':
|
||||
armor = 2;
|
||||
break;
|
||||
armor = 2;
|
||||
break;
|
||||
case 'A':
|
||||
anon = 1;
|
||||
break;
|
||||
anon = 1;
|
||||
break;
|
||||
case 'F':
|
||||
if(strncmp(optarg, "pbp", 3) == 0) {
|
||||
exportformat = EXP_FORMAT_PBP;
|
||||
}
|
||||
else if(strncmp(optarg, "pcp", 3) == 0) {
|
||||
exportformat = EXP_FORMAT_NATIVE;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "WARN: Unknown export format specified, using native\n");
|
||||
exportformat = EXP_FORMAT_NATIVE;
|
||||
}
|
||||
break;
|
||||
if(strncmp(optarg, "pbp", 3) == 0) {
|
||||
exportformat = EXP_FORMAT_PBP;
|
||||
}
|
||||
else if(strncmp(optarg, "pcp", 3) == 0) {
|
||||
exportformat = EXP_FORMAT_NATIVE;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "WARN: Unknown export format specified, using native\n");
|
||||
exportformat = EXP_FORMAT_NATIVE;
|
||||
}
|
||||
break;
|
||||
case 'j':
|
||||
#ifdef HAVE_JSON
|
||||
ptx->json = 1;
|
||||
ptx->json = 1;
|
||||
#else
|
||||
fprintf(stderr, "WARN: -j set, but no JSON support compiled in. Recompile with --with-json\n");
|
||||
fprintf(stderr, "WARN: -j set, but no JSON support compiled in. Recompile with --with-json\n");
|
||||
#endif
|
||||
break;
|
||||
break;
|
||||
case 'g':
|
||||
mode += PCP_MODE_SIGN;
|
||||
usevault = 1;
|
||||
break;
|
||||
mode += PCP_MODE_SIGN;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'c':
|
||||
mode += PCP_MODE_VERIFY;
|
||||
usevault = 1;
|
||||
break;
|
||||
mode += PCP_MODE_VERIFY;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'C':
|
||||
mode += PCP_MODE_CHECKSUM;
|
||||
break;
|
||||
mode += PCP_MODE_CHECKSUM;
|
||||
break;
|
||||
case 'f':
|
||||
sigfile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(sigfile, optarg, strlen(optarg)+1);
|
||||
detach = 1;
|
||||
break;
|
||||
sigfile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(sigfile, optarg, strlen(optarg)+1);
|
||||
detach = 1;
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
strncpy(vaultfile, optarg, 1024);
|
||||
break;
|
||||
strncpy(vaultfile, optarg, 1024);
|
||||
break;
|
||||
case 'O':
|
||||
if(strncmp(optarg, "-", 2) > 0) {
|
||||
outfile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(outfile, optarg, strlen(optarg)+1);
|
||||
}
|
||||
break;
|
||||
if(strncmp(optarg, "-", 2) > 0) {
|
||||
outfile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(outfile, optarg, strlen(optarg)+1);
|
||||
}
|
||||
break;
|
||||
case 'I':
|
||||
if(strncmp(optarg, "-", 2) > 0) {
|
||||
infile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(infile, optarg, strlen(optarg)+1);
|
||||
}
|
||||
break;
|
||||
if(strncmp(optarg, "-", 2) > 0) {
|
||||
infile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(infile, optarg, strlen(optarg)+1);
|
||||
}
|
||||
break;
|
||||
case 'X':
|
||||
xpassfile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(xpassfile, optarg, strlen(optarg)+1);
|
||||
xpf = 1;
|
||||
break;
|
||||
xpassfile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(xpassfile, optarg, strlen(optarg)+1);
|
||||
xpf = 1;
|
||||
break;
|
||||
case 'i':
|
||||
keyid = ucmalloc(19);
|
||||
strncpy(keyid, optarg, 19);
|
||||
useid = 1;
|
||||
break;
|
||||
keyid = ucmalloc(19);
|
||||
strncpy(keyid, optarg, 19);
|
||||
useid = 1;
|
||||
break;
|
||||
case 'x':
|
||||
xpass = smalloc(strlen(optarg)+1);
|
||||
strncpy(xpass, optarg, strlen(optarg)+1);
|
||||
break;
|
||||
xpass = smalloc(strlen(optarg)+1);
|
||||
strncpy(xpass, optarg, strlen(optarg)+1);
|
||||
break;
|
||||
case LONG_EXTPASS:
|
||||
askpass = malloc(strlen(optarg)+1);
|
||||
strncpy(askpass, optarg, strlen(optarg)+1);
|
||||
break;
|
||||
askpass = malloc(strlen(optarg)+1);
|
||||
strncpy(askpass, optarg, strlen(optarg)+1);
|
||||
break;
|
||||
case 'r':
|
||||
p_add(&recipient, optarg);
|
||||
userec = 1;
|
||||
break;
|
||||
p_add(&recipient, optarg);
|
||||
userec = 1;
|
||||
break;
|
||||
case 'M':
|
||||
p_add_me(&recipient);
|
||||
userec = 1;
|
||||
break;
|
||||
|
||||
p_add_me(&recipient);
|
||||
userec = 1;
|
||||
break;
|
||||
case 'D':
|
||||
debug = 1;
|
||||
break;
|
||||
debug = 1;
|
||||
break;
|
||||
case '0':
|
||||
version();
|
||||
version();
|
||||
case 'v':
|
||||
ptx->verbose = 1;
|
||||
break;
|
||||
ptx->verbose = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage(0);
|
||||
usage(0);
|
||||
default:
|
||||
usage(1);
|
||||
usage(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,65 +349,65 @@ int main (int argc, char **argv) {
|
||||
switch (mode) {
|
||||
case PCP_MODE_DECRYPT:
|
||||
if(infile == NULL) {
|
||||
infile = extra;
|
||||
useex = 1;
|
||||
infile = extra;
|
||||
useex = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_ENCRYPT:
|
||||
if(infile == NULL) {
|
||||
infile = extra;
|
||||
useex = 1;
|
||||
infile = extra;
|
||||
useex = 1;
|
||||
}
|
||||
else if(userec == 0 && useid == 0) {
|
||||
userec = 1;
|
||||
int i;
|
||||
for (i=0; i<argc; i++) {
|
||||
p_add(&recipient, argv[i]);
|
||||
}
|
||||
userec = 1;
|
||||
int i;
|
||||
for (i=0; i<argc; i++) {
|
||||
p_add(&recipient, argv[i]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_IMPORT:
|
||||
if(infile == NULL) {
|
||||
infile = extra;
|
||||
useex = 1;
|
||||
infile = extra;
|
||||
useex = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_EXPORT_SECRET:
|
||||
case PCP_MODE_EXPORT_PUBLIC:
|
||||
if(outfile == NULL) {
|
||||
outfile = extra;
|
||||
useex = 1;
|
||||
outfile = extra;
|
||||
useex = 1;
|
||||
}
|
||||
else if(useid == 0 && userec == 0) {
|
||||
p_add(&recipient, extra);
|
||||
useex = 1;
|
||||
userec = 1;
|
||||
p_add(&recipient, extra);
|
||||
useex = 1;
|
||||
userec = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_VERIFY:
|
||||
if(infile == NULL) {
|
||||
infile = extra;
|
||||
useex = 1;
|
||||
infile = extra;
|
||||
useex = 1;
|
||||
}
|
||||
else if (useid == 0) {
|
||||
id = extra;
|
||||
useid = 1;
|
||||
useex = 1;
|
||||
id = extra;
|
||||
useid = 1;
|
||||
useex = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_SIGN:
|
||||
if(infile == NULL) {
|
||||
infile = extra;
|
||||
useex = 1;
|
||||
infile = extra;
|
||||
useex = 1;
|
||||
}
|
||||
else if(outfile == NULL && detach == 0) {
|
||||
outfile = extra;
|
||||
useex = 1;
|
||||
outfile = extra;
|
||||
useex = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -457,128 +456,128 @@ int main (int argc, char **argv) {
|
||||
if(vault != NULL) {
|
||||
switch (mode) {
|
||||
case PCP_MODE_KEYGEN:
|
||||
pcp_keygen(xpass);
|
||||
break;
|
||||
pcp_keygen(xpass);
|
||||
break;
|
||||
|
||||
case PCP_MODE_LISTKEYS:
|
||||
pcp_listkeys();
|
||||
break;
|
||||
pcp_listkeys();
|
||||
break;
|
||||
|
||||
case PCP_MODE_EXPORT_SECRET:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcp_exportsecret(id, useid, outfile, armor, xpass);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pcp_exportsecret(NULL, useid, outfile, armor, xpass);
|
||||
}
|
||||
break;
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcp_exportsecret(id, useid, outfile, armor, xpass);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pcp_exportsecret(NULL, useid, outfile, armor, xpass);
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_EXPORT_PUBLIC:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id == NULL)
|
||||
break;
|
||||
}
|
||||
pcp_exportpublic(id, xpass, outfile, exportformat, armor);
|
||||
break;
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id == NULL)
|
||||
break;
|
||||
}
|
||||
pcp_exportpublic(id, xpass, outfile, exportformat, armor);
|
||||
break;
|
||||
|
||||
case PCP_MODE_IMPORT:
|
||||
if(infile == NULL) {
|
||||
altin(NULL, xpf);
|
||||
in = stdin;
|
||||
}
|
||||
else {
|
||||
if((in = fopen(infile, "rb")) == NULL) {
|
||||
fatal(ptx, "Could not open input file %s\n", infile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pcp_import(vault, in, xpass);
|
||||
break;
|
||||
if(infile == NULL) {
|
||||
altin(NULL, xpf);
|
||||
in = stdin;
|
||||
}
|
||||
else {
|
||||
if((in = fopen(infile, "rb")) == NULL) {
|
||||
fatal(ptx, "Could not open input file %s\n", infile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pcp_import(vault, in, xpass);
|
||||
break;
|
||||
|
||||
case PCP_MODE_DELETE_KEY:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpdelete_key(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fatal(ptx, "You need to specify a key id (--keyid)!\n");
|
||||
}
|
||||
break;
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpdelete_key(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fatal(ptx, "You need to specify a key id (--keyid)!\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_EDIT:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpedit_key(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fatal(ptx, "You need to specify a key id (--keyid)!\n");
|
||||
}
|
||||
break;
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpedit_key(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fatal(ptx, "You need to specify a key id (--keyid)!\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_ENCRYPT:
|
||||
if(useid == 1 && userec == 0) {
|
||||
/* one dst, FIXME: make id a list as well */
|
||||
id = pcp_normalize_id(keyid);
|
||||
pcpencrypt(id, altin(infile, xpf), outfile, xpass, NULL, signcrypt, armor, anon);
|
||||
}
|
||||
else if(useid == 0 && userec == 1) {
|
||||
/* multiple dst */
|
||||
pcpencrypt(NULL, altin(infile, xpf), outfile, xpass, recipient, signcrypt, armor, anon);
|
||||
}
|
||||
else {
|
||||
/* -i and -r specified */
|
||||
fatal(ptx, "You can't specify both -i and -r, use either -i or -r!\n");
|
||||
}
|
||||
if(useid == 1 && userec == 0) {
|
||||
/* one dst, FIXME: make id a list as well */
|
||||
id = pcp_normalize_id(keyid);
|
||||
pcpencrypt(id, altin(infile, xpf), outfile, xpass, NULL, signcrypt, armor, anon);
|
||||
}
|
||||
else if(useid == 0 && userec == 1) {
|
||||
/* multiple dst */
|
||||
pcpencrypt(NULL, altin(infile, xpf), outfile, xpass, recipient, signcrypt, armor, anon);
|
||||
}
|
||||
else {
|
||||
/* -i and -r specified */
|
||||
fatal(ptx, "You can't specify both -i and -r, use either -i or -r!\n");
|
||||
}
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case PCP_MODE_DECRYPT:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpdecrypt(id, useid, altin(infile, xpf), outfile, xpass, signcrypt);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pcpdecrypt(NULL, useid, altin(infile, xpf), outfile, xpass, signcrypt);
|
||||
}
|
||||
break;
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpdecrypt(id, useid, altin(infile, xpf), outfile, xpass, signcrypt);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pcpdecrypt(NULL, useid, altin(infile, xpf), outfile, xpass, signcrypt);
|
||||
}
|
||||
break;
|
||||
|
||||
case PCP_MODE_SIGN:
|
||||
if(detach) {
|
||||
if(outfile != NULL && sigfile != NULL)
|
||||
fatal(ptx, "You can't both specify -O and -f, use -O for std signatures and -f for detached ones\n");
|
||||
else
|
||||
pcpsign(altin(infile, xpf), sigfile, xpass, armor, detach);
|
||||
}
|
||||
else
|
||||
pcpsign(altin(infile, xpf), outfile, xpass, armor, detach);
|
||||
break;
|
||||
if(detach) {
|
||||
if(outfile != NULL && sigfile != NULL)
|
||||
fatal(ptx, "You can't both specify -O and -f, use -O for std signatures and -f for detached ones\n");
|
||||
else
|
||||
pcpsign(altin(infile, xpf), sigfile, xpass, armor, detach);
|
||||
}
|
||||
else
|
||||
pcpsign(altin(infile, xpf), outfile, xpass, armor, detach);
|
||||
break;
|
||||
|
||||
case PCP_MODE_VERIFY:
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpverify(altin(infile, xpf), sigfile, id, detach);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pcpverify(altin(infile, xpf), sigfile, NULL, detach);
|
||||
}
|
||||
break;
|
||||
if(useid) {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcpverify(altin(infile, xpf), sigfile, id, detach);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pcpverify(altin(infile, xpf), sigfile, NULL, detach);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/* */
|
||||
goto ELSEMODE;
|
||||
break;
|
||||
/* */
|
||||
goto ELSEMODE;
|
||||
break;
|
||||
}
|
||||
pcpvault_close(ptx, vault);
|
||||
}
|
||||
@@ -600,37 +599,37 @@ int main (int argc, char **argv) {
|
||||
|
||||
case PCP_MODE_TEXT:
|
||||
if(infile != NULL) {
|
||||
pcptext_infile(infile);
|
||||
pcptext_infile(infile);
|
||||
}
|
||||
else {
|
||||
vault = pcpvault_init(ptx, vaultfile);
|
||||
if(! useid && infile == NULL) {
|
||||
pcptext_vault(vault);
|
||||
}
|
||||
else {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcptext_key(id);
|
||||
}
|
||||
}
|
||||
pcpvault_close(ptx, vault);
|
||||
vault = pcpvault_init(ptx, vaultfile);
|
||||
if(! useid && infile == NULL) {
|
||||
pcptext_vault(vault);
|
||||
}
|
||||
else {
|
||||
id = pcp_normalize_id(keyid);
|
||||
if(id != NULL) {
|
||||
pcptext_key(id);
|
||||
}
|
||||
}
|
||||
pcpvault_close(ptx, vault);
|
||||
}
|
||||
break;
|
||||
case PCP_MODE_CHECKSUM:
|
||||
if(infile == NULL) {
|
||||
if(argc == 0) {
|
||||
char *list[1];
|
||||
list[0] = NULL;
|
||||
pcpchecksum(list, 1, xpass);
|
||||
}
|
||||
else {
|
||||
pcpchecksum(argv, argc, xpass);
|
||||
}
|
||||
if(argc == 0) {
|
||||
char *list[1];
|
||||
list[0] = NULL;
|
||||
pcpchecksum(list, 1, xpass);
|
||||
}
|
||||
else {
|
||||
pcpchecksum(argv, argc, xpass);
|
||||
}
|
||||
}
|
||||
else {
|
||||
char *list[1];
|
||||
list[0] = infile;
|
||||
pcpchecksum(list, 1, xpass);
|
||||
char *list[1];
|
||||
list[0] = infile;
|
||||
pcpchecksum(list, 1, xpass);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of Pretty Curved Privacy (pcp1).
|
||||
|
||||
Copyright (C) 2013-2015 T.Linden.
|
||||
Copyright (C) 2013-2016 T.Linden.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -57,7 +57,7 @@ int pcpsign(char *infile, char *outfile, char *passwd, int z85, int detach) {
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(ptx, &passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1, NULL);
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1, NULL);
|
||||
}
|
||||
else {
|
||||
passphrase = smalloc(strlen(passwd)+1);
|
||||
|
||||
Reference in New Issue
Block a user