started to implement pbp compatibility, added support for multiple -r options,

using it now to look through the vault for recipients, -i to follow. current
state: encrypt produces output without errors or crashes; decrypt is incompatible
for the moment.
This commit is contained in:
git@daemon.de
2014-01-21 16:11:04 +01:00
parent 6714dd1c3b
commit 26d4ee43c5
8 changed files with 229 additions and 24 deletions

View File

@@ -124,15 +124,33 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
}
else {
// found one by id, copy into local hash
pcp_pubkey_t *pub = ucmalloc(sizeof(pcp_pubkey_t));
pub = ucmalloc(sizeof(pcp_pubkey_t));
memcpy(pub, tmp, sizeof(pcp_pubkey_t));
HASH_ADD_STR( pubhash, id, tmp);
}
}
else if(recipient != NULL) {
// lookup by recipient list
// FIXME: implement, iterate through global hashlist
// copy matches into temporary pubhash
// iterate through global hashlist
// copy matches into temporary pubhash
plist_t *rec;
pcphash_iteratepub(tmp) {
rec = recipient->first;
while (rec->next != 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, tmp);
//fprintf(stderr, " => found a matching key %s\n", tmp->id);
}
rec = rec->next;
}
}
if(HASH_COUNT(pubhash) == 0) {
fatal("no matching key found for specified recipient(s)!\n");
goto erren3;
}
}
else {
fatal("id or recipient list required!\n");
@@ -164,12 +182,22 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
size_t clen = pcp_encrypt_file(in, out, secret, pubhash, self);
if(clen > 0) {
fprintf(stderr, "Encrypted %d bytes for 0x%s successfully\n", (int)clen, id);
if(id != NULL)
fprintf(stderr, "Encrypted %d bytes for 0x%s successfully\n", (int)clen, id);
else {
fprintf(stderr, "Encrypted %d bytes for:\n", (int)clen);
pcp_pubkey_t *cur, *t;
HASH_ITER(hh, pubhash, cur, t) {
fprintf(stderr, "%s <%s>\n", cur->owner, cur->mail);
}
free(t);
free(cur);
}
return 0;
}
erren2:
free(pubhash);
free(pubhash); // FIXME: it's a uthash, dont use free() but func instead
free(tmp);
free(pub);

View File

@@ -490,10 +490,3 @@ char *pcp_find_id_byrec(char *recipient) {
return id;
}
char *_lc(char *in) {
size_t len = strlen(in);
int i;
for(i=0; i<len; ++i)
in[i] = towlower(in[i]);
return in;
}

View File

@@ -38,6 +38,7 @@
#include "readpass.h"
#include "keyprint.h"
#include "keyhash.h"
#include "util.h"
#define _WITH_GETLINE
@@ -55,6 +56,5 @@ int pcp_importpublic (vault_t *vault, FILE *in);
int pcp_importsecret (vault_t *vault, FILE *in);
void pcpdelete_key(char *keyid);
char *pcp_find_id_byrec(char *recipient);
char *_lc(char *in);
#endif // _HAVE_KEYMGMT_H

View File

@@ -63,7 +63,6 @@ int main (int argc, char **argv) {
useid = 0;
userec = 0;
lo = 0;
static struct option longopts[] = {
// generics
{ "vault", required_argument, NULL, 'V' },
@@ -334,7 +333,7 @@ int main (int argc, char **argv) {
}
else if(useid == 0 && userec == 1) {
// multiple dst
pcpencrypt(id, infile, outfile, xpass, recipient);
pcpencrypt(NULL, infile, outfile, xpass, recipient);
}
else if(useid == 0 && userec == 0) {
// self mode
@@ -352,7 +351,7 @@ int main (int argc, char **argv) {
if(xpass != NULL)
free(xpass);
if(recipient != NULL)
free(recipient);
p_clean(recipient);
break;