@@ -2,7 +2,7 @@ use std::{collections::HashMap, sync::Arc, time::Duration};
2
2
3
3
use futures:: { channel:: oneshot, lock:: Mutex } ;
4
4
#[ cfg( any( feature = "tokio-runtime" , feature = "async-std-runtime" ) ) ]
5
- use native_tls:: Certificate ;
5
+ use native_tls:: { Certificate , Identity } ;
6
6
use rand:: Rng ;
7
7
#[ cfg( all(
8
8
any( feature = "tokio-rustls-runtime" , feature = "async-std-rustls-runtime" ) ,
@@ -81,6 +81,12 @@ pub struct TlsOptions {
81
81
/// contains a list of PEM encoded certificates
82
82
pub certificate_chain : Option < Vec < u8 > > ,
83
83
84
+ /// PEM encoded X509 certificates
85
+ pub certificate : Option < Vec < u8 > > ,
86
+
87
+ /// is a PEM encoded PKCS #8 formatted private key for the leaf certificate
88
+ pub private_key : Option < Vec < u8 > > ,
89
+
84
90
/// allow insecure TLS connection if set to true
85
91
///
86
92
/// defaults to *false*
@@ -97,6 +103,8 @@ impl Default for TlsOptions {
97
103
fn default ( ) -> Self {
98
104
Self {
99
105
certificate_chain : None ,
106
+ certificate : None ,
107
+ private_key : None ,
100
108
allow_insecure_connection : false ,
101
109
tls_hostname_verification_enabled : true ,
102
110
}
@@ -123,6 +131,8 @@ pub struct ConnectionManager<Exe: Executor> {
123
131
pub ( crate ) operation_retry_options : OperationRetryOptions ,
124
132
tls_options : TlsOptions ,
125
133
certificate_chain : Vec < Certificate > ,
134
+ #[ cfg( any( feature = "tokio-runtime" , feature = "async-std-runtime" ) ) ]
135
+ identity : Option < Identity > ,
126
136
}
127
137
128
138
impl < Exe : Executor > ConnectionManager < Exe > {
@@ -178,6 +188,17 @@ impl<Exe: Executor> ConnectionManager<Exe> {
178
188
}
179
189
} ;
180
190
191
+ #[ cfg( any( feature = "tokio-runtime" , feature = "async-std-runtime" ) ) ]
192
+ let identity = match (
193
+ tls_options. certificate . as_ref ( ) ,
194
+ tls_options. private_key . as_ref ( ) ,
195
+ ) {
196
+ ( None , _) | ( _, None ) => None ,
197
+ ( Some ( certificate) , Some ( privatekey) ) => {
198
+ Some ( native_tls:: Identity :: from_pkcs8 ( & certificate, & privatekey) ?)
199
+ }
200
+ } ;
201
+
181
202
if let Some ( auth) = auth. clone ( ) {
182
203
auth. lock ( ) . await . initialize ( ) . await ?;
183
204
}
@@ -191,6 +212,8 @@ impl<Exe: Executor> ConnectionManager<Exe> {
191
212
operation_retry_options,
192
213
tls_options,
193
214
certificate_chain,
215
+ #[ cfg( any( feature = "tokio-runtime" , feature = "async-std-runtime" ) ) ]
216
+ identity,
194
217
} ;
195
218
let broker_address = BrokerAddress {
196
219
url : url. clone ( ) ,
@@ -308,6 +331,8 @@ impl<Exe: Executor> ConnectionManager<Exe> {
308
331
self . auth . clone ( ) ,
309
332
proxy_url. clone ( ) ,
310
333
& self . certificate_chain ,
334
+ #[ cfg( any( feature = "tokio-runtime" , feature = "async-std-runtime" ) ) ]
335
+ & self . identity ,
311
336
self . tls_options . allow_insecure_connection ,
312
337
self . tls_options . tls_hostname_verification_enabled ,
313
338
self . connection_retry_options . connection_timeout ,
0 commit comments