]> Cypherpunks.ru repositories - govpn.git/blob - doc/govpn.texi
3bdf72faddc3ccb254c9dfed48cad765bcec2600
[govpn.git] / doc / govpn.texi
1 \input texinfo
2 @setfilename govpn.info
3 @documentencoding UTF-8
4 @settitle GoVPN
5
6 @copying
7 @quotation
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 @end quotation
18 @end copying
19
20 @node Top
21 @top GoVPN
22
23 This manual is for GoVPN -- simple secure free software virtual private
24 network (VPN) daemon, written entirely on Go programming language.
25
26 @menu
27 * Overview::
28 * News::
29 * Getting and building source code::
30 * User manual::
31 * Developer manual::
32 * Reporting bugs::
33 * Copying conditions::
34 @end menu
35
36 @node Overview
37 @unnumbered Overview
38
39 GoVPN is simple secure virtual private network daemon. It uses
40 @url{https://en.wikipedia.org/wiki/Encrypted_key_exchange, Diffie-Hellman Encrypted Key Exchange}
41 (DH-EKE) for mutual zero-knowledge peers authentication and
42 authenticated encrypted data transport. It is written entirely on
43 @url{http://golang.org/, Go programming language}.
44
45 All packets captured on network interface are encrypted, authenticated
46 and sent to remote server, that writes them to his interface, and vice
47 versa. Client and server use pre-shared authentication key (PSK) and
48 128-bit identification key.
49
50 Because of stateless UDP nature, after some timeout of inactivity peers
51 forget about each other and have to retry handshake process again,
52 therefore background heartbeat process will be ran.
53
54 Handshake is used to mutually authenticate peers, exchange common secret
55 per-session encryption key and check UDP transport availability.
56
57 Because of UDP and authentication overhead: each packet grows in size
58 during transmission, so you have to lower you maximum transmission unit
59 (MTU) on virtual network interface.
60
61 High security is the goal for that daemon. It uses fast cryptography
62 algorithms with 128bit security margin, strong mutual zero-knowledge
63 authentication and perfect-forward secrecy property. An attacker can not
64 know anything about payload (except it's size and time) from captured
65 traffic, even if pre-shared key is compromised. Rehandshake is performed
66 by client every 4 GiB of transfered data.
67
68 Each client also has it's own identification key and server works with
69 all of them independently. Identification key is not secret, but it is
70 encrypted (obfuscated) during transmission.
71
72 @itemize @bullet
73 @item
74 Works with @url{https://en.wikipedia.org/wiki/TAP_(network_driver), TAP}
75 network interfaces on top of UDP entirely
76 @item
77 @url{https://www.gnu.org/, GNU}/Linux and
78 @url{http://www.freebsd.org/, FreeBSD} support
79 @item IPv6 compatible
80 @item Encrypted and authenticated transport
81 @item Relatively fast handshake
82 @item
83 @url{https://en.wikipedia.org/wiki/Replay_attack, Replay attack} protection
84 @item
85 @url{https://en.wikipedia.org/wiki/Forward_secrecy, Perfect forward secrecy}
86 (if long-term pre-shared keys are compromised, no captured traffic can
87 be decrypted anyway)
88 @item
89 Mutual two-side authentication (noone will send real network interface
90 data unless the other side is authenticated)
91 @item
92 @url{https://en.wikipedia.org/wiki/Zero-knowledge_password_proof, Zero knowledge}
93 authentication (pre-shared key is not transmitted in any form between
94 the peers, not even it's hash value)
95 @item Built-in rehandshake and heartbeat features
96 @item Several simultaneous clients support
97 @end itemize
98
99 @node News
100 @unnumbered News
101
102 @verbatiminclude ../NEWS
103
104 @node Getting and building source code
105 @unnumbered Getting and building source code
106
107 GoVPN is written on Go programming language, But
108 @url{https://www.gnu.org/software/make/, Make} program is recommended
109 also to be used. @url{https://www.gnu.org/software/texinfo/, Texinfo} is
110 used for building documentation. Also it depends on
111 @code{golang.org/x/crypto} Go libraries.
112
113 @include download.texi
114
115 You @strong{have to} verify downloaded archives integrity and check
116 their signature to be sure that you have got trusted, untampered
117 software. For integrity and authentication of downloaded binaries
118 @url{https://www.gnupg.org/, The GNU Privacy Guard} is used. You must
119 download signature provided with the tarball and run for example:
120
121 @example
122 gpg --verify govpn-1.5.tar.xz.sig govpn-1.5.tar.xz
123 @end example
124
125 For the very first time you must also import signing public keys. They
126 are provided below, but be sure that you are reading them from the
127 trusted source. Alternatively check this page from other sources and
128 look for the mailing list announcements.
129
130 You have to set up @code{$GOPATH} properly first. For example you can
131 clone the repository or decompress tarball and set path like this:
132
133 @example
134 % mkdir -p govpn/src
135 % git clone https://github.com/stargrave/govpn govpn/src/govpn
136 or
137 % tar xfC govpn-1.5.tar.xz govpn/src && mv govpn/src/govpn-1.5 govpn/src/govpn
138 % export GOPATH=$(pwd)/govpn:$GOPATH
139 @end example
140
141 After that you can just type @code{make} and all necessary Go libraries
142 will be installed and client/server binaries are built in the current
143 directory:
144
145 @example
146 % cd govpn/src/govpn
147 % make
148 [or gmake under FreeBSD]
149 @end example
150
151 @include pubkey.texi
152
153 @node User manual
154 @unnumbered User manual
155
156 GoVPN is split into two pieces: client and server. Each of them work on
157 top of UDP and TAP virtual network interfaces. Client and server have
158 several common configuration command line options:
159
160 @table @asis
161 @item Timeout
162 Because of stateless UDP nature there is no way to know if
163 remote peer is dead, but after some timeout. Client and server
164 heartbeats each other every third part of heartbeat. Also this timeout
165 is the time when server purge his obsolete handshake and peers states.
166 @item Allowable nonce difference
167 To prevent replay attacks we just remembers
168 latest received nonce number from the remote peer and drops those who
169 has lower ones. Because UDP packets can be reordered during: that
170 behaviour can lead to dropping of not replayed ones. This options gives
171 ability to create some window of allows difference. That opens the door
172 for replay attacks for narrow time interval.
173 @item MTU
174 Maximum transmission unit.
175 @end table
176
177 Client needs to know his identification, path to the authentication key,
178 remote server's address, TAP interface name, and optional path to up and
179 down scripts, that will be executed after connection is either initiated
180 or terminated.
181
182 Server needs to know only the address to listen on and path to directory
183 containing peers information. This directory must contain subdirectories
184 with the names equal to client's identifications. Each of them must have
185 key file with corresponding authentication key, up.sh script that has to
186 print interface's name on the first line and optional down.sh.
187
188 @menu
189 * Example usage::
190 @end menu
191
192 @node Example usage
193 @section Example usage
194
195 Let's assume that there is some insecure link between your computer and
196 WiFi-reachable gateway. You have got preconfigured @code{wlan0} network
197 interface with 192.168.0/24 network. You want to create virtual
198 encrypted and authenticated 172.16.0/24 network and use it as a default
199 transport. MTU for that wlan0 is 1500 bytes. GoVPN will say that maximum
200 MTU for the link is 1476, however it does not take in account TAP's
201 Ethernet frame header length, that in my case is 14 bytes long (1476 - 14).
202
203 Do not forget about setting @code{GOMAXPROC} environment variable for
204 using more than one CPU.
205
206 GNU/Linux IPv4 client-server example:
207
208 @example
209 server% mkdir -p peers/CLIENTID
210 server% umask 066
211 server% echo MYLONG64HEXKEY > peers/CLIENTID/key
212 server% echo "#!/bin/sh" > peers/CLIENTID/up.sh
213 server% echo "echo tap10" > peers/CLIENTID/up.sh
214 server% chmod 500 peers/CLIENTID/up.sh
215 server% ip addr add 192.168.0.1/24 dev wlan0
216 server% tunctl -t tap10
217 server% ip link set mtu 1462 dev tap10
218 server% ip addr add 172.16.0.1/24 dev tap10
219 server% ip link set up dev tap10
220 server% GOMAXPROC=4 govpn-server -bind 192.168.0.1:1194
221 @end example
222
223 @example
224 client% umask 066
225 client% echo MYLONG64HEXKEY > key.txt
226 client% ip addr add 192.168.0.2/24 dev wlan0
227 client% tunctl -t tap10
228 client% ip link set mtu 1462 dev tap10
229 client% ip addr add 172.16.0.2/24 dev tap10
230 client% ip link set up dev tap10
231 client% ip route add default via 172.16.0.1
232 client% export GOMAXPROC=4
233 client% while :; do
234     govpn-client -key key.txt -id CLIENTID -iface tap10 -remote 192.168.0.1:1194
235 done
236 @end example
237
238 FreeBSD IPv6 client-server example:
239
240 @example
241 server% mkdir -p peers/CLIENTID
242 server% umask 066
243 server% echo MYLONG64HEXKEY > peers/CLIENTID/key
244 server% echo "#!/bin/sh" > 
245 server% cat > peers/CLIENTID/up.sh <<EOF
246 #!/bin/sh
247 $tap=$(ifconfig tap create)
248 ifconfig $tap inet6 fc00::1/96 mtu 1462 up
249 echo $tap
250 EOF
251 server% chmod 500 peers/CLIENTID/up.sh
252 server% ifconfig em0 inet6 fe80::1/64
253 server% GOMAXPROC=4 govpn-server -bind fe80::1%em0
254 @end example
255
256 @example
257 client% ifconfig me0 inet6 -ifdisabled auto_linklocal
258 client% ifconfig tap10
259 client% ifconfig tap10 inet6 fc00::2/96 mtu 1462 up
260 client% route -6 add default fc00::1
261 client% export GOMAXPROC=4
262 client% while :; do
263     govpn-client -key key.txt -id CLIENTID -iface tap10 -remote [fe80::1%me0]:1194
264 done
265 @end example
266
267 Example up-script:
268
269 @example
270 client% cat > up.sh <<EOF
271 #!/bin/sh
272 dhclient $1
273 rtsol $1
274 EOF
275 client% chmod +x up.sh
276 client% govpn -id CLIENTID -key key.txt -iface tap10 -remote [fe80::1%me0]:1194 -up ./up.sh
277 @end example
278
279 Client will exit if won't finish handshake during @code{-timeout}.
280 If no packets are received from remote side during timeout, then daemon
281 will stop sending packets to the client and client will exit. In all
282 cases you have to rehandshake again.
283
284 @node Developer manual
285 @unnumbered Developer manual
286
287 @table @asis
288 @item Nonce and identification encryption
289 @url{http://143.53.36.235:8080/tea.htm, XTEA}
290 @item Data encryption
291 @url{http://cr.yp.to/snuffle.html, Salsa20}
292 @item Message authentication
293 @url{http://cr.yp.to/mac.html, Poly1305}
294 @item Password authenticated key agreement
295 @url{http://cr.yp.to/ecdh.html, Curve25519} based DH-EKE
296 @item Packet overhead
297 24 bytes per packet
298 @item Handshake overhead
299 4 UDP (2 from client, 2 from server) packets, 240 bytes total payload
300 @end table
301
302 @menu
303 * Transport protocol::
304 * Handshake protocol::
305 @end menu
306
307 @node Transport protocol
308 @section Transport protocol
309
310 @verbatim
311 ENCn(SERIAL) + ENC(KEY, ENCn(SERIAL), DATA) +
312     AUTH(ENCn(SERIAL) + ENC(KEY, ENCn(SERIAL), DATA))
313 @end verbatim
314
315 Each transport message is indistinguishable from pseudo random noise.
316
317 @code{SERIAL} is message's serial number. Odds are reserved for
318 client(→server) messages, evens for server(→client) messages.
319
320 @code{ENCn} is XTEA block cipher algorithm used here as PRP (pseudo
321 random permutation) to randomize, obfuscate @code{SERIAL}. Plaintext
322 @code{SERIAL} state is kept in peers internal state, but encrypted
323 before transmission. XTEA is compact and fast enough. Salsa20 is PRF
324 function and requires much more code to create PRP from it. XTEA's
325 encryption key is the first 128-bit of Salsa20's output with established
326 common key and zero nonce (message nonces start from 1).
327
328 Encrypted @code{SERIAL} is used as a nonce for @code{DATA} encryption:
329 encryption key is different during each handshake, so (key, nonce) pair
330 is always used only once. @code{ENC} is Salsa20 cipher, with established
331 session @code{KEY} and encrypted @code{SERIAL} used as a nonce.
332
333 @code{AUTH} is Poly1305 authentication function. First 256 bits of
334 Salsa20 output are used as a one-time key for @code{AUTH}. Next 256 bits
335 of Salsa20 are ignored. All remaining output is XORed with the data,
336 encrypting it.
337
338 To prevent replay attacks we remember latest @code{SERIAL} from the
339 remote peer. If received message's @code{SERIAL} is not greater that the
340 saved one, then drop it. Optionally, because some UDP packets can be
341 reordered during transmission, we can allow some window for valid
342 serials with the @code{-noncediff} option. @code{-noncediff 10} with
343 current saved serial state equals to 78 allows messages with 68…78
344 serials. That time window can be used by attacker to replay packets, so
345 by default it equals to 1. However it can improve performance because of
346 rearranged UDP packets.
347
348 @node Handshake protocol
349 @section Handshake protocol
350
351 @verbatiminclude handshake.utxt
352
353 @enumerate
354 @item
355 client generates @code{CPubKey}, random 64bit @code{R} that is used as a
356 nonce for encryption, and an encrypted @code{R} with XTEA, where the key
357 equals to client's identity
358 @item
359 @verb{|R + enc(PSK, R, CPubKey) + xtea(ID, R) + NULL + NULLs -> Server|} [65 bytes]
360 @item
361 server remembers clients address, decrypt @code{CPubKey}, generates
362 @code{SPrivKey}/@code{SPubKey}, computes common shared key @code{K}
363 (based on @code{CPubKey} and @code{SPrivKey}), generates 64bit random
364 number @code{RS} and 256bit random @code{SS}. PSK-encryption uses
365 incremented @code{R} (from previous message) for nonce
366 @item
367 @verb{|enc(PSK, SPubKey) + enc(K, RS + SS) + NULLs -> Client|} [88 bytes]
368 @item
369 client decrypt @code{SPubKey}, computes @code{K}, decrypts @code{RS},
370 @code{SS} with key @code{K}, remembers @code{SS}, generates 64bit random
371 number @code{RC} and 256bit random @code{SC},
372 @item
373 @verb{|enc(K, RS + RC + SC) + NULLs -> Server|} [64 bytes]
374 @item
375 server decrypt @code{RS}, @code{RC}, @code{SC} with key @code{K},
376 compares @code{RS} with it's own one send before, computes final main
377 encryption key @code{S = SS XOR SC}
378 @item
379 @verb{|ENC(K, RC) + NULLs -> Client|} [24 bytes]
380 @item
381 server switches to the new client
382 @item
383 client decrypts @code{RC} and compares with it's own generated one,
384 computes final main encryption key @code{S}
385 @end enumerate
386
387 Where PSK is 256bit pre-shared key, @code{NULLs} are 16 null-bytes.
388 @code{R*} are required for handshake randomization and two-way
389 authentication. K key is used only during handshake. @code{NULLs} are
390 required to differentiate common transport protocol messages from
391 handshake ones. DH public keys can be trivially derived from private
392 ones.
393
394 @node Reporting bugs
395 @unnumbered Reporting bugs
396
397 Please send all your bug requests, patches and related questions to
398 @email{govpn-devel@@lists.cypherpunks.ru} mailing list.
399 Visit @url{https://lists.cypherpunks.ru/mailman/listinfo/govpn-devel}
400 for information about subscription options and archived messages access.
401
402 Development Git source code repository currently is located on:
403 @url{https://github.com/stargrave/govpn}.
404
405 @node Copying conditions
406 @unnumbered Copying conditions
407
408 @insertcopying
409
410 @bye