Added server
This commit is contained in:
Generated
+99
@@ -34,6 +34,12 @@ dependencies = [
|
|||||||
"fs_extra",
|
"fs_extra",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.22.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bindgen"
|
name = "bindgen"
|
||||||
version = "0.69.5"
|
version = "0.69.5"
|
||||||
@@ -125,6 +131,15 @@ version = "0.8.7"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deranged"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e"
|
||||||
|
dependencies = [
|
||||||
|
"powerfmt",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dunce"
|
name = "dunce"
|
||||||
version = "1.0.5"
|
version = "1.0.5"
|
||||||
@@ -180,6 +195,7 @@ dependencies = [
|
|||||||
name = "ghostnet-rs"
|
name = "ghostnet-rs"
|
||||||
version = "0.0.1-alpha"
|
version = "0.0.1-alpha"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"rcgen",
|
||||||
"rustls",
|
"rustls",
|
||||||
"rustls-native-certs",
|
"rustls-native-certs",
|
||||||
]
|
]
|
||||||
@@ -280,6 +296,12 @@ dependencies = [
|
|||||||
"minimal-lexical",
|
"minimal-lexical",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-conv"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.21.3"
|
version = "1.21.3"
|
||||||
@@ -292,6 +314,22 @@ version = "0.1.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
|
checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pem"
|
||||||
|
version = "3.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "38af38e8470ac9dee3ce1bae1af9c1671fffc44ddfd8bd1d0a3445bf349a8ef3"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "powerfmt"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prettyplease"
|
name = "prettyplease"
|
||||||
version = "0.2.36"
|
version = "0.2.36"
|
||||||
@@ -326,6 +364,19 @@ version = "5.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rcgen"
|
||||||
|
version = "0.14.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0068c5b3cab1d4e271e0bb6539c87563c43411cad90b057b15c79958fbeb41f7"
|
||||||
|
dependencies = [
|
||||||
|
"pem",
|
||||||
|
"ring",
|
||||||
|
"rustls-pki-types",
|
||||||
|
"time",
|
||||||
|
"yasna",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.11.1"
|
version = "1.11.1"
|
||||||
@@ -468,6 +519,26 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.219"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.219"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
@@ -491,6 +562,25 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.3.41"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40"
|
||||||
|
dependencies = [
|
||||||
|
"deranged",
|
||||||
|
"num-conv",
|
||||||
|
"powerfmt",
|
||||||
|
"serde",
|
||||||
|
"time-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-core"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
@@ -701,6 +791,15 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yasna"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd"
|
||||||
|
dependencies = [
|
||||||
|
"time",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zeroize"
|
name = "zeroize"
|
||||||
version = "1.8.1"
|
version = "1.8.1"
|
||||||
|
|||||||
@@ -7,5 +7,6 @@ edition = "2024"
|
|||||||
name = "ghostnet-rs"
|
name = "ghostnet-rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
rcgen = "0.14.3"
|
||||||
rustls = "0.23.31"
|
rustls = "0.23.31"
|
||||||
rustls-native-certs = "0.8.1"
|
rustls-native-certs = "0.8.1"
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
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rbYLiwasTpEzQNtrNSekgKLEyqpyUeYR6ML7T
|
||||||
|
WLZw2jtEHj4tUSwcmEqrHoLhy1zDdBmB0Wx10JeCM+5uotX8eGQ2GGVWZYTVBWYW
|
||||||
|
DrMJHqlWerESxFQaLE8Uv3TKKn/P/8GTwq1h110CgYB/u9aKYtsR85hITdqWRq2f
|
||||||
|
fCON+9WrOfAbt/H50qEBk2xVKKSPVDrTekqMPAuTagdA5+Y/pRA9zyy6wmfDfnC6
|
||||||
|
IyxVnhWRlLnByiHcs58N7vytTWmiKHQDrXAiWyxUy0ao/2Jyb/gLkj1avIfok0r/
|
||||||
|
5DMLZeOcLmweCkEEwXAG5w==
|
||||||
|
-----END PRIVATE KEY-----
|
||||||
@@ -2,6 +2,7 @@ use std::io::{Read, Write};
|
|||||||
|
|
||||||
use rustls::Stream;
|
use rustls::Stream;
|
||||||
|
|
||||||
|
pub mod server;
|
||||||
pub mod tls;
|
pub mod tls;
|
||||||
|
|
||||||
pub fn request(gateway: &str, addr: &str) -> String {
|
pub fn request(gateway: &str, addr: &str) -> String {
|
||||||
|
|||||||
+5
-5
@@ -1,7 +1,7 @@
|
|||||||
use ghostnet_rs::request;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let result = request("localhost", "github.com");
|
ghostnet_rs::server::run().unwrap();
|
||||||
|
// println!(
|
||||||
println!("Result: {result}");
|
// "Result: {}",
|
||||||
|
// ghostnet_rs::request("localhost", "github.com")
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
use std::error::Error as StdError;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
use std::net::TcpListener;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use rustls::Stream;
|
||||||
|
use rustls::pki_types::pem::PemObject;
|
||||||
|
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
|
||||||
|
|
||||||
|
pub fn run() -> Result<(), Box<dyn StdError>> {
|
||||||
|
let cert_file = "cert.pem";
|
||||||
|
let private_key_file = "key.pem";
|
||||||
|
|
||||||
|
let certs = CertificateDer::pem_file_iter(cert_file)
|
||||||
|
.unwrap()
|
||||||
|
.map(|cert| cert.unwrap())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let private_key = PrivateKeyDer::from_pem_file(private_key_file).unwrap();
|
||||||
|
|
||||||
|
let config = Arc::new(
|
||||||
|
rustls::ServerConfig::builder()
|
||||||
|
.with_no_client_auth()
|
||||||
|
.with_single_cert(certs, private_key)?,
|
||||||
|
);
|
||||||
|
|
||||||
|
let listener = TcpListener::bind(format!("0.0.0.0:{}", 443)).unwrap();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let (mut tcp_stream, _) = listener.accept()?;
|
||||||
|
let mut conn = rustls::ServerConnection::new(config.clone())?;
|
||||||
|
let mut tls_stream = rustls::Stream::new(&mut conn, &mut tcp_stream);
|
||||||
|
|
||||||
|
let mut buf = [0; 1024];
|
||||||
|
if let Ok(len) = tls_stream.read(&mut buf) {
|
||||||
|
let buf_str = String::from_utf8_lossy(&buf[..len]).to_string();
|
||||||
|
if buf_str.starts_with("ROUTE") {
|
||||||
|
let addr = buf_str
|
||||||
|
.split_once("\n")
|
||||||
|
.unwrap()
|
||||||
|
.0
|
||||||
|
.split_once(" ")
|
||||||
|
.unwrap()
|
||||||
|
.1;
|
||||||
|
let http = buf_str.split_once("\n").unwrap().1;
|
||||||
|
tls_stream
|
||||||
|
.write_all(&send_request(addr, http.as_bytes()))
|
||||||
|
.unwrap();
|
||||||
|
tls_stream.flush()?;
|
||||||
|
} else {
|
||||||
|
tls_stream
|
||||||
|
.write_all(&send_request("github.com", buf_str.as_bytes()))
|
||||||
|
.unwrap();
|
||||||
|
tls_stream.flush()?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_request(addr: &str, buf: &[u8]) -> Vec<u8> {
|
||||||
|
let (mut conn, mut tcp) = crate::tls::mask_tls(addr).unwrap();
|
||||||
|
let mut tls = Stream::new(&mut conn, &mut tcp);
|
||||||
|
tls.write_all(buf).unwrap();
|
||||||
|
let mut resp = Vec::new();
|
||||||
|
tls.read_to_end(&mut resp).unwrap();
|
||||||
|
resp
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user