Skip to content

Commit

Permalink
Added openssl 1.x compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ancwrd1 committed Jan 8, 2025
1 parent 5fe61ac commit 96ae6b7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions snx-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ libc = "0.2"
tracing-subscriber = "0.3"
clap = { version = "4.5.4", features = ["derive"] }
ipnet = { version = "2", features = ["serde"] }
openssl-sys = "0.9"
openssl = "0.10"

[features]
Expand Down
8 changes: 8 additions & 0 deletions snx-rs/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
if let Ok(v) = std::env::var("DEP_OPENSSL_VERSION_NUMBER") {
let version = u64::from_str_radix(&v, 16).unwrap();
if version >= 0x3000_0000 {
println!("cargo:rustc-cfg=openssl3");
}
}
}
29 changes: 18 additions & 11 deletions snx-rs/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use std::{
collections::VecDeque,
future::Future,
sync::{Arc, OnceLock},
};
#![allow(unexpected_cfgs)]

use std::{collections::VecDeque, future::Future, sync::Arc};

use anyhow::anyhow;
use clap::Parser;
use futures::pin_mut;
use openssl::provider::Provider;
use tokio::{
signal::unix,
sync::{mpsc, oneshot},
Expand Down Expand Up @@ -61,6 +58,20 @@ where
}
}

fn init_openssl() {
#[cfg(openssl3)]
{
use openssl::provider::Provider;
use std::sync::OnceLock;

static LEGACY_PROVIDER: OnceLock<Provider> = OnceLock::new();

if let Ok(provider) = Provider::try_load(None, "legacy", true) {
let _ = LEGACY_PROVIDER.set(provider);
}
}
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cmdline_params = CmdlineParams::parse();
Expand All @@ -69,11 +80,7 @@ async fn main() -> anyhow::Result<()> {
return Err(anyhow!("Please run me as a root user!"));
}

static LEGACY_PROVIDER: OnceLock<Provider> = OnceLock::new();

if let Ok(provider) = Provider::try_load(None, "legacy", true) {
let _ = LEGACY_PROVIDER.set(provider);
}
init_openssl();

let mode = cmdline_params.mode;

Expand Down

0 comments on commit 96ae6b7

Please sign in to comment.