@@ -7,6 +7,7 @@ use self::security_framework::base;
7
7
use self :: security_framework:: certificate:: SecCertificate ;
8
8
use self :: security_framework:: identity:: SecIdentity ;
9
9
use self :: security_framework:: import_export:: { ImportedIdentity , Pkcs12ImportOptions } ;
10
+ use self :: security_framework:: random:: SecRandom ;
10
11
use self :: security_framework:: secure_transport:: {
11
12
self , ClientBuilder , SslConnectionType , SslContext , SslProtocol , SslProtocolSide ,
12
13
} ;
@@ -91,7 +92,7 @@ impl Identity {
91
92
92
93
let dir = TempDir :: new ( ) . map_err ( |_| Error ( base:: Error :: from ( errSecIO) ) ) ?;
93
94
let keychain = keychain:: CreateOptions :: new ( )
94
- . password ( "password" )
95
+ . password ( & random_password ( ) ? )
95
96
. create ( dir. path ( ) . join ( "identity.keychain" ) ) ?;
96
97
97
98
let mut items = SecItems :: default ( ) ;
@@ -180,6 +181,19 @@ impl Identity {
180
181
}
181
182
}
182
183
184
+ fn random_password ( ) -> Result < String , Error > {
185
+ use std:: fmt:: Write ;
186
+ let mut bytes = [ 0_u8 ; 10 ] ;
187
+ SecRandom :: default ( )
188
+ . copy_bytes ( & mut bytes)
189
+ . map_err ( |_| Error ( base:: Error :: from ( errSecIO) ) ) ?;
190
+ let mut s = String :: with_capacity ( 2 * bytes. len ( ) ) ;
191
+ for byte in bytes {
192
+ write ! ( s, "{:02X}" , byte) . map_err ( |_| Error ( base:: Error :: from ( errSecIO) ) ) ?;
193
+ }
194
+ Ok ( s)
195
+ }
196
+
183
197
#[ derive( Clone ) ]
184
198
pub struct Certificate ( SecCertificate ) ;
185
199
0 commit comments