4 curvetun is a lightweight, high-speed ECDH multiuser IP tunnel for Linux
5 that is based on epoll(2). curvetun uses the Linux TUN/TAP interface and
6 supports {IPv4,IPv6} over {IPv4,IPv6} with UDP or TCP as carrier protocols.
7 It has an integrated packet forwarding trie, thus multiple users with
8 different IPs can be handled via a single tunnel device on the server side
9 and flows are scheduled for processing in a CPU-local manner. As an appropriate
10 key management, public-key cryptography based on elliptic curves are being
11 used and packets are encrypted end-to-end by a symmetric stream cipher (Salsa20)
12 and authenticated by a MAC (Poly1305), where keys have previously been computed
13 with the ECDH key agreement protocol (Curve25519). Cryptography is based on
14 Daniel J. Bernsteins Networking and Cryptography library (NaCl). By design,
15 curvetun does not provide any particular pattern or default port numbers
16 that gives certainty that the software from a particular packet stream is
17 actually curvetun. However, if you have further needs to bypass censorship,
18 you can try using curvetun in combination with Tor's obfsproxy [1] [2].
19 Furthermore, curvetun also protects you against replay attacks and DH man
20 in the mittle. Optionally, server event logging can be disabled.
22 [1] https://www.torproject.org/projects/obfsproxy.html.en
23 [2] git clone git://git.torproject.org/obfsproxy.git
28 IP tunnels are usually used to create virtual private networks (VPN), where
29 parts of the network can only be reached via an unsecure or untrusted underlay
30 network like the Internet. Only few software exists to create such tunnels,
31 or, VPNs. Two popular representatives of such software are OpenVPN and VTUN.
32 The latter also introduced the TUN/TAP interfaces into the Linux kernel.
33 VTUN only has a rather basic encryption module, that doesn't fit into todays
34 cryptographic needs. By default MD5 is used to create 128-Bit wide keys for
35 the symmetric BlowFish cipher in ECB mode [1]. Although OpenSSL is used in both,
36 VTUN and OpenVPN, OpenVPN is much more feature rich regarding ciphers and user
37 authentication. Nevertheless, letting people choose ciphers or authentication
38 methods does not necessarily mean a good thing: administrators could either
39 prefer speed over security and therefore choose weak ciphers, so that the
40 communication system will be as good as without any cipher, they could choose
41 weak passwords for symmetric encryption or they could misconfigure the
42 communication system by having too much choices of ciphers and too little
43 experience for picking the right one. Next to the administration issues,
44 there are also software development issues. Cryptographic libraries like
45 OpenSSL are too low-level and too complex to fully understand or correctly
46 apply, so that they form a further ground for vulnerabilities of such software.
47 In 2010, the famous cryptographers Tanja Lange and Daniel J. Bernstein have
48 therefore created and published a cryptography library for networking, which
49 is called NaCl (pronounced 'salt'). NaCl challenges such addressed problems
50 as in OpenSSL and, in contrast to the rather generic use of OpenSSL, was
51 created with a strong focus on public-key authenticated encryption based on
52 elliptic curve cryptography, which is used in curvetun.
54 [1] http://www.off.net/~jme/vtun_secu.html
56 Elliptic-curve cryptography and Curve25519
57 //////////////////////////////////////////
59 From http://dnscurve.org/crypto.html:
61 RSA is somewhat older than elliptic-curve cryptography: RSA was introduced
62 in 1977, while elliptic-curve cryptography was introduced in 1985. However,
63 RSA has shown many more weaknesses than elliptic-curve cryptography. RSA's
64 effective security level was dramatically reduced by the linear sieve in the
65 late 1970s, by the quadratic sieve and ECM in the 1980s, and by the
66 number-field sieve in the 1990s. For comparison, a few attacks have been
67 developed against some rare elliptic curves having special algebraic
68 structures, and the amount of computer power available to attackers has
69 predictably increased, but typical elliptic curves require just as much
70 computer power to break today as they required twenty years ago.
72 IEEE P1363 standardized elliptic-curve cryptography in the late 1990s,
73 including a stringent list of security criteria for elliptic curves. NIST
74 used the IEEE P1363 criteria to select fifteen specific elliptic curves at
75 five different security levels. In 2005, NSA issued a new "Suite B"
76 standard, recommending the NIST elliptic curves (at two specific security
77 levels) for all public-key cryptography and withdrawing previous
78 recommendations of RSA.
80 [curvetun] uses a particular elliptic curve, Curve25519, introduced in the
81 following paper: Daniel J. Bernstein, "Curve25519: new Diffie–Hellman speed
82 records," pages 207–228 in Proceedings of PKC 2006, edited by Moti Yung,
83 Yevgeniy Dodis, Aggelos Kiayias, and Tal Malkin, Lecture Notes in Computer
84 Science 3958, Springer, 2006, ISBN 3-540-33851-9.
86 This elliptic curve follows all of the standard IEEE P1363 security criteria.
87 It also follows new recommendations that achieve "side-channel immunity"
88 and "twist security" while improving speed. What this means is that secure
89 implementations of Curve25519 are considerably simpler and faster than secure
90 implementations of (e.g.) NIST P-256; there are fewer opportunities for
91 implementors to make mistakes that compromise security, and mistakes are
92 more easily caught by reviewers.
94 An attacker who spends a billion dollars on special-purpose chips to attack
95 Curve25519, using the best attacks available today, has about 1 chance in
96 1000000000000000000000000000 of breaking Curve25519 after a year of computation.
97 One could achieve similar levels of security with 3000-bit RSA, but
98 encryption and authentication with 3000-bit RSA are not nearly fast enough
99 to handle [tunnel traffic] and would require much more space in [network]
102 More can be found here: http://cr.yp.to/highspeed/naclcrypto-20090310.pdf
104 Using the curvetun tunnel for browsing the web (example howto):
105 ///////////////////////////////////////////////////////////////
107 curvetun inital setup example:
109 If you've never run curvetun before, you need to do an initial setup once.
111 At first, make sure that the servers and clients clocks are periodically
112 synced, i.e. with ntpdate ntp.ubuntu.com pool.ntp.org as a cronjob or simply
113 install the ntp daemon. This is necessary to protect against replay attacks.
115 Also, make sure if you have read/write access to /dev/net/tun. You should not
116 run curvetun as root!
118 Then, the first step is to create keys and config files. On both, the client
123 You are asked for a username. You can use an email address or whatever. Here,
124 we assume, you've entered 'mysrv1' on the server and 'myclient1' on the client
127 Now on the necessary file have been created:
128 ~/.curvetun/priv.key - Your private key
129 ~/.curvetun/pub.key - Your public key
130 ~/.curvetun/username - Your username (here: mysrv1 or myclient1)
131 ~/.curvetun/clients - Participants the server accepts
132 ~/.curvetun/servers - Possible servers the client can connect to
134 'clients' and 'servers' are empty at the beginning and need to be filled now.
135 The 'clients' file is meant for the server, so that it knows what clients
136 may connect. The 'servers' file is for the client, where it can select
137 curvetun servers to connect to.
139 Now the client exports it's public key for the server:
143 ... where it prints sth like:
145 myclient1;11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11
146 \_______/ \_____________________________________________________________________________________________/
147 username 32 byte public key for 'myclient1'
149 This line is transferred to the server admin, where the admin add this entry
150 into his 'clients' file like:
152 server$ echo "myclient1;11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11" >> ~/.curvetun/clients
154 The server admin can check, if the server has registered it properly by ...
158 ... which prints all parsed clients from ~/.curvetun/clients.
160 [Note: in src/ there is also a Perl script curvetun_ldap.pl that can generate
161 a client file from LDAP entries!]
163 Now, the client 'myclient1' is known to the server; that's it for the server
164 config. The next step is to tell the client what he needs to connect to the
167 We hereby assume, the tunnel server has an public IP i.e. 1.2.3.4, runs on
168 port 6666 and uses UDP as a carrier protocol. In case you are behind a NAT,
169 you can use curvetun's --stun option for starting the server, to obtain your
170 mapping. However, in this example we continue with 1.2.3.4 and 6666, UDP.
172 First, the server needs to export its key to the client, as:
176 ... where it prints sth like:
178 mysrv1;22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22
179 \____/ \_____________________________________________________________________________________________/
180 username 32 byte public key for 'mysrv1'
181 ^-- you need this public key
183 Now, you give the client your connection information:
187 * Pubkey 22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22
189 ... and the client puts it all together in its config like:
191 client$ echo "myfirstserver;1.2.3.4;6666;udp;22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22:22" >> ~/.curvetun/servers
193 ... again, where he can check his config with:
197 Okay, assuming we've made it, then we start the server with:
199 server$ curvetun -s -p 6666 -u
200 server# ifconfig curves0 up
201 server# ifconfig curves0 10.0.0.1/24
203 Server-side information, errors or warnings will appear in syslog!
205 Then, we start the client with ...
207 client$ curvetun -c=myfirstserver
208 client# ifconfig curvec0 up
209 client# ifconfig curvec0 10.0.0.2/24
211 Also, client-side information, errors or warnings will appear in syslog!
212 ... and we're now able to ping the server:
214 client$ ping 10.0.0.1
218 IPv4 routing example:
220 Server side: your public IP on eth0 is i.e. 1.2.3.4
222 server$ ... start curvetun server ...
223 server# ifconfig curves0 up
224 server# ifconfig curves0 10.0.0.1/24
225 server# echo 1 > /proc/sys/net/ipv4/ip_forward
226 server# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
227 server# iptables -A FORWARD -i eth0 -o curves0 -m state --state RELATED,ESTABLISHED -j ACCEPT
228 server# iptables -A FORWARD -i curves0 -o eth0 -j ACCEPT
230 Client side: your IP on eth0 is i.e. 5.6.7.8
232 client$ ... start curvetun client ...
233 client# ... lookup your default gateway ...
234 -> either stated in route, or
235 -> traceroute google.ch and take the first IP entry
236 -> default gw here i.e. 5.6.7.9
237 client# ifconfig curvec0 up
238 client# ifconfig curvec0 10.0.0.2/24
239 client# route add -net 1.2.3.0 netmask 255.255.255.0 gw 5.6.7.9 dev eth0
240 client# route add default gw 10.0.0.1
241 client# route del default gw 5.6.7.9
243 ... and there you go, now open your browser on the client side and surf the
244 web or do whatever you want. For instance, with curvetun we were able to watch
245 Youtube videos in FullHD without problems. All your traffic will then be
246 tunneled encrypted to your server.