Skip to content

Commit

Permalink
Robustified, with better management of LEEC caller state.
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier-Boudeville committed Aug 24, 2023
1 parent cc722bd commit 80e2217
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions src/class_USCertificateManager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -552,19 +552,21 @@ destruct( State ) ->
ok;

LEECCallerState ->
?notice_fmt( "Shutting down LEEC (~ts).",
[ leec:caller_state_to_string( LEECCallerState ) ] ),
LCSStr = leec:caller_state_to_string( LEECCallerState ),

?notice_fmt( "Shutting down LEEC (~ts).", [ LCSStr ] ),
try

leec:terminate( LEECCallerState )

catch AnyClass:Exception ->
?error_fmt( "Final termination failed, with a thrown "
"exception ~p (of class: ~p).", [ Exception, AnyClass ] )
"exception ~p (of class: ~p); ~ts.",
[ Exception, AnyClass, LCSStr ] )

end,

?notice_fmt( "LEEC (~w) shut down.", [ LEECCallerState ] )
?notice_fmt( "~ts shut down.", [ LCSStr ] )

end,

Expand Down Expand Up @@ -698,8 +700,8 @@ request_certificate( State ) ->
ok;

CallerState ->
?error_fmt( "Ignoring unexpected former LEEC caller state ~w.",
[ CallerState ] )
?error_fmt( "Ignoring unexpected former ~ts.",
[ leec:caller_state_to_string( CallerState ) ] )

end,

Expand All @@ -708,8 +710,9 @@ request_certificate( State ) ->
?getAttr(bridge_spec) ) of

{ ok, LEECCallerState } ->
?notice_fmt( "New LEEC caller state ~w created for '~ts'.",
[ LEECCallerState, FQDN ] ),

LCSStr = leec:caller_state_to_string( LEECCallerState ),
?notice_fmt( "New ~ts created for '~ts'.", [ LCSStr, FQDN ] ),

try
async = leec:obtain_certificate_for( FQDN, LEECCallerState,
Expand All @@ -723,7 +726,8 @@ request_certificate( State ) ->

catch AnyClass:Exception ->
?error_fmt( "Certificate request failed, with a thrown "
"exception ~p (of class: ~p).", [ Exception, AnyClass ] ),
"exception ~p (of class: ~p); ~ts.",
[ Exception, AnyClass, LCSStr ] ),
State

end;
Expand Down Expand Up @@ -863,8 +867,9 @@ manage_renewal( MaybeRenewDelay, MaybeBinCertFilePath, State ) ->

catch AnyClass:Exception ->
?error_fmt( "Termination after renewal failed, "
"with a thrown exception ~p (of class: ~p).",
[ Exception, AnyClass ] )
"with a thrown exception ~p (of class: ~p); ~ts",
[ Exception, AnyClass,
leec:caller_state_to_string( LEECCallerState ) ] )

end,

Expand Down Expand Up @@ -937,17 +942,20 @@ getChallenge( State, TargetPid ) ->
% Opaque:
LCS = ?getAttr(leec_caller_state),

LCSStr = leec:maybe_caller_state_to_string( LCS ),

?notice_fmt( "Requested to return the current thumbprint challenges "
"from LEEC caller state ~w, on behalf of (and to) ~w.",
[ LCS, TargetPid ] ),
"with ~ts, on behalf of (and to) ~w.", [ LCSStr, TargetPid ] ),

try

leec:send_ongoing_challenges( LCS, TargetPid )

catch AnyClass:Exception ->
catch AnyClass:Exception:StackTrace ->
?error_fmt( "Sending of challenges failed, with a thrown "
"exception ~p (of class: ~p).", [ Exception, AnyClass ] )
"exception ~p (of class: ~p; stacktrace: ~ts; ~ts).",
[ Exception, AnyClass,
code_utils:interpret_stacktrace( StackTrace ), LCSStr ] )

end,

Expand Down Expand Up @@ -988,19 +996,22 @@ onWOOPERExitReceived( State, CrashPid, ExitType ) ->

timer:sleep( WaitDurationMs ),

{ MaybeLEECFsmPid, _RenewPeriodSecs, StartOpts, _BridgeSpec } =
{ MaybeLEECCallerState, _RenewPeriodSecs, StartOpts, _BridgeSpec } =
init_leec( FQDN, ?getAttr(cert_mode), ?getAttr(challenge_type),
?getAttr(dns_provider), ?getAttr(credentials_dir),
?getAttr(cert_dir), ?getAttr(private_key_path), State ),

?notice_fmt( "New LEEC instance started for '~ts': ~w (start options: ~p);"
" requesting a new certificate.",
[ FQDN, MaybeLEECFsmPid, StartOpts ] ),
?notice_fmt( "New LEEC instance started for '~ts', "
"with ~ts (start options: ~p); "
"requesting a new certificate.",
[ FQDN, leec:maybe_caller_state_to_string( MaybeLEECCallerState ),
StartOpts ] ),

% Immediately retries:
self() ! renewCertificate,

RestartState = setAttribute( State, leec_caller_state, MaybeLEECFsmPid ),
RestartState =
setAttribute( State, leec_caller_state, MaybeLEECCallerState ),

wooper:return_state( RestartState ).

Expand Down Expand Up @@ -1299,15 +1310,7 @@ to_string( State ) ->

end,

FSMStr = case ?getAttr(leec_caller_state) of

undefined ->
"no LEEC FSM";

LeecPid ->
text_utils:format( "LEEC FSM of PID ~w", [ LeecPid ] )

end,
FSMStr = leec:maybe_caller_state_to_string( ?getAttr(leec_caller_state) ),

CertStr = case ?getAttr(cert_path) of

Expand Down

0 comments on commit 80e2217

Please sign in to comment.