mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 20:00:58 +01:00
added -M; removed CBC support, fixed asym-self-mode
This commit is contained in:
@@ -166,11 +166,11 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
||||
pcp_pubkey_t *pub = NULL;
|
||||
pcp_key_t *secret = NULL;
|
||||
byte *symkey = NULL;
|
||||
int self = 0;
|
||||
int symmode = 0;
|
||||
|
||||
if(id == NULL && recipient == NULL) {
|
||||
/* self mode */
|
||||
self = 1;
|
||||
/* sym mode */
|
||||
symmode = 1;
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(&passphrase,
|
||||
@@ -195,8 +195,9 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
||||
pcp_key_t *s = pcphash_keyexists(ptx, id);
|
||||
if(s != NULL) {
|
||||
tmp = pcpkey_pub_from_secret(s);
|
||||
HASH_ADD_STR( pubhash, id, tmp);
|
||||
self = 1;
|
||||
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",
|
||||
@@ -220,7 +221,8 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
||||
rec = recipient->first;
|
||||
while (rec != NULL) {
|
||||
_lc(rec->value);
|
||||
if(strnstr(tmp->mail, rec->value, 255) != NULL || strnstr(tmp->owner, rec->value, 255) != NULL) {
|
||||
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);
|
||||
@@ -229,6 +231,19 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
||||
rec = rec->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* look if we need to add ourselfes */
|
||||
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;
|
||||
}
|
||||
rec = rec->next;
|
||||
}
|
||||
|
||||
if(HASH_COUNT(pubhash) == 0) {
|
||||
fatal(ptx, "no matching key found for specified recipient(s)!\n");
|
||||
goto erren3;
|
||||
@@ -236,7 +251,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
||||
}
|
||||
|
||||
|
||||
if(self != 1) {
|
||||
if(symmode != 1) {
|
||||
/* we're using a random secret keypair on our side */
|
||||
if(anon) {
|
||||
secret = pcpkey_new();
|
||||
@@ -295,7 +310,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
||||
ps_armor(pout, PCP_BLOCK_SIZE/2);
|
||||
}
|
||||
|
||||
if(self == 1) {
|
||||
if(symmode == 1) {
|
||||
clen = pcp_encrypt_stream_sym(ptx, pin, pout, symkey, 0, NULL);
|
||||
sfree(symkey);
|
||||
}
|
||||
@@ -339,5 +354,8 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
||||
|
||||
erren3:
|
||||
|
||||
if(tmp != NULL)
|
||||
ucfree(tmp, sizeof(pcp_pubkey_t));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -99,9 +99,10 @@ int main (int argc, char **argv) {
|
||||
|
||||
/* crypto */
|
||||
{ "encrypt", no_argument, NULL, 'e' },
|
||||
{ "encrypt-me", no_argument, NULL, 'm' },
|
||||
{ "encrypt-sym", no_argument, NULL, 'm' },
|
||||
{ "decrypt", no_argument, NULL, 'd' },
|
||||
{ "anonymous", no_argument, NULL, 'A' },
|
||||
{ "add-myself", no_argument, NULL, 'M' },
|
||||
|
||||
/* encoding */
|
||||
{ "z85-encode", no_argument, NULL, 'z' },
|
||||
@@ -122,7 +123,7 @@ int main (int argc, char **argv) {
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcymf:b1F:0KA",
|
||||
while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcymf:b1F:0KAM",
|
||||
longopts, NULL)) != -1) {
|
||||
|
||||
switch (opt) {
|
||||
@@ -265,6 +266,10 @@ int main (int argc, char **argv) {
|
||||
p_add(&recipient, optarg);
|
||||
userec = 1;
|
||||
break;
|
||||
case 'M':
|
||||
p_add_me(&recipient);
|
||||
userec = 1;
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
debug = 1;
|
||||
|
||||
Reference in New Issue
Block a user