cty123 / TrojanRust

Trojan-rust is a rust implementation for Trojan protocol that is targeted to circumvent GFW. This implementation focus on performance and stability above everything else.
MIT License
113 stars 24 forks source link

trojan-rust

Build Stage

中文zh-CN

Trojan-rust is a rust implementation for Trojan protocol that is targeted to circumvent GFW. This implementation focus on performance and stability above everything else.

Why trojan-rust

How to compile

Currently there is no existing binary file that you can just download and use, and it is recommanded to compile and build yourself. To do so, first you need to set up the Rust environment, by installing through here https://www.rust-lang.org/. Once you have rust installed, you can simply go to command line and run,

cargo build --release

and it should generate a binary program under ./target/release/trojan-rust.

Alternatively, you can also run it directly through,

cargo run --release

To enable logs, on MacOs or Linux, run,

RUST_LOG=info cargo run --release

On windows powershell, run,

$Env:RUST_LOG = "info"
cargo run --release

Examples

Create Certificate

Quick short script for your convenience,

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes

Sample for Trojan

Server config

{
    "inbound": {
        "protocol": "TROJAN",
        "address": "0.0.0.0",
        "secret": "123123",
        "port": 8081,
        "mode": "TCP",
        "tls": {
            "cert_path": "./cert.pem",
            "key_path": "./key.pem"
        }
    },
    "outbound": {
        "protocol": "DIRECT"
    }
}

Client config

{
    "inbound": {
        "protocol": "SOCKS",
        "address": "0.0.0.0",
        "port": 8081
    },
    "outbound": {
        "protocol": "TROJAN",
        "address": "0.0.0.0",
        "port": 8082,
        "secret": "123123",
        "mode": "TCP",
        "tls": {
            "host_name": "example.com",
            "allow_insecure": true
        }
    }
}

For using GRPC as transport layer

Just add GRPC to transport under inbound or outbound

    "inbound": {
        "protocol": "TROJAN",
        "address": "0.0.0.0",
        "secret": "123123",
        "port": 8081,
        "tls": {
            "cert_path": "./cert.pem",
            "key_path": "./key.pem"
        },
        "mode": "GRPC"
    },
    "outbound": {
        "protocol": "DIRECT"
    }

Run the program

trojan-rust -h

Trojan Rust 0.0.1
Anonymous
Trojan Rust is a rust implementation of the trojan protocol to circumvent GFW

USAGE:
    trojan-rust [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --config <FILE>    Sets the config file, readers ./config/config.json by default

Run trojan-rust with specified config file

trojan-rust --config ./config.json

Roadmap

Beta stage 0.0.1 - 1.0.0(For developers)

Official release 0.4.0 and above(For general users)