@@ -1025,13 +1025,20 @@ namespace ccf
10251025 OPENSSL_cleanse (const_cast <char *>(share.data ()), share.size ());
10261026
10271027 size_t submitted_shares_count = 0 ;
1028+ bool full_key_submitted = false ;
10281029 try
10291030 {
10301031 submitted_shares_count = share_manager.submit_recovery_share (
10311032 ctx.tx , member_id.value (), raw_recovery_share);
1033+
1034+ full_key_submitted = ShareManager::is_full_key (raw_recovery_share);
1035+
1036+ OPENSSL_cleanse (raw_recovery_share.data (), raw_recovery_share.size ());
10321037 }
10331038 catch (const std::exception& e)
10341039 {
1040+ OPENSSL_cleanse (raw_recovery_share.data (), raw_recovery_share.size ());
1041+
10351042 constexpr auto error_msg = " Error submitting recovery shares." ;
10361043 GOV_FAIL_FMT (error_msg);
10371044 GOV_DEBUG_FMT (" Error: {}" , e.what ());
@@ -1042,61 +1049,60 @@ namespace ccf
10421049 error_msg);
10431050 return ;
10441051 }
1045- OPENSSL_cleanse (raw_recovery_share.data (), raw_recovery_share.size ());
10461052
1047- if (
1048- submitted_shares_count <
1049- InternalTablesAccess::get_recovery_threshold (ctx.tx ))
1053+ const auto threshold =
1054+ InternalTablesAccess::get_recovery_threshold (ctx.tx );
1055+
1056+ std::string message;
1057+ if (full_key_submitted)
10501058 {
1051- // The number of shares required to re-assemble the secret has not yet
1052- // been reached
1053- auto recovery_share = SubmitRecoveryShare::Out{fmt::format (
1054- " {}/{} recovery shares successfully submitted." ,
1055- submitted_shares_count,
1056- InternalTablesAccess::get_recovery_threshold (ctx.tx ))};
1057- ctx.rpc_ctx ->set_response_header (
1058- ccf::http::headers::CONTENT_TYPE,
1059- http::headervalues::contenttype::JSON);
1060- ctx.rpc_ctx ->set_response_body (nlohmann::json (recovery_share).dump ());
1061- ctx.rpc_ctx ->set_response_status (HTTP_STATUS_OK);
1062- return ;
1059+ message = " Full recovery key successfully submitted" ;
10631060 }
1064-
1065- GOV_DEBUG_FMT (
1066- " Reached recovery threshold {}" ,
1067- InternalTablesAccess::get_recovery_threshold (ctx.tx ));
1068-
1069- try
1061+ else
10701062 {
1071- node_operation->initiate_private_recovery (ctx.tx );
1063+ // Same format of message, whether this is sufficient to trigger
1064+ // recovery or not
1065+ message = fmt::format (
1066+ " {}/{} recovery shares successfully submitted" ,
1067+ submitted_shares_count,
1068+ threshold);
10721069 }
1073- catch (const std::exception& e)
1070+
1071+ if (submitted_shares_count >= threshold || full_key_submitted)
10741072 {
1075- // Clear the submitted shares if combination fails so that members can
1076- // start over.
1077- constexpr auto error_msg = " Failed to initiate private recovery." ;
1078- GOV_FAIL_FMT (error_msg);
1079- GOV_DEBUG_FMT (" Error: {}" , e.what ());
1080- ShareManager::clear_submitted_recovery_shares (ctx.tx );
1081- ctx.rpc_ctx ->set_apply_writes (true );
1082- set_gov_error (
1083- ctx.rpc_ctx ,
1084- HTTP_STATUS_INTERNAL_SERVER_ERROR,
1085- errors::InternalError,
1086- error_msg);
1087- return ;
1073+ message += " \n End of recovery procedure initiated" ;
1074+ GOV_INFO_FMT (" {} - initiating recovery" , message);
1075+
1076+ // Initiate recovery
1077+ try
1078+ {
1079+ node_operation->initiate_private_recovery (ctx.tx );
1080+ }
1081+ catch (const std::exception& e)
1082+ {
1083+ // Clear the submitted shares if combination fails so that members
1084+ // can start over.
1085+ constexpr auto error_msg = " Failed to initiate private recovery." ;
1086+ GOV_FAIL_FMT (error_msg);
1087+ GOV_DEBUG_FMT (" Error: {}" , e.what ());
1088+ ShareManager::clear_submitted_recovery_shares (ctx.tx );
1089+ ctx.rpc_ctx ->set_apply_writes (true );
1090+ set_gov_error (
1091+ ctx.rpc_ctx ,
1092+ HTTP_STATUS_INTERNAL_SERVER_ERROR,
1093+ errors::InternalError,
1094+ error_msg);
1095+ return ;
1096+ }
10881097 }
10891098
1090- auto recovery_share = SubmitRecoveryShare::Out{fmt::format (
1091- " {}/{} recovery shares successfully submitted. End of recovery "
1092- " procedure initiated." ,
1093- submitted_shares_count,
1094- InternalTablesAccess::get_recovery_threshold (ctx.tx ))};
1099+ auto recovery_share = SubmitRecoveryShare::Out{message};
10951100 ctx.rpc_ctx ->set_response_header (
10961101 ccf::http::headers::CONTENT_TYPE,
10971102 http::headervalues::contenttype::JSON);
10981103 ctx.rpc_ctx ->set_response_body (nlohmann::json (recovery_share).dump ());
10991104 ctx.rpc_ctx ->set_response_status (HTTP_STATUS_OK);
1105+ return ;
11001106 };
11011107 make_endpoint (
11021108 " /recovery_share" ,
0 commit comments