示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }