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