2 * curvetun - the cipherspace wormhole creator
3 * Part of the netsniff-ng project
4 * By Daniel Borkmann <daniel@netsniff-ng.org>
5 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
6 * Swiss federal institute of technology (ETH Zurich)
43 static sig_atomic_t sigint
= 0;
45 static const char *short_options
= "k:c:m:svhp:t:l";
47 static struct option long_options
[] = {
48 {"client", optional_argument
, 0, 'c'},
49 {"mode", required_argument
, 0, 'm'},
50 {"port", required_argument
, 0, 'p'},
51 {"stun", required_argument
, 0, 't'},
52 {"keygen", optional_argument
, 0, 'k'},
53 {"server", no_argument
, 0, 's'},
54 {"list-curves", no_argument
, 0, 'l'},
55 {"version", no_argument
, 0, 'v'},
56 {"help", no_argument
, 0, 'h'},
60 static void signal_handler(int number
)
73 static void header(void)
75 printf("%s%s%s\n", colorize_start(bold
), "curvetun "
76 VERSION_STRING
, colorize_end());
79 static void help(void)
81 printf("\ncurvetun %s, ``Elliptic Curve Crypto''-based IP-tunnel\n",
83 printf("http://www.netsniff-ng.org\n\n");
84 printf("Usage: curvetun [options]\n");
86 printf(" -k|--keygen[=curve] Generate public/private keypair\n");
87 printf(" Default curve: 'secp256r1/nistp256'\n");
88 printf(" -l|--list-curves Show available curves\n");
89 printf(" Client settings:\n");
90 printf(" -c|--client[=alias] Client mode, server alias optional\n");
91 printf(" -m|--mode <mode> Working mode, if no alias specified\n");
92 printf(" `--- latency Select server with lowest latency\n");
93 printf(" `-- rrobin Select servers in round robin\n");
94 printf(" `- random Select servers randomly (default)\n");
95 printf(" Server settings:\n");
96 printf(" -s|--server Server mode\n");
97 printf(" -p|--port <num> Port number (mandatory)\n");
98 printf(" -t|--stun <server> Show public IP/Port mapping via STUN\n");
100 printf(" -v|--version Print version\n");
101 printf(" -h|--help Print this help\n");
103 printf("Example:\n");
104 printf(" Keygen: curvetun --keygen=secp384r1/nistp384\n");
105 printf(" Server: curvetun --server --port 6666 --stun stun.ekiga.net\n");
106 printf(" Client: curvetun --client --mode random\n");
107 printf(" Where both participants have the following files specified:\n");
108 printf(" ~/.curvetun/clients - Participants the server accepts\n");
109 printf(" line-format: username:pubkey\n");
110 printf(" ~/.curvetun/servers - Possible servers the client can connect to\n");
111 printf(" line-format: alias:serverip|servername:port:pubkey\n");
112 printf(" ~/.curvetun/priv.key - Your private key\n");
113 printf(" ~/.curvetun/pub.key - Your public key\n");
114 printf(" ~/.curvetun/username - Your username\n");
117 printf(" There is no default port specified, so that users are forced\n");
118 printf(" to select their own!\n");
119 printf(" Elliptic Curve Crypto powered by Bertram Poettering's SECCURE\n");
121 printf("Please report bugs to <bugs@netsniff-ng.org>\n");
122 printf("Copyright (C) 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n");
123 printf("Swiss federal institute of technology (ETH Zurich)\n");
124 printf("License: GNU GPL version 2\n");
125 printf("This is free software: you are free to change and redistribute it.\n");
126 printf("There is NO WARRANTY, to the extent permitted by law.\n\n");
131 static void version(void)
133 printf("\ncurvetun %s, ``Elliptic Curve Crypto''-based IP-tunnel\n",
135 printf("http://www.netsniff-ng.org\n\n");
136 printf("Please report bugs to <bugs@netsniff-ng.org>\n");
137 printf("Copyright (C) 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n");
138 printf("Swiss federal institute of technology (ETH Zurich)\n");
139 printf("License: GNU GPL version 2\n");
140 printf("This is free software: you are free to change and redistribute it.\n");
141 printf("There is NO WARRANTY, to the extent permitted by law.\n\n");
146 int main_keygen(char *curve
)
149 panic("No curve supplied for keygen!\n");
150 if (!curve_by_name(curve
))
151 panic("No such curve available!\n");
152 info("Using curve %s!\n", curve
);
158 int main_client(enum client_mode cmode
)
164 int main_server(int port
)
170 int main(int argc
, char **argv
)
173 uint16_t port
, stun_port
= 3478; /* Future: via --stun */
174 char *stun
= NULL
, *curve
= NULL
;
175 enum working_mode wmode
= MODE_UNKNOW
;
176 enum client_mode cmode
= MODE_ALL_RANDOM
;
178 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
179 &opt_index
)) != EOF
) {
191 cmode
= MODE_ALL_RANDOM
;
196 curve
= xstrdup(optarg
);
198 curve
= xstrdup("secp256r1/nistp256");
204 stun
= xstrdup(optarg
);
218 panic("Option -%c requires an argument!\n",
222 whine("Unknown option character "
223 "`0x%X\'!\n", optopt
);
234 register_signal(SIGINT
, signal_handler
);
235 register_signal(SIGHUP
, signal_handler
);
236 register_signal(SIGSEGV
, muntrace_handler
);
250 panic("No port specified!\n");
252 print_stun_probe(stun
, stun_port
, port
);
258 panic("Either select keygen, client or server mode!\n");