Ejemplo n.º 1
0
        public void Test01FunctionalTest()
        {
            var st = new SpanTable();

            var span = new Span(0, 0, 10);

            st.Insert(0, 10);
            Assert.AreEqual(span, st.Head);

            //	0 1 2 3 4 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9
            //	0, 5/0, 10/5, 5
            st.Insert(5, 10);
            var temp = st.Head;

            span = new Span(0, 0, 5);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(1, 0, 10);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(0, 5, 5);
            Assert.AreEqual(span, temp);
        }
Ejemplo n.º 2
0
        public void Test05FunctionalDelete()
        {
            //	0 1 2 3 4 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9 a b
            //	0 1 2 3 J 5 6 7 8 9 a b
            //	0, 4/9, 1/5, 5/10, 2
            var st = new SpanTable();

            st.Insert(0, 10);
            st.Insert(5, 10);
            st.Insert(20, 2);
            st.Delete(4, 10);
            var temp = st.Head;
            var span = new Span(0, 0, 4);

            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(1, 9, 1);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(0, 5, 5);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(1, 10, 2);
            Assert.AreEqual(span, temp);
            Assert.IsNull(temp.Next);
        }
Ejemplo n.º 3
0
        public void Test02FunctionalInsertTest()
        {
            //	0 1 2 3 4 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J a b 5 6 7 8 9
            //	0, 5/0, 10/10, 2/5, 5
            var st = new SpanTable();

            st.Insert(0, 10);
            st.Insert(5, 10);
            st.Insert(15, 2);
            var temp = st.Head;
            var span = new Span(0, 0, 5);

            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(1, 0, 10);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(1, 10, 2);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(0, 5, 5);
            Assert.AreEqual(span, temp);
            Assert.IsNull(temp.Next);
        }
Ejemplo n.º 4
0
        public static SpanTable CreateEmptySpanTable(int initialBufferIndex)
        {
            var span = new Span(initialBufferIndex, 0, 0);
            var table = new SpanTable();
            table._head = table._tail = span;
            table.Length = 0;

            return table;
        }
Ejemplo n.º 5
0
 internal SecurityS2ReportTask(SecurityManagerInfo securityManagerInfo,
                               SecurityS2CryptoProvider securityS2CryptoProvider, SpanTable spanTable, MpanTable mpanTable)
     : base(0, 0, new ByteIndex(COMMAND_CLASS_SECURITY_2.ID))
 {
     _securityManagerInfo      = securityManagerInfo;
     _securityS2CryptoProvider = securityS2CryptoProvider;
     _spanTable = spanTable;
     _mpanTable = mpanTable;
     _securityTestSettingsService = new SecurityTestSettingsService(_securityManagerInfo, false);
 }
Ejemplo n.º 6
0
        public static SpanTable CreateEmptySpanTable(int initialBufferIndex)
        {
            var span  = new Span(initialBufferIndex, 0, 0);
            var table = new SpanTable();

            table._head  = table._tail = span;
            table.Length = 0;

            return(table);
        }
Ejemplo n.º 7
0
 internal SecurityManagerInfo(NetworkViewPoint network, NetworkKey[] networkKeys, byte[] privateKey)
 {
     _nvrSecretKeyS2 = privateKey;
     Network         = network;
     _nodesMask      = new byte[NetworkViewPoint.MAX_NODES];
     for (int i = 0; i < _nodesMask.Length; i++)
     {
         _nodesMask[i] = (byte)(i + 1);
     }
     Network.EnableSecuritySchemeSettingsChanged += Network_S2SchemeSettingsChanged;
     _networkKeys = networkKeys;
     MpanTable    = new MpanTable();
     SpanTable    = new SpanTable();
     ScKeys       = new Dictionary <InvariantPeerNodeId, SinglecastKey>();
     McKeys       = new Dictionary <NodeGroupId, MulticastKey>();
 }
Ejemplo n.º 8
0
 public byte[] TestOverrideMessageEncapsulation(SinglecastKey sckey, SpanTable spanTable, SecurityS2CryptoProvider _securityS2CryptoProvider, SubstituteSettings substituteSettings, byte nodeId, byte[] data, InvariantPeerNodeId peerNodeId, Extensions extensions, byte[] encryptedMsg, byte[] initData)
 {
     byte[] ret = initData;
     if (TestFramesS2.ContainsKey(SecurityS2TestFrames.MessageEncapsulation))
     {
         var testData  = data;
         var testFrame = TestFramesS2[SecurityS2TestFrames.MessageEncapsulation];
         if (testFrame.DelaySpecified && testFrame.Delay > 0)
         {
             Thread.Sleep(testFrame.Delay);
         }
         if (testFrame.Command != null)
         {
             testData = testFrame.Command;
         }
         if (!testFrame.IsEncryptedSpecified || testFrame.IsEncrypted)
         {
             if (testFrame.IsTemp)
             {
                 if (testFrame.NetworkKey != null)
                 {
                     ActivateNetworkKeyS2CustomForNode(peerNodeId, testFrame.IsTemp, testFrame.NetworkKey);
                 }
                 else
                 {
                     ActivateNetworkKeyS2CustomForNode(peerNodeId, testFrame.IsTemp, GetActualNetworkKeyS2Temp());
                 }
             }
             else
             {
                 if (testFrame.NetworkKey != null)
                 {
                     ActivateNetworkKeyS2CustomForNode(peerNodeId, testFrame.IsTemp, testFrame.NetworkKey);
                 }
             }
             ret = _securityS2CryptoProvider.EncryptSinglecastCommand(sckey, spanTable, Network.NodeId, nodeId, Network.HomeId, testData, extensions, substituteSettings);
         }
         else
         {
             var msgEncapCryptedData = (COMMAND_CLASS_SECURITY_2.SECURITY_2_MESSAGE_ENCAPSULATION)encryptedMsg;
             msgEncapCryptedData.ccmCiphertextObject = new List <byte>(testData);
             ret = msgEncapCryptedData;
         }
     }
     return(ret);
 }
Ejemplo n.º 9
0
        public void Test04FunctionalInsertTest()
        {
            //	0 1 2 3 4 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9 a b
            //	0, 5/0, 10/5, 5/10, 2
            var st = new SpanTable();

            st.Insert(0, 10);
            st.Insert(5, 10);
            st.Insert(20, 2);
            var temp = st.Tail;
            var span = new Span(1, 10, 2);

            Assert.AreEqual(span, temp);
            Assert.IsNull(temp.Next);
        }
Ejemplo n.º 10
0
 internal SendDataSecureS2Task(SecurityManagerInfo securityManagerInfo,
                               SecurityS2CryptoProvider securityS2CryptoProvider, SinglecastKey sckey, SpanTable spanTable, MpanTable mpanTable,
                               byte nodeId,
                               byte[] data,
                               TransmitOptions txOptions)
     : base(false, null, false)
 {
     _securityManagerInfo      = securityManagerInfo;
     _securityS2CryptoProvider = securityS2CryptoProvider;
     _mpanTable = mpanTable;
     _spanTable = spanTable;
     _sckey     = sckey;
     SubstituteSettings.SetFlag(SubstituteFlags.DenySecurity);
     CommandToSecureSend = data;
     NodeId      = nodeId;
     _peerNodeId = new InvariantPeerNodeId(_securityManagerInfo.Network.NodeId, NodeId);
     TxOptions   = txOptions;
     _securityTestSettingsService = new SecurityTestSettingsService(_securityManagerInfo, false);
 }
Ejemplo n.º 11
0
        public void Test08FunctionalDeleteMultiSpanExtraLength()
        {
            //	0 1 2 3 4 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9 a b
            //	0 1 2 3 4 A B C D E F G H I J 5
            //	0, 5/0, 10/5, 1
            var st = new SpanTable();

            st.Insert(0, 10);
            st.Insert(5, 10);
            st.Insert(20, 2);
            var temp = st.Head;
            var span = new Span(0, 0, 5);

            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            Assert.IsNotNull(temp.Previous);
            Assert.IsNotNull(temp.Next);
            span = new Span(1, 0, 10);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            st.Delete(16, 1000);

            temp = st.Head;
            span = new Span(0, 0, 5);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(1, 0, 10);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(0, 5, 1);
            Assert.AreEqual(span, temp);
            Assert.IsNull(temp.Next);
        }
Ejemplo n.º 12
0
        public void Test07FunctionalDeleteSingleSpanTail()
        {
            //	0 1 2 3 4 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9 a b
            //	0 1 2 3 4 A B C D E F G H I J 5 6 7 8 9
            //	0, 5/0, 10/5, 5
            var st = new SpanTable();

            st.Insert(0, 10);
            st.Insert(5, 10);
            st.Insert(20, 2);
            var temp = st.Head;
            var span = new Span(0, 0, 5);

            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            Assert.IsNotNull(temp.Previous);
            Assert.IsNotNull(temp.Next);
            span = new Span(1, 0, 10);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            st.Delete(20, 2);

            temp = st.Head;
            span = new Span(0, 0, 5);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(1, 0, 10);
            Assert.AreEqual(span, temp);
            Assert.IsNotNull(temp.Next);

            temp = temp.Next;
            span = new Span(0, 5, 5);
            Assert.AreEqual(span, temp);
            Assert.IsNull(temp.Next);
        }
Ejemplo n.º 13
0
        private void FireNetworkKeyS2Changed(InvariantPeerNodeId peerNodeId, byte[] networkKey, SecuritySchemes securityScheme)
        {
            var mpanKey         = new byte[SecurityS2Utils.KEY_SIZE];
            var ccmKey          = new byte[SecurityS2Utils.KEY_SIZE];
            var personalization = new byte[SecurityS2Utils.PERSONALIZATION_SIZE];

            if (securityScheme == SecuritySchemes.S2_TEMP)
            {
                SecurityS2Utils.TempKeyExpand(networkKey, ccmKey, personalization, mpanKey);
            }
            else
            {
                SecurityS2Utils.NetworkKeyExpand(networkKey, ccmKey, personalization, mpanKey);
            }

            switch (peerNodeId.NodeId2)
            {
            case 0:
                for (int ii = 0; ii <= ushort.MaxValue; ii++)
                {
                    var index = new InvariantPeerNodeId(ii);
                    if (ScKeys.ContainsKey(index) && !ScKeys[index].CcmKey.SequenceEqual(ccmKey) &&
                        ScKeys[index].SecurityScheme == securityScheme)
                    {
                        ScKeys[index].CcmKey          = ccmKey;
                        ScKeys[index].Personalization = personalization;
                        if (SpanTable.GetSpanState(index) != SpanStates.ReceiversNonce)
                        {
                            SpanTable.SetNonceFree(index);
                        }
                    }
                }
                for (int i = 0; i <= ushort.MaxValue; i++)
                {
                    var index = new NodeGroupId(i);
                    if (McKeys.ContainsKey(index) && !McKeys[index].CcmKey.SequenceEqual(ccmKey) &&
                        McKeys[index].SecurityScheme == securityScheme)
                    {
                        MpanTable.RemoveRecord(index);
                    }
                }
                break;

            case 0xFF:
                for (int ii = 0; ii <= ushort.MaxValue; ii++)
                {
                    var i = new InvariantPeerNodeId(ii);
                    if (ScKeys.ContainsKey(i))
                    {
                        ScKeys[i].CcmKey          = ccmKey;
                        ScKeys[i].Personalization = personalization;
                        ScKeys[i].SecurityScheme  = securityScheme;
                    }
                }
                MpanTable.ClearMpanTable();
                SpanTable.ClearNonceTable();
                break;

            default:
                if (ScKeys.ContainsKey(peerNodeId))
                {
                    ScKeys[peerNodeId].CcmKey          = ccmKey;
                    ScKeys[peerNodeId].Personalization = personalization;
                    ScKeys[peerNodeId].SecurityScheme  = securityScheme;
                }
                else
                {
                    ScKeys.Add(peerNodeId,
                               new SinglecastKey
                    {
                        CcmKey          = ccmKey,
                        Personalization = personalization,
                        SecurityScheme  = securityScheme
                    });
                }

                if (SpanTable.GetSpanState(peerNodeId) != SpanStates.ReceiversNonce)
                {
                    SpanTable.SetNonceFree(peerNodeId);
                }
                break;
            }

            if (IsInclusion && securityScheme == SecuritySchemes.S2_TEMP)
            {
                IsTempKeyActivatedOnInclusion = true;
            }

            if (NetworkKeyS2Changed != null)
            {
                NetworkKeyS2Changed(peerNodeId, networkKey, securityScheme, IsInclusion);
            }
            if (peerNodeId.NodeId2 == 0)
            {
                for (int ii = 0; ii <= ushort.MaxValue; ii++)
                {
                    var index = new InvariantPeerNodeId(ii);
                    // TODO S2 if (_scKeys.ContainsKey(index) && !_scKeys[index].CcmKey.SequenceEqual(ccmKey) && _scKeys[index].SecurityScheme == securityScheme)
                    {
                        RetransmissionTableS2.Clear();
                    }
                }
            }
            else if (peerNodeId.NodeId2 == 0xFF)
            {
                RetransmissionTableS2.Clear();
            }
            else
            {
                if (RetransmissionTableS2.ContainsKey(peerNodeId))
                {
                    RetransmissionTableS2.Remove(peerNodeId);
                }
            }
        }