2013-11-04 17:43:22 +01:00
|
|
|
/*
|
|
|
|
|
This file is part of Pretty Curved Privacy (pcp1).
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2013 T.Linden.
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
You can contact me by mail: <tlinden AT cpan DOT org>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2013-10-28 22:50:05 +01:00
|
|
|
#include "keyprint.h"
|
|
|
|
|
|
|
|
|
|
|
2013-11-12 16:58:59 +01:00
|
|
|
int pcptext_infile(char *infile) {
|
|
|
|
|
FILE *in;
|
|
|
|
|
int insize;
|
|
|
|
|
|
|
|
|
|
if((in = fopen(infile, "rb")) == NULL) {
|
|
|
|
|
fatal("Could not open input file %s\n", infile);
|
|
|
|
|
goto errtinf1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fseek(in, 0, SEEK_END);
|
|
|
|
|
insize = ftell(in);
|
|
|
|
|
fseek(in, 0, SEEK_SET);
|
|
|
|
|
|
|
|
|
|
if(insize == 40) {
|
|
|
|
|
fprintf(stdout, "%s seems to be an empty vault file\n", infile);
|
|
|
|
|
goto tdone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// maybe a vault?
|
|
|
|
|
vault_t *v = pcpvault_init(infile);
|
|
|
|
|
if(v != NULL) {
|
|
|
|
|
fprintf(stdout, "%s is a vault file\n", infile);
|
|
|
|
|
pcptext_vault(v);
|
|
|
|
|
goto tdone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// try z85ing it
|
|
|
|
|
char *z85 = pcp_readz85file(in);
|
|
|
|
|
if(z85 == NULL) {
|
|
|
|
|
fprintf(stdout, "Can't handle %s - unknown file type.\n", infile);
|
|
|
|
|
goto errtinf1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t clen;
|
|
|
|
|
unsigned char *bin = pcp_z85_decode((char *)z85, &clen);
|
|
|
|
|
free(z85);
|
2013-11-18 17:38:03 +01:00
|
|
|
|
2013-11-12 16:58:59 +01:00
|
|
|
if(bin == NULL) {
|
|
|
|
|
fprintf(stdout, "%s isn't properly Z85 encoded - unknown file type.\n", infile);
|
|
|
|
|
goto errtinf1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-18 17:38:03 +01:00
|
|
|
//fprintf(stdout, "have: %d, secret: %d, public: %d, sig: %d, hh: %d\n", (int)clen,
|
|
|
|
|
// (int)sizeof(pcp_key_t), (int)sizeof(pcp_pubkey_t), (int)sizeof(pcp_sig_t), (int)sizeof(UT_hash_handle));
|
|
|
|
|
|
|
|
|
|
if(clen == PCP_RAW_KEYSIZE) {
|
2013-11-12 16:58:59 +01:00
|
|
|
// secret key?
|
|
|
|
|
pcp_key_t *key = (pcp_key_t *)bin;
|
|
|
|
|
key2native(key);
|
|
|
|
|
if(pcp_sanitycheck_key(key) == 0) {
|
|
|
|
|
fprintf(stdout, "%s is a secret key file:\n", infile);
|
|
|
|
|
pcpkey_print(key, stdout);
|
|
|
|
|
free(key);
|
|
|
|
|
goto tdone;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(stdout, "%s looks like a secret key but failed sanity checking.\n", infile);
|
|
|
|
|
free(key);
|
|
|
|
|
goto errtinf1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-18 17:38:03 +01:00
|
|
|
if(clen == PCP_RAW_PUBKEYSIZE) {
|
2013-11-12 16:58:59 +01:00
|
|
|
// public key?
|
|
|
|
|
pcp_pubkey_t *key = (pcp_pubkey_t *)bin;
|
|
|
|
|
pubkey2native(key);
|
|
|
|
|
if(pcp_sanitycheck_pub(key) == 0) {
|
|
|
|
|
fprintf(stdout, "%s is a public key file:\n", infile);
|
2014-01-28 16:53:26 +01:00
|
|
|
pcppubkey_print(key, stdout, 0);
|
2013-11-12 16:58:59 +01:00
|
|
|
free(key);
|
|
|
|
|
goto tdone;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(stdout, "%s looks like a publickey but failed sanity checking.\n", infile);
|
|
|
|
|
free(key);
|
|
|
|
|
goto errtinf1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// still there?
|
|
|
|
|
fprintf(stdout, "%s looks Z85 encoded but otherwise unknown and is possibly encrypted.\n", infile);
|
|
|
|
|
|
|
|
|
|
tdone:
|
|
|
|
|
fatals_reset();
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
errtinf1:
|
|
|
|
|
fatals_reset();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-10-28 22:50:05 +01:00
|
|
|
void pcptext_key(char *keyid) {
|
2013-11-13 13:06:01 +01:00
|
|
|
pcp_key_t *s = pcphash_keyexists(keyid);
|
2013-10-28 22:50:05 +01:00
|
|
|
if(s != NULL) {
|
2013-11-08 12:50:04 +01:00
|
|
|
if(debug)
|
|
|
|
|
pcp_dumpkey(s);
|
2013-10-28 22:50:05 +01:00
|
|
|
pcpkey_print(s, stdout);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-11-13 13:06:01 +01:00
|
|
|
pcp_pubkey_t *p = pcphash_pubkeyexists(keyid);
|
2013-10-28 22:50:05 +01:00
|
|
|
if(p != NULL) {
|
2013-11-08 12:50:04 +01:00
|
|
|
if(debug)
|
|
|
|
|
pcp_dumppubkey(p);
|
2014-01-28 16:53:26 +01:00
|
|
|
pcppubkey_print(p, stdout, 0);
|
2013-10-28 22:50:05 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fatal("No key with id 0x%s found!\n", keyid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pcptext_vault(vault_t *vault) {
|
|
|
|
|
printf(" Key vault: %s\n", vault->filename);
|
|
|
|
|
printf("Vault version: %08X\n", vault->version);
|
|
|
|
|
printf(" Checksum: ");
|
|
|
|
|
|
|
|
|
|
int i;
|
2013-11-03 19:38:35 +01:00
|
|
|
for ( i = 0;i <15 ;++i) printf("%02X:",(unsigned int) vault->checksum[i]);
|
|
|
|
|
printf("%02X", vault->checksum[15]);
|
2013-10-28 22:50:05 +01:00
|
|
|
printf("\n ");
|
2013-11-03 19:38:35 +01:00
|
|
|
for ( i = 16;i <31 ;++i) printf("%02X:",(unsigned int) vault->checksum[i]);
|
|
|
|
|
printf("%02X", vault->checksum[31]);
|
2013-10-28 22:50:05 +01:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
printf(" Secret keys: %d\n", HASH_COUNT(pcpkey_hash));
|
|
|
|
|
printf(" Public keys: %d\n", HASH_COUNT(pcppubkey_hash));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pcpkey_printlineinfo(pcp_key_t *key) {
|
|
|
|
|
struct tm *c;
|
|
|
|
|
time_t t = (time_t)key->ctime;
|
|
|
|
|
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",
|
|
|
|
|
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
|
|
|
|
c->tm_hour, c->tm_min, c->tm_sec,
|
|
|
|
|
key->owner, key->mail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
|
key->id,
|
|
|
|
|
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
|
|
|
|
c->tm_hour, c->tm_min, c->tm_sec,
|
|
|
|
|
key->owner, key->mail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void pcpkey_print(pcp_key_t *key, FILE* out) {
|
|
|
|
|
size_t zlen;
|
2013-11-04 14:03:43 +01:00
|
|
|
key2be(key);
|
2013-11-18 17:38:03 +01:00
|
|
|
void *blob = ucmalloc(PCP_RAW_KEYSIZE);
|
|
|
|
|
pcp_seckeyblob(blob, key);
|
|
|
|
|
char *z85encoded = pcp_z85_encode((unsigned char*)blob, PCP_RAW_KEYSIZE, &zlen);
|
2013-11-04 14:03:43 +01:00
|
|
|
key2native(key);
|
2013-10-28 22:50:05 +01:00
|
|
|
|
2013-11-18 17:38:03 +01:00
|
|
|
free(blob);
|
|
|
|
|
|
2013-10-28 22:50:05 +01:00
|
|
|
struct tm *c;
|
|
|
|
|
time_t t = (time_t)key->ctime;
|
|
|
|
|
c = localtime(&t);
|
|
|
|
|
|
|
|
|
|
fprintf(out, "%s\n", PCP_KEY_HEADER);
|
|
|
|
|
|
|
|
|
|
fprintf(out, " Generated by: %s Version %d.%d.%d\n",
|
|
|
|
|
PCP_ME, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
|
|
|
|
|
|
|
|
|
|
fprintf(out, " Cipher: %s\n", PCP_KEY_PRIMITIVE);
|
|
|
|
|
|
|
|
|
|
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
|
|
|
|
|
|
|
|
|
//2004-06-14T23:34:30.
|
|
|
|
|
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
|
|
|
|
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
|
|
|
|
c->tm_hour, c->tm_min, c->tm_sec);
|
|
|
|
|
|
|
|
|
|
fprintf(out, " Serial Number: 0x%08X\n", key->serial);
|
|
|
|
|
fprintf(out, " Key Version: 0x%08X\n", key->version);
|
|
|
|
|
|
|
|
|
|
fprintf(out, "\n%s\n", z85encoded);
|
|
|
|
|
|
|
|
|
|
fprintf(out, "%s\n", PCP_KEY_FOOTER);
|
|
|
|
|
|
|
|
|
|
free(z85encoded);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
void pcppubkey_print(pcp_pubkey_t *key, FILE* out, int pbpcompat) {
|
|
|
|
|
struct tm *c;
|
|
|
|
|
time_t t = (time_t)key->ctime;
|
|
|
|
|
c = localtime(&t);
|
2013-11-18 21:48:24 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
if(pbpcompat == 1) {
|
|
|
|
|
// sign(mk, master public | cipher public | sign public | created[32] | valid[32] | name... )
|
|
|
|
|
// dates='{:<32}{:<32}'.format(self.created.isoformat(), self.valid.isoformat())
|
|
|
|
|
// fd.write(nacl.crypto_sign(self.mp+self.sp+self.cp+dates+self.name, self.ms))
|
|
|
|
|
// >>> dates='{:<32}{:<32}'.format(c.isoformat(), c.isoformat())
|
|
|
|
|
// >>> dates
|
|
|
|
|
// '2014-01-28T13:30:32.674394 2014-01-28T13:30:32.674394 '
|
2014-01-30 13:16:26 +01:00
|
|
|
size_t namelen = strlen(key->owner) + 2 + strlen(key->mail);
|
|
|
|
|
pbp_pubkey_t *b = ucmalloc(sizeof(pbp_pubkey_t));
|
|
|
|
|
memcpy(b->pub, key->pub, crypto_box_PUBLICKEYBYTES);
|
|
|
|
|
memcpy(b->edpub, key->edpub, crypto_sign_PUBLICKEYBYTES);
|
|
|
|
|
memcpy(b->sigpub, key->pub, crypto_box_PUBLICKEYBYTES);
|
|
|
|
|
sprintf(b->name, "%s<%s>", key->owner, key->mail);
|
2014-01-28 16:53:26 +01:00
|
|
|
|
|
|
|
|
struct tm *v;
|
|
|
|
|
time_t vt = t + 31536000;
|
|
|
|
|
v = localtime(&vt);
|
|
|
|
|
|
2014-01-30 13:16:26 +01:00
|
|
|
char *date = ucmalloc(65);
|
|
|
|
|
|
|
|
|
|
sprintf(date, "%04d-%02d-%02dT%02d:%02d:%02d %04d-%02d-%02dT%02d:%02d:%02d ",
|
2014-01-28 16:53:26 +01:00
|
|
|
c->tm_year+1900-1, c->tm_mon+1, c->tm_mday, // wtf? why -1?
|
|
|
|
|
c->tm_hour, c->tm_min, c->tm_sec,
|
|
|
|
|
v->tm_year+1900-1, v->tm_mon+1, v->tm_mday,
|
|
|
|
|
v->tm_hour, v->tm_min, v->tm_sec);
|
|
|
|
|
|
2014-01-30 13:16:26 +01:00
|
|
|
memcpy(b->iso_ctime, date, 32);
|
|
|
|
|
memcpy(b->iso_expire, &date[32], 32);
|
2014-01-28 16:53:26 +01:00
|
|
|
|
2014-01-30 13:16:26 +01:00
|
|
|
size_t pbplen = sizeof(pbp_pubkey_t) - (1024 - namelen);
|
2014-01-28 16:53:26 +01:00
|
|
|
|
|
|
|
|
pcp_key_t *secret = NULL;
|
|
|
|
|
secret = pcp_find_primary_secret();
|
|
|
|
|
|
|
|
|
|
if(secret == NULL) {
|
|
|
|
|
fatal("Could not find a secret key in vault %s!\n", vault->filename);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
char *passphrase;
|
|
|
|
|
pcp_readpass(&passphrase,
|
|
|
|
|
"Enter passphrase to decrypt your secret key for signing the export", NULL, 1);
|
|
|
|
|
|
|
|
|
|
secret = pcpkey_decrypt(secret, passphrase);
|
|
|
|
|
if(secret != NULL) {
|
2014-01-30 13:16:26 +01:00
|
|
|
unsigned char *sig = pcp_ed_sign((unsigned char*)b, pbplen, secret);
|
|
|
|
|
if(sig != NULL) {
|
|
|
|
|
size_t siglen = pbplen + crypto_sign_BYTES;
|
|
|
|
|
size_t blen = ((siglen / 4) * 5) + siglen + 1;
|
|
|
|
|
char *b85sig = ucmalloc(blen);
|
|
|
|
|
encode_85(b85sig, sig, siglen);
|
|
|
|
|
fprintf(out, "%s", b85sig);
|
|
|
|
|
free(b85sig);
|
|
|
|
|
free(sig);
|
|
|
|
|
}
|
2014-01-28 16:53:26 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
size_t zlen;
|
2013-11-18 21:48:24 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
//printf("version: %08x\n", key->version);
|
2013-11-18 17:38:03 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
pubkey2be(key);
|
2013-10-28 22:50:05 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
void *blob = ucmalloc(PCP_RAW_PUBKEYSIZE);
|
|
|
|
|
pcp_pubkeyblob(blob, key);
|
|
|
|
|
char *z85encoded = pcp_z85_encode((unsigned char*)blob, PCP_RAW_PUBKEYSIZE, &zlen);
|
|
|
|
|
pubkey2native(key);
|
|
|
|
|
|
|
|
|
|
free(blob);
|
2013-11-18 17:38:03 +01:00
|
|
|
|
2013-10-28 22:50:05 +01:00
|
|
|
|
|
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
fprintf(out, "%s\n", PCP_PUBKEY_HEADER);
|
2013-10-28 22:50:05 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
fprintf(out, " Generated by: %s Version %d.%d.%d\n",
|
|
|
|
|
PCP_ME, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH);
|
2013-10-28 22:50:05 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
fprintf(out, " Cipher: %s\n", PCP_KEY_PRIMITIVE);
|
2013-10-28 22:50:05 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
fprintf(out, " Owner: %s\n", key->owner);
|
|
|
|
|
fprintf(out, " Mail: %s\n", key->mail);
|
2013-10-28 22:50:05 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
fprintf(out, " Key-ID: 0x%s\n", key->id);
|
|
|
|
|
fprintf(out, " Public-Key: %s\n", pcp_z85_encode(key->pub, 32, &zlen));
|
2013-10-28 22:50:05 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
//2004-06-14T23:34:30.
|
|
|
|
|
fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
|
|
|
|
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
|
|
|
|
c->tm_hour, c->tm_min, c->tm_sec);
|
2013-10-28 22:50:05 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
unsigned char *hash = pcppubkey_getchecksum(key);
|
|
|
|
|
fprintf(out, " Checksum: ");
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 0;i <15 ;++i) fprintf(out, "%02X:",(unsigned int) hash[i]);
|
|
|
|
|
fprintf(out, "%02X", hash[15]);
|
|
|
|
|
fprintf(out, "\n ");
|
|
|
|
|
for ( i = 16;i <31 ;++i) fprintf(out, "%02X:",(unsigned int) hash[i]);
|
|
|
|
|
fprintf(out, "%02X", hash[31]);
|
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
fprintf(out, " Serial Number: 0x%08X\n", key->serial);
|
|
|
|
|
fprintf(out, " Key Version: 0x%08X\n", key->version);
|
2013-10-28 22:50:05 +01:00
|
|
|
|
2014-01-28 16:53:26 +01:00
|
|
|
char *r = pcppubkey_get_art(key);
|
|
|
|
|
fprintf(out, " Random Art ID: ");
|
|
|
|
|
for (i=0; i<strlen(r); ++i) {
|
|
|
|
|
if(r[i] == '\n') {
|
|
|
|
|
fprintf(out, "\n ");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(out, "%c", r[i]);
|
|
|
|
|
}
|
2013-10-28 22:50:05 +01:00
|
|
|
}
|
2014-01-28 16:53:26 +01:00
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
|
|
fprintf(out, "\n%s\n", z85encoded);
|
|
|
|
|
|
|
|
|
|
fprintf(out, "%s\n", PCP_PUBKEY_FOOTER);
|
|
|
|
|
|
|
|
|
|
free(hash);
|
|
|
|
|
free(r);
|
|
|
|
|
free(z85encoded);
|
2013-10-28 22:50:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void pcp_dumpkey(pcp_key_t *k) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
printf("Dumping pcp_key_t raw values:\n");
|
|
|
|
|
printf(" public: ");
|
2013-11-29 20:01:42 +01:00
|
|
|
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->pub[i]);
|
2013-10-28 22:50:05 +01:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
printf(" secret: ");
|
|
|
|
|
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->secret[i]);
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
2013-11-08 12:50:04 +01:00
|
|
|
printf(" edpub: ");
|
|
|
|
|
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->edpub[i]);
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
2013-11-10 14:32:48 +01:00
|
|
|
printf(" edsecret: ");
|
|
|
|
|
for ( i = 0;i < 64;++i) printf("%02x",(unsigned int) k->edsecret[i]);
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
2013-10-28 22:50:05 +01:00
|
|
|
printf(" nonce: ");
|
|
|
|
|
for ( i = 0;i < 24;++i) printf("%02x",(unsigned int) k->nonce[i]);
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
printf("encrypted: ");
|
2013-11-11 08:24:05 +01:00
|
|
|
for ( i = 0;i < 80;++i) printf("%02x",(unsigned int) k->encrypted[i]);
|
2013-10-28 22:50:05 +01:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
printf(" owner: %s\n", k->owner);
|
|
|
|
|
|
|
|
|
|
printf(" mail: %s\n", k->mail);
|
|
|
|
|
|
|
|
|
|
printf(" id: %s\n", k->id);
|
|
|
|
|
|
2013-11-18 17:38:03 +01:00
|
|
|
printf(" ctime: %ld\n", (long int)k->ctime);
|
2013-10-28 22:50:05 +01:00
|
|
|
|
|
|
|
|
printf(" version: 0x%08X\n", k->version);
|
|
|
|
|
|
|
|
|
|
printf(" serial: 0x%08X\n", k->serial);
|
|
|
|
|
|
|
|
|
|
printf(" type: 0x%02X\n", k->type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void pcp_dumppubkey(pcp_pubkey_t *k) {
|
|
|
|
|
int i;
|
|
|
|
|
printf("Dumping pcp_pubkey_t raw values:\n");
|
|
|
|
|
printf(" public: ");
|
2013-11-29 20:01:42 +01:00
|
|
|
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->pub[i]);
|
2013-10-28 22:50:05 +01:00
|
|
|
printf("\n");
|
|
|
|
|
|
2013-11-08 12:50:04 +01:00
|
|
|
printf(" edpub: ");
|
|
|
|
|
for ( i = 0;i < 32;++i) printf("%02x",(unsigned int) k->edpub[i]);
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
2013-10-28 22:50:05 +01:00
|
|
|
printf(" owner: %s\n", k->owner);
|
|
|
|
|
|
|
|
|
|
printf(" mail: %s\n", k->mail);
|
|
|
|
|
|
|
|
|
|
printf(" id: %s\n", k->id);
|
|
|
|
|
|
2013-11-18 17:38:03 +01:00
|
|
|
printf(" ctime: %ld\n", (long int)k->ctime);
|
2013-10-28 22:50:05 +01:00
|
|
|
|
|
|
|
|
printf(" version: 0x%08X\n", k->version);
|
|
|
|
|
|
|
|
|
|
printf(" serial: 0x%08X\n", k->serial);
|
|
|
|
|
|
|
|
|
|
printf(" type: 0x%02X\n", k->type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pcpkey_printshortinfo(pcp_key_t *key) {
|
|
|
|
|
int i;
|
|
|
|
|
printf(" Key-ID: 0x%s\n", key->id);
|
|
|
|
|
printf(" Owner: %s\n", key->owner);
|
|
|
|
|
char *r = pcpkey_get_art(key);
|
|
|
|
|
printf(" Random Art ID: ");
|
|
|
|
|
for (i=0; i<strlen(r); ++i) {
|
|
|
|
|
if(r[i] == '\n') {
|
|
|
|
|
printf("\n ");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("%c", r[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
free(r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pcppubkey_printshortinfo(pcp_pubkey_t *key) {
|
|
|
|
|
int i;
|
|
|
|
|
printf(" Key-ID: 0x%s\n", key->id);
|
|
|
|
|
printf(" Owner: %s\n", key->owner);
|
2013-10-29 22:14:34 +01:00
|
|
|
char *r = pcppubkey_get_art(key);
|
2013-10-28 22:50:05 +01:00
|
|
|
printf(" Random Art ID: ");
|
|
|
|
|
for (i=0; i<strlen(r); ++i) {
|
|
|
|
|
if(r[i] == '\n') {
|
|
|
|
|
printf("\n ");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("%c", r[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
free(r);
|
|
|
|
|
}
|
2013-11-09 14:32:42 +01:00
|
|
|
|
|
|
|
|
void pcpexport_yaml(char *outfile) {
|
|
|
|
|
FILE *out;
|
|
|
|
|
|
|
|
|
|
if(outfile == NULL) {
|
|
|
|
|
out = stdout;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if((out = fopen(outfile, "wb+")) == NULL) {
|
|
|
|
|
fatal("Could not create output file %s", outfile);
|
|
|
|
|
out = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(out != NULL) {
|
|
|
|
|
pcp_key_t *s;
|
|
|
|
|
pcp_pubkey_t *p;
|
|
|
|
|
|
|
|
|
|
struct tm *c;
|
|
|
|
|
time_t t = time(0);
|
|
|
|
|
c = localtime(&t);
|
|
|
|
|
|
|
|
|
|
fprintf(out, "#\n# YAML export of vault %s.\n", vault->filename);
|
|
|
|
|
fprintf(out, "# Generated on: %04d-%02d-%02dT%02d:%02d:%02d\n",
|
|
|
|
|
c->tm_year+1900, c->tm_mon+1, c->tm_mday,
|
|
|
|
|
c->tm_hour, c->tm_min, c->tm_sec);
|
|
|
|
|
fprintf(out, "---\n");
|
|
|
|
|
fprintf(out, "secret-keys:\n");
|
|
|
|
|
|
2013-11-13 13:06:01 +01:00
|
|
|
pcphash_iterate(s) {
|
2013-11-09 15:35:43 +01:00
|
|
|
fprintf(out, " -\n");
|
|
|
|
|
fprintf(out, " id: %s\n", s->id);
|
|
|
|
|
fprintf(out, " owner: %s\n", s->owner);
|
|
|
|
|
fprintf(out, " mail: %s\n", s->mail);
|
2013-11-18 17:38:03 +01:00
|
|
|
fprintf(out, " ctime: %ld\n", (long int)s->ctime);
|
2013-11-09 15:35:43 +01:00
|
|
|
fprintf(out, " version: %08x\n", s->version);
|
|
|
|
|
fprintf(out, " serial: %08x\n", s->serial);
|
|
|
|
|
fprintf(out, " type: %s\n",
|
2013-11-09 14:32:42 +01:00
|
|
|
(s->type == PCP_KEY_TYPE_MAINSECRET) ? "primary" : " secret");
|
2013-11-29 20:01:42 +01:00
|
|
|
fprintf(out, " public: "); pcpprint_bin(out, s->pub, 32); fprintf(out, "\n");
|
2013-11-09 14:45:14 +01:00
|
|
|
if(s->secret[0] == 0) {
|
2013-11-09 15:35:43 +01:00
|
|
|
fprintf(out, " encrypted: yes\n");
|
|
|
|
|
fprintf(out, " nonce: "); pcpprint_bin(out, s->nonce, 24); fprintf(out, "\n");
|
2013-11-10 14:32:48 +01:00
|
|
|
fprintf(out, " secret: "); pcpprint_bin(out, s->encrypted, 80); fprintf(out, "\n");
|
2013-11-09 14:45:14 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2013-11-09 15:35:43 +01:00
|
|
|
fprintf(out, " encrypted: no\n");
|
|
|
|
|
fprintf(out, " secret: "); pcpprint_bin(out, s->secret, 32); fprintf(out, "\n");
|
2013-11-10 14:32:48 +01:00
|
|
|
fprintf(out, " edsecret: "); pcpprint_bin(out, s->edsecret, 64); fprintf(out, "\n");
|
2013-11-09 14:45:14 +01:00
|
|
|
}
|
2013-11-09 15:35:43 +01:00
|
|
|
fprintf(out, " edpub: "); pcpprint_bin(out, s->edpub, 32); fprintf(out, "\n");
|
2013-11-09 14:32:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(out, "public-keys:\n");
|
2013-11-13 13:06:01 +01:00
|
|
|
pcphash_iteratepub(p) {
|
2013-11-09 15:35:43 +01:00
|
|
|
fprintf(out, " -\n");
|
|
|
|
|
fprintf(out, " id: %s\n", p->id);
|
|
|
|
|
fprintf(out, " owner: %s\n", p->owner);
|
|
|
|
|
fprintf(out, " mail: %s\n", p->mail);
|
2013-11-18 17:38:03 +01:00
|
|
|
fprintf(out, " ctime: %ld\n", (long int)p->ctime);
|
2013-11-09 15:35:43 +01:00
|
|
|
fprintf(out, " version: %08x\n", p->version);
|
|
|
|
|
fprintf(out, " serial: %08x\n", p->serial);
|
|
|
|
|
fprintf(out, " type: public\n");
|
2013-11-29 20:01:42 +01:00
|
|
|
fprintf(out, " public: "); pcpprint_bin(out, p->pub, 32); fprintf(out, "\n");
|
2013-11-09 15:35:43 +01:00
|
|
|
fprintf(out, " edpub: "); pcpprint_bin(out, p->edpub, 32); fprintf(out, "\n");
|
2013-11-09 14:32:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pcpprint_bin(FILE *out, unsigned char *data, size_t len) {
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 0;i < len;++i)
|
|
|
|
|
fprintf(out, "%02x", (unsigned int) data[i]);
|
|
|
|
|
}
|