@@ -52,7 +52,7 @@ impl ProductionDebugUnlock {
5252 pub fn handle_request (
5353 & mut self ,
5454 trng : & mut caliptra_drivers:: Trng ,
55- soc_ifc : & caliptra_drivers:: SocIfc ,
55+ soc_ifc : & mut caliptra_drivers:: SocIfc ,
5656 dma : & mut caliptra_drivers:: Dma ,
5757 cmd_bytes : & [ u8 ] ,
5858 resp : & mut [ u8 ] ,
@@ -73,20 +73,32 @@ impl ProductionDebugUnlock {
7373 return Err ( CaliptraError :: RUNTIME_DEBUG_UNLOCK_INVALID_LIFECYCLE ) ;
7474 }
7575
76- // Use common function to create challenge
77- let challenge =
78- caliptra_common:: debug_unlock:: create_debug_unlock_challenge ( trng, soc_ifc, dma, & req) ?;
76+ // Set debug unlock in progress
77+ soc_ifc. set_ss_dbg_unlock_in_progress ( true ) ;
78+
79+ let result = ( || -> CaliptraResult < usize > {
80+ // Use common function to create challenge
81+ let challenge = caliptra_common:: debug_unlock:: create_debug_unlock_challenge (
82+ trng, soc_ifc, dma, & req,
83+ ) ?;
84+
85+ // Store the challenge for future token validation
86+ let stored_challenge = challenge. clone ( ) ;
87+ self . last_challenge = Some ( stored_challenge) ;
88+ self . last_request = Some ( req) ;
7989
80- // Store the challenge for future token validation
81- let stored_challenge = challenge. clone ( ) ;
82- self . last_challenge = Some ( stored_challenge) ;
83- self . last_request = Some ( req) ;
90+ cprintln ! ( "[rt] Production debug unlock challenge generated" ) ;
8491
85- cprintln ! ( "[rt] Production debug unlock challenge generated" ) ;
92+ let resp = mutrefbytes :: < ProductionAuthDebugUnlockChallenge > ( resp) ?;
93+ * resp = challenge;
94+ Ok ( core:: mem:: size_of :: < ProductionAuthDebugUnlockChallenge > ( ) )
95+ } ) ( ) ;
8696
87- let resp = mutrefbytes :: < ProductionAuthDebugUnlockChallenge > ( resp) ?;
88- * resp = challenge;
89- Ok ( core:: mem:: size_of :: < ProductionAuthDebugUnlockChallenge > ( ) )
97+ if result. is_err ( ) {
98+ soc_ifc. set_ss_dbg_unlock_in_progress ( false ) ;
99+ }
100+
101+ result
90102 }
91103
92104 /// Handle the production debug unlock token verification
@@ -127,9 +139,6 @@ impl ProductionDebugUnlock {
127139 . take ( )
128140 . ok_or ( CaliptraError :: RUNTIME_DEBUG_UNLOCK_NO_REQUEST ) ?;
129141
130- // Set debug unlock in progress
131- soc_ifc. set_ss_dbg_unlock_in_progress ( true ) ;
132-
133142 // Use the common validation logic
134143 let result = caliptra_common:: debug_unlock:: validate_debug_unlock_token (
135144 soc_ifc,
0 commit comments