private void OnRequestCompleted(ActionCompletedUnit tu) { OnOperationCompletedBefore(tu); requestData.NewToken(); }
private void OnNKReport(ActionCompletedUnit ou) { if (_NKGetNKReport.Result) { if (_NKGetNKReport.SpecificResult.RxSecurityScheme == SecuritySchemes.S2_TEMP) { COMMAND_CLASS_SECURITY_2.SECURITY_2_NETWORK_KEY_GET get = _NKGetNKReport.Data; COMMAND_CLASS_SECURITY_2.SECURITY_2_NETWORK_KEY_REPORT rpt = _NKGetNKReport.SpecificResult.Command; if (rpt.grantedKey == get.requestedKey && rpt.networkKey != null && rpt.networkKey.Length == 16) { NetworkKeyS2Flags verifyKey = (NetworkKeyS2Flags)rpt.grantedKey; var scheme = SecurityManagerInfo.ConvertToSecurityScheme(verifyKey); if (scheme != SecuritySchemes.NONE) { _grantedSchemes.Add(scheme); SpecificResult.SecuritySchemes = _grantedSchemes.ToArray(); _securityManagerInfo.SetNetworkKey(rpt.networkKey, scheme); if (scheme == SecuritySchemes.S0) { _securityManagerInfo.ActivateNetworkKeyS0(); } _securityManagerInfo.ActivateNetworkKeyS2ForNode(_peerNodeId, scheme); _NKVerifyTransferEnd.NewToken(); _NKVerifyTransferEnd.DestNodeId = NodeId; _NKVerifyTransferEnd.SrcNodeId = VirtualNodeId; var cmd = new COMMAND_CLASS_SECURITY_2.SECURITY_2_NETWORK_KEY_VERIFY(); _NKVerifyTransferEnd.Data = cmd; #region TestFrame Section switch (scheme) { case SecuritySchemes.S0: #region NetworkKeyVerify_S0 _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyVerify_S0, _NKVerifyTransferEnd); #endregion break; case SecuritySchemes.S2_UNAUTHENTICATED: #region NetworkKeyVerify_S2Unauthenticated _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyVerify_S2Unauthenticated, _NKVerifyTransferEnd); #endregion break; case SecuritySchemes.S2_AUTHENTICATED: #region NetworkKeyVerify_S2Authenticated _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyVerify_S2Authenticated, _NKVerifyTransferEnd); #endregion break; case SecuritySchemes.S2_ACCESS: #region NetworkKeyVerify_S2Access _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyVerify_S2Access, _NKVerifyTransferEnd); #endregion break; } #endregion _NKVerifyTransferEnd.SendDataSubstituteCallback = () => { _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId); }; } else { _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId); _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity); _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL { kexFailType = 0x0A }; // KEX_FAIL_KEY_REPORT _KexFail.NodeId = NodeId; _KexFail.BridgeNodeId = VirtualNodeId; ou.SetNextActionItems(_KexFail); } } else { _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId); _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity); _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL { kexFailType = 0x0A }; // KEX_FAIL_KEY_REPORT _KexFail.NodeId = NodeId; _KexFail.BridgeNodeId = VirtualNodeId; ou.SetNextActionItems(_KexFail); } } else { _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId); _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity); _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL { kexFailType = 0x07 }; // KEX_FAIL_AUTH _KexFail.NodeId = NodeId; _KexFail.BridgeNodeId = VirtualNodeId; ou.SetNextActionItems(_KexFail); } } else { SetStateCompletedSecurityFailed(ou); } }
private void OnTransferEnd(ActionCompletedUnit ou) { if (_NKVerifyTransferEnd.Result) { if (_NKVerifyTransferEnd.SpecificResult.RxSecurityScheme == SecuritySchemes.S2_TEMP) { COMMAND_CLASS_SECURITY_2.SECURITY_2_TRANSFER_END rpt = _NKVerifyTransferEnd.SpecificResult.Command; if (rpt.properties1.keyVerified > 0) { if (_grantedKeys.Count > 0) { _NKGetNKReport.NewToken(); var cmd = new COMMAND_CLASS_SECURITY_2.SECURITY_2_NETWORK_KEY_GET(); var key = _grantedKeys.Dequeue(); cmd.requestedKey = (byte)key; _NKGetNKReport.Data = cmd; #region TestFrame Section var scheme = SecurityManagerInfo.ConvertToSecurityScheme(key); switch (scheme) { case SecuritySchemes.S0: #region NetworkKeyGet _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S0, _NKGetNKReport); #endregion break; case SecuritySchemes.S2_UNAUTHENTICATED: #region NetworkKeyGet _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Unauthenticated, _NKGetNKReport); #endregion break; case SecuritySchemes.S2_AUTHENTICATED: #region NetworkKeyGet _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Authenticated, _NKGetNKReport); #endregion break; case SecuritySchemes.S2_ACCESS: #region NetworkKeyGet _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Access, _NKGetNKReport); #endregion break; } #endregion ou.SetNextActionItems(_NKGetNKReport); } else { _TransferEnd.NodeId = NodeId; _TransferEnd.BridgeNodeId = VirtualNodeId; var cmd = new COMMAND_CLASS_SECURITY_2.SECURITY_2_TRANSFER_END(); cmd.properties1.keyRequestComplete = 1; cmd.properties1.keyVerified = 0; _TransferEnd.Data = cmd; #region TransferEndB _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.TransferEndB, _TransferEnd); #endregion ou.SetNextActionItems(_TransferEnd); } } else { SetStateCompletedSecurityFailed(ou); } } else { _securityManagerInfo.ActivateNetworkKeyS2TempForNode(_peerNodeId); _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity); _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL { kexFailType = 0x07 }; // KEX_FAIL_AUTH _KexFail.NodeId = NodeId; _KexFail.BridgeNodeId = VirtualNodeId; ou.SetNextActionItems(_KexFail); } } else { SetStateCompletedSecurityFailed(ou); } }
private void OnKEXReportEcho(ActionCompletedUnit ou) { if (_KEXSetEchoKEXReportEcho.Result) { _isWaitingForKexReportEcho = false; if (_KEXSetEchoKEXReportEcho.SpecificResult.RxSecurityScheme == SecuritySchemes.S2_TEMP) { if (ValidateKexReportEcho(_KEXSetEchoKEXReportEcho.SpecificResult.Command)) { _NKGetNKReport.DestNodeId = NodeId; _NKGetNKReport.SrcNodeId = VirtualNodeId; if (_grantedKeys.Count > 0) { var cmd = new COMMAND_CLASS_SECURITY_2.SECURITY_2_NETWORK_KEY_GET(); var key = _grantedKeys.Dequeue(); cmd.requestedKey = (byte)key; _NKGetNKReport.Data = cmd; ou.SetNextActionItems(_NKGetNKReport); #region TestFrame Section var scheme = SecurityManagerInfo.ConvertToSecurityScheme(key); switch (scheme) { case SecuritySchemes.S0: #region NetworkKeyGet _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S0, _NKGetNKReport); #endregion break; case SecuritySchemes.S2_UNAUTHENTICATED: #region NetworkKeyGet _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Unauthenticated, _NKGetNKReport); #endregion break; case SecuritySchemes.S2_AUTHENTICATED: #region NetworkKeyGet _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Authenticated, _NKGetNKReport); #endregion break; case SecuritySchemes.S2_ACCESS: #region NetworkKeyGet _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.NetworkKeyGet_S2Access, _NKGetNKReport); #endregion break; } #endregion } else { _TransferEnd.NodeId = NodeId; _TransferEnd.BridgeNodeId = VirtualNodeId; var cmd = new COMMAND_CLASS_SECURITY_2.SECURITY_2_TRANSFER_END(); cmd.properties1.keyRequestComplete = 1; cmd.properties1.keyVerified = 0; _TransferEnd.Data = cmd; #region TransferEndB _securityTestSettingsService.ActivateTestPropertiesForFrame(SecurityS2TestFrames.TransferEndB, _TransferEnd); #endregion ou.SetNextActionItems(_TransferEnd); } } else { _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity); _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL { kexFailType = 0x07 }; // KEX_FAIL_AUTH _KexFail.NodeId = NodeId; _KexFail.BridgeNodeId = VirtualNodeId; ou.SetNextActionItems(_KexFail); } } else { _KexFail.SubstituteSettings.ClearFlag(SubstituteFlags.DenySecurity); _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL { kexFailType = 0x07 }; // KEX_FAIL_AUTH _KexFail.NodeId = NodeId; _KexFail.BridgeNodeId = VirtualNodeId; ou.SetNextActionItems(_KexFail); } } else if (_isClientSideAuthGranted) { _KexFail.Data = new COMMAND_CLASS_SECURITY_2.KEX_FAIL { kexFailType = 0x06 }; // KEX_FAIL_CANCEL _KexFail.NodeId = NodeId; _KexFail.BridgeNodeId = VirtualNodeId; ou.SetNextActionItems(_KexFail); } else if ((DateTime.Now - _PkReportReceivedTimeStamp).TotalMilliseconds < InclusionS2TimeoutConstants.Including.UserInputDsk) { _KEXSetEchoKEXReportEcho.NewToken(); ou.SetNextActionItems(_KEXSetEchoKEXReportEcho); } else { SetStateCompletedSecurityFailed(ou); } }