Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aab

Check warning on line 1 in .github/actions/spelling/expect.txt

View workflow job for this annotation

GitHub Actions / Check Spelling

Skipping `.github/actions/spelling/expect.txt` because it seems to have more noise (385) than unique words (0) (total: 386 / 0). (noisy-file)
AAFFBB
aarch
abe
Expand Down Expand Up @@ -365,4 +365,22 @@
xxxx
xxxxxxxx
xxxxxxxxxxx
zipsas
zipsas
CALG
CNG
detials
HCRYPTPROV
hostgap
innerbandwidth
innerlatency
KSP
ncrypt
outwardbandwidth
outwardlatency
PCWSTR
PSTR
psz
rsm
SELFSIGN
vmsettings
hostgaplugin

Check warning on line 386 in .github/actions/spelling/expect.txt

View workflow job for this annotation

GitHub Actions / Check Spelling

Missing newline at eof. (no-newline-at-eof)
62 changes: 61 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions proxy_agent_shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ http = "1.1.0"
http-body-util = "0.1"
hyper = { version = "1", features = ["server", "http1", "client"] }
hyper-util = { version = "0.1", features = ["tokio"] }
base64 = "0.22.1"

[dependencies.uuid]
version = "1.3.0"
Expand Down Expand Up @@ -56,5 +57,14 @@ features = [
"Win32_Storage_FileSystem",
]

[target.'cfg(windows)'.dependencies.windows]
version = "0.61.3"
features = [
"Win32_Foundation",
"Win32_Security_Cryptography",
"Win32_System_SystemInformation",
"Win32_System_Memory",
]

[target.'cfg(not(windows))'.dependencies]
os_info = "3.7.0" # read Linux OS version and arch
3 changes: 3 additions & 0 deletions proxy_agent_shared/src/certificate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod certificate_helper;
#[cfg(windows)]
pub mod certificate_helper_windows;
103 changes: 103 additions & 0 deletions proxy_agent_shared/src/certificate/certificate_helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#[cfg(windows)]
use crate::certificate::certificate_helper_windows::CertificateDetailsWindows;
use crate::formatted_error_message::FormattedErrorMessage;

#[cfg(windows)]
type CertDetailsType = CertificateDetailsWindows;

#[cfg(not(windows))]
type CertDetailsType = ();

pub struct CertificateDetailsWrapper {
pub cert_details: CertDetailsType,
}

impl CertificateDetailsWrapper {
pub fn get_public_cert_der(&self) -> &[u8] {
#[cfg(windows)]
{
&self.cert_details.public_key_der
}
#[cfg(not(windows))]
{
todo!()
}
}
}

pub fn generate_self_signed_certificate(
_subject_name: &str,
) -> Result<CertificateDetailsWrapper, FormattedErrorMessage> {
#[cfg(windows)]
{
use crate::certificate::certificate_helper_windows::generate_self_signed_certificate_windows;

generate_self_signed_certificate_windows(_subject_name)
}
#[cfg(not(windows))]
{
Err("Linux version is not implemented.".to_string().into())
}
}

pub fn decrypt_from_base64(
_base64_input: &str,
_cert_details: &CertificateDetailsWrapper,
) -> Result<String, FormattedErrorMessage> {
#[cfg(windows)]
{
use crate::certificate::certificate_helper_windows::decrypt_from_base64_windows;

decrypt_from_base64_windows(_base64_input, _cert_details)
}
#[cfg(not(windows))]
{
Err("Linux version is not implemented.".to_string().into())
}
}

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn generate_self_signed_certificate_test() {
#[cfg(windows)]
{
let subject_name = "TestSubject";
let cert_details_result = generate_self_signed_certificate(subject_name);
assert!(cert_details_result.is_ok());
let cert_details = cert_details_result.unwrap();
let public_cert_der = cert_details.get_public_cert_der();
assert!(!public_cert_der.is_empty());
}
#[cfg(not(windows))]
{
// On non-Windows platforms, the function is not implemented.
// This test will simply ensure that the function is called without panic.
let subject_name = "TestSubject";
let cert_details_result = generate_self_signed_certificate(subject_name);
assert!(cert_details_result.is_err());
}
}

#[test]
fn decrypt_from_base64_test() {
#[cfg(windows)]
{
let subject_name = "TestSubject";
let cert_details_result = generate_self_signed_certificate(subject_name);
assert!(cert_details_result.is_ok());
let cert_details = cert_details_result.unwrap();
let result = decrypt_from_base64("invalid input", &cert_details);
assert!(result.is_err());
}
#[cfg(not(windows))]
{
let result = decrypt_from_base64(
"invalid input",
&CertificateDetailsWrapper { cert_details: () },
);
assert!(result.is_err());
}
}
}
Loading
Loading