#
# Makefile for onak.
#
-# $Id: Makefile,v 1.18 2003/10/03 23:07:31 noodles Exp $
+# $Id: Makefile,v 1.19 2004/05/27 01:25:37 noodles Exp $
#
CC = gcc
PROGS = add lookup gpgwww onak splitkeys
CORE_OBJS = armor.o charfuncs.o decodekey.o getcgi.o hash.o keydb_$(DBTYPE).o \
- keyid.o keyindex.o ll.o mem.o onak-conf.o parsekey.o sha.o md5.o log.o
+ keyid.o keyindex.o ll.o mem.o onak-conf.o parsekey.o sha.o md5.o \
+ log.o photoid.o
OBJS = merge.o stats.o sendsync.o $(CORE_OBJS)
SRCS = armor.c parsekey.c merge.c keyid.c md5.c sha.c main.c getcgi.c stats.c \
keyindex.c mem.c lookup.c add.c keydb_$(DBTYPE).c ll.c hash.c \
- gpgwww.c onak-conf.c charfuncs.c sendsync.c log.c
+ gpgwww.c onak-conf.c charfuncs.c sendsync.c log.c photoid.c
all: .depend $(PROGS) testparse maxpath sixdegrees splitkeys
*
* Copyright 2002 Project Purple
*
- * $Id: keyindex.c,v 1.14 2004/05/26 17:48:02 noodles Exp $
+ * $Id: keyindex.c,v 1.15 2004/05/27 01:25:37 noodles Exp $
*/
#include <assert.h>
return 0;
}
-int list_uids(struct openpgp_signedpacket_list *uids, bool verbose, bool html)
+int list_uids(uint64_t keyid, struct openpgp_signedpacket_list *uids,
+ bool verbose, bool html)
{
char buf[1024];
+ int imgindx = 0;
while (uids != NULL) {
if (uids->packet->tag == 13) {
printf(" %s\n",
(html) ? txt2html(buf) : buf);
} else if (uids->packet->tag == 17) {
- printf(" "
- "[photo id]\n");
+ printf(" ");
+ if (html) {
+ printf("<img src=\"lookup?op=photo&search=0x%llX&idx=%d\" alt=\"[photo id]\">\n",
+ keyid,
+ imgindx);
+ imgindx++;
+ } else {
+ printf("[photo id]\n");
+ }
}
if (verbose) {
list_sigs(uids->sigs, html);
int type = 0;
int length = 0;
char buf[1024];
+ uint64_t keyid;
if (html) {
puts("<pre>");
keys->publickey->data[0]);
}
+ keyid = (get_keyid(keys) & 0xFFFFFFFF),
printf("pub %5d%c/%08X %04d/%02d/%02d ",
length,
(type == 1) ? 'R' : ((type == 16) ? 'g' :
((type == 17) ? 'D' : '?')),
- (uint32_t) (get_keyid(keys) & 0xFFFFFFFF),
+ (uint32_t) keyid,
created->tm_year + 1900,
created->tm_mon + 1,
created->tm_mday);
}
}
- list_uids(curuid, verbose, html);
+ list_uids(keyid, curuid, verbose, html);
if (verbose) {
list_subkeys(keys->subkeys, verbose, html);
}
*
* Copyright 2002 Project Purple
*
- * $Id: lookup.c,v 1.14 2004/05/26 18:53:14 noodles Exp $
+ * $Id: lookup.c,v 1.15 2004/05/27 01:25:37 noodles Exp $
*/
#include <inttypes.h>
#include "mem.h"
#include "onak-conf.h"
#include "parsekey.h"
+#include "photoid.h"
#define OP_UNKNOWN 0
#define OP_GET 1
#define OP_INDEX 2
#define OP_VINDEX 3
+#define OP_PHOTO 4
void find_keys(char *search, uint64_t keyid, bool ishex,
bool fingerprint, bool exact, bool verbose, bool mrhkp)
char **params = NULL;
int op = OP_UNKNOWN;
int i;
+ int indx = 0;
bool fingerprint = false;
bool exact = false;
bool ishex = false;
op = OP_INDEX;
} else if (!strcmp(params[i+1], "vindex")) {
op = OP_VINDEX;
+ } else if (!strcmp(params[i+1], "photo")) {
+ op = OP_PHOTO;
}
} else if (!strcmp(params[i], "search")) {
search = params[i+1];
ishex = true;
}
}
+ } else if (!strcmp(params[i], "idx")) {
+ indx = atoi(params[i+1]);
} else if (!strcmp(params[i], "fingerprint")) {
if (!strcmp(params[i+1], "on")) {
fingerprint = true;
if (mrhkp) {
puts("Content-Type: text/plain\n");
+ } else if (op == OP_PHOTO) {
+ puts("Content-Type: image/jpeg\n");
} else {
start_html("Lookup of key");
}
find_keys(search, keyid, ishex, fingerprint, exact,
true, mrhkp);
break;
+ case OP_PHOTO:
+ if (fetch_key(keyid, &publickey, false)) {
+ struct openpgp_packet *photo = NULL;
+ photo = getphoto(publickey, 0);
+ if (photo != NULL) {
+ fwrite(photo->data+19,
+ 1,
+ (photo->length - 19),
+ stdout);
+ }
+ free_publickey(publickey);
+ publickey = NULL;
+ }
+ break;
default:
puts("Unknown operation!");
}
*
* Copyright 2002 Project Purple
*
- * $Id: onak.c,v 1.19 2004/03/23 12:33:47 noodles Exp $
+ * $Id: onak.c,v 1.20 2004/05/27 01:25:37 noodles Exp $
*/
#include <stdio.h>
#include "merge.h"
#include "onak-conf.h"
#include "parsekey.h"
+#include "photoid.h"
void find_keys(char *search, uint64_t keyid, bool ishex,
bool fingerprint, bool exact, bool verbose)
} else if (!strcmp("vindex", argv[optind])) {
find_keys(search, keyid, ishex, fingerprint,
false, true);
+ } else if (!strcmp("getphoto", argv[optind])) {
+ if (!ishex) {
+ puts("Can't get a key on uid text."
+ " You must supply a keyid.");
+ } else if (fetch_key(keyid, &keys, false)) {
+ struct openpgp_packet *photo = NULL;
+ FILE *photof = NULL;
+ photo = getphoto(keys, 0);
+ if (photo != NULL) {
+ photof = fopen("keyphoto.jpg", "w");
+ fwrite(photo->data+19,
+ 1,
+ (photo->length - 19),
+ photof);
+ fclose(photof);
+ }
+ free_publickey(keys);
+ keys = NULL;
+ } else {
+ puts("Key not found");
+ }
} else if (!strcmp("delete", argv[optind])) {
delete_key(getfullkeyid(keyid), false);
} else if (!strcmp("get", argv[optind])) {
--- /dev/null
+/*
+ * photoid.c - Routines for OpenPGP id photos.
+ *
+ * Jonathan McDowell <noodles@earth.li>
+ *
+ * Copyright 2004 Project Purple
+ *
+ * $Id: photoid.c,v 1.1 2004/05/27 01:25:37 noodles Exp $
+ */
+
+#include <assert.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "keyid.h"
+#include "keyindex.h"
+#include "keystructs.h"
+
+/**
+ * getphoto - returns an OpenPGP packet containing a photo id.
+ * @key: The key to return the photo id from.
+ * @index: The index of the photo to return.
+ *
+ * This function returns the OpenPGP packet containing a photo id from a
+ * supplied key. index specifies which photo id should be returned. If
+ * there's no such photo id NULL is returned.
+ */
+struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index)
+{
+ struct openpgp_signedpacket_list *curuid = NULL;
+ struct openpgp_packet *photo = NULL;
+ int i = 0;
+
+ assert(key != NULL);
+
+ curuid = key->uids;
+ i = 0;
+ while (photo == NULL && curuid != NULL && i <= index) {
+ if (curuid->packet->tag == 17) {
+ if (i == index) {
+ photo = curuid->packet;
+ } else {
+ i++;
+ }
+ }
+ curuid = curuid->next;
+ }
+
+ return photo;
+}
--- /dev/null
+/*
+ * photoid.h - Routines for OpenPGP id photos.
+ *
+ * Jonathan McDowell <noodles@earth.li>
+ *
+ * Copyright 2004 Project Purple
+ *
+ * $Id: photoid.h,v 1.1 2004/05/27 01:25:37 noodles Exp $
+ */
+
+#ifndef __PHOTOID_H__
+#define __PHOTOID_H__
+
+#include "keystructs.h"
+
+/**
+ * getphoto - returns an OpenPGP packet containing a photo id.
+ * @key: The key to return the photo id from.
+ * @index: The index of the photo to return.
+ *
+ * This function returns the OpenPGP packet containing a photo id from a
+ * supplied key. index specifies which photo id should be returned. If
+ * there's no such photo id NULL is returned.
+ */
+struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index);
+
+#endif /* __PHOTOID_H__ */