It would be nicer if client ssl connection allow insecure cert. #966
Murasame233
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
[dependencies]
xitca-client = { git = "https://github.com/HFQR/xitca-web", features = ["openssl"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
openssl = "0.10"
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
use xitca_client::{error::Error, http::Version, Io, Service};
#[tokio::main]
async fn main() {
let cli = xitca_client::Client::builder()
.tls_connector(MyConnector::new())
.finish();
}
impl<'n> Service<(&'n str, Box<dyn Io>)> for MyConnector {
type Response = (Box<dyn Io>, Version);
type Error = Error;
async fn call(&self, req: (&'n str, Box<dyn Io>)) -> Result<Self::Response, Self::Error> {
// just forward the connector logic to default SslConnector because
// the custom logic only happens in the builder phase.
self.0.call(req).await
}
}
struct MyConnector(SslConnector);
impl MyConnector {
fn new() -> Self {
let mut ssl = SslConnector::builder(SslMethod::tls()).unwrap();
// your custom verification mod goes here
ssl.set_verify(SslVerifyMode::empty());
ssl.set_alpn_protos(b"\x08http/1.1\x02h2").unwrap();
MyConnector(ssl.build())
}
} Apparently this is powerful and verbose at the same time and I'm open to alternatives with less boilerplate. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
set verify
There are lots of usage when using local network. We only can provide insecure cert during development.
Beta Was this translation helpful? Give feedback.
All reactions