Server needs to know only the address to listen on and path to directory
containing peers information. This directory must contain subdirectories
with the names equal to client's identifications. Each of them must have
-key file with corresponding authentication key, up.sh script that has to
-print interface's name on the first line and optional down.sh.
+@strong{key} file with corresponding authentication key, @strong{up.sh}
+script that has to print interface's name on the first output line.
+Optionally there can be @code{down.sh} that will be executed when client
+disconnects, and @code{name} file containing human readable client's name.
@menu
* Example usage::
@example
% ./utils/newclient.sh Alice
-peers/9b40701bdaf522f2b291cb039490312/Alice
+9b40701bdaf522f2b291cb039490312
@end example
@code{9b40701bdaf522f2b291cb039490312} is client's identification.
-@code{Alice} is just an empty file that can help to search them like
-this: @verb{|find peers -name Alice|}. @code{key} file inside peer's
-directory contains authentication key.
+@code{peers/9b40701bdaf522f2b291cb039490312/name} contains @emph{Alice},
+@code{peers/9b40701bdaf522f2b291cb039490312/key} contains authentication key and
+@code{peers/9b40701bdaf522f2b291cb039490312/up.sh} contains currently
+dummy empty up-script.
GNU/Linux IPv4 client-server example:
@example
-server% echo "#!/bin/sh" > peers/CLIENTID/up.sh
server% echo "echo tap10" >> peers/CLIENTID/up.sh
-server% chmod 500 peers/CLIENTID/up.sh
server% ip addr add 192.168.0.1/24 dev wlan0
server% tunctl -t tap10
server% ip link set mtu 1462 dev tap10
ifconfig $tap inet6 fc00::1/96 mtu 1462 up
echo $tap
EOF
-server% chmod 500 peers/CLIENTID/up.sh
server% ifconfig em0 inet6 fe80::1/64
server% GOMAXPROC=4 govpn-server -bind fe80::1%em0
@end example
import (
"crypto/subtle"
"encoding/hex"
+ "io/ioutil"
"log"
"os"
+ "path"
+ "strings"
"sync"
"time"
return hex.EncodeToString(id[:])
}
+// Return human readable name of the peer.
+// It equals either to peers/PEER/name file contents or PEER's hex.
+func (id PeerId) MarshalJSON() ([]byte, error) {
+ result := id.String()
+ if name, err := ioutil.ReadFile(path.Join(PeersPath, result, "name")); err == nil {
+ result = strings.TrimRight(string(name), "\n")
+ }
+ return []byte(`"` + result + `"`), nil
+}
+
type cipherCache map[PeerId]*xtea.Cipher
var (
[ -n "$1" ] || {
cat <<EOF
Example script for creating new user peer for GoVPN.
-It just creates directory with random peer ID and random key in it,
-and adds empty file with human readable username.
+It just creates directory with random peer ID, random key,
+saves username in it and creates dummy up.sh executable script.
Usage: $0 <username>
EOF
umask 077
mkdir -p peers/$peerid
getrand 32 > peers/$peerid/key
-touch peers/$peerid/$1
-echo peers/$peerid/$1
+echo $username > peers/$peerid/name
+echo '#!/bin/sh' > peers/$peerid/up.sh
+chmod 700 peers/$peerid/up.sh
+echo $peerid