aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport-certificate-creation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-01 20:59:42 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-01 20:59:42 +0000
commitde5131875f4ee71b7b6fd21c3db59df1d55d1f3a (patch)
treeb8a318b1035570a9e44dc8453cb886860a0e3047 /src/transport/gnunet-transport-certificate-creation.c
parent84f1d73fbe2480d9544cfd80fd165882340cb9d3 (diff)
downloadgnunet-de5131875f4ee71b7b6fd21c3db59df1d55d1f3a.tar.gz
gnunet-de5131875f4ee71b7b6fd21c3db59df1d55d1f3a.zip
LRN: added new file
Diffstat (limited to 'src/transport/gnunet-transport-certificate-creation.c')
-rw-r--r--src/transport/gnunet-transport-certificate-creation.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/transport/gnunet-transport-certificate-creation.c b/src/transport/gnunet-transport-certificate-creation.c
new file mode 100644
index 000000000..1256b93ba
--- /dev/null
+++ b/src/transport/gnunet-transport-certificate-creation.c
@@ -0,0 +1,116 @@
1#include "platform.h"
2#include "gnunet_disk_lib.h"
3#include "gnunet_os_lib.h"
4
5/* GNUnet TLS certificate shell scricpt
6 Creates a TSL certificate to use with HTTPS transport plugin
7*/
8
9void removecerts (char *file1, char *file2)
10{
11 if (GNUNET_DISK_file_test (file1) == GNUNET_YES)
12 {
13 CHMOD (file1, 0777);
14 REMOVE (file1);
15 }
16 if (GNUNET_DISK_file_test (file2) == GNUNET_YES)
17 {
18 CHMOD (file2, 0777);
19 REMOVE (file2);
20 }
21}
22
23int
24main (int argc, char **argv)
25{
26 struct GNUNET_OS_Process *openssl;
27 enum GNUNET_OS_ProcessStatusType status_type;
28 unsigned long code;
29
30/*
31if [ $# -ne 2 ]; then
32 exit 1
33fi
34*/
35 if (argc != 3)
36 return 1;
37
38/*
39rm -f $1 $2
40*/
41 removecerts (argv[1], argv[2]);
42 /* Create RSA Private Key */
43/*
44openssl genrsa -out $1 1024 2> /dev/null
45*/
46 openssl = GNUNET_OS_start_process (NULL, NULL, "openssl", "openssl", "genrsa", "-out", argv[1], "1024", NULL);
47/*
48if [ $? -ne 0 ]; then
49 rm -f $1 $2
50 exit 1
51fi
52*/
53 if (openssl == NULL)
54 return 2;
55 if (GNUNET_OS_process_wait (openssl) != GNUNET_OK)
56 {
57 GNUNET_OS_process_kill (openssl, SIGTERM);
58 removecerts (argv[1], argv[2]);
59 return 3;
60 }
61 if (GNUNET_OS_process_status (openssl, &status_type, &code) != GNUNET_OK)
62 {
63 GNUNET_OS_process_kill (openssl, SIGTERM);
64 removecerts (argv[1], argv[2]);
65 return 4;
66 }
67 if (status_type != GNUNET_OS_PROCESS_EXITED || code != 0)
68 {
69 GNUNET_OS_process_kill (openssl, SIGTERM);
70 removecerts (argv[1], argv[2]);
71 return 5;
72 }
73 GNUNET_OS_process_close (openssl);
74
75 /* Create a self-signed certificate in batch mode using rsa key*/
76/*
77 openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null
78*/
79 openssl = GNUNET_OS_start_process (NULL, NULL, "openssl", "openssl", "req", "-batch", "-days", "365", "-out", argv[2], "-new", "-x509", "-key", argv[1], NULL);
80/*
81if [ $? -ne 0 ]; then
82 rm -f $1 $2
83 exit 1
84fi
85*/
86 if (openssl == NULL)
87 return 6;
88 if (GNUNET_OS_process_wait (openssl) != GNUNET_OK)
89 {
90 GNUNET_OS_process_kill (openssl, SIGTERM);
91 removecerts (argv[1], argv[2]);
92 return 7;
93 }
94 if (GNUNET_OS_process_status (openssl, &status_type, &code) != GNUNET_OK)
95 {
96 GNUNET_OS_process_kill (openssl, SIGTERM);
97 removecerts (argv[1], argv[2]);
98 return 8;
99 }
100 if (status_type != GNUNET_OS_PROCESS_EXITED || code != 0)
101 {
102 GNUNET_OS_process_kill (openssl, SIGTERM);
103 removecerts (argv[1], argv[2]);
104 return 9;
105 }
106 GNUNET_OS_process_close (openssl);
107/*
108chmod 0400 $1 $2
109*/
110 CHMOD (argv[1], 0400);
111 CHMOD (argv[2], 0400);
112/*
113exit 0
114*/
115 return 0;
116}