Skip to content

Commit d0250cd

Browse files
committed
Use random password
1 parent 2a720f6 commit d0250cd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ security-framework-sys = "2.0.0"
2121
lazy_static = "1.4.0"
2222
libc = "0.2"
2323
tempfile = "3.1.0"
24+
rand = "0.8.4"
2425

2526
[target.'cfg(target_os = "windows")'.dependencies]
2627
schannel = "0.1.17"

src/imp/security_framework.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extern crate libc;
2+
extern crate rand;
23
extern crate security_framework;
34
extern crate security_framework_sys;
45
extern crate tempfile;
@@ -91,7 +92,7 @@ impl Identity {
9192

9293
let dir = TempDir::new().map_err(|_| Error(base::Error::from(errSecIO)))?;
9394
let keychain = keychain::CreateOptions::new()
94-
.password("password")
95+
.password(&random_password())
9596
.create(dir.path().join("identity.keychain"))?;
9697

9798
let mut items = SecItems::default();
@@ -180,6 +181,16 @@ impl Identity {
180181
}
181182
}
182183

184+
fn random_password() -> String {
185+
use self::rand::{distributions::Alphanumeric, Rng};
186+
187+
self::rand::thread_rng()
188+
.sample_iter(&Alphanumeric)
189+
.take(10)
190+
.map(char::from)
191+
.collect()
192+
}
193+
183194
#[derive(Clone)]
184195
pub struct Certificate(SecCertificate);
185196

0 commit comments

Comments
 (0)