abandoned yaml, perl and c key exporters, added json exporter using libjansson, enable with --with-json

This commit is contained in:
TLINDEN
2015-07-06 23:02:04 +02:00
parent 325493189d
commit 57517a1000
21 changed files with 267 additions and 309 deletions

View File

@@ -357,7 +357,7 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int
/* now, we're ready for the actual export */
if(format == EXP_FORMAT_NATIVE) {
if(is_foreign == 0) {
exported_pk = pcp_export_rfc_pub(sk);
exported_pk = pcp_export_rfc_pub(ptx, sk);
if(exported_pk != NULL) {
if(armor == 1) {
size_t zlen;
@@ -395,24 +395,6 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int
goto errpcpexpu1;
}
}
else if(format == EXP_FORMAT_YAML) {
exported_pk = pcp_export_yaml_pub(sk);
if(exported_pk != NULL) {
fprintf(out, "%s", buffer_get_str(exported_pk));
}
}
else if(format == EXP_FORMAT_PERL) {
exported_pk = pcp_export_perl_pub(sk);
if(exported_pk != NULL) {
fprintf(out, "%s", buffer_get_str(exported_pk));
}
}
else if(format == EXP_FORMAT_C) {
exported_pk = pcp_export_c_pub(sk);
if(exported_pk != NULL) {
fprintf(out, "%s", buffer_get_str(exported_pk));
}
}
errpcpexpu1:
;

View File

@@ -298,74 +298,6 @@ void pcppubkey_printshortinfo(pcp_pubkey_t *key) {
free(r);
}
void pcpexport_yaml(char *outfile) {
FILE *out;
if(outfile == NULL) {
out = stdout;
}
else {
if((out = fopen(outfile, "wb+")) == NULL) {
fatal(ptx, "Could not create output file %s\n", 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");
pcphash_iterate(ptx, s) {
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", (long int)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->pub, 32); fprintf(out, "\n");
if(s->secret[0] == 0) {
fprintf(out, " encrypted: yes\n");
fprintf(out, " nonce: "); pcpprint_bin(out, s->nonce, 24); fprintf(out, "\n");
fprintf(out, " secret: "); pcpprint_bin(out, s->encrypted, 80); fprintf(out, "\n");
}
else {
fprintf(out, " encrypted: no\n");
fprintf(out, " secret: "); pcpprint_bin(out, s->secret, 32); fprintf(out, "\n");
fprintf(out, " edsecret: "); pcpprint_bin(out, s->edsecret, 64); fprintf(out, "\n");
}
fprintf(out, " edpub: "); pcpprint_bin(out, s->edpub, 32); fprintf(out, "\n");
}
fprintf(out, "public-keys:\n");
pcphash_iteratepub(ptx, p) {
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", (long int)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->pub, 32); fprintf(out, "\n");
fprintf(out, " edpub: "); pcpprint_bin(out, p->edpub, 32); fprintf(out, "\n");
}
}
}
void pcpprint_bin(FILE *out, byte *data, size_t len) {
size_t i;
for ( i = 0;i < len;++i)

View File

@@ -44,7 +44,6 @@ void pcptext_key(char *keyid);
void pcptext_vault(vault_t *vault);
int pcptext_infile(char *infile);
void pcpexport_yaml(char *outfile);
void pcpprint_bin(FILE *out, byte *data, size_t len);
#endif /* _HAVE_PCP_KEYPRINT_H */

View File

@@ -106,7 +106,6 @@ int main (int argc, char **argv) {
{ "import-key", no_argument, NULL, 'K' }, /* alias -K */
{ "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 */
@@ -121,6 +120,7 @@ int main (int argc, char **argv) {
{ "armor", no_argument, NULL, 'a' }, /* alias -z */
{ "textmode", no_argument, NULL, 'a' }, /* alias -z */
{ "z85-decode", no_argument, NULL, 'Z' },
{ "json-io", no_argument, NULL, 'j' },
/* globals */
{ "help", no_argument, NULL, 'h' },
@@ -135,7 +135,7 @@ int main (int argc, char **argv) {
{ NULL, 0, NULL, 0 }
};
while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcymf:b1F:0KAMX:",
while ((opt = getopt_long(argc, argv, "klLV:vdehsO:i:I:pSPRtEx:DzaZr:gcmf:b1F:0KAMX:j",
longopts, NULL)) != -1) {
switch (opt) {
@@ -210,26 +210,18 @@ int main (int argc, char **argv) {
else if(strncmp(optarg, "pcp", 3) == 0) {
exportformat = EXP_FORMAT_NATIVE;
}
else if(strncmp(optarg, "yaml", 3) == 0) {
exportformat = EXP_FORMAT_YAML;
}
else if(strncmp(optarg, "c", 3) == 0) {
exportformat = EXP_FORMAT_C;
}
else if(strncmp(optarg, "py", 3) == 0) {
exportformat = EXP_FORMAT_PY;
}
else if(strncmp(optarg, "perl", 3) == 0) {
exportformat = EXP_FORMAT_PERL;
}
else if(strncmp(optarg, "c", 3) == 0) {
exportformat = EXP_FORMAT_C;
}
else {
warn("Unknown export format specified, using native\n");
exportformat = EXP_FORMAT_NATIVE;
}
break;
case 'j':
#ifdef HAVE_JSON
ptx->json = 1;
#else
fprintf(stderr, "WARN: -j set, but no JSON support compiled in. Recompile with --with-json\n");
#endif
break;
case 'g':
mode += PCP_MODE_SIGN;
usevault = 1;
@@ -243,10 +235,6 @@ int main (int argc, char **argv) {
strncpy(sigfile, optarg, strlen(optarg)+1);
detach = 1;
break;
case 'y':
mode += PCP_MODE_YAML;
usevault = 1;
break;
case 'V':
strncpy(vaultfile, optarg, 1024);
@@ -566,10 +554,6 @@ int main (int argc, char **argv) {
}
break;
case PCP_MODE_YAML:
pcpexport_yaml(outfile);
break;
default:
/* */
goto ELSEMODE;

View File

@@ -28,9 +28,10 @@
"-s --export-secret Export a secret key.\n" \
"-p --export-public Export a public key.\n" \
"-K --import Import a secret or public key.\n" \
"-y --export-yaml Export all keys as YAML formatted text.\n" \
"-F --export-format <fmt> Specify exportformat, either 'pbp' or 'pcp'.\n" \
" 'pcp' is the default if unspecified.\n" \
"-j --json Enable JSON ex- and import of keys.\n" \
"\n" \
"Encryption Options:\n" \
"-e --encrypt Asym-Encrypt a message. If none of -i or -r\n" \
" has been given, encrypt the message symetrically.\n" \
@@ -50,6 +51,5 @@
"Arguments:\n" \
"Extra arguments after options are treated as filenames or\n" \
"recipients, depending on operation mode.\n" \
"\n" \
"\n"
""
#endif

View File

@@ -6,5 +6,5 @@ echo -n "#define PCP_HELP " >> usage.h
cat usage.txt | sed -e 's/^/"/' -e 's/$/\\n" \\/' >> usage.h
echo "\"\\n\"" >> usage.h
printf "\"\"\\n" >> usage.h
echo "#endif" >> usage.h

View File

@@ -26,9 +26,10 @@ Keymanagement Options:
-s --export-secret Export a secret key.
-p --export-public Export a public key.
-K --import Import a secret or public key.
-y --export-yaml Export all keys as YAML formatted text.
-F --export-format <fmt> Specify exportformat, either 'pbp' or 'pcp'.
'pcp' is the default if unspecified.
-j --json Enable JSON ex- and import of keys.
Encryption Options:
-e --encrypt Asym-Encrypt a message. If none of -i or -r
has been given, encrypt the message symetrically.
@@ -48,4 +49,3 @@ Encoding Options:
Arguments:
Extra arguments after options are treated as filenames or
recipients, depending on operation mode.