Skip to content

Commit

Permalink
fix some more issues with tls-related examples
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDC committed Sep 19, 2024
1 parent fc9d5ef commit 4a342f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 12 additions & 1 deletion examples/http_mitm_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use rama::{
net::http::RequestContext,
net::stream::layer::http::BodyLimitLayer,
net::tls::{
client::{ClientConfig, ClientHelloExtension, ServerVerifyMode},
server::{SelfSignedData, ServerAuth, ServerConfig},
ApplicationProtocol,
},
Expand Down Expand Up @@ -195,7 +196,17 @@ async fn http_mitm_proxy(ctx: Context, req: Request) -> Result<Response, Infalli

// NOTE: use a custom connector (layers) in case you wish to add custom features,
// such as upstream proxies or other configurations
let client = HttpClient::default();
let mut client = HttpClient::default();
client.set_tls_config(ClientConfig {
server_verify_mode: ServerVerifyMode::Disable,
extensions: Some(vec![
ClientHelloExtension::ApplicationLayerProtocolNegotiation(vec![
ApplicationProtocol::HTTP_2,
ApplicationProtocol::HTTP_11,
]),
]),
..Default::default()
});
match client.serve(ctx, req).await {
Ok(resp) => Ok(resp),
Err(err) => {
Expand Down
6 changes: 1 addition & 5 deletions examples/tls_termination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use rama::{
};
use rama_net::tls::{
server::{SelfSignedData, ServerAuth, ServerConfig},
ApplicationProtocol, KeyLogIntent,
KeyLogIntent,
};

// everything else is provided by the standard library, community crates or tokio
Expand All @@ -85,10 +85,6 @@ async fn main() {

let mut tls_server_config =
ServerConfig::new(ServerAuth::SelfSigned(SelfSignedData::default()));
tls_server_config.application_layer_protocol_negotiation = Some(vec![
ApplicationProtocol::HTTP_2,
ApplicationProtocol::HTTP_11,
]);
if let Ok(keylog_file) = std::env::var("SSLKEYLOGFILE") {
tls_server_config.key_logger = KeyLogIntent::File(keylog_file.into());
}
Expand Down

0 comments on commit 4a342f2

Please sign in to comment.