GNUnet  0.10.x
Functions
gnunet-transport-certificate-creation.c File Reference

create certificate for HTTPS transport More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for gnunet-transport-certificate-creation.c:

Go to the source code of this file.

Functions

static void make_dev_zero (int fd, int flags)
 Turn the given file descriptor in to '/dev/null'. More...
 
static void removecerts (const char *file1, const char *file2)
 
int main (int argc, char **argv)
 

Detailed Description

create certificate for HTTPS transport

Author
LRN

Definition in file gnunet-transport-certificate-creation.c.

Function Documentation

◆ make_dev_zero()

static void make_dev_zero ( int  fd,
int  flags 
)
static

Turn the given file descriptor in to '/dev/null'.

Parameters
fdfd to bind to /dev/null
flagsflags to use (O_RDONLY or O_WRONLY)

Definition at line 37 of file gnunet-transport-certificate-creation.c.

References GNUNET_assert, and GNUNET_break.

Referenced by main().

39 {
40  int z;
41 
42  GNUNET_assert (0 == close (fd));
43  z = open ("/dev/null", flags);
44  GNUNET_assert (-1 != z);
45  if (z == fd)
46  return;
47  GNUNET_break (fd == dup2 (z, fd));
48  GNUNET_assert (0 == close (z));
49 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Here is the caller graph for this function:

◆ removecerts()

static void removecerts ( const char *  file1,
const char *  file2 
)
static

Definition at line 54 of file gnunet-transport-certificate-creation.c.

References CHMOD, GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror_file, GNUNET_YES, and REMOVE.

Referenced by main().

56 {
57  if (GNUNET_YES == GNUNET_DISK_file_test (file1))
58  {
59  if (0 != CHMOD (file1, S_IWUSR | S_IRUSR))
61  if (0 != REMOVE (file1))
63  }
64  if (GNUNET_YES == GNUNET_DISK_file_test (file2))
65  {
66  if (0 != CHMOD (file2, S_IWUSR | S_IRUSR))
68  if (0 != REMOVE (file2))
70  }
71 }
int GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:669
#define CHMOD(f, p)
Definition: plibc.h:657
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define REMOVE(p)
Definition: plibc.h:661
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 75 of file gnunet-transport-certificate-creation.c.

References CHMOD, GNUNET_assert, GNUNET_DISK_directory_create_for_file(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_OS_process_destroy(), GNUNET_OS_process_wait(), GNUNET_OS_start_process(), make_dev_zero(), and removecerts().

76 {
77  struct GNUNET_OS_Process *openssl;
78 
79  if (3 != argc)
80  {
81  fprintf (stderr,
82  "Invalid arguments.\n");
83  return 1;
84  }
85  removecerts (argv[1], argv[2]);
88  /* eliminate stderr */
89 #if WINDOWS
90  (void) close (2);
91 #else
92  make_dev_zero (2, O_WRONLY);
93 #endif
94  /* Create RSA Private Key */
95  /* openssl genrsa -out $1 1024 2> /dev/null */
96  openssl =
98  NULL, NULL, NULL,
99  "openssl", "openssl", "genrsa",
100  "-out", argv[1], "1024", NULL);
101  if (NULL == openssl)
102  {
103  fprintf (stderr,
104  "Failed to run openssl. Is openssl installed?\n");
105  return 2;
106  }
108  GNUNET_OS_process_destroy (openssl);
109 
110  /* Create a self-signed certificate in batch mode using rsa key */
111  /* openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null */
112  openssl =
114  NULL, NULL, NULL,
115  "openssl", "openssl", "req",
116  "-batch", "-days", "365", "-out", argv[2],
117  "-new", "-x509", "-key", argv[1], NULL);
118  if (NULL == openssl)
119  {
120  fprintf (stderr,
121  "Failed to create self-signed certificate with openssl.\n");
122  return 3;
123  }
125  GNUNET_OS_process_destroy (openssl);
126  if (0 != CHMOD (argv[1], S_IRUSR))
128  if (0 != CHMOD (argv[2], S_IRUSR))
130  return 0;
131 }
static void make_dev_zero(int fd, int flags)
Turn the given file descriptor in to '/dev/null'.
#define CHMOD(f, p)
Definition: plibc.h:657
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:364
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_OS_Process * GNUNET_OS_start_process(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
Definition: os_priority.c:1400
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:833
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void removecerts(const char *file1, const char *file2)
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
When these flags are set, the child process will inherit stdout and stderr of the parent...
Definition: gnunet_os_lib.h:98
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1762
Here is the call graph for this function: