added option -y which allows to export the whole vault as yaml.

This commit is contained in:
TLINDEN
2013-11-09 14:32:42 +01:00
parent 1a772e15b8
commit 2d8d0a27d9
8 changed files with 95 additions and 6 deletions

View File

@@ -180,7 +180,9 @@ Pretty Curved Privacy \- File encryption using eliptic curve cryptography.
\& from a file. \& from a file.
\& \-P \-\-import\-public Import a public key. Use \-I to import \& \-P \-\-import\-public Import a public key. Use \-I to import
\& from a file. \& 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: \& Encryption Options:
\& \-e \-\-encrypt Encrypt a message. Read from stdin or \& \-e \-\-encrypt Encrypt a message. Read from stdin or
\& specified via \-I. If a keyid (\-i) has been \& specified via \-I. If a keyid (\-i) has been

View File

@@ -52,7 +52,9 @@ Pretty Curved Privacy - File encryption using eliptic curve cryptography.
from a file. from a file.
-P --import-public Import a public key. Use -I to import -P --import-public Import a public key. Use -I to import
from a file. 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: Encryption Options:
-e --encrypt Encrypt a message. Read from stdin or -e --encrypt Encrypt a message. Read from stdin or
specified via -I. If a keyid (-i) has been specified via -I. If a keyid (-i) has been

View File

@@ -283,3 +283,72 @@ void pcppubkey_printshortinfo(pcp_pubkey_t *key) {
printf("\n"); printf("\n");
free(r); 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]);
}

View File

@@ -43,4 +43,7 @@ void pcppubkey_printlineinfo(pcp_pubkey_t *key);
void pcptext_key(char *keyid); void pcptext_key(char *keyid);
void pcptext_vault(vault_t *vault); 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 #endif // _HAVE_PCP_KEYPRINT_H

View File

@@ -82,6 +82,7 @@ int main (int argc, char **argv) {
{ "import-public", no_argument, NULL, 'P' }, { "import-public", no_argument, NULL, 'P' },
{ "remove-key", no_argument, NULL, 'R' }, { "remove-key", no_argument, NULL, 'R' },
{ "edit-key", no_argument, NULL, 'E' }, { "edit-key", no_argument, NULL, 'E' },
{ "export-yaml", no_argument, NULL, 'y' },
// crypto // crypto
{ "encrypt", no_argument, NULL, 'e' }, { "encrypt", no_argument, NULL, 'e' },
@@ -102,7 +103,7 @@ int main (int argc, char **argv) {
{ NULL, 0, NULL, 0 } { 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) { longopts, NULL)) != -1) {
switch (opt) { switch (opt) {
@@ -175,6 +176,10 @@ int main (int argc, char **argv) {
strncpy(sigfile, optarg, strlen(optarg)+1); strncpy(sigfile, optarg, strlen(optarg)+1);
usevault = 1; usevault = 1;
break; break;
case 'y':
mode += PCP_MODE_YAML;
usevault = 1;
break;
case 'V': case 'V':
strncpy(vaultfile, optarg, 1024); strncpy(vaultfile, optarg, 1024);
@@ -377,7 +382,9 @@ int main (int argc, char **argv) {
pcpverify(infile, sigfile); pcpverify(infile, sigfile);
break; break;
case PCP_MODE_YAML:
pcpexport_yaml(outfile);
break;
default: default:
// //

View File

@@ -63,6 +63,8 @@
#define PCP_MODE_ZDECODE 0x00000962 #define PCP_MODE_ZDECODE 0x00000962
#define PCP_MODE_SIGN 0x00000FF6 #define PCP_MODE_SIGN 0x00000FF6
#define PCP_MODE_VERIFY 0x00001B25 #define PCP_MODE_VERIFY 0x00001B25
#define PCP_MODE_YAML 0x00002E25
/* /*
0x00001B25 0x00001B25
0x00002E27 0x00002E27

View File

@@ -47,7 +47,9 @@
" from a file.\n" \ " from a file.\n" \
"-P --import-public Import a public key. Use -I to import\n" \ "-P --import-public Import a public key. Use -I to import\n" \
" from a file.\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" \ "Encryption Options:\n" \
"-e --encrypt Encrypt a message. Read from stdin or\n" \ "-e --encrypt Encrypt a message. Read from stdin or\n" \
" specified via -I. If a keyid (-i) has been\n" \ " specified via -I. If a keyid (-i) has been\n" \

View File

@@ -45,7 +45,9 @@ Keymanagement Options:
from a file. from a file.
-P --import-public Import a public key. Use -I to import -P --import-public Import a public key. Use -I to import
from a file. 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: Encryption Options:
-e --encrypt Encrypt a message. Read from stdin or -e --encrypt Encrypt a message. Read from stdin or
specified via -I. If a keyid (-i) has been specified via -I. If a keyid (-i) has been