docs: removed paragraph with compression in curvetun
[netsniff-ng.git] / Documentation / Curvetun
blob5bd2df99d6296052bb10f96ed967d0a8a0d7d6ae
1 What is curvetun?
2 /////////////////
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 by a symmetric stream cipher (Salsa20) and
12 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).
16 Motivation
17 //////////
19 IP tunnels are usually used to create virtual private networks (VPN) where
20 parts of the network can only be reached via an unsecure or untrusted underlay
21 network like the Internet. Only few software exists to create such tunnels, 
22 or, VPNs. Two popular representatives of such software are OpenVPN and VTUN.
23 The latter also introduced the TUN/TAP interfaces into the Linux kernel.
24 VTUN only has a rather basic encryption module, that doesn’t fit into todays
25 cryptographic needs. By default MD5 is used to create 128-Bit wide keys for
26 the symmetric BlowFish cipher in ECB mode. Although OpenSSL is used in both,
27 VTUN and OpenVPN, OpenVPN is much more feature rich regarding ciphers and user
28 authentication. Nevertheless, letting people choose ciphers or authentication
29 methods does not necessarily mean a good thing: administrators could either
30 prefer speed over security and therefore choose weak ciphers, so that the
31 communication system will be as good as without any cipher, they could choose
32 weak passwords for symmetric encryption or they could misconfigure the
33 communication system by having too much choices of ciphers and too little
34 experience for picking the right one. Next to the administration issues,
35 there are also software development issues. Cryptographic libraries like
36 OpenSSL are too low-level and too complex to fully understand or correctly
37 apply, so that they form a further ground for vulnerabilities of such software.
38 In 2010, the famous cryptographers Tanja Lange and Daniel J. Bernstein have
39 therefore created and published a cryptography library for networking, which
40 is called NaCl (pronounced 'salt'). NaCl challenges such addressed problems
41 as in OpenSSL and, in contrast to the rather generic use of OpenSSL, was
42 created with a strong focus on public-key authenticated encryption based on
43 elliptic curve cryptography, which is used in curvetun.
45 Elliptic-curve cryptography and Curve25519
46 //////////////////////////////////////////
48 From http://dnscurve.org/crypto.html:
50 RSA is somewhat older than elliptic-curve cryptography: RSA was introduced
51 in 1977, while elliptic-curve cryptography was introduced in 1985. However,
52 RSA has shown many more weaknesses than elliptic-curve cryptography. RSA's
53 effective security level was dramatically reduced by the linear sieve in the
54 late 1970s, by the quadratic sieve and ECM in the 1980s, and by the
55 number-field sieve in the 1990s. For comparison, a few attacks have been
56 developed against some rare elliptic curves having special algebraic
57 structures, and the amount of computer power available to attackers has
58 predictably increased, but typical elliptic curves require just as much
59 computer power to break today as they required twenty years ago.
61 IEEE P1363 standardized elliptic-curve cryptography in the late 1990s,
62 including a stringent list of security criteria for elliptic curves. NIST
63 used the IEEE P1363 criteria to select fifteen specific elliptic curves at
64 five different security levels. In 2005, NSA issued a new "Suite B"
65 standard, recommending the NIST elliptic curves (at two specific security
66 levels) for all public-key cryptography and withdrawing previous
67 recommendations of RSA.
69 [curvetun] uses a particular elliptic curve, Curve25519, introduced in the
70 following paper: Daniel J. Bernstein, "Curve25519: new Diffie–Hellman speed
71 records," pages 207–228 in Proceedings of PKC 2006, edited by Moti Yung,
72 Yevgeniy Dodis, Aggelos Kiayias, and Tal Malkin, Lecture Notes in Computer
73 Science 3958, Springer, 2006, ISBN 3-540-33851-9.
75 This elliptic curve follows all of the standard IEEE P1363 security criteria.
76 It also follows new recommendations that achieve "side-channel immunity"
77 and "twist security" while improving speed. What this means is that secure
78 implementations of Curve25519 are considerably simpler and faster than secure
79 implementations of (e.g.) NIST P-256; there are fewer opportunities for
80 implementors to make mistakes that compromise security, and mistakes are
81 more easily caught by reviewers.
83 An attacker who spends a billion dollars on special-purpose chips to attack
84 Curve25519, using the best attacks available today, has about 1 chance in
85 1000000000000000000000000000 of breaking Curve25519 after a year of computation.
86 One could achieve similar levels of security with 3000-bit RSA, but
87 encryption and authentication with 3000-bit RSA are not nearly fast enough
88 to handle [tunnel traffic] and would require much more space in [network]
89 packets.
91 More can be found here: http://cr.yp.to/highspeed/naclcrypto-20090310.pdf
93 Using the curvetun tunnel for browsing the web (example howto):
94 ///////////////////////////////////////////////////////////////
96 curvetun inital setup example:
98 If you've never run curvetun before, you need to do an initial setup once.
100 At first, make sure that the servers and clients clocks are periodically
101 synced, i.e. with ntpdate ntp.ubuntu.com pool.ntp.org as a cronjob or simply
102 install the ntp daemon. This is necessary to protect against replay attacks.
104 Also, make sure if you have read/write access to /dev/net/tun. You should not
105 run curvetun as root!
107 Then, the first step is to create keys and config files. On both, the client
108 and server do:
110 $ curvetun -k
112 You are asked for a username. You can use an email address or whatever. Here,
113 we assume, you've entered 'mysrv1' on the server and 'myclient1' on the client
114 side.
116 Now on the necessary file have been created:
117         ~/.curvetun/priv.key   - Your private key
118         ~/.curvetun/pub.key    - Your public key
119         ~/.curvetun/username   - Your username (here: mysrv1 or myclient1)
120         ~/.curvetun/clients    - Participants the server accepts
121         ~/.curvetun/servers    - Possible servers the client can connect to
123 'clients' and 'servers' are empty at the beginning and need to be filled now.
124 The 'clients' file is meant for the server, so that it knows what clients
125 may connect. The 'servers' file is for the client, where it can select
126 curvetun servers to connect to.
128 Now the client exports it's public key for the server:
130 client$ curvetun -x
132 ... where it prints sth like:
134   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
135   \_______/ \_____________________________________________________________________________________________/
136    username  32 byte public key for 'myclient1'
138 This line is transferred to the server admin, where the admin add this entry
139 into his 'clients' file like:
141 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
143 The server admin can check, if the server has registered it properly by ...
145 server$ curvetun -C
147 ... which prints all parsed clients from ~/.curvetun/clients.
149 [Note: in src/ there is also a Perl script curvetun_ldap.pl that can generate
150  a client file from LDAP entries!]
152 Now, the client 'myclient1' is known to the server; that's it for the server
153 config. The next step is to tell the client what he needs to connect to the
154 server.
156 We hereby assume, the tunnel server has an public IP i.e. 1.2.3.4, runs on
157 port 6666 and uses UDP as a carrier protocol. In case you are behind a NAT,
158 you can use curvetun's --stun option for starting the server, to obtain your
159 mapping. However, in this example we continue with 1.2.3.4 and 6666, UDP.
161 First, the server needs to export its key to the client, as:
163 server$ curvetun -x
165 ... where it prints sth like:
167   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
168   \____/ \_____________________________________________________________________________________________/
169  username  32 byte public key for 'mysrv1'
170            ^-- you need this public key
172 Now, you give the client your connection information:
173    * IP 1.2.3.4
174    * Port 6666
175    * Proto UDP
176    * 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
178 ... and the client puts it all together in its config like:
180 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
182 ... again, where he can check his config with:
184 client$ curvetun -S
186 Okay, assuming we've made it, then we start the server with:
188 server$ curvetun -s -p 6666 -u
189 server# ifconfig curves0 up
190 server# ifconfig curves0 10.0.0.1/24
192 Server-side information, errors or warnings will appear in syslog!
194 Then, we start the client with ...
196 client$ curvetun -c=myfirstserver
197 client# ifconfig curvec0 up
198 client# ifconfig curvec0 10.0.0.2/24
200 Also, client-side information, errors or warnings will appear in syslog!
201 ... and we're now able to ping the server:
203 client$ ping 10.0.0.1
205 That's it!
207 IPv4 routing example:
209 Server side: your public IP on eth0 is i.e. 1.2.3.4
211 server$ ... start curvetun server ...
212 server# ifconfig curves0 up
213 server# ifconfig curves0 10.0.0.1/24
214 server# echo 1 > /proc/sys/net/ipv4/ip_forward
215 server# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
216 server# iptables -A FORWARD -i eth0 -o curves0 -m state --state RELATED,ESTABLISHED -j ACCEPT
217 server# iptables -A FORWARD -i curves0 -o eth0 -j ACCEPT
219 Client side: your IP on eth0 is i.e. 5.6.7.8
221 client$ ... start curvetun client ...
222 client# ... lookup your default gateway ...
223          -> either stated in route, or
224          -> traceroute google.ch and take the first IP entry
225          -> default gw here i.e. 5.6.7.9
226 client# ifconfig curvec0 up
227 client# ifconfig curvec0 10.0.0.2/24
228 client# route add -net 1.2.3.0 netmask 255.255.255.0 gw 5.6.7.9 dev eth0
229 client# route add default gw 10.0.0.1
230 client# route del default gw 5.6.7.9
232 ... and there you go, now open your browser on the client side and surf the
233 web or do whatever you want. For instance, with curvetun we were able to watch
234 Youtube videos in FullHD without problems. All your traffic will then be
235 tunneled encrypted to your server.