Skip to content

Commit

Permalink
ureq http client with tls support
Browse files Browse the repository at this point in the history
- at this time just native-tls is supported
- rustls would be much easier to add when ureq 3.0 is released
  • Loading branch information
mzachar committed Sep 11, 2024
1 parent b5ae19f commit 1cc1386
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 562 deletions.
494 changes: 460 additions & 34 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pbkdf2 = { version = "0.12", optional = true, default-features = false, features
serde_json = { version = "1", optional = true }
rusb = { version = "0.9.4", optional = true }
tiny_http = { version = "0.12", optional = true }
ureq = { version = "2.10.1", optional = true, default-features = false, features = ["gzip"] }
native-tls = { version = "0", optional = true }

[dev-dependencies]
ed25519-dalek = "2"
Expand All @@ -61,14 +63,18 @@ x509-cert = { version = "0.2.5", features = ["builder"] }
[features]
default = ["http", "passwords", "setup"]
http-server = ["tiny_http"]
http = []
http = ["ureq"]
native-tls = ["ureq/native-tls", "dep:native-tls", "_tls"]
native-tls-vendored = ["native-tls", "native-tls/vendored"]
mockhsm = ["ecdsa/arithmetic", "ed25519-dalek", "p256/ecdsa", "secp256k1"]
passwords = ["hmac", "pbkdf2"]
secp256k1 = ["k256"]
setup = ["passwords", "serde_json", "uuid/serde"]
untested = []
usb = ["rusb"]

_tls = []

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Expand Down
19 changes: 7 additions & 12 deletions src/connector/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use crate::error::{BoxError, Context};
use std::{fmt, io, num::ParseIntError, str::Utf8Error};
use thiserror::Error;

#[cfg(feature = "http")]
use super::http;

/// `yubihsm-connector` related errors
pub type Error = crate::Error<ErrorKind>;

Expand Down Expand Up @@ -67,15 +64,13 @@ impl From<io::Error> for Error {
}

#[cfg(feature = "http")]
impl From<http::client::Error> for Error {
fn from(err: http::client::Error) -> Error {
impl From<ureq::Error> for Error {
fn from(err: ureq::Error) -> Error {
let kind = match err.kind() {
http::client::ErrorKind::AddrInvalid => ErrorKind::AddrInvalid,
http::client::ErrorKind::IoError => ErrorKind::IoError,
http::client::ErrorKind::ParseError | http::client::ErrorKind::ResponseError => {
ErrorKind::ResponseError
}
http::client::ErrorKind::RequestError => ErrorKind::RequestError,
ureq::ErrorKind::Dns => ErrorKind::AddrInvalid,
ureq::ErrorKind::Io => ErrorKind::IoError,
ureq::ErrorKind::HTTP => ErrorKind::ResponseError,
_ => ErrorKind::RequestError,
};

kind.context(err).into()
Expand All @@ -91,7 +86,7 @@ impl From<rusb::Error> for Error {
rusb::Error::Pipe => format_err!(ErrorKind::UsbError, "lost connection to USB device"),
_ => format_err!(ErrorKind::UsbError, "{}", err),
}
.into()
.into()
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/connector/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//!
//! <https://developers.yubico.com/YubiHSM2/Component_Reference/yubihsm-connector/>

pub(super) mod client;
mod config;
#[cfg(feature = "http")]
mod connection;
#[cfg(feature = "http-server")]
mod server;
Expand All @@ -12,6 +12,7 @@ pub use self::config::HttpConfig;
#[cfg(feature = "http-server")]
pub use self::server::Server;

#[cfg(feature = "http")]
use self::connection::HttpConnection;
use crate::connector::{self, Connectable, Connection};

Expand Down
18 changes: 0 additions & 18 deletions src/connector/http/client.rs

This file was deleted.

90 changes: 0 additions & 90 deletions src/connector/http/client/connection.rs

This file was deleted.

149 changes: 0 additions & 149 deletions src/connector/http/client/error.rs

This file was deleted.

39 changes: 0 additions & 39 deletions src/connector/http/client/path.rs

This file was deleted.

Loading

0 comments on commit 1cc1386

Please sign in to comment.