Esempio n. 1
0
        private UpdateConfig GetConfig()
        {
            this.MaxAttempts = int.Parse(this.maxAttemptsTextBox.Text);
            var pilotStrategy = SecuCode.PilotTagSelectionFromIndex(this.pilotSelection.SelectedIndex);

            var validTags = this.activeTags.Values.Where(t => t.Valid).ToArray();

            if (validTags.Length == 0)
            {
                throw new Exception("No vaild tags, (tip: you may want to try the 'Update Valid Tags' button first).");
            }

            var sendMode   = this.GetSendMode();
            var attestMode = this.GetAttestMode();

            if (sendMode == SendMode.None && attestMode == AttestMode.None)
            {
                throw new Exception("Both 'SendMode' and 'AttestMode' cannot be None");
            }

            return(new UpdateConfig
            {
                TargetTags = validTags.ToDictionary(t => t.TagId),
                SessionKey = this.sessionKey,
                Firmware = this.firmware,
                TargetVersion = byte.Parse(this.version.Text),
                MaxAttempts = this.MaxAttempts,
                ReaderSleepTimeMs = (int)(double.Parse(this.readerOffTime.Text) * 1000.0),
                BlockSize = byte.Parse(this.maxBlockSize.Text),
                PilotSelectionStrategy = pilotStrategy,
                SendMode = sendMode,
                AttestMode = attestMode,
            });
        }
Esempio n. 2
0
        private byte[] GetSessionData(Tag tag, bool isObserver = false)
        {
            if (this.sessionKey == null || tag == null || this.bytesToSend == null)
            {
                throw new Exception("Tag, firmware, and/or session key was null");
            }

            var newVersion = this.version.Dispatcher.Invoke(() => byte.Parse(this.version.Text));
            var signature  = SecuCode.GenerateSignature(this.sessionKey, this.bytesToSend, tag.Version, newVersion);

            byte sleepTime = 0, activeTime = 0;

            this.Dispatcher.Invoke(() =>
            {
                if (string.IsNullOrWhiteSpace(this.sleepTime.Text) | string.IsNullOrWhiteSpace(this.activeTime.Text))
                {
                    (sleepTime, activeTime) = Native.PAM.ComputePAM((ushort)tag.Voltage);
                }
                else
                {
                    sleepTime  = byte.Parse(this.sleepTime.Text);
                    activeTime = byte.Parse(this.activeTime.Text);
                }
            });
            var observerFlag = isObserver ? (byte)0x01 : (byte)0x00;

            return(Native.TinyCrypt.AesEncrypt_DefaultIV(tag.DeviceKey, this.sessionKey)
                   .Concat(signature)
                   .Concat(new byte[] { newVersion, sleepTime, activeTime, observerFlag })
                   .ToArray());
        }
Esempio n. 3
0
        private void UpdateEncryptedDataTextBox()
        {
            this.payloadBytes.Dispatcher.Invoke(() =>
            {
                if (this.bytesToSend != null && this.sessionKey != null)
                {
                    var encryptedPayload = SecuCode.EncryptPacket(this.bytesToSend, this.sessionKey);
                    var decryptedPayload = Native.Aes.DecryptBytes(encryptedPayload, this.sessionKey, CipherMode.CBC);

                    Console.WriteLine($"Encrypted: {encryptedPayload.ToByteString("0x", ",")} Length = {encryptedPayload.Length}");
                    Console.WriteLine($"Decrypted: {decryptedPayload.ToByteString("0x", ",")} Length = {decryptedPayload.Length}");

                    this.payloadBytes.Text          = decryptedPayload.ToByteString();
                    this.encryptedPayloadBytes.Text = encryptedPayload.ToByteString();
                }
            });
        }