内容纲要

TunSafe 编译

TunSafe 使用 clang-6.0 编译,编译步骤

sudo apt-get install clang-6.0
git clone https://github.com/TunSafe/TunSafe.git
cd TunSafe
make
sudo make install

运行 TunSafe

TunSafe 需要配置文件,如果是服务器端,需要 Server.conf

[Interface]
PrivateKey = MDO1jdes1H6WoNd5KPtA93fxk17pWLAKTYZ6XZ61oVo=
Address = 10.0.0.1/24 
ObfuscateKey = 9370
PostUp   = iptables -A FORWARD -i tun0 -j ACCEPT; iptables -A FORWARD -o tun0 -j ACCEPT; iptables -t nat -A POSTROUTING -o ens33 -j MASQUERADE
PostDown = iptables -D FORWARD -i tun0 -j ACCEPT; iptables -D FORWARD -o tun0 -j ACCEPT; iptables -t nat -D POSTROUTING -o ens33 -j MASQUERADE
ListenPort = 33263
DNS = 8.8.8.8
MTU = 1380

[Peer]
PublicKey = 6YKOavOEDneWmcp3PV9svFaZMMyAz8iQwyR/vd0aLng=
AllowedIPs = 10.0.0.2/32

然后执行

$ sudo tunsafe start -d Server.conf

将以 daemon 进程方式启动。

查看 tunsafe 状态

$ sudo tunsafe show
interface: tun0
  public key: v7q89OS6XHf/RAe9Ejz9wMsbwldodwk8QrSCsu2UJGM=
  private key: (hidden)
  listening port: 33263
  address: 10.0.0.1/24

peer: 6YKOavOEDneWmcp3PV9svFaZMMyAz8iQwyR/vd0aLng=
  endpoint: 192.168.59.133:36941
  allowed ips: 10.0.0.2/32
  latest handshake: 9 seconds ago
  transfer: 4.23 KiB received, 1.69 KiB sent

停止 TunSafe

$ sudo tunsafe stop tun0

vscode 加断点调试

vscode 打开 TunSafe 目录,然后调试,生成 launch.json,配置

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "gdb",
            "request": "launch",
            "name": "Launch Program",
            "target": "./tunsafe",
            "arguments": "start -d Server.conf",          
            "cwd": "${workspaceRoot}",
            "valuesFormatting": "parseText"
        }      
    ]
}

修改 build_linux.sh,将 CURARGS 改为 "$DBGARGS",以便生成调试版可执行文件。

#!/bin/sh
set -e

RELARGS="-O3 -DNDEBUG"
DBGARGS="-g -D_DEBUG"
CURARGS="$DBGARGS"

clang++-6.0 -c -march=skylake-avx512 crypto/poly1305/poly1305-x64-linux.s crypto/chacha20/chacha20-x64-linux.s
clang++-6.0 -I . $CURARGS -DWITH_NETWORK_BSD=1 -mssse3 -pthread -lrt -o tunsafe \
tunsafe_amalgam.cpp \
crypto/aesgcm/aesni_gcm-x64-linux.s \
crypto/aesgcm/aesni-x64-linux.s \
crypto/aesgcm/ghash-x64-linux.s \
chacha20-x64-linux.o \
poly1305-x64-linux.o \

然后重新以 sudo code 方式启动 vscode,安装 C/C++ 和 Native Debug 扩展,在代码中加断点调试。

发表评论

电子邮件地址不会被公开。 必填项已用*标注