コード例 #1
0
        private void OnNetworkKeySet(ActionCompletedUnit ou)
        {
            const byte keyLength = 16;

            if (requestNetworkKey.Result.State == ActionStates.Completed)
            {
                COMMAND_CLASS_SECURITY.NETWORK_KEY_SET cmd = requestNetworkKey.SpecificResult.Command;
                byte[] key = new byte[keyLength];
                if (cmd.networkKeyByte != null && cmd.networkKeyByte.Count() == keyLength)
                {
                    Array.Copy(cmd.networkKeyByte.ToArray(), 0, key, 0, Math.Min(cmd.networkKeyByte.Count, keyLength));
                    _securityManagerInfo.SetNetworkKey(key, SecuritySchemes.S0);
                    _securityManagerInfo.ActivateNetworkKeyS0();
                    if (VirtualNodeId > 0 || !IsController)
                    {
                        sendNetworkKeyVerify.NodeId       = NodeId;
                        sendNetworkKeyVerify.BridgeNodeId = VirtualNodeId;
                        ou.SetNextActionItems(sendNetworkKeyVerify);
                    }
                    else
                    {
                        requestSchemeInherit.DestNodeId = NodeId;
                        requestSchemeInherit.SrcNodeId  = VirtualNodeId;
                        ou.SetNextActionItems(requestSchemeInherit);
                        if (_securityManagerInfo.DelaysS0.ContainsKey(SecurityS0Delays.NetworkKeyVerify))
                        {
                            requestSchemeInherit.DataDelay = _securityManagerInfo.DelaysS0[SecurityS0Delays.NetworkKeyVerify];
                        }
                    }
                }
                else
                {
                    SpecificResult.SubstituteStatus = SubstituteStatuses.Failed;
                    SetStateCompletedSecurityFailed(ou);
                }
            }
            else
            {
                SpecificResult.SubstituteStatus = SubstituteStatuses.Failed;
                SetStateCompletedSecurityFailed(ou);
            }
        }
コード例 #2
0
        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);
            }
        }