2 #include "gnunet_disk_lib.h"
3 #include "gnunet_os_lib.h"
5 /* GNUnet TLS certificate shell scricpt
6 Creates a TSL certificate to use with HTTPS transport plugin
9 void removecerts (char *file1, char *file2)
11 if (GNUNET_DISK_file_test (file1) == GNUNET_YES)
16 if (GNUNET_DISK_file_test (file2) == GNUNET_YES)
24 main (int argc, char **argv)
26 struct GNUNET_OS_Process *openssl;
27 enum GNUNET_OS_ProcessStatusType status_type;
41 removecerts (argv[1], argv[2]);
42 /* Create RSA Private Key */
44 openssl genrsa -out $1 1024 2> /dev/null
46 openssl = GNUNET_OS_start_process (NULL, NULL, "openssl", "openssl", "genrsa", "-out", argv[1], "1024", NULL);
55 if (GNUNET_OS_process_wait (openssl) != GNUNET_OK)
57 GNUNET_OS_process_kill (openssl, SIGTERM);
58 removecerts (argv[1], argv[2]);
61 if (GNUNET_OS_process_status (openssl, &status_type, &code) != GNUNET_OK)
63 GNUNET_OS_process_kill (openssl, SIGTERM);
64 removecerts (argv[1], argv[2]);
67 if (status_type != GNUNET_OS_PROCESS_EXITED || code != 0)
69 GNUNET_OS_process_kill (openssl, SIGTERM);
70 removecerts (argv[1], argv[2]);
73 GNUNET_OS_process_close (openssl);
75 /* Create a self-signed certificate in batch mode using rsa key*/
77 openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null
79 openssl = GNUNET_OS_start_process (NULL, NULL, "openssl", "openssl", "req", "-batch", "-days", "365", "-out", argv[2], "-new", "-x509", "-key", argv[1], NULL);
88 if (GNUNET_OS_process_wait (openssl) != GNUNET_OK)
90 GNUNET_OS_process_kill (openssl, SIGTERM);
91 removecerts (argv[1], argv[2]);
94 if (GNUNET_OS_process_status (openssl, &status_type, &code) != GNUNET_OK)
96 GNUNET_OS_process_kill (openssl, SIGTERM);
97 removecerts (argv[1], argv[2]);
100 if (status_type != GNUNET_OS_PROCESS_EXITED || code != 0)
102 GNUNET_OS_process_kill (openssl, SIGTERM);
103 removecerts (argv[1], argv[2]);
106 GNUNET_OS_process_close (openssl);
110 CHMOD (argv[1], 0400);
111 CHMOD (argv[2], 0400);