-i is now optional for encryption if recipient specified, -R exchanged with -r, added virtual env for manual tests in tests/env/

This commit is contained in:
TLINDEN
2013-11-03 14:39:16 +01:00
parent bf5556e1ec
commit 79068fce66
29 changed files with 944 additions and 1515 deletions

View File

@@ -547,3 +547,20 @@ void pcpedit_key(char *keyid) {
}
char *pcp_find_id_byrec(char *recipient) {
pcp_pubkey_t *p;
char *id = NULL;
for(p=pcppubkey_hash; p != NULL; p=(pcp_pubkey_t*)(p->hh.next)) {
if(strncmp(p->owner, recipient, 255) == 0) {
id = ucmalloc(17);
strncpy(id, p->id, 17);
break;
}
if(strncmp(p->mail, recipient, 255) == 0) {
id = ucmalloc(17);
strncpy(id, p->id, 17);
break;
}
}
return id;
}

View File

@@ -31,6 +31,6 @@ int pcp_sanitycheck_pub(pcp_pubkey_t *key);
int pcp_importsecret (vault_t *vault, FILE *in);
int pcp_sanitycheck_key(pcp_key_t *key);
void pcpdelete_key(char *keyid);
char *pcp_find_id_byrec(char *recipient);
#endif // _HAVE_KEYMGMT_H

View File

@@ -48,7 +48,7 @@ int main (int argc, char **argv) {
{ "keyid", required_argument, NULL, 'i' },
{ "text", required_argument, NULL, 't' },
{ "xpass", required_argument, NULL, 'x' },
{ "recipient", required_argument, NULL, 'R' },
{ "recipient", required_argument, NULL, 'r' },
// key management
{ "keygen", no_argument, NULL, 'k' },
@@ -57,7 +57,7 @@ int main (int argc, char **argv) {
{ "export-public", no_argument, NULL, 'p' },
{ "import-secret", no_argument, NULL, 'S' },
{ "import-public", no_argument, NULL, 'P' },
{ "remove-key", no_argument, NULL, 'r' },
{ "remove-key", no_argument, NULL, 'R' },
{ "edit-key", no_argument, NULL, 'E' },
// crypto
@@ -75,7 +75,7 @@ int main (int argc, char **argv) {
{ NULL, 0, NULL, 0 }
};
while ((opt = getopt_long(argc, argv, "klV:vdehsO:i:I:pSPrtEx:DzZR:",
while ((opt = getopt_long(argc, argv, "klV:vdehsO:i:I:pSPRtEx:DzZr:",
longopts, NULL)) != -1) {
switch (opt) {
@@ -105,7 +105,7 @@ int main (int argc, char **argv) {
mode += PCP_MODE_IMPORT_SECRET;
usevault = 1;
break;
case 'r':
case 'R':
mode += PCP_MODE_DELETE_KEY;
usevault = 1;
break;
@@ -153,7 +153,7 @@ int main (int argc, char **argv) {
xpass = ucmalloc(strlen(optarg)+1);
strncpy(xpass, optarg, strlen(optarg)+1);
break;
case 'R':
case 'r':
recipient = ucmalloc(strlen(optarg)+1);
strncpy(recipient, optarg, strlen(optarg)+1);
userec = 1;
@@ -289,17 +289,20 @@ int main (int argc, char **argv) {
case PCP_MODE_ENCRYPT:
if(useid) {
id = pcp_normalize_id(keyid);
if(id != NULL) {
pcpencrypt(id, infile, outfile, xpass, recipient);
free(id);
if(xpass != NULL)
free(xpass);
if(recipient != NULL)
free(recipient);
}
}
if(useid == 0 && userec == 1) {
id = pcp_find_id_byrec(recipient);
}
if(id != NULL) {
pcpencrypt(id, infile, outfile, xpass, recipient);
free(id);
if(xpass != NULL)
free(xpass);
if(recipient != NULL)
free(recipient);
}
else {
fatal("You need to specify a key id (--keyid)!\n");
fatal("You need to specify a key id (--keyid) or a recipient (--recipient)!\n");
}
break;

View File

@@ -11,7 +11,7 @@
"-I --infile <file> Input file. If not specified, stdin\n" \
" will be used.\n" \
"-i --keyid <id> Specify a key id to import/export.\n" \
"-R --recipient <string> Specify a recpipient, used for public\n" \
"-r --recipient <string> Specify a recpipient, used for public\n" \
" key export and encryption.\n" \
"-t --text Print textual representation of some\n" \
" item. Either -V or -i must be specified\n" \
@@ -29,7 +29,7 @@
" vault. Only the key id's and some info\n" \
" about the keys will be printed, not the\n" \
" actual keys.\n" \
"-r --remove-key Remove a key from the vault. Requires\n" \
"-R --remove-key Remove a key from the vault. Requires\n" \
" option -i <keyid>.\n" \
"-s --export-secret Export a secret key. If your vault only\n" \
" contains one secret key, this one will\n" \

View File

@@ -9,7 +9,7 @@ General Options:
-I --infile <file> Input file. If not specified, stdin
will be used.
-i --keyid <id> Specify a key id to import/export.
-R --recipient <string> Specify a recpipient, used for public
-r --recipient <string> Specify a recpipient, used for public
key export and encryption.
-t --text Print textual representation of some
item. Either -V or -i must be specified
@@ -27,7 +27,7 @@ Keymanagement Options:
vault. Only the key id's and some info
about the keys will be printed, not the
actual keys.
-r --remove-key Remove a key from the vault. Requires
-R --remove-key Remove a key from the vault. Requires
option -i <keyid>.
-s --export-secret Export a secret key. If your vault only
contains one secret key, this one will