mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 03:50:57 +01:00
added anonymous sender key (-A) support
This commit is contained in:
@@ -29,6 +29,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
||||
byte *symkey = NULL;
|
||||
size_t dlen;
|
||||
uint8_t head;
|
||||
int anon = 0;
|
||||
|
||||
if(infile == NULL)
|
||||
in = stdin;
|
||||
@@ -77,7 +78,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
||||
ucfree(passphrase, strlen(passwd)+1);
|
||||
free(salt);
|
||||
}
|
||||
else if(head == PCP_ASYM_CIPHER || head == PCP_ASYM_CIPHER_SIG) {
|
||||
else if(head == PCP_ASYM_CIPHER || head == PCP_ASYM_CIPHER_SIG || head == PCP_ASYM_CIPHER_ANON) {
|
||||
/* asymetric mode */
|
||||
if(useid) {
|
||||
secret = pcphash_keyexists(ptx, id);
|
||||
@@ -111,6 +112,9 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
||||
if(secret == NULL)
|
||||
goto errde3;
|
||||
|
||||
if(head == PCP_ASYM_CIPHER_ANON)
|
||||
anon = 1;
|
||||
|
||||
if(head == PCP_ASYM_CIPHER_SIG)
|
||||
verify = 1;
|
||||
}
|
||||
@@ -126,10 +130,10 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, i
|
||||
}
|
||||
|
||||
if(symkey == NULL) {
|
||||
dlen = pcp_decrypt_stream(ptx, pin, pout, secret, NULL, verify);
|
||||
dlen = pcp_decrypt_stream(ptx, pin, pout, secret, NULL, verify, anon);
|
||||
}
|
||||
else {
|
||||
dlen = pcp_decrypt_stream(ptx, pin, pout, NULL, symkey, verify);
|
||||
dlen = pcp_decrypt_stream(ptx, pin, pout, NULL, symkey, verify, 0);
|
||||
ucfree(symkey, 64);
|
||||
}
|
||||
|
||||
@@ -154,7 +158,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 pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *recipient, int signcrypt, int armor, int anon) {
|
||||
FILE *in = NULL;
|
||||
FILE *out = NULL;
|
||||
pcp_pubkey_t *pubhash = NULL; /* FIXME: add free() */
|
||||
@@ -234,32 +238,33 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
||||
|
||||
if(self != 1) {
|
||||
/* we're using a random secret keypair on our side */
|
||||
#ifdef PCP_ASYM_ADD_SENDER_PUB
|
||||
secret = pcpkey_new();
|
||||
#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 erren2;
|
||||
if(anon) {
|
||||
secret = pcpkey_new();
|
||||
}
|
||||
|
||||
if(secret->secret[0] == 0) {
|
||||
/* encrypted, decrypt it */
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(&passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1);
|
||||
}
|
||||
else {
|
||||
passphrase = ucmalloc(strlen(passwd)+1);
|
||||
strncpy(passphrase, passwd, strlen(passwd)+1);
|
||||
}
|
||||
secret = pcpkey_decrypt(ptx, secret, passphrase);
|
||||
ucfree(passphrase, strlen(passwd)+1);
|
||||
if(secret == NULL)
|
||||
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 erren2;
|
||||
}
|
||||
|
||||
if(secret->secret[0] == 0) {
|
||||
/* encrypted, decrypt it */
|
||||
char *passphrase;
|
||||
if(passwd == NULL) {
|
||||
pcp_readpass(&passphrase,
|
||||
"Enter passphrase to decrypt your secret key", NULL, 1);
|
||||
}
|
||||
else {
|
||||
passphrase = ucmalloc(strlen(passwd)+1);
|
||||
strncpy(passphrase, passwd, strlen(passwd)+1);
|
||||
}
|
||||
secret = pcpkey_decrypt(ptx, secret, passphrase);
|
||||
ucfree(passphrase, strlen(passwd)+1);
|
||||
if(secret == NULL)
|
||||
goto erren2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if(infile == NULL)
|
||||
@@ -295,7 +300,7 @@ int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *rec
|
||||
ucfree(symkey, 64);
|
||||
}
|
||||
else {
|
||||
clen = pcp_encrypt_stream(ptx, pin, pout, secret, pubhash, signcrypt);
|
||||
clen = pcp_encrypt_stream(ptx, pin, pout, secret, pubhash, signcrypt, anon);
|
||||
}
|
||||
|
||||
if(armor == 1) {
|
||||
|
||||
@@ -39,6 +39,6 @@
|
||||
#include "context.h"
|
||||
|
||||
int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd, int verify);
|
||||
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *recipient, int signcrypt, int armor);
|
||||
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, plist_t *recipient, int signcrypt, int armor, int anon);
|
||||
|
||||
#endif /* _HAVE_ENCRYPTION_H */
|
||||
|
||||
15
src/pcp.c
15
src/pcp.c
@@ -46,7 +46,7 @@ char *default_vault() {
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int opt, mode, usevault, useid, userec, lo, armor, detach, signcrypt, exportformat;
|
||||
int opt, mode, usevault, useid, userec, lo, armor, detach, signcrypt, exportformat, anon;
|
||||
char *vaultfile = default_vault();
|
||||
char *outfile = NULL;
|
||||
char *infile = NULL;
|
||||
@@ -68,6 +68,7 @@ int main (int argc, char **argv) {
|
||||
armor = 0;
|
||||
detach = 0;
|
||||
signcrypt = 0;
|
||||
anon = 0;
|
||||
exportformat = EXP_FORMAT_NATIVE;
|
||||
|
||||
ptx = ptx_new();
|
||||
@@ -100,6 +101,7 @@ int main (int argc, char **argv) {
|
||||
{ "encrypt", no_argument, NULL, 'e' },
|
||||
{ "encrypt-me", no_argument, NULL, 'm' },
|
||||
{ "decrypt", no_argument, NULL, 'd' },
|
||||
{ "anonymous", no_argument, NULL, 'A' },
|
||||
|
||||
/* encoding */
|
||||
{ "z85-encode", no_argument, NULL, 'z' },
|
||||
@@ -120,7 +122,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:0K",
|
||||
while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcymf:b1F:0KA",
|
||||
longopts, NULL)) != -1) {
|
||||
|
||||
switch (opt) {
|
||||
@@ -185,6 +187,9 @@ int main (int argc, char **argv) {
|
||||
case 'Z':
|
||||
armor = 2;
|
||||
break;
|
||||
case 'A':
|
||||
anon = 1;
|
||||
break;
|
||||
case 'F':
|
||||
if(strncmp(optarg, "pbp", 3) == 0) {
|
||||
exportformat = EXP_FORMAT_PBP;
|
||||
@@ -475,11 +480,11 @@ int main (int argc, char **argv) {
|
||||
if(useid == 1 && userec == 0) {
|
||||
/* one dst, FIXME: make id a list as well */
|
||||
id = pcp_normalize_id(keyid);
|
||||
pcpencrypt(id, infile, outfile, xpass, NULL, signcrypt, armor);
|
||||
pcpencrypt(id, infile, outfile, xpass, NULL, signcrypt, armor, anon);
|
||||
}
|
||||
else if(useid == 0 && userec == 1) {
|
||||
/* multiple dst */
|
||||
pcpencrypt(NULL, infile, outfile, xpass, recipient, signcrypt, armor);
|
||||
pcpencrypt(NULL, infile, outfile, xpass, recipient, signcrypt, armor, anon);
|
||||
}
|
||||
else {
|
||||
/* -i and -r specified */
|
||||
@@ -547,7 +552,7 @@ int main (int argc, char **argv) {
|
||||
break;
|
||||
|
||||
case PCP_MODE_ENCRYPT_ME:
|
||||
pcpencrypt(NULL, infile, outfile, xpass, NULL, 0, armor);
|
||||
pcpencrypt(NULL, infile, outfile, xpass, NULL, 0, armor, 0);
|
||||
break;
|
||||
|
||||
case PCP_MODE_TEXT:
|
||||
|
||||
Reference in New Issue
Block a user