Пример #1
0
 public void getScheme(ZWaveNode node)
 {
     if (adding_node)
     {
         schemeRequestSent = true;
         node.SendRequest(new byte[] {
             (byte)CommandClass.Security,
             (byte)SecurityCommand.SchemeGet,
             0
         });
     }
 }
Пример #2
0
        public void SendNonceReport(ZWaveNode node)
        {
            byte[] message = new byte[10];

            message[0] = (byte)CommandClass.Security;
            message[1] = (byte)SecurityCommand.NonceReport;

            Array.Copy(c_currentNonce, 0, message, 2, 8);

            node.SendRequest(message);

            c_nonceTimer.Reset();
        }
Пример #3
0
        private bool sendRequestNonce(ZWaveNode node)
        {
            Utility.logMessage("In sendRequestNonce - SecurityHandler");

            if (waitingForNonce)
            {
                return(false);
            }

            Utility.logMessage("In sendRequestNonce - not waiting for Nonce - SecurityHandler");
            waitingForNonce = true;

            node.SendRequest(new byte[] {
                (byte)CommandClass.Security,
                (byte)SecurityCommand.NonceGet
            });

            return(true);
        }
Пример #4
0
        // IN the mesage to be Encrypted
        // OUT - true - message processed and sent - proceed to next one
        //     - false - we need to wait for the nonce report to come
        private bool EncryptMessage(ZWaveNode node, byte[] message)
        {
            if (enc == null)
            {
                init(node);
            }

            Utility.logMessage("In EncryptMessage - secure_payload [" + secure_payload.Count + "]  - " + d_nonceTimer.ElapsedMilliseconds);

            // if we get true we need to wait for the new Nonce
            // if we get false we need to proceed
            //            if (sendRequestNonce())
            //                return false;
            if (d_nonceTimer.ElapsedMilliseconds > 10000)
            {
                return(false);
            }

            SecutiryPayload payload = null;

            lock (secure_payload)
            {
                if (secure_payload.Count > 0)
                {
                    payload = secure_payload.First();
                    secure_payload.Remove(payload);
                }
            }

            if (payload != null)
            {
                int len = payload.length + 20;

                byte[] t_message = new byte[len];

                int i = 0;

                t_message[i]      = (byte)CommandClass.Security;
                i++; t_message[i] = (byte)SecurityCommand.MessageEncap;

                byte[] initializationVector = new byte[16];
                for (int a = 0; a < 8; a++)
                {
                    initializationVector[a] = (byte)0xAA;
                    i++;
                    t_message[i] = initializationVector[a];
                }

                Array.Copy(d_currentNonce, 0, initializationVector, 8, 8);

                int sequence = 0;

                if (payload.part == 1)
                {
                    ++m_sequenceCounter;
                    sequence  = m_sequenceCounter & (byte)0x0f;
                    sequence |= (byte)0x10;
                }
                else if (payload.part == 2)
                {
                    ++m_sequenceCounter;
                    sequence  = m_sequenceCounter & (byte)0x0f;
                    sequence |= (byte)0x30;
                }

                byte[] plaintextmsg = new byte[payload.length + 1];
                plaintextmsg[0] = (byte)sequence;
                for (int a = 0; a < payload.length; a++)
                {
                    plaintextmsg[a + 1] = payload.message[a];
                }

                byte[] encryptedPayload = new byte[30];

                encryptedPayload = enc.OFB_EncryptMessage(encryptKey, initializationVector, plaintextmsg);

//                Utility.logMessage("authKey " + Utility.ByteArrayToString(authKey));
//                Utility.logMessage("EncryptKey " + Utility.ByteArrayToString(encryptKey));
                Utility.logMessage("Input Packet: " + Utility.ByteArrayToString(plaintextmsg));
//                Utility.logMessage("IV " + Utility.ByteArrayToString(initializationVector));
//                Utility.logMessage("encryptedPayload " + Utility.ByteArrayToString(encryptedPayload));

                for (int a = 0; a < payload.length + 1; ++a)
                {
                    i++;
                    t_message[i] = encryptedPayload[a];
                }

                i++; t_message[i] = d_currentNonce[0];

                //GenerateAuthentication
                int    start = 1;
                byte[] mac   = GenerateAuthentication(t_message, start, t_message.Length + 2 - start - 1, 0x01, node.Id, initializationVector, enc);
                for (int a = 0; a < 8; ++a)
                {
                    i++;
                    t_message[i] = mac[a];
                }

                node.SendRequest(t_message);
                Utility.logMessage("In EncryptMessage - message sent");

                if ((networkKeySet == false) && payload.message[0] == 0x98 && payload.message[1] == 0x06)
                {
                    networkKeySet = true;
                    adding_node   = false;
                    SetupNetworkKey(node);
                }

                return(true);
            }
            return(true);
        }