33//! Provides unified support for TPM, YubiKey, HSMs, and other PKCS#11-compatible devices.
44
55use anyhow:: { Context , Result } ;
6- use cryptoki:: context:: { CInitializeArgs , Pkcs11 } ;
6+ use cryptoki:: context:: { CInitializeArgs , CInitializeFlags , Pkcs11 } ;
77use cryptoki:: mechanism:: Mechanism ;
88use cryptoki:: object:: { Attribute , AttributeType , ObjectClass , ObjectHandle } ;
99use cryptoki:: session:: { Session , UserType } ;
@@ -662,7 +662,7 @@ pub fn init_pkcs11_session(
662662 let pkcs11 = Pkcs11 :: new ( module_path) . context ( "Failed to load PKCS#11 module" ) ?;
663663
664664 pkcs11
665- . initialize ( CInitializeArgs :: OsThreads )
665+ . initialize ( CInitializeArgs :: new ( CInitializeFlags :: OS_LOCKING_OK ) )
666666 . context ( "Failed to initialize PKCS#11" ) ?;
667667
668668 // Find token
@@ -675,7 +675,7 @@ pub fn init_pkcs11_session(
675675
676676 // Login - auth should contain the PIN already
677677 if !auth. is_empty ( ) {
678- let auth_pin = AuthPin :: new ( auth. to_string ( ) ) ;
678+ let auth_pin = AuthPin :: new ( auth. to_string ( ) . into ( ) ) ;
679679 session
680680 . login ( UserType :: User , Some ( & auth_pin) )
681681 . context ( "Failed to login to PKCS#11 device" ) ?;
@@ -705,7 +705,7 @@ pub fn delete_pkcs11_key(uri: &str) -> Result<()> {
705705 let pkcs11 = Pkcs11 :: new ( module_path) . context ( "Failed to load PKCS#11 module" ) ?;
706706
707707 pkcs11
708- . initialize ( CInitializeArgs :: OsThreads )
708+ . initialize ( CInitializeArgs :: new ( CInitializeFlags :: OS_LOCKING_OK ) )
709709 . context ( "Failed to initialize PKCS#11" ) ?;
710710
711711 // Find the token
@@ -719,7 +719,7 @@ pub fn delete_pkcs11_key(uri: &str) -> Result<()> {
719719 // For deletion, we need to login with PIN
720720 let pin_str = rpassword:: prompt_password ( "Enter PIN to delete hardware key: " )
721721 . context ( "Failed to read PIN" ) ?;
722- let auth_pin = AuthPin :: new ( pin_str. clone ( ) ) ;
722+ let auth_pin = AuthPin :: new ( pin_str. clone ( ) . into ( ) ) ;
723723
724724 session
725725 . login ( UserType :: User , Some ( & auth_pin) )
@@ -808,7 +808,7 @@ pub fn sign_with_pkcs11_device(
808808 if requires_auth {
809809 // Key requires per-operation authentication (common with YubiKey)
810810 // Use the provided PIN for context-specific login
811- let auth_pin = AuthPin :: new ( pin. to_string ( ) ) ;
811+ let auth_pin = AuthPin :: new ( pin. to_string ( ) . into ( ) ) ;
812812
813813 // Context-specific login for this operation
814814 session
0 commit comments