@@ -1055,15 +1055,25 @@ pub async fn send_request_handler(
1055
1055
let ( mut sender, worker) = if use_tls {
1056
1056
#[ cfg( any( target_arch = "riscv64" , target_arch = "s390x" ) ) ]
1057
1057
{
1058
- return Err ( crate :: bindings:: http:: types:: ErrorCode :: InternalError (
1059
- Some ( "unsupported architecture for SSL" . to_string ( ) ) ,
1060
- ) ) ;
1058
+ return Err (
1059
+ wasmtime_wasi_http:: bindings:: http:: types:: ErrorCode :: InternalError ( Some (
1060
+ "unsupported architecture for SSL" . to_string ( ) ,
1061
+ ) ) ,
1062
+ ) ;
1061
1063
}
1062
1064
1063
1065
#[ cfg( not( any( target_arch = "riscv64" , target_arch = "s390x" ) ) ) ]
1064
1066
{
1065
1067
use rustls:: pki_types:: ServerName ;
1066
- let config = get_client_tls_config_for_authority ( & authority, client_tls_opts) ;
1068
+ let config =
1069
+ get_client_tls_config_for_authority ( & authority, client_tls_opts) . map_err ( |e| {
1070
+ wasmtime_wasi_http:: bindings:: http:: types:: ErrorCode :: InternalError ( Some (
1071
+ format ! (
1072
+ "failed to configure client tls config for authority. error: {}" ,
1073
+ e
1074
+ ) ,
1075
+ ) )
1076
+ } ) ?;
1067
1077
let connector = tokio_rustls:: TlsConnector :: from ( std:: sync:: Arc :: new ( config) ) ;
1068
1078
let mut parts = authority_str. split ( ":" ) ;
1069
1079
let host = parts. next ( ) . unwrap_or ( & authority_str) ;
@@ -1150,7 +1160,7 @@ pub async fn send_request_handler(
1150
1160
fn get_client_tls_config_for_authority (
1151
1161
authority : & Authority ,
1152
1162
client_tls_opts : Option < HashMap < Authority , ParsedClientTlsOpts > > ,
1153
- ) -> rustls:: ClientConfig {
1163
+ ) -> Result < rustls:: ClientConfig > {
1154
1164
// derived from https://github.com/tokio-rs/tls/blob/master/tokio-rustls/examples/client/src/main.rs
1155
1165
let mut root_cert_store = rustls:: RootCertStore {
1156
1166
roots : webpki_roots:: TLS_SERVER_ROOTS . into ( ) ,
@@ -1159,18 +1169,18 @@ fn get_client_tls_config_for_authority(
1159
1169
let client_tls_opts = match client_tls_opts {
1160
1170
Some ( opts) => opts,
1161
1171
_ => {
1162
- return rustls:: ClientConfig :: builder ( )
1172
+ return Ok ( rustls:: ClientConfig :: builder ( )
1163
1173
. with_root_certificates ( root_cert_store)
1164
- . with_no_client_auth ( ) ;
1174
+ . with_no_client_auth ( ) ) ;
1165
1175
}
1166
1176
} ;
1167
1177
1168
1178
let client_tls_opts_for_host = match client_tls_opts. get ( authority) {
1169
1179
Some ( opts) => opts,
1170
1180
_ => {
1171
- return rustls:: ClientConfig :: builder ( )
1181
+ return Ok ( rustls:: ClientConfig :: builder ( )
1172
1182
. with_root_certificates ( root_cert_store)
1173
- . with_no_client_auth ( ) ;
1183
+ . with_no_client_auth ( ) ) ;
1174
1184
}
1175
1185
} ;
1176
1186
@@ -1179,7 +1189,10 @@ fn get_client_tls_config_for_authority(
1179
1189
match root_cert_store. add ( cer. to_owned ( ) ) {
1180
1190
Ok ( _) => { }
1181
1191
Err ( e) => {
1182
- tracing:: warn!( "failed to add custom cert to root_cert_store. error: {}" , e)
1192
+ return Err ( anyhow:: anyhow!(
1193
+ "failed to add custom cert to root_cert_store. error: {}" ,
1194
+ e
1195
+ ) ) ;
1183
1196
}
1184
1197
}
1185
1198
}
@@ -1189,13 +1202,13 @@ fn get_client_tls_config_for_authority(
1189
1202
& client_tls_opts_for_host. cert_chain ,
1190
1203
& client_tls_opts_for_host. private_key ,
1191
1204
) {
1192
- ( Some ( cert_chain) , Some ( private_key) ) => rustls:: ClientConfig :: builder ( )
1205
+ ( Some ( cert_chain) , Some ( private_key) ) => Ok ( rustls:: ClientConfig :: builder ( )
1193
1206
. with_root_certificates ( root_cert_store)
1194
1207
. with_client_auth_cert ( cert_chain. to_owned ( ) , private_key. clone_key ( ) )
1195
- . unwrap ( ) ,
1196
- _ => rustls:: ClientConfig :: builder ( )
1208
+ . unwrap ( ) ) ,
1209
+ _ => Ok ( rustls:: ClientConfig :: builder ( )
1197
1210
. with_root_certificates ( root_cert_store)
1198
- . with_no_client_auth ( ) ,
1211
+ . with_no_client_auth ( ) ) ,
1199
1212
}
1200
1213
}
1201
1214
0 commit comments