Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https: ureq http client with tls support #560

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
494 changes: 460 additions & 34 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ 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 }
rustls = { version = "0", default-features = false, features = ["ring", "logging", "std", "tls12"], optional = true }
rustls-pemfile = { version = "2.1.3", optional = true }
rustls-platform-verifier = { version = "0.3.4", optional = true }

[dev-dependencies]
ed25519-dalek = "2"
Expand All @@ -61,14 +66,19 @@ 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"]
rustls = ["ureq/tls", "dep:rustls", "dep:rustls-pemfile", "dep:rustls-platform-verifier", "_tls"]
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