@@ -558,6 +558,8 @@ private async Task<bool> BootstrapS2(Node node)
558558 await sec2 . KexFail ( KexFailType . KEX_FAIL_KEX_SCHEME ) ;
559559 return false ;
560560 }
561+ if ( this . pin == 0 )
562+ requestedKeys . Keys = requestedKeys . Keys & SecurityKey . S2Unauthenticated ; //We need a pin for higher levels
561563 SecurityManager ! . StoreRequestedKeys ( node . ID , requestedKeys ) ;
562564 Log . Information ( "Sending " + requestedKeys . ToString ( ) ) ;
563565 Memory < byte > pub ;
@@ -585,6 +587,7 @@ private async Task<bool> BootstrapS2(Node node)
585587 SecurityManager ? . RevokeKey ( node . ID , SecurityManager . RecordType . S2Access ) ;
586588 SecurityManager ? . RevokeKey ( node . ID , SecurityManager . RecordType . S2Auth ) ;
587589 SecurityManager ? . RevokeKey ( node . ID , SecurityManager . RecordType . S2UnAuth ) ;
590+ SecurityManager ? . RevokeKey ( node . ID , SecurityManager . RecordType . ECDH_TEMP ) ;
588591 return false ;
589592 }
590593 await node . Interview ( true ) . ConfigureAwait ( false ) ;
@@ -670,24 +673,18 @@ private async Task EventLoop()
670673 {
671674 Log . Information ( "Added " + node . ToString ( ) ) ;
672675 if ( SecurityManager != null )
673- {
674- if ( ( currentStrategy == InclusionStrategy . S2Only || currentStrategy == InclusionStrategy . PreferS2 ) && node . HasCommandClass ( CommandClass . Security2 ) )
675- _ = Task . Run ( ( ) => BootstrapS2 ( node ) ) ;
676- else if ( ( currentStrategy == InclusionStrategy . PreferS2 || currentStrategy == InclusionStrategy . LegacyS0Only ) && node . HasCommandClass ( CommandClass . Security0 ) )
677- _ = Task . Run ( ( ) => BootstrapS0 ( node ) ) ;
678- else
679- _ = Task . Run ( ( ) => BootstrapUnsecure ( node ) ) ;
680- }
676+ await Task . Factory . StartNew ( ( ) => ExecuteStrategy ( node ) ) . ConfigureAwait ( false ) ;
681677 }
682678 }
683679 }
684680 else if ( inc . Function == Function . RemoveNodeFromNetwork && inc . NodeID > 0 )
685681 {
686682 if ( Nodes . Remove ( inc . NodeID , out Node ? node ) )
687683 {
684+ node . NodeFailed = true ;
688685 if ( NodeExcluded != null )
689686 NodeExcluded . Invoke ( node , EventArgs . Empty ) ;
690- Log . Information ( $ "Successfully exluded node { inc . NodeID } ") ;
687+ Log . Information ( $ "Successfully excluded node { inc . NodeID } ") ;
691688 }
692689 if ( inc . Status == InclusionExclusionStatus . OperationComplete )
693690 await StopExclusion ( ) ;
@@ -701,6 +698,23 @@ private async Task EventLoop()
701698 }
702699 }
703700
701+ private async Task ExecuteStrategy ( Node node )
702+ {
703+ if ( ( currentStrategy == InclusionStrategy . S2Only || currentStrategy == InclusionStrategy . AnySecure || currentStrategy == InclusionStrategy . PreferS2 ) && node . HasCommandClass ( CommandClass . Security2 ) )
704+ {
705+ if ( await BootstrapS2 ( node ) || currentStrategy == InclusionStrategy . S2Only )
706+ return ; //Successful S2 or abort if failed with S2 only strategy
707+ if ( ( node . HasCommandClass ( CommandClass . Security0 ) && await BootstrapS0 ( node ) ) || currentStrategy == InclusionStrategy . AnySecure )
708+ return ; //Successful S0 or abort if secure required
709+ }
710+ else if ( ( currentStrategy == InclusionStrategy . PreferS2 || currentStrategy == InclusionStrategy . AnySecure || currentStrategy == InclusionStrategy . LegacyS0Only ) && node . HasCommandClass ( CommandClass . Security0 ) )
711+ {
712+ if ( await BootstrapS0 ( node ) || currentStrategy == InclusionStrategy . LegacyS0Only || currentStrategy == InclusionStrategy . AnySecure )
713+ return ; //Successful S0 or abort if failed with S0 only or any secure strategy
714+ }
715+ await BootstrapUnsecure ( node ) ;
716+ }
717+
704718 private byte [ ] NodeIDToBytes ( ushort nodeId )
705719 {
706720 if ( WideID )
0 commit comments