Skip to content

Commit

Permalink
chore: update package
Browse files Browse the repository at this point in the history
  • Loading branch information
AutisticShark committed Mar 27, 2024
1 parent 8ba88e5 commit b0d60e5
Show file tree
Hide file tree
Showing 16 changed files with 10 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 0 additions & 6 deletions bin/trojan-sspanel.rs
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;
Expand Down
8 changes: 0 additions & 8 deletions src/lib.rs
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;
Expand Down
7 changes: 1 addition & 6 deletions src/proto/addr.rs
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};
Expand Down
8 changes: 0 additions & 8 deletions src/proto/mod.rs
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.
Expand Down
6 changes: 0 additions & 6 deletions src/proto/udp_packet.rs
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;
Expand Down
7 changes: 1 addition & 6 deletions src/session/context.rs
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;
Expand Down
7 changes: 1 addition & 6 deletions src/session/mod.rs
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;
Expand Down
7 changes: 0 additions & 7 deletions src/sspanel/client/context.rs
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)]
Expand Down
6 changes: 0 additions & 6 deletions src/sspanel/client/mod.rs
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;
Expand Down
7 changes: 0 additions & 7 deletions src/sspanel/mod.rs
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;
7 changes: 1 addition & 6 deletions src/sspanel/server/context.rs
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;
Expand All @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions src/sspanel/server/mod.rs
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;
Expand Down
12 changes: 4 additions & 8 deletions src/tls.rs
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};
Expand All @@ -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};

Expand All @@ -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)]
Expand All @@ -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()
Expand All @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions src/utils/limiter.rs
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;
Expand Down
6 changes: 0 additions & 6 deletions src/utils/mod.rs
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};

Expand Down

0 comments on commit b0d60e5

Please sign in to comment.