diff --git a/man/pcp1.1 b/man/pcp1.1 index 94effd5..3d6310c 100644 --- a/man/pcp1.1 +++ b/man/pcp1.1 @@ -180,7 +180,9 @@ Pretty Curved Privacy \- File encryption using eliptic curve cryptography. \& from a file. \& \-P \-\-import\-public Import a public key. Use \-I to import \& from a file. -\& +\& \-y \-\-export\-yaml Export all keys stored in your vault +\& as YAML formatted text. Use \-O to put +\& the export into a file. \& Encryption Options: \& \-e \-\-encrypt Encrypt a message. Read from stdin or \& specified via \-I. If a keyid (\-i) has been diff --git a/man/pcp1.pod b/man/pcp1.pod index 2726c75..61033d5 100644 --- a/man/pcp1.pod +++ b/man/pcp1.pod @@ -52,7 +52,9 @@ Pretty Curved Privacy - File encryption using eliptic curve cryptography. from a file. -P --import-public Import a public key. Use -I to import from a file. - + -y --export-yaml Export all keys stored in your vault + as YAML formatted text. Use -O to put + the export into a file. Encryption Options: -e --encrypt Encrypt a message. Read from stdin or specified via -I. If a keyid (-i) has been diff --git a/src/keyprint.c b/src/keyprint.c index 6de7f6a..ff42681 100644 --- a/src/keyprint.c +++ b/src/keyprint.c @@ -283,3 +283,72 @@ void pcppubkey_printshortinfo(pcp_pubkey_t *key) { printf("\n"); free(r); } + +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"); + + for(s=pcpkey_hash; s != NULL; s=(pcp_key_t*)(s->hh.next)) { + fprintf(out, "-\n"); + fprintf(out, " id: %s\n", s->id); + fprintf(out, " owner: %s\n", s->owner); + fprintf(out, " mail: %s\n", s->mail); + fprintf(out, " ctime: %ld\n", s->ctime); + fprintf(out, " version: %08x\n", s->version); + fprintf(out, " serial: %08x\n", s->serial); + fprintf(out, " type: %s\n", + (s->type == PCP_KEY_TYPE_MAINSECRET) ? "primary" : " secret"); + fprintf(out, " public: "); pcpprint_bin(out, s->public, 32); fprintf(out, "\n"); + fprintf(out, " secret: "); pcpprint_bin(out, s->secret, 32); fprintf(out, "\n"); + fprintf(out, " edpub: "); pcpprint_bin(out, s->edpub, 32); fprintf(out, "\n"); + fprintf(out, " nonce: "); pcpprint_bin(out, s->nonce, 24); fprintf(out, "\n"); + fprintf(out, " encrypted: "); pcpprint_bin(out, s->encrypted, 48); fprintf(out, "\n"); + fprintf(out, "\n"); + } + + fprintf(out, "public-keys:\n"); + for(p=pcppubkey_hash; p != NULL; p=(pcp_pubkey_t*)(p->hh.next)) { + fprintf(out, "-\n"); + fprintf(out, " id: %s\n", p->id); + fprintf(out, " owner: %s\n", p->owner); + fprintf(out, " mail: %s\n", p->mail); + fprintf(out, " ctime: %ld\n", p->ctime); + fprintf(out, " version: %08x\n", p->version); + fprintf(out, " serial: %08x\n", p->serial); + fprintf(out, " type: public\n"); + fprintf(out, " public: "); pcpprint_bin(out, p->public, 32); fprintf(out, "\n"); + fprintf(out, " edpub: "); pcpprint_bin(out, p->edpub, 32); fprintf(out, "\n"); + fprintf(out, "\n"); + } + } +} + +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]); +} diff --git a/src/keyprint.h b/src/keyprint.h index 56aaefe..2b55af0 100644 --- a/src/keyprint.h +++ b/src/keyprint.h @@ -43,4 +43,7 @@ void pcppubkey_printlineinfo(pcp_pubkey_t *key); void pcptext_key(char *keyid); void pcptext_vault(vault_t *vault); +void pcpexport_yaml(char *outfile); +void pcpprint_bin(FILE *out, unsigned char *data, size_t len); + #endif // _HAVE_PCP_KEYPRINT_H diff --git a/src/pcp.c b/src/pcp.c index 6091be2..a4580ec 100644 --- a/src/pcp.c +++ b/src/pcp.c @@ -82,6 +82,7 @@ int main (int argc, char **argv) { { "import-public", no_argument, NULL, 'P' }, { "remove-key", no_argument, NULL, 'R' }, { "edit-key", no_argument, NULL, 'E' }, + { "export-yaml", no_argument, NULL, 'y' }, // crypto { "encrypt", no_argument, NULL, 'e' }, @@ -102,7 +103,7 @@ int main (int argc, char **argv) { { NULL, 0, NULL, 0 } }; - while ((opt = getopt_long(argc, argv, "klV:vdehsO:i:I:pSPRtEx:DzZr:gc:", + while ((opt = getopt_long(argc, argv, "klV:vdehsO:i:I:pSPRtEx:DzZr:gc:y", longopts, NULL)) != -1) { switch (opt) { @@ -175,6 +176,10 @@ int main (int argc, char **argv) { strncpy(sigfile, optarg, strlen(optarg)+1); usevault = 1; break; + case 'y': + mode += PCP_MODE_YAML; + usevault = 1; + break; case 'V': strncpy(vaultfile, optarg, 1024); @@ -377,7 +382,9 @@ int main (int argc, char **argv) { pcpverify(infile, sigfile); break; - + case PCP_MODE_YAML: + pcpexport_yaml(outfile); + break; default: // diff --git a/src/pcp.h b/src/pcp.h index f61bbbe..18800cb 100644 --- a/src/pcp.h +++ b/src/pcp.h @@ -63,6 +63,8 @@ #define PCP_MODE_ZDECODE 0x00000962 #define PCP_MODE_SIGN 0x00000FF6 #define PCP_MODE_VERIFY 0x00001B25 +#define PCP_MODE_YAML 0x00002E25 + /* 0x00001B25 0x00002E27 diff --git a/src/usage.h b/src/usage.h index 29f428c..5e1b8ec 100644 --- a/src/usage.h +++ b/src/usage.h @@ -47,7 +47,9 @@ " from a file.\n" \ "-P --import-public Import a public key. Use -I to import\n" \ " from a file.\n" \ -"\n" \ +"-y --export-yaml Export all keys stored in your vault\n" \ +" as YAML formatted text. Use -O to put\n" \ +" the export into a file.\n" \ "Encryption Options:\n" \ "-e --encrypt Encrypt a message. Read from stdin or\n" \ " specified via -I. If a keyid (-i) has been\n" \ diff --git a/src/usage.txt b/src/usage.txt index bf76055..9caba8e 100644 --- a/src/usage.txt +++ b/src/usage.txt @@ -45,7 +45,9 @@ Keymanagement Options: from a file. -P --import-public Import a public key. Use -I to import from a file. - +-y --export-yaml Export all keys stored in your vault + as YAML formatted text. Use -O to put + the export into a file. Encryption Options: -e --encrypt Encrypt a message. Read from stdin or specified via -I. If a keyid (-i) has been