-makefile for new test_stream_local (commented)
[oweals/gnunet.git] / src / transport / gnunet-transport-certificate-creation.c
1 /*
2      This file is part of GNUnet.
3      (C) 2011 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file transport/gnunet-transport-certificate-creation.c
23  * @brief create certificate for HTTPS transport
24  * @author LRN
25  *
26  */
27 #include "platform.h"
28 #include "gnunet_disk_lib.h"
29 #include "gnunet_os_lib.h"
30
31
32 static void
33 removecerts (const char *file1, const char *file2)
34 {
35   if (GNUNET_DISK_file_test (file1) == GNUNET_YES)
36   {
37     CHMOD (file1, S_IWUSR | S_IRUSR);
38     REMOVE (file1);
39   }
40   if (GNUNET_DISK_file_test (file2) == GNUNET_YES)
41   {
42     CHMOD (file2, S_IWUSR | S_IRUSR);
43     REMOVE (file2);
44   }
45 }
46
47
48 int
49 main (int argc, char **argv)
50 {
51   struct GNUNET_OS_Process *openssl;
52
53   if (argc != 3)
54     return 1;
55   removecerts (argv[1], argv[2]);
56   close (2);                    /* eliminate stderr */
57   /* Create RSA Private Key */
58   /* openssl genrsa -out $1 1024 2> /dev/null */
59   openssl =
60       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "openssl", "openssl", "genrsa",
61                                "-out", argv[1], "1024", NULL);
62   if (openssl == NULL)
63     return 2;
64   GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK);
65   GNUNET_OS_process_close (openssl);
66
67   /* Create a self-signed certificate in batch mode using rsa key */
68   /* openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null */
69   openssl =
70       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "openssl", "openssl", "req",
71                                "-batch", "-days", "365", "-out", argv[2],
72                                "-new", "-x509", "-key", argv[1], NULL);
73   if (openssl == NULL)
74     return 3;
75   GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK);
76   GNUNET_OS_process_close (openssl);
77   CHMOD (argv[1], S_IRUSR);
78   CHMOD (argv[2], S_IRUSR);
79   return 0;
80 }
81
82 /* end of gnunet-transport-certificate-creation.c */