]> mj.ucw.cz Git - moe.git/commitdiff
Added a simple utility for key generation.
authorMartin Mares <mj@ucw.cz>
Tue, 5 Jun 2007 12:14:22 +0000 (14:14 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 5 Jun 2007 12:14:22 +0000 (14:14 +0200)
submit/Makefile
submit/privkey.c [new file with mode: 0644]

index 7866155972f22fd6e6d3d98a8613a8a0d4179500..71a392b13682f3fd463a8af0e2e87c7585de4b44 100644 (file)
@@ -1,14 +1,15 @@
 TLSCF:=$(shell libgnutls-config --cflags)
 TLSLF:=$(shell libgnutls-config --libs)
+GCRCF:=$(shell libgcrypt-config --cflags)
 
-CFLAGS=-O2 -Iinclude -g -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -std=gnu99 $(TLSCF)
+CFLAGS=-O2 -Iinclude -g -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -std=gnu99 $(TLSCF) $(GCRCF)
 LDFLAGS=$(TLSLF)
 
 CC=gcc-4.1.1
 CFLAGS+=-Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers
 LDFLAGS+=-lpthread     # FIXME: Use libucw without threads
 
-all: submitd connect
+all: submitd connect privkey
 
 submitd: submitd.o commands.o tasks.o lib/libsh.a lib/libucw.a
 submitd.o: submitd.c submitd.h
@@ -16,6 +17,8 @@ commands.o: commands.c submitd.h
 tasks.o: tasks.c submitd.h
 connect: connect.o lib/libucw.a
 connect.o: connect.c
+privkey: privkey.o lib/libucw.a
+privkey.o: privkey.c
 
 certs:
        certtool --generate-privkey --outfile ca-key.pem
diff --git a/submit/privkey.c b/submit/privkey.c
new file mode 100644 (file)
index 0000000..acc093d
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  This is a trivial private key generator using a less secure
+ *  random generator (/dev/urandom). This should be safe enough
+ *  for the short-lived contest keys and it helps us to avoid
+ *  spending hours by generating super-safe random numbers.
+ *
+ *  (c) 2007 Martin Mares <mj@ucw.cz>
+ */
+
+#include "lib/lib.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+#include <gcrypt.h>
+
+int main(void)
+{
+  gnutls_x509_privkey key;
+  int err;
+
+  gnutls_global_init();
+  gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM);
+  err = gnutls_x509_privkey_init(&key);
+  if (err < 0)
+    die("privkey_init: %s", gnutls_strerror(err));
+  err = gnutls_x509_privkey_generate(key, GNUTLS_PK_RSA, 1024, 0);
+  if (err < 0)
+    die("privkey_generate: %s", gnutls_strerror(err));
+
+  byte buf[32768];
+  size_t size = sizeof(buf);
+  err = gnutls_x509_privkey_export(key, GNUTLS_X509_FMT_PEM, buf, &size);
+  if (err < 0)
+    die("privkey_export: %s", gnutls_strerror(err));
+  puts(buf);
+
+  return 0;
+}