mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 03:50:57 +01:00
added -L, enhanced -E
This commit is contained in:
@@ -120,7 +120,7 @@ void pcp_listkeys() {
|
||||
int nkeys = HASH_COUNT(pcpkey_hash) + HASH_COUNT(pcppubkey_hash);
|
||||
|
||||
if(nkeys > 0) {
|
||||
printf("Key ID Type Creation Time Owner\n");
|
||||
printf("Key ID Type Creation Time Owner\n");
|
||||
|
||||
pcphash_iterate(k) {
|
||||
pcpkey_printlineinfo(k);
|
||||
@@ -600,31 +600,76 @@ void pcpdelete_key(char *keyid) {
|
||||
|
||||
void pcpedit_key(char *keyid) {
|
||||
pcp_key_t *key = pcphash_keyexists(keyid);
|
||||
|
||||
|
||||
if(key != NULL) {
|
||||
if(key->secret[0] == 0) {
|
||||
char *passphrase;
|
||||
pcp_readpass(&passphrase, "Enter passphrase to decrypt the key", NULL, 1);
|
||||
key = pcpkey_decrypt(key, passphrase);
|
||||
ucfree(passphrase, strlen(passphrase));
|
||||
}
|
||||
|
||||
if(key != NULL) {
|
||||
char *owner = pcp_getstdin("Enter the name of the key owner");
|
||||
memcpy(key->owner, owner, strlen(owner) + 1);
|
||||
fprintf(stderr, "Current owner: %s\n", key->owner);
|
||||
char *owner = pcp_getstdin(" enter new name or press enter to keep current");
|
||||
if(strlen(owner) > 0)
|
||||
memcpy(key->owner, owner, strlen(owner) + 1);
|
||||
|
||||
char *mail = pcp_getstdin("Enter the email address of the key owner");
|
||||
memcpy(key->mail, mail, strlen(mail) + 1);
|
||||
fprintf(stderr, "Current mail: %s\n", key->mail);
|
||||
char *mail = pcp_getstdin(" enter new email or press enter to keep current");
|
||||
if(strlen(mail) > 0)
|
||||
memcpy(key->mail, mail, strlen(mail) + 1);
|
||||
|
||||
free(owner);
|
||||
free(mail);
|
||||
|
||||
if(key->type != PCP_KEY_TYPE_MAINSECRET) {
|
||||
pcp_key_t *other = NULL;
|
||||
uint8_t haveprimary = 0;
|
||||
pcphash_iterate(other) {
|
||||
if(other->type == PCP_KEY_TYPE_MAINSECRET) {
|
||||
haveprimary = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char *yes = NULL;
|
||||
if(! haveprimary) {
|
||||
fprintf(stderr, "There is currently no primary secret in your vault,\n");
|
||||
yes = pcp_getstdin("want to make this one the primary [yes|NO]?");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "The key %s is currently the primary secret,\n", other->id);
|
||||
yes = pcp_getstdin("want to make this one the primary instead [yes|NO]?");
|
||||
}
|
||||
|
||||
if(strncmp(yes, "yes", 1024) == 0) {
|
||||
key->type = PCP_KEY_TYPE_MAINSECRET;
|
||||
if(haveprimary) {
|
||||
fprintf(stderr, "other type: %d\n", other->type);
|
||||
other->type = PCP_KEY_TYPE_SECRET;
|
||||
fprintf(stderr, " new type: %d\n", other->type);
|
||||
}
|
||||
}
|
||||
free(yes);
|
||||
}
|
||||
|
||||
char *passphrase;
|
||||
pcp_readpass(&passphrase, "Enter passphrase for key encryption", NULL, 1);
|
||||
key = pcpkey_encrypt(key, passphrase);
|
||||
pcp_readpass(&passphrase,
|
||||
"Enter new passphrase for key encryption (press enter to keep current)",
|
||||
"Enter the passphrase again", 1);
|
||||
|
||||
if(strnlen(passphrase, 1024) > 0) {
|
||||
key = pcpkey_encrypt(key, passphrase);
|
||||
ucfree(passphrase, strlen(passphrase));
|
||||
}
|
||||
|
||||
if(key != NULL) {
|
||||
if(debug)
|
||||
pcp_dumpkey(key);
|
||||
|
||||
vault->unsafed = 1; /* will be safed automatically */
|
||||
fprintf(stderr, "Key key changed.\n");
|
||||
fprintf(stderr, "Key %s changed.\n", key->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,21 +123,72 @@ void pcpkey_printlineinfo(pcp_key_t *key) {
|
||||
c = localtime(&t);
|
||||
printf("0x%s %s %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n",
|
||||
key->id,
|
||||
(key->type == PCP_KEY_TYPE_MAINSECRET) ? "primary" : " secret",
|
||||
(key->type == PCP_KEY_TYPE_MAINSECRET) ? "primary secret" : "secret ",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec,
|
||||
key->owner, key->mail);
|
||||
|
||||
if(PCPVERBOSE) {
|
||||
printf(" ");
|
||||
byte *hash = pcpkey_getchecksum(key);
|
||||
int i, y;
|
||||
for(i=0; i<32; i+=4) {
|
||||
for(y=0; y<4; y++) {
|
||||
printf("%02x", hash[i+y]);
|
||||
}
|
||||
printf(" ");
|
||||
}
|
||||
free(hash);
|
||||
printf("\n encrypted: %s, serial: %08x, version: %d\n",
|
||||
(key->secret[0] == '\0') ? "yes" : " no",
|
||||
key->serial, (int)key->version);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void pcppubkey_printlineinfo(pcp_pubkey_t *key) {
|
||||
struct tm *c;
|
||||
time_t t = (time_t)key->ctime;
|
||||
c = localtime(&t);
|
||||
printf("0x%s public %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n",
|
||||
printf("0x%s %s %04d-%02d-%02dT%02d:%02d:%02d %s <%s>\n",
|
||||
key->id,
|
||||
(key->valid == 1) ? "valid public " : "public ",
|
||||
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
||||
c->tm_hour, c->tm_min, c->tm_sec,
|
||||
key->owner, key->mail);
|
||||
|
||||
if(PCPVERBOSE) {
|
||||
printf(" ");
|
||||
byte *hash = pcppubkey_getchecksum(key);
|
||||
int i, y;
|
||||
for(i=0; i<32; i+=4) {
|
||||
for(y=0; y<4; y++) {
|
||||
printf("%02x", hash[i+y]);
|
||||
}
|
||||
printf(" ");
|
||||
}
|
||||
free(hash);
|
||||
printf("\n signed: %s, serial: %08x, version: %d, ",
|
||||
(key->valid == 1) ? "yes" : " no",
|
||||
key->serial, (int)key->version);
|
||||
pcp_keysig_t *sig = pcphash_keysigexists(key->id);
|
||||
if(sig != NULL) {
|
||||
printf("signature fingerprint:\n ");
|
||||
byte *checksum = sig->checksum;
|
||||
for(i=0; i<32; i+=4) {
|
||||
for(y=0; y<4; y++) {
|
||||
printf("%02x", checksum[i+y]);
|
||||
}
|
||||
printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
else {
|
||||
printf("fail: no signature stored.\n");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void pcppubkey_print(pcp_pubkey_t *key, FILE* out) {
|
||||
|
||||
42
src/pcp.c
42
src/pcp.c
@@ -71,6 +71,8 @@ int main (int argc, char **argv) {
|
||||
signcrypt = 0;
|
||||
exportformat = EXP_FORMAT_NATIVE;
|
||||
|
||||
PCPVERBOSE = 0;
|
||||
|
||||
static struct option longopts[] = {
|
||||
/* generics */
|
||||
{ "vault", required_argument, NULL, 'V' },
|
||||
@@ -84,27 +86,33 @@ int main (int argc, char **argv) {
|
||||
/* key management */
|
||||
{ "keygen", no_argument, NULL, 'k' },
|
||||
{ "listkeys", no_argument, NULL, 'l' },
|
||||
{ "listkeys-verbose",no_argument, NULL, 'L' }, /* alias for -l -v */
|
||||
{ "export-secret", no_argument, NULL, 's' },
|
||||
{ "export-public", no_argument, NULL, 'p' },
|
||||
{ "export", no_argument, NULL, 'p' }, /* alias -p */
|
||||
{ "import-secret", no_argument, NULL, 'S' },
|
||||
{ "import-public", no_argument, NULL, 'P' },
|
||||
{ "import", no_argument, NULL, 'P' }, /* alias -P */
|
||||
{ "remove-key", no_argument, NULL, 'R' },
|
||||
{ "edit-key", no_argument, NULL, 'E' },
|
||||
{ "export-yaml", no_argument, NULL, 'y' },
|
||||
{ "export-format", required_argument, NULL, 'F' },
|
||||
|
||||
/* crypto */
|
||||
{ "encrypt", no_argument, NULL, 'e' },
|
||||
{ "encrypt-me", no_argument, NULL, 'm' },
|
||||
{ "decrypt", no_argument, NULL, 'd' },
|
||||
{ "encrypt", no_argument, NULL, 'e' },
|
||||
{ "encrypt-me", no_argument, NULL, 'm' },
|
||||
{ "decrypt", no_argument, NULL, 'd' },
|
||||
|
||||
/* encoding */
|
||||
{ "z85-encode", no_argument, NULL, 'z' },
|
||||
{ "z85-decode", no_argument, NULL, 'Z' },
|
||||
{ "z85-encode", no_argument, NULL, 'z' },
|
||||
{ "armor", no_argument, NULL, 'a' }, /* alias -z */
|
||||
{ "textmode", no_argument, NULL, 'a' }, /* alias -z */
|
||||
{ "z85-decode", no_argument, NULL, 'Z' },
|
||||
|
||||
/* globals */
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'v' },
|
||||
{ "version", no_argument, NULL, '0' }, /* no short opt, FIXME: how to avoid? */
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "debug", no_argument, NULL, 'D' },
|
||||
|
||||
/* signing */
|
||||
@@ -114,7 +122,7 @@ int main (int argc, char **argv) {
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "klV:vdehsO:i:I:pSPRtEx:DzZr:gcymf:b1F:",
|
||||
while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcymf:b1F:0",
|
||||
longopts, NULL)) != -1) {
|
||||
|
||||
switch (opt) {
|
||||
@@ -130,6 +138,8 @@ int main (int argc, char **argv) {
|
||||
mode += PCP_MODE_KEYGEN;
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'L':
|
||||
PCPVERBOSE = 1; /* no break by purpose, turn on -l */
|
||||
case 'l':
|
||||
mode += PCP_MODE_LISTKEYS;
|
||||
usevault = 1;
|
||||
@@ -175,6 +185,7 @@ int main (int argc, char **argv) {
|
||||
usevault = 1;
|
||||
break;
|
||||
case 'z':
|
||||
case 'a':
|
||||
armor = 1;
|
||||
break;
|
||||
case 'Z':
|
||||
@@ -229,12 +240,16 @@ int main (int argc, char **argv) {
|
||||
strncpy(vaultfile, optarg, 1024);
|
||||
break;
|
||||
case 'O':
|
||||
outfile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(outfile, optarg, strlen(optarg)+1);
|
||||
if(strncmp(optarg, "-", 2) > 0) {
|
||||
outfile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(outfile, optarg, strlen(optarg)+1);
|
||||
}
|
||||
break;
|
||||
case 'I':
|
||||
infile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(infile, optarg, strlen(optarg)+1);
|
||||
if(strncmp(optarg, "-", 2) > 0) {
|
||||
infile = ucmalloc(strlen(optarg)+1);
|
||||
strncpy(infile, optarg, strlen(optarg)+1);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
keyid = ucmalloc(19);
|
||||
@@ -255,8 +270,11 @@ int main (int argc, char **argv) {
|
||||
case 'D':
|
||||
debug = 1;
|
||||
break;
|
||||
case 'v':
|
||||
case '0':
|
||||
version();
|
||||
case 'v':
|
||||
PCPVERBOSE = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage(0);
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user