Skip to content

Commit

Permalink
Use random password
Browse files Browse the repository at this point in the history
  • Loading branch information
kazk committed Jan 3, 2022
1 parent 2a720f6 commit 658800e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/imp/security_framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use self::security_framework::base;
use self::security_framework::certificate::SecCertificate;
use self::security_framework::identity::SecIdentity;
use self::security_framework::import_export::{ImportedIdentity, Pkcs12ImportOptions};
use self::security_framework::random::SecRandom;
use self::security_framework::secure_transport::{
self, ClientBuilder, SslConnectionType, SslContext, SslProtocol, SslProtocolSide,
};
Expand Down Expand Up @@ -91,7 +92,7 @@ impl Identity {

let dir = TempDir::new().map_err(|_| Error(base::Error::from(errSecIO)))?;
let keychain = keychain::CreateOptions::new()
.password("password")
.password(&random_password()?)
.create(dir.path().join("identity.keychain"))?;

let mut items = SecItems::default();
Expand Down Expand Up @@ -180,6 +181,19 @@ impl Identity {
}
}

fn random_password() -> Result<String, Error> {
use std::fmt::Write;
let mut bytes = [0_u8; 10];
SecRandom::default()
.copy_bytes(&mut bytes)
.map_err(|_| Error(base::Error::from(errSecIO)))?;
let mut s = String::with_capacity(2 * bytes.len());
for byte in bytes {
write!(s, "{:02X}", byte).map_err(|_| Error(base::Error::from(errSecIO)))?;
}
Ok(s)
}

#[derive(Clone)]
pub struct Certificate(SecCertificate);

Expand Down

0 comments on commit 658800e

Please sign in to comment.