client: improve fingerprint variable names

and pass as reference instead of cloning.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-05-10 10:52:32 +02:00 committed by Thomas Lamprecht
parent dda1b4fa44
commit 56d98ba966
1 changed files with 7 additions and 7 deletions

View File

@ -298,13 +298,13 @@ impl HttpClient {
let verified_fingerprint = Arc::new(Mutex::new(None)); let verified_fingerprint = Arc::new(Mutex::new(None));
let mut fingerprint = options.fingerprint.take(); let mut expected_fingerprint = options.fingerprint.take();
if fingerprint.is_some() { if expected_fingerprint.is_some() {
// do not store fingerprints passed via options in cache // do not store fingerprints passed via options in cache
options.fingerprint_cache = false; options.fingerprint_cache = false;
} else if options.fingerprint_cache && options.prefix.is_some() { } else if options.fingerprint_cache && options.prefix.is_some() {
fingerprint = load_fingerprint(options.prefix.as_ref().unwrap(), server); expected_fingerprint = load_fingerprint(options.prefix.as_ref().unwrap(), server);
} }
let mut ssl_connector_builder = SslConnector::builder(SslMethod::tls()).unwrap(); let mut ssl_connector_builder = SslConnector::builder(SslMethod::tls()).unwrap();
@ -316,7 +316,7 @@ impl HttpClient {
let fingerprint_cache = options.fingerprint_cache; let fingerprint_cache = options.fingerprint_cache;
let prefix = options.prefix.clone(); let prefix = options.prefix.clone();
ssl_connector_builder.set_verify_callback(openssl::ssl::SslVerifyMode::PEER, move |valid, ctx| { ssl_connector_builder.set_verify_callback(openssl::ssl::SslVerifyMode::PEER, move |valid, ctx| {
let (valid, fingerprint) = Self::verify_callback(valid, ctx, fingerprint.clone(), interactive); let (valid, fingerprint) = Self::verify_callback(valid, ctx, expected_fingerprint.as_ref(), interactive);
if valid { if valid {
if let Some(fingerprint) = fingerprint { if let Some(fingerprint) = fingerprint {
if fingerprint_cache && prefix.is_some() { if fingerprint_cache && prefix.is_some() {
@ -474,9 +474,9 @@ impl HttpClient {
} }
fn verify_callback( fn verify_callback(
valid: bool, ctx: valid: bool,
&mut X509StoreContextRef, ctx: &mut X509StoreContextRef,
expected_fingerprint: Option<String>, expected_fingerprint: Option<&String>,
interactive: bool, interactive: bool,
) -> (bool, Option<String>) { ) -> (bool, Option<String>) {
if valid { return (true, None); } if valid { return (true, None); }