-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ba88e5
commit b0d60e5
Showing
16 changed files
with
10 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name = "trojan-x" | |
version = "0.0.5" | ||
edition = "2021" | ||
license = "MPL-2.0" | ||
authors = ["Irohaede <[email protected]>"] | ||
authors = ["SSPanel-UIM Team <[email protected]>"] | ||
|
||
[dependencies] | ||
bytes = "1.5" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::collections::HashMap; | ||
use std::fs::File; | ||
use std::io; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
//! Trojan | ||
pub mod proto; | ||
pub mod tls; | ||
pub mod session; | ||
|
||
#[cfg(feature = "sspanel")] | ||
pub mod sspanel; | ||
|
||
pub mod utils; | ||
|
||
pub use session::Fallback; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::fmt::{self, Display, Formatter}; | ||
use std::io; | ||
use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; | ||
|
||
use bytes::Bytes; | ||
|
||
use tokio::net::{TcpStream, UdpSocket}; | ||
|
||
use super::{AssembleError, ProtocolError}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
//! Trojan Protocol | ||
//! | ||
//! Trojan is designed to build a tunnel through firewalls to bypass blocking and censorship. | ||
//! | ||
//! Using TLS just like modern browsers and web servers to reduce potential risks of detection. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::{ptr, mem}; | ||
|
||
use bytes::Bytes; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::io; | ||
use std::net::SocketAddr; | ||
use std::pin::Pin; | ||
use std::task::{ready, Context, Poll}; | ||
|
||
use bytes::Bytes; | ||
|
||
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt}; | ||
use tokio::net::TcpStream; | ||
use tokio_rustls::server::TlsStream; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::future::poll_fn; | ||
use std::net::{IpAddr, Ipv6Addr}; | ||
use std::{io, mem, vec}; | ||
|
||
use bytes::Bytes; | ||
|
||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; | ||
use tokio::net::{TcpStream, UdpSocket}; | ||
use tokio::sync::mpsc; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::net::IpAddr; | ||
|
||
use serde::{Deserialize, Deserializer, Serialize}; | ||
|
||
use crate::proto::Password; | ||
|
||
pub type UserFetchResponse = Response<Vec<UserRaw>>; | ||
|
||
pub type UpdateResponse = Response<String>; | ||
|
||
#[derive(Deserialize)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,2 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
//! Trojan Multi-User for SSPanel | ||
pub mod client; | ||
pub mod server; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::collections::{HashMap, HashSet}; | ||
use std::future::Future; | ||
use std::io; | ||
|
@@ -15,6 +9,7 @@ use std::task::{Context, Poll}; | |
use std::time::Duration; | ||
|
||
use bytes::Bytes; | ||
|
||
use tokio::net::TcpStream; | ||
use tokio::time::{self, Instant, Sleep}; | ||
use tokio_rustls::rustls::ServerConfig; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::io::{self, Read}; | ||
use std::net::SocketAddr; | ||
use std::sync::Arc; | ||
|
||
use bytes::Bytes; | ||
|
||
use tokio::io::AsyncReadExt; | ||
use tokio::net::{TcpListener, TcpStream}; | ||
use tokio::time::Instant; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::collections::HashMap; | ||
use std::fs::File; | ||
use std::io::{self, BufReader}; | ||
|
@@ -14,6 +8,7 @@ use tokio_rustls::rustls::server::{ | |
ClientHello, NoServerSessionStorage, ResolvesServerCert, ResolvesServerCertUsingSni, | ||
ServerSessionMemoryCache, | ||
}; | ||
|
||
use tokio_rustls::rustls::sign::{any_supported_type, CertifiedKey}; | ||
use tokio_rustls::rustls::{Certificate, PrivateKey, ServerConfig}; | ||
|
||
|
@@ -24,7 +19,6 @@ pub struct TlsConfig { | |
servers: HashMap<String, Server>, | ||
#[serde(default)] | ||
prefer_server_cipher: bool, | ||
|
||
#[serde(default)] | ||
max_early_data: u32, | ||
#[serde(default)] | ||
|
@@ -38,7 +32,6 @@ pub struct TlsConfig { | |
impl TlsConfig { | ||
pub fn build_server(self) -> io::Result<Arc<ServerConfig>> { | ||
let cert_resolver = Arc::new(CertResolver::new(self.servers)?); | ||
|
||
let mut ctx = ServerConfig::builder() | ||
.with_safe_defaults() | ||
.with_no_client_auth() | ||
|
@@ -63,15 +56,18 @@ impl TlsConfig { | |
use tokio_rustls::rustls::RootCertStore; | ||
|
||
let mut root_certs = RootCertStore::empty(); | ||
|
||
for cert in rustls_native_certs::load_native_certs()? { | ||
root_certs | ||
.add(&tokio_rustls::rustls::Certificate(cert.0)) | ||
.unwrap(); | ||
} | ||
|
||
let mut ctx = tokio_rustls::rustls::ClientConfig::builder() | ||
.with_safe_defaults() | ||
.with_root_certificates(root_certs) | ||
.with_no_client_auth(); | ||
|
||
ctx.alpn_protocols = self.alpn.into_iter().map(String::into_bytes).collect(); | ||
ctx.max_fragment_size = self.max_fragment_size; | ||
ctx.enable_early_data = self.max_early_data > 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
use std::sync::Mutex; | ||
use std::time::Duration; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 irohaede <[email protected]> | ||
|
||
use std::hash::{BuildHasher, Hasher}; | ||
use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; | ||
|
||
|