summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
Diffstat (limited to 'host')
-rw-r--r--host/Makefile19
-rw-r--r--host/cryptopad.c122
-rw-r--r--host/get.c103
-rw-r--r--host/main.c104
-rw-r--r--host/project.h1
-rw-r--r--host/set.c103
6 files changed, 132 insertions, 320 deletions
diff --git a/host/Makefile b/host/Makefile
index 317bc59..2013f89 100644
--- a/host/Makefile
+++ b/host/Makefile
@@ -2,23 +2,22 @@ INCLUDES=$(shell pkg-config --cflags libusb-1.0)
LIBS=-Bstatic $(shell pkg-config --libs libusb-1.0) -lpthread -Bdynamic -ludev
LDFLAGS=-s
-PROGS=main set get
-LIBSRCS=hexdump.c
+PROG=cryptopad
+SRCS=hexdump.c cryptopad.c
-LIBOBJS=${LIBSRCS:%.c=%.o}
+OBJS=${SRCS:%.c=%.o}
CFLAGS=${OPT}
CPPFLAGS=${INCLUDES} ${DEFINES}
-default:${PROGS}
+default:${PROG}
-${PROGS}: %:%.o ${LIBOBJS}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $@.o ${OBJS} ${LIBS}
-
-#${PROG}:${OBJS}
-# ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${LIBS}
+${PROG}:${OBJS}
+ ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${LIBS}
+install: ${PROG}
+ install -c -m 755 ${PROG} /sbin/${PROG}
clean:
- /bin/rm -f *~ *.d ${PROGS} ${OBJS}
+ /bin/rm -f *~ *.d ${PROG} ${OBJS}
diff --git a/host/cryptopad.c b/host/cryptopad.c
new file mode 100644
index 0000000..42b1d36
--- /dev/null
+++ b/host/cryptopad.c
@@ -0,0 +1,122 @@
+#include "project.h"
+#include "../common/vendor_req.h"
+
+#define TIMEOUT 4000
+
+struct libusb_device * find_device(libusb_context *ctx)
+{
+ libusb_device **list;
+ ssize_t num_devs;
+ ssize_t i;
+
+ num_devs = libusb_get_device_list(ctx, &list);
+ for (i = 0; i < num_devs; ++i) {
+ struct libusb_device_descriptor desc;
+ struct libusb_device *dev = list[i];
+
+ if (libusb_get_device_descriptor(dev, &desc))
+ continue;
+
+
+ if (desc.idVendor!=0x1d6b) continue;
+ if (desc.idProduct!=0x1932) continue;
+
+ return dev;
+
+ }
+ libusb_free_device_list(list, 0);
+
+ return NULL;
+}
+
+
+static void usage(char *n)
+{
+fprintf(stderr,"Usage:\n"
+ "%s [-g [-n secs]] [-s [-p pwd]] [-h]\n"
+ " -h display this message\n"
+ " -g ask cryptopad to type password\n"
+ " -n secs wait secs before typing password\n"
+ " -s set password in cryptopad\n"
+ " -p pwd password to set, prompts otherwise\n"
+ " -w wipe password from cryptopad\n",
+ n);
+
+exit(1);
+}
+
+
+
+
+int main(int argc,char *argv[])
+{
+ libusb_context *ctx;
+ libusb_device *dev;
+ libusb_device_handle *devh;
+ int wflag=0,gflag=0,sflag=0;
+ char *pass=NULL;
+ int c,ret;
+ int delay=0;
+
+
+ while((c=getopt(argc,argv,"hwgsp:n:"))!=-1) {
+ switch(c) {
+ case 'n':
+ if (optarg) delay=atoi(optarg);
+ break;
+ case 'g':
+ gflag++;
+ break;
+ case 's':
+ sflag++;
+ break;
+ case 'w':
+ wflag++;
+ break;
+ case 'p':
+ pass=optarg;
+ break;
+ default:
+ usage(argv[0]);
+ }
+ }
+
+ if ((ret=libusb_init(&ctx)))
+ errx(EX_IOERR, "unable to initialize libusb: %i", ret);
+
+ dev=find_device(ctx);
+
+ if (!dev) err(1,"no cryptopad found");
+
+ if ((ret=libusb_open(dev, &devh))) err(1,"unable to open usb device: %i",ret);
+
+
+ if (sflag) {
+ char *pwd;
+ if (!pass) pass=getpass("Enter password:");
+
+ pwd=malloc(strlen(pass)+2);
+ strcpy(pwd,pass);
+ strcat(pwd,"\n");
+
+ libusb_control_transfer( devh, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, VENDOR_REQ_SET_KEY, 0, 0, pwd, strlen(pwd), TIMEOUT );
+ }
+
+
+ if (gflag)
+ libusb_control_transfer( devh, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, VENDOR_REQ_SEND_KEY, delay, 0, NULL, 0, TIMEOUT );
+
+ if (wflag)
+ libusb_control_transfer( devh, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, VENDOR_REQ_CLEAR_KEY, 0, 0, NULL, 0, TIMEOUT );
+
+
+ libusb_close(devh);
+
+ return 0;
+}
+
+
+
+
+
+
diff --git a/host/get.c b/host/get.c
deleted file mode 100644
index 79a6a40..0000000
--- a/host/get.c
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "project.h"
-#include "../common/vendor_req.h"
-
-
-
-static void poke(libusb_device_handle *devh)
-{
-uint32_t timeout=4000;
-int len;
-
-
-
-len= libusb_control_transfer( devh,
- /* bmRequestType */ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
- /* bRequest */ VENDOR_REQ_SEND_KEY,
- /* wValue */ 0x23,
- /* wIndex */ 0,
- /* Data */ NULL,
- /* wLength */ 0, timeout );
-
-
-
-
-//if (len>=0)
-//hexdump(">",buf,len);
-
-
-}
-
-
-
-static void poke_device(libusb_device *dev, struct libusb_device_descriptor *desc)
-{
-int ret;
-libusb_device_handle *devh;
-
-ret=libusb_open(dev, &devh);
-
-if (ret) {
- warn("unable to open device: %i",ret);
- return;
-}
-
-printf("poke\n");
-
-poke(devh);
-
-libusb_close(devh);
-
-}
-
-void probe_devices(libusb_context *ctx)
-{
- libusb_device **list;
- ssize_t num_devs;
- ssize_t i;
-
- num_devs = libusb_get_device_list(ctx, &list);
- for (i = 0; i < num_devs; ++i) {
- struct libusb_device_descriptor desc;
- struct libusb_device *dev = list[i];
-
- if (libusb_get_device_descriptor(dev, &desc))
- continue;
-
-
- if (desc.idVendor!=0x1d6b) continue;
- if (desc.idProduct!=0x1932) continue;
-
- poke_device(dev,&desc);
-
- }
- libusb_free_device_list(list, 0);
-}
-
-
-
-
-
-int main(int argc,char *argv)
-{
- int ret;
-
- libusb_context *ctx;
-
-
- ret = libusb_init(&ctx);
- if (ret)
- errx(EX_IOERR, "unable to initialize libusb: %i", ret);
-
-
- //libusb_set_debug(ctx, 255);
-
- probe_devices(ctx);
-
- return 0;
-}
-
-
-
-
-
-
diff --git a/host/main.c b/host/main.c
deleted file mode 100644
index 5a61963..0000000
--- a/host/main.c
+++ /dev/null
@@ -1,104 +0,0 @@
-#include "project.h"
-#include "../common/vendor_req.h"
-
-
-
-static void poke(libusb_device_handle *devh)
-{
-uint32_t timeout=4000;
-char buf[128];
-int len;
-
-
-
-len= libusb_control_transfer( devh,
- /* bmRequestType */ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
- /* bRequest */ VENDOR_REQ_KEYPRESS,
- /* wValue */ 0x23,
- /* wIndex */ 0,
- /* Data */ buf,
- /* wLength */ sizeof(buf), timeout );
-
-
-
-
-//if (len>=0)
-//hexdump(">",buf,len);
-
-
-}
-
-
-
-static void poke_device(libusb_device *dev, struct libusb_device_descriptor *desc)
-{
-int ret;
-libusb_device_handle *devh;
-
-ret=libusb_open(dev, &devh);
-
-if (ret) {
- warn("unable to open device: %i",ret);
- return;
-}
-
-printf("poke\n");
-
-poke(devh);
-
-libusb_close(devh);
-
-}
-
-void probe_devices(libusb_context *ctx)
-{
- libusb_device **list;
- ssize_t num_devs;
- ssize_t i;
-
- num_devs = libusb_get_device_list(ctx, &list);
- for (i = 0; i < num_devs; ++i) {
- struct libusb_device_descriptor desc;
- struct libusb_device *dev = list[i];
-
- if (libusb_get_device_descriptor(dev, &desc))
- continue;
-
-
- if (desc.idVendor!=0x1d6b) continue;
- if (desc.idProduct!=0x1932) continue;
-
- poke_device(dev,&desc);
-
- }
- libusb_free_device_list(list, 0);
-}
-
-
-
-
-
-int main(int argc,char *argv)
-{
- int ret;
-
- libusb_context *ctx;
-
-
- ret = libusb_init(&ctx);
- if (ret)
- errx(EX_IOERR, "unable to initialize libusb: %i", ret);
-
-
- //libusb_set_debug(ctx, 255);
-
- probe_devices(ctx);
-
- return 0;
-}
-
-
-
-
-
-
diff --git a/host/project.h b/host/project.h
index 2302570..cf932b6 100644
--- a/host/project.h
+++ b/host/project.h
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <libusb.h>
+#include <stdarg.h>
#ifdef HAVE_ERR
# include <err.h>
diff --git a/host/set.c b/host/set.c
deleted file mode 100644
index e004c4f..0000000
--- a/host/set.c
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "project.h"
-#include "../common/vendor_req.h"
-
-
-
-static void poke(libusb_device_handle *devh)
-{
-uint32_t timeout=4000;
-//char buf[]="The quick brown fox jumps over the lazy dog\n";
-char buf[]="fishsoup\n";
-int len;
-
-
-
-len= libusb_control_transfer( devh,
- /* bmRequestType */ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
- /* bRequest */ VENDOR_REQ_SET_KEY,
- /* wValue */ 0x0,
- /* wIndex */ 0x0,
- /* Data */ buf,
- /* wLength */ sizeof(buf)-1, timeout );
-
-
-//if (len>=0)
-//hexdump(">",buf,len);
-
-
-}
-
-
-
-static void poke_device(libusb_device *dev, struct libusb_device_descriptor *desc)
-{
-int ret;
-libusb_device_handle *devh;
-
-ret=libusb_open(dev, &devh);
-
-if (ret) {
- warn("unable to open device: %i",ret);
- return;
-}
-
-printf("poke\n");
-
-poke(devh);
-
-libusb_close(devh);
-
-}
-
-void probe_devices(libusb_context *ctx)
-{
- libusb_device **list;
- ssize_t num_devs;
- ssize_t i;
-
- num_devs = libusb_get_device_list(ctx, &list);
- for (i = 0; i < num_devs; ++i) {
- struct libusb_device_descriptor desc;
- struct libusb_device *dev = list[i];
-
- if (libusb_get_device_descriptor(dev, &desc))
- continue;
-
-
- if (desc.idVendor!=0x1d6b) continue;
- if (desc.idProduct!=0x1932) continue;
-
- poke_device(dev,&desc);
-
- }
- libusb_free_device_list(list, 0);
-}
-
-
-
-
-
-int main(int argc,char *argv)
-{
- int ret;
-
- libusb_context *ctx;
-
-
- ret = libusb_init(&ctx);
- if (ret)
- errx(EX_IOERR, "unable to initialize libusb: %i", ret);
-
-
- //libusb_set_debug(ctx, 255);
-
- probe_devices(ctx);
-
- return 0;
-}
-
-
-
-
-
-