From: Martin Mares Date: Tue, 5 Jun 2007 12:14:22 +0000 (+0200) Subject: Added a simple utility for key generation. X-Git-Tag: python-dummy-working~392 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=6ba25cc29e49770947a269a56cf5054ec5ee21b9;hp=2ce10cfd9c89f54e9f9fab9973bd1b66f4413211;p=moe.git Added a simple utility for key generation. --- diff --git a/submit/Makefile b/submit/Makefile index 7866155..71a392b 100644 --- a/submit/Makefile +++ b/submit/Makefile @@ -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 index 0000000..acc093d --- /dev/null +++ b/submit/privkey.c @@ -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 + */ + +#include "lib/lib.h" + +#include +#include +#include +#include +#include + +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; +}