Browse Source

Main: Reintroduce signing

Reintroducing signing of files and piped input
master
David Lanzendörfer 3 months ago
parent
commit
1f5905394f
1 changed files with 40 additions and 44 deletions
  1. +40
    -44
      src/main.c

+ 40
- 44
src/main.c View File

@ -38,6 +38,10 @@
#include <sys/param.h>
#endif
#ifdef HAVE_OPENSSL_BN_H
#include <openssl/bn.h>
#endif
#include <sys/stat.h>
#include <regex.h>
@ -185,7 +189,6 @@ typedef struct prog_t {
int cmd; /* netpgp command */
} prog_t;
/* print a usage message */
static void
print_usage(const char *usagemsg, char *progname)
@ -375,8 +378,8 @@ int pgp_generate_keypair(netpgp_t *netpgp, prog_t *p)
fprintf(stderr,"No cipher set\n");
return 0;
}*/
cipher = "tripledes";
hashalg = "sha1";
cipher = "aes256";
hashalg = "sha512";
if(snprintf(newid, sizeof(newid), "%s <%s>", username, address) >= sizeof(newid)) return 0;
// Generate the key
@ -398,53 +401,49 @@ int pgp_generate_keypair(netpgp_t *netpgp, prog_t *p)
fprintf(stdout, "Created key with UID: %s\n",newid);
return 0;
return 1;
}
int
sign_data(netpgp_t *netpgp, prog_t *p, char *in, size_t size)
{
/*if (f == NULL) {
cc = stdin_to_mem(netpgp, &in, &out, &maxsize);
ret = pgp_sign_buf(netpgp,
netpgp_getvar(netpgp, "userid"),
in, cc, out,
maxsize, p->armour,
(p->cmd == CLEARSIGN) ? cleartext :
!cleartext);
ret = show_output(out, ret, "Bad memory signature");
free(in);
free(out);
return ret;
}
return netpgp_sign_file(netpgp,
netpgp_getvar(netpgp, "userid"),
f, p->output,
p->armour,
(p->cmd == CLEARSIGN) ? cleartext :
!cleartext,
p->detached);*/
pgp_memory_t *mem;
pgp_seckey_t *seckey = NULL;
pgp_key_t *signer;
char *userid = NULL;
int status;
uint8_t keyid[PGP_KEY_ID_SIZE];
unsigned from = 0;
size_t len = PGP_KEY_ID_SIZE;
userid = netpgp_getvar(netpgp, "userid");
string_to_uint(userid, &keyid, &len);
signer = pgp_getkeybyid(netpgp->io, netpgp->secring, keyid, &from, NULL, NULL, 0, 0 );
seckey = pgp_key_get_certkey(signer);
// Sign data
mem = pgp_sign_buf(
netpgp->io,
in, size,
seckey,
time(NULL), /* birthtime */
0 /* duration */,
"sha1",
p->armour, /* armored */
0, /* cleartext */
&status
);
if(pgp_mem_len(mem)) {
process_output(p, pgp_mem_data(mem), pgp_mem_len(mem));
}
return 1;
}
int
verify_data(netpgp_t *netpgp, prog_t *p, char *in, size_t size)
{
/* TODO
pgp_validation_t *vresult = malloc(sizeof(pgp_validation_t));
pgp_memory_t *mem;
key_id_t *recipients_key_ids = NULL;
unsigned recipients_count = 0;
mem = pgp_validate_buf(
netpgp,
vresult,
in, size,
p->armour,
&recipients_key_ids, &recipients_count
);
*/
return 1;
}
@ -479,7 +478,6 @@ encrypt_data(netpgp_t *netpgp, prog_t *p, char *in, size_t size, int sign)
char *userid = NULL;
char *recipients = NULL;
char *to = NULL;
pgp_io_t* io;
uint8_t keyid[PGP_KEY_ID_SIZE];
size_t len = PGP_KEY_ID_SIZE;
@ -490,8 +488,6 @@ encrypt_data(netpgp_t *netpgp, prog_t *p, char *in, size_t size, int sign)
pgp_keyring_t *rcpts;
pgp_seckey_t *seckey = NULL;
io = netpgp->io;
userid=netpgp_getvar(netpgp, "userid");
recipients=netpgp_getvar(netpgp, "recipients");
if(!userid && sign) {
@ -522,7 +518,7 @@ encrypt_data(netpgp_t *netpgp, prog_t *p, char *in, size_t size, int sign)
// find private key
from=0;
string_to_uint(userid, &keyid, &len);
signer = pgp_getkeybyid(io, netpgp->secring, keyid, &from, NULL, NULL, 0, 0 );
signer = pgp_getkeybyid(netpgp->io, netpgp->secring, keyid, &from, NULL, NULL, 0, 0 );
if(!signer && sign) {
printf("Error! Private key not found! (UID: %s)\n",userid);
return 0;
@ -535,7 +531,7 @@ encrypt_data(netpgp_t *netpgp, prog_t *p, char *in, size_t size, int sign)
to=strtok(recipients,",");
while(to) {
string_to_uint(to, &keyid, &len);
key=pgp_getkeybyid(io, netpgp->pubring, keyid, &from, NULL, NULL, 0, 0 );
key=pgp_getkeybyid(netpgp->io, netpgp->pubring, keyid, &from, NULL, NULL, 0, 0 );
if(key) {
pgp_keyring_add(rcpts,key);
}


Loading…
Cancel
Save