Skip to content

Commit f0201c9

Browse files
committed
Use unique container name
1 parent 7493a48 commit f0201c9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/imp/schannel.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ impl Identity {
111111
)
112112
})?)?;
113113

114+
let name = gen_container_name();
114115
let mut options = AcquireOptions::new();
115-
options.container("schannel");
116+
options.container(&name);
116117
let type_ = ProviderType::rsa_full();
117118

118119
let mut container = match options.acquire(type_) {
@@ -122,7 +123,7 @@ impl Identity {
122123
container.import().import_pkcs8_pem(&key)?;
123124

124125
cert.set_key_prov_info()
125-
.container("schannel")
126+
.container(&name)
126127
.type_(type_)
127128
.keep_open(true)
128129
.key_spec(KeySpec::key_exchange())
@@ -137,6 +138,13 @@ impl Identity {
137138
}
138139
}
139140

141+
// The name of the container must be unique to have multiple active keys.
142+
fn gen_container_name() -> String {
143+
use std::sync::atomic::{AtomicUsize, Ordering};
144+
static COUNTER: AtomicUsize = AtomicUsize::new(0);
145+
format!("native-tls-{}", COUNTER.fetch_add(1, Ordering::Relaxed))
146+
}
147+
140148
#[derive(Clone)]
141149
pub struct Certificate(CertContext);
142150

0 commit comments

Comments
 (0)