@@ -7,6 +7,7 @@ use self::security_framework::base;
77use self :: security_framework:: certificate:: SecCertificate ;
88use self :: security_framework:: identity:: SecIdentity ;
99use self :: security_framework:: import_export:: { ImportedIdentity , Pkcs12ImportOptions } ;
10+ use self :: security_framework:: random:: SecRandom ;
1011use self :: security_framework:: secure_transport:: {
1112 self , ClientBuilder , SslConnectionType , SslContext , SslProtocol , SslProtocolSide ,
1213} ;
@@ -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,19 @@ impl Identity {
180181 }
181182}
182183
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+
183197#[ derive( Clone ) ]
184198pub struct Certificate ( SecCertificate ) ;
185199
0 commit comments