Browse Source

Stripped JSON related code, and disabled build of command line tools. Only src/lib remains being built.

master
Edouard Tisserant 7 years ago
parent
commit
150e3b0aa6
8 changed files with 3 additions and 397 deletions
  1. +1
    -1
      dist/Makefile.am
  2. +0
    -6
      dist/configure.ac
  3. +1
    -1
      dist/src/Makefile.am
  4. +1
    -4
      dist/src/lib/Makefile.am
  5. +0
    -39
      dist/src/lib/keyring.c
  6. +0
    -5
      dist/src/lib/keyring.h
  7. +0
    -256
      dist/src/lib/netpgp.c
  8. +0
    -85
      dist/src/lib/packet-print.c

+ 1
- 1
dist/Makefile.am View File

@ -1,3 +1,3 @@
## $NetBSD$
SUBDIRS = include src tests
SUBDIRS = include src

+ 0
- 6
dist/configure.ac View File

@ -116,13 +116,7 @@ AC_CONFIG_FILES([
Makefile
include/Makefile
src/Makefile
src/libmj/Makefile
src/lib/Makefile
src/hkpclient/Makefile
src/netpgp/Makefile
src/netpgpkeys/Makefile
tests/Makefile
tests/atlocal
])
AC_OUTPUT


+ 1
- 1
dist/src/Makefile.am View File

@ -1,3 +1,3 @@
## $NetBSD$
SUBDIRS = libmj lib netpgp netpgpkeys hkpclient
SUBDIRS = lib

+ 1
- 4
dist/src/lib/Makefile.am View File

@ -4,7 +4,7 @@ AM_CFLAGS = $(WARNCFLAGS)
lib_LTLIBRARIES = libnetpgp.la
libnetpgp_la_CPPFLAGS = -I$(top_srcdir)/include -I../libmj -D_GNU_SOURCE
libnetpgp_la_CPPFLAGS = -I$(top_srcdir)/include -D_GNU_SOURCE
libnetpgp_la_SOURCES = \
bufgap.c \
@ -20,7 +20,6 @@ libnetpgp_la_SOURCES = \
packet-show.c \
reader.c \
signature.c \
ssh2pgp.c \
symmetric.c \
validate.c \
writer.c
@ -42,6 +41,4 @@ pkginclude_HEADERS = \
writer.h \
validate.h
libnetpgp_la_LIBADD = ../libmj/libmj.la
dist_man_MANS = libnetpgp.3

+ 0
- 39
dist/src/lib/keyring.c View File

@ -1350,45 +1350,6 @@ pgp_keyring_list(pgp_io_t *io, const pgp_keyring_t *keyring, const int psigs)
return 1;
}
int
pgp_keyring_json(pgp_io_t *io, const pgp_keyring_t *keyring, mj_t *obj, const int psigs)
{
pgp_key_t *key;
unsigned n;
(void) memset(obj, 0x0, sizeof(*obj));
mj_create(obj, "array");
obj->size = keyring->keyvsize;
if (pgp_get_debug_level(__FILE__)) {
(void) fprintf(io->errs, "pgp_keyring_json: vsize %u\n", obj->size);
}
if ((obj->value.v = calloc(sizeof(*obj->value.v), obj->size)) == NULL) {
(void) fprintf(io->errs, "calloc failure\n");
return 0;
}
for (n = 0, key = keyring->keys; n < keyring->keyc; ++n, ++key) {
if (pgp_is_key_secret(key)) {
pgp_sprint_mj(io, keyring, key, &obj->value.v[obj->c],
"sec", &key->key.seckey.pubkey, psigs);
} else {
pgp_sprint_mj(io, keyring, key, &obj->value.v[obj->c],
"signature ", &key->key.pubkey, psigs);
}
if (obj->value.v[obj->c].type != 0) {
obj->c += 1;
}
}
if (pgp_get_debug_level(__FILE__)) {
char *s;
mj_asprint(&s, obj, MJ_JSON_ENCODE);
(void) fprintf(stderr, "pgp_keyring_json: '%s'\n", s);
free(s);
}
return 1;
}
/* this interface isn't right - hook into callback for getting passphrase */
char *
pgp_export_key(pgp_io_t *io, const pgp_key_t *keydata, uint8_t *passphrase)


+ 0
- 5
dist/src/lib/keyring.h View File

@ -55,7 +55,6 @@
#include "packet.h"
#include "packet-parse.h"
#include "mj.h"
#include "memory.h"
enum {
@ -126,7 +125,6 @@ pgp_keyring_read_from_mem(pgp_io_t *io,
pgp_memory_t *mem);
int pgp_keyring_list(pgp_io_t *, const pgp_keyring_t *, const int);
int pgp_keyring_json(pgp_io_t *, const pgp_keyring_t *, mj_t *, const int);
void pgp_forget(void *, unsigned);
@ -151,9 +149,6 @@ void pgp_keydata_init(pgp_key_t *, const pgp_content_enum);
int pgp_sprint_keydata(pgp_io_t *, const pgp_keyring_t *,
const pgp_key_t *, char **, const char *,
const pgp_pubkey_t *, const int);
int pgp_sprint_mj(pgp_io_t *, const pgp_keyring_t *,
const pgp_key_t *, mj_t *, const char *,
const pgp_pubkey_t *, const int);
int pgp_hkp_sprint_keydata(pgp_io_t *, const pgp_keyring_t *,
const pgp_key_t *, char **,
const pgp_pubkey_t *, const int);


+ 0
- 256
dist/src/lib/netpgp.c View File

@ -490,164 +490,6 @@ isarmoured(pgp_io_t *io, const char *f, const void *memory, const char *text)
return armoured;
}
/* vararg print function */
static void
p(FILE *fp, const char *s, ...)
{
va_list args;
va_start(args, s);
while (s != NULL) {
(void) fprintf(fp, "%s", s);
s = va_arg(args, char *);
}
va_end(args);
}
/* print a JSON object to the FILE stream */
static void
pobj(FILE *fp, mj_t *obj, int depth)
{
unsigned i;
char *s;
if (obj == NULL) {
(void) fprintf(stderr, "No object found\n");
return;
}
for (i = 0 ; i < (unsigned)depth ; i++) {
p(fp, " ", NULL);
}
switch(obj->type) {
case MJ_NULL:
case MJ_FALSE:
case MJ_TRUE:
p(fp, (obj->type == MJ_NULL) ? "null" : (obj->type == MJ_FALSE) ? "false" : "true", NULL);
break;
case MJ_NUMBER:
p(fp, obj->value.s, NULL);
break;
case MJ_STRING:
if ((i = mj_asprint(&s, obj, MJ_HUMAN)) > 2) {
(void) fprintf(fp, "%.*s", (int)i - 2, &s[1]);
free(s);
}
break;
case MJ_ARRAY:
for (i = 0 ; i < obj->c ; i++) {
pobj(fp, &obj->value.v[i], depth + 1);
if (i < obj->c - 1) {
(void) fprintf(fp, ", ");
}
}
(void) fprintf(fp, "\n");
break;
case MJ_OBJECT:
for (i = 0 ; i < obj->c ; i += 2) {
pobj(fp, &obj->value.v[i], depth + 1);
p(fp, ": ", NULL);
pobj(fp, &obj->value.v[i + 1], 0);
if (i < obj->c - 1) {
p(fp, ", ", NULL);
}
}
p(fp, "\n", NULL);
break;
default:
break;
}
}
/* return the time as a string */
static char *
ptimestr(char *dest, size_t size, time_t t)
{
struct tm *tm;
tm = gmtime(&t);
(void) snprintf(dest, size, "%04d-%02d-%02d",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday);
return dest;
}
/* format a JSON object */
static void
format_json_key(FILE *fp, mj_t *obj, const int psigs)
{
int64_t birthtime;
int64_t duration;
time_t now;
char tbuf[32];
char *s;
mj_t *sub;
int i;
if (pgp_get_debug_level(__FILE__)) {
mj_asprint(&s, obj, MJ_HUMAN);
(void) fprintf(stderr, "formatobj: json is '%s'\n", s);
free(s);
}
if (obj->c == 2 && obj->value.v[1].type == MJ_STRING &&
strcmp(obj->value.v[1].value.s, "[REVOKED]") == 0) {
/* whole key has been rovoked - just return */
return;
}
pobj(fp, &obj->value.v[mj_object_find(obj, "header", 0, 2) + 1], 0);
p(fp, " ", NULL);
pobj(fp, &obj->value.v[mj_object_find(obj, "key bits", 0, 2) + 1], 0);
p(fp, "/", NULL);
pobj(fp, &obj->value.v[mj_object_find(obj, "pka", 0, 2) + 1], 0);
p(fp, " ", NULL);
pobj(fp, &obj->value.v[mj_object_find(obj, "key id", 0, 2) + 1], 0);
birthtime = (int64_t)strtoll(obj->value.v[mj_object_find(obj, "birthtime", 0, 2) + 1].value.s, NULL, 10);
p(fp, " ", ptimestr(tbuf, sizeof(tbuf), birthtime), NULL);
duration = (int64_t)strtoll(obj->value.v[mj_object_find(obj, "duration", 0, 2) + 1].value.s, NULL, 10);
if (duration > 0) {
now = time(NULL);
p(fp, " ", (birthtime + duration < now) ? "[EXPIRED " : "[EXPIRES ",
ptimestr(tbuf, sizeof(tbuf), birthtime + duration), "]", NULL);
}
p(fp, "\n", "Key fingerprint: ", NULL);
pobj(fp, &obj->value.v[mj_object_find(obj, "fingerprint", 0, 2) + 1], 0);
p(fp, "\n", NULL);
/* go to field after \"duration\" */
for (i = mj_object_find(obj, "duration", 0, 2) + 2; i < mj_arraycount(obj) ; i += 2) {
if (strcmp(obj->value.v[i].value.s, "uid") == 0) {
sub = &obj->value.v[i + 1];
p(fp, "uid", NULL);
pobj(fp, &sub->value.v[0], (psigs) ? 4 : 14); /* human name */
pobj(fp, &sub->value.v[1], 1); /* any revocation */
p(fp, "\n", NULL);
} else if (strcmp(obj->value.v[i].value.s, "encryption") == 0) {
sub = &obj->value.v[i + 1];
p(fp, "encryption", NULL);
pobj(fp, &sub->value.v[0], 1); /* size */
p(fp, "/", NULL);
pobj(fp, &sub->value.v[1], 0); /* alg */
p(fp, " ", NULL);
pobj(fp, &sub->value.v[2], 0); /* id */
p(fp, " ", ptimestr(tbuf, sizeof(tbuf),
(time_t)strtoll(sub->value.v[3].value.s, NULL, 10)),
"\n", NULL);
} else if (strcmp(obj->value.v[i].value.s, "sig") == 0) {
sub = &obj->value.v[i + 1];
p(fp, "sig", NULL);
pobj(fp, &sub->value.v[0], 8); /* size */
p(fp, " ", ptimestr(tbuf, sizeof(tbuf),
(time_t)strtoll(sub->value.v[1].value.s, NULL, 10)),
" ", NULL); /* time */
pobj(fp, &sub->value.v[2], 0); /* human name */
p(fp, "\n", NULL);
} else {
fprintf(stderr, "weird '%s'\n", obj->value.v[i].value.s);
pobj(fp, &obj->value.v[i], 0); /* human name */
}
}
p(fp, "\n", NULL);
}
/* save a pgp pubkey to a temp file */
static int
savepubkey(char *res, char *f, size_t size)
@ -954,27 +796,6 @@ netpgp_list_keys(netpgp_t *netpgp, const int psigs)
return pgp_keyring_list(netpgp->io, netpgp->pubring, psigs);
}
/* list the keys in a keyring, returning a JSON encoded string */
int
netpgp_list_keys_json(netpgp_t *netpgp, char **json, const int psigs)
{
mj_t obj;
int ret;
if (netpgp->pubring == NULL) {
(void) fprintf(stderr, "No keyring\n");
return 0;
}
(void) memset(&obj, 0x0, sizeof(obj));
if (!pgp_keyring_json(netpgp->io, netpgp->pubring, &obj, psigs)) {
(void) fprintf(stderr, "No keys in keyring\n");
return 0;
}
ret = mj_asprint(json, &obj, MJ_JSON_ENCODE);
mj_delete(&obj);
return ret;
}
DEFINE_ARRAY(strings_t, char *);
#ifndef HKP_VERSION
@ -1031,51 +852,6 @@ netpgp_match_keys(netpgp_t *netpgp, char *name, const char *fmt, void *vp, const
return pubs.c;
}
/* find and list some keys in a keyring - return JSON string */
int
netpgp_match_keys_json(netpgp_t *netpgp, char **json, char *name, const char *fmt, const int psigs)
{
const pgp_key_t *key;
unsigned k;
mj_t id_array;
char *newkey;
int ret;
if (name[0] == '0' && name[1] == 'x') {
name += 2;
}
(void) memset(&id_array, 0x0, sizeof(id_array));
k = 0;
*json = NULL;
mj_create(&id_array, "array");
do {
key = pgp_getnextkeybyname(netpgp->io, netpgp->pubring,
name, &k);
if (key != NULL) {
if (strcmp(fmt, "mr") == 0) {
pgp_hkp_sprint_keydata(netpgp->io, netpgp->pubring,
key, &newkey,
&key->key.pubkey, 0);
if (newkey) {
printf("%s\n", newkey);
free(newkey);
}
} else {
ALLOC(mj_t, id_array.value.v, id_array.size,
id_array.c, 10, 10, "netpgp_match_keys_json", return 0);
pgp_sprint_mj(netpgp->io, netpgp->pubring,
key, &id_array.value.v[id_array.c++],
"signature ",
&key->key.pubkey, psigs);
}
k += 1;
}
} while (key != NULL);
ret = mj_asprint(json, &id_array, MJ_JSON_ENCODE);
mj_delete(&id_array);
return ret;
}
/* find and list some public keys in a keyring */
int
netpgp_match_pubkeys(netpgp_t *netpgp, char *name, void *vp)
@ -1972,38 +1748,6 @@ netpgp_validate_sigs(netpgp_t *netpgp)
return 1;
}
/* print the json out on 'fp' */
int
netpgp_format_json(void *vp, const char *json, const int psigs)
{
mj_t ids;
FILE *fp;
int from;
int idc;
int tok;
int to;
int i;
if ((fp = (FILE *)vp) == NULL || json == NULL) {
return 0;
}
/* ids is an array of strings, each containing 1 entry */
(void) memset(&ids, 0x0, sizeof(ids));
from = to = tok = 0;
/* convert from string into an mj structure */
(void) mj_parse(&ids, json, &from, &to, &tok);
if ((idc = mj_arraycount(&ids)) == 1 && strchr(json, '{') == NULL) {
idc = 0;
}
(void) fprintf(fp, "%d key%s found\n", idc, (idc == 1) ? "" : "s");
for (i = 0 ; i < idc ; i++) {
format_json_key(fp, &ids.value.v[i], psigs);
}
/* clean up */
mj_delete(&ids);
return idc;
}
/* find a key in keyring, and write it in ssh format */
int
netpgp_write_sshkey(netpgp_t *netpgp, char *s, const char *userid, char *out, size_t size)


+ 0
- 85
dist/src/lib/packet-print.c View File

@ -77,7 +77,6 @@ __RCSID("$NetBSD$");
#include "netpgpsdk.h"
#include "packet.h"
#include "netpgpdigest.h"
#include "mj.h"
/* static functions */
@ -480,90 +479,6 @@ pgp_sprint_keydata(pgp_io_t *io, const pgp_keyring_t *keyring,
uidbuf);
}
/* return the key info as a JSON encoded string */
int
pgp_sprint_mj(pgp_io_t *io, const pgp_keyring_t *keyring,
const pgp_key_t *key, mj_t *keyjson, const char *header,
const pgp_pubkey_t *pubkey, const int psigs)
{
const pgp_key_t *trustkey;
unsigned from;
unsigned i;
unsigned j;
mj_t sub_obj;
char keyid[PGP_KEY_ID_SIZE * 3];
char fp[(PGP_FINGERPRINT_SIZE * 3) + 1];
if (key == NULL || iskeyrevoked(key)) {
return -1;
}
(void) memset(keyjson, 0x0, sizeof(*keyjson));
mj_create(keyjson, "object");
mj_append_field(keyjson, "header", "string", header, -1);
mj_append_field(keyjson, "key bits", "integer", (int64_t) numkeybits(pubkey));
mj_append_field(keyjson, "pka", "string", pgp_show_pka(pubkey->alg), -1);
mj_append_field(keyjson, "key id", "string", strhexdump(keyid, key->pubkeyid, PGP_KEY_ID_SIZE, ""), -1);
mj_append_field(keyjson, "fingerprint", "string",
strhexdump(fp, key->pubkeyfpr.fingerprint, key->pubkeyfpr.length, " "), -1);
mj_append_field(keyjson, "birthtime", "integer", pubkey->birthtime);
mj_append_field(keyjson, "duration", "integer", pubkey->duration);
for (i = 0; i < key->uidc; i++) {
(void) memset(&sub_obj, 0x0, sizeof(sub_obj));
mj_create(&sub_obj, "array");
mj_append(&sub_obj, "string", key->uids[i], -1);
//mj_append(&sub_obj, "string", (r >= 0) ? "[REVOKED]" : "", -1);
mj_append_field(keyjson, "uid", "array", &sub_obj);
mj_delete(&sub_obj);
for (j = 0 ; j < key->uidsigc ; j++) {
if (psigs) {
if (key->uidsigs[j].uid != i) {
continue;
}
} else {
if (!(key->uidsigs[j].siginfo.version == 4 &&
key->uidsigs[j].siginfo.type == PGP_SIG_SUBKEY &&
i == key->uidc - 1)) {
continue;
}
}
(void) memset(&sub_obj, 0x0, sizeof(sub_obj));
mj_create(&sub_obj, "array");
if (key->uidsigs[j].siginfo.version == 4 &&
key->uidsigs[j].siginfo.type == PGP_SIG_SUBKEY) {
const uint8_t *encid;
const pgp_pubkey_t *enckey = pgp_key_get_enckey(key, &encid);
mj_append(&sub_obj, "integer", (int64_t)numkeybits(enckey));
mj_append(&sub_obj, "string",
(const char *)pgp_show_pka(enckey->alg), -1);
mj_append(&sub_obj, "string",
strhexdump(keyid, encid, PGP_KEY_ID_SIZE, ""), -1);
mj_append(&sub_obj, "integer", (int64_t)enckey->birthtime);
mj_append_field(keyjson, "encryption", "array", &sub_obj);
mj_delete(&sub_obj);
} else {
mj_append(&sub_obj, "string",
strhexdump(keyid, key->uidsigs[j].siginfo.signer_id, PGP_KEY_ID_SIZE, ""), -1);
mj_append(&sub_obj, "integer",
(int64_t)(key->uidsigs[j].siginfo.birthtime));
from = 0;
trustkey = pgp_getkeybyid(io, keyring, key->uidsigs[j].siginfo.signer_id, &from, NULL, NULL, 0, 0);
mj_append(&sub_obj, "string",
(trustkey) ? (char *)trustkey->uids[pgp_key_get_uid0(trustkey)] : "[unknown]", -1);
mj_append_field(keyjson, "sig", "array", &sub_obj);
mj_delete(&sub_obj);
}
}
}
if (pgp_get_debug_level(__FILE__)) {
char *buf;
mj_asprint(&buf, keyjson, 1);
(void) fprintf(stderr, "pgp_sprint_mj: '%s'\n", buf);
free(buf);
}
return 1;
}
int
pgp_hkp_sprint_keydata(pgp_io_t *io, const pgp_keyring_t *keyring,
const pgp_key_t *key, char **buf,


Loading…
Cancel
Save