/// <summary>
        /// Roundabout sets keys to a array so i can iterate them in a check.
        /// This is going to be part of a intensively repetitious operation per frame.
        /// Since there are a ton of keys i want a contiguous block for fast iteration.
        /// </summary>
        public static void Initialize()
        {
            // disallow double initializations.
            if (isInitialize == false)
            {
                // make a single listing to remove duplicates.
                var         temp    = ((Keys[])Enum.GetValues(typeof(Keys))).ToList();
                List <Keys> thekeys = new List <Keys>();
                for (int j = 0; j < temp.Count(); j++)
                {
                    bool match = false;
                    for (int k = 0; k < thekeys.Count(); k++)
                    {
                        if (thekeys[k].ToString() == temp[j].ToString())
                        {
                            match = true;
                        }
                    }
                    if (match == false)
                    {
                        thekeys.Add(temp[j]);
                        Console.WriteLine("new DrawUsKeyStruct( Keys." + thekeys[j].ToString() + " ,  new Rectangle( 0, 0, 20, 20 ) ),");
                    }
                }

                // size the arrays since they are a set size as are our keyboard keys.
                var len = thekeys.Count;
                keyArray      = new Keys[len];
                keyName       = new string[len];
                charIsControl = new bool[len];
                charIsAvailableAsTextInput = new bool[len];
                charUpper = new char[len];
                charLower = new char[len];

                // set this keyboards keys to arrays for faster lookups.
                for (int i = 0; i < thekeys.Count; i++)
                {
                    Keys k = thekeys[i];
                    // Pull out more specific info that keys simply doesn't have or basically denys you access to as there is no char or unicode lookups possible on them.
                    KeyInformation ki = KeyInformation.GetKeyInfo(k);
                    keyArray[i]      = k;
                    keyName[i]       = ki.KeyName;
                    charIsControl[i] = ki.IsControl;
                    charIsAvailableAsTextInput[i] = ki.hasInputCharacter;
                    char U = ' ';
                    char L = ' ';
                    if (ki.characterUpper.Length > 0)
                    {
                        U = ki.characterUpper[0];
                    }
                    if (ki.characterLower.Length > 0)
                    {
                        L = ki.characterLower[0];
                    }
                    charUpper[i] = (U);
                    charLower[i] = (L);
                }
                isInitialize = true;
            }
        }
Exemplo n.º 2
0
        public override void HandleKeyPressed(KeyInformation key)
        {
            if (!IsFocused)
            {
                return;
            }

            base.HandleKeyPressed(key);

            if (key.VirtualKey == VirtualKeyCode.Backspace)
            {
                if (!HasText)
                {
                    return;
                }

                if (LabelText.Text.Length > 1)
                {
                    LabelText.Text = LabelText.Text.Remove(LabelText.Text.Length - 1);
                }
                else
                {
                    LabelText.Text = ".";
                }

                IconInputBar.Position -= new Vector(12, 0);
            }
        }
        public void HasExpiredTest()
        {
            var keyInfo = new KeyInformation()
            {
                ExpirationDate = DateTime.Today.AddDays(1)
            };


            Assert.IsTrue(keyInfo.HasNotExpired()
                          .IsValid());


            keyInfo.ExpirationDate = DateTime.Today;

            Assert.IsTrue(keyInfo.HasNotExpired()
                          .IsValid());

            Assert.IsTrue(keyInfo.HasNotExpired(checkWithInternetTime: true)
                          .IsValid());


            keyInfo.ExpirationDate = DateTime.Today.AddDays(-1);

            Assert.IsTrue(!keyInfo.HasNotExpired()
                          .IsValid());
        }
Exemplo n.º 4
0
 private void SetFileStringCache(KeyInformation keyInformation, string fileString)
 {
     if (keyInformation.ExpireTime > DateTime.Now)//if key is valid
     {
         _cacheManager.Set(CachedFilePrefix + keyInformation.MatchedGuid, fileString,
                           keyInformation.ExpireTime.Subtract(DateTime.Now));
     }
 }
Exemplo n.º 5
0
        public void KeyValidation()
        {
            // please add SKGL as a reference (using SKGL)

            /**
             *
             * STEP 1: MACHINE CODE
             * This code should be generated by the client.
             **/

            var machineCode = SKM.getMachineCode(SKM.getSHA1);

            System.Diagnostics.Debug.WriteLine(machineCode);

            /**
             *
             * STEP 2: VALIDATION OF ACTIVATION FILE
             *
             * The code is already pre-configured for you; you only need to specify the file path.
             * You can specify the file path in the string filePath variable below
             *
             * */

            // where the activation file is located
            string filePath     = "c:\\test\\ActivationFile20150020.skm";
            string rsaPublicKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

            var keyInfo = new KeyInformation();

            keyInfo = keyInfo.LoadFromFile(filePath, json: true, activationFile: true);

            if (keyInfo.HasValidSignature(rsaPublicKey)
                .IsValid())
            {
                // if we have come so far, the user has a valid activation file
                // where no information has been altered.
                // below this line, please put some logic handle


                if (keyInfo.IsOnRightMachine().IsValid())
                {
                    // if this is not true, the user tries to activate
                    // an activation file that belongs to another computer.
                    // therefore, it's invalid operation and should FAIL.
                    // note, this method assumes you use SHA1 as hashing algorithm
                    // for the machine code.
                }


                // here we can retrieve some useful info
                Console.WriteLine(keyInfo.CreationDate);
                //... etc.
            }
            else
            {
                Assert.Fail();
            }
        }
Exemplo n.º 6
0
            /// <summary>
            /// Gets the A clone.
            /// </summary>
            /// <returns>a new instance with same value</returns>
            public KeyInformation GetAClone()
            {
                KeyInformation cloned = new KeyInformation();

                cloned.m_Id = m_Id;
                cloned.m_BuildEventCodeId = m_BuildEventCodeId;

                return(cloned);
            }
Exemplo n.º 7
0
            /// <summary>
            /// Gets the A clone.
            /// </summary>
            /// <returns>a new instance with same value</returns>
            public KeyInformation GetAClone()
            {
                KeyInformation cloned = new KeyInformation();

                cloned.m_Id   = m_Id;
                cloned.m_Name = m_Name;

                return(cloned);
            }
Exemplo n.º 8
0
        private string GetFileStringFromCache(KeyInformation keyInformation)
        {
            string result = "";

            if (keyInformation.ExpireTime > DateTime.Now)
            {
                result = _cacheManager.Get <string>(CachedFilePrefix + keyInformation.MatchedGuid);
            }
            return(result);
        }
Exemplo n.º 9
0
        public KeyboardEventArgs(SDL.SDL_Event rawEvent)
            : base(rawEvent)
        {
            RawTimeStamp = rawEvent.key.timestamp;
            repeat       = rawEvent.key.repeat;

            KeyInformation = new KeyInformation(rawEvent.key.keysym.scancode, rawEvent.key.keysym.sym, rawEvent.key.keysym.mod);
            State          = (KeyState)rawEvent.key.state;
            WindowID       = rawEvent.key.windowID;
        }
            public static KeyInformation GetKeyInfo(Keys k)
            {
                KeyInformation result = keysInfo[0];

                foreach (var ki in keysInfo)
                {
                    if (ki.key == k)
                    {
                        result = ki;
                    }
                }
                return(result);
            }
        public void HasFeatureTest()
        {
            var ki = new KeyInformation()
            {
                ExpirationDate = DateTime.Today.AddDays(3),
                Features       = new bool[] { true, false, false, false, true, true, true, true }
            };

            bool result = ki.HasFeature(1)
                          .HasNotFeature(2)
                          .HasFeature(5)
                          .HasNotExpired()
                          .IsValid();

            Assert.IsTrue(result);
        }
        public void IsOnRightMachineTest()
        {
            var ki = new KeyInformation();

            var result = ki.IsOnRightMachine().IsValid();

            ki = new KeyInformation()
            {
                Mid = "hi"
            };

            Assert.IsFalse(ki.IsOnRightMachine().IsValid());

            ki.Mid = SKM.getMachineCode(SKM.getSHA1);

            Assert.IsTrue(ki.IsOnRightMachine().IsValid());
        }
Exemplo n.º 13
0
        public void EnqueueKey(SettingsKeyboardKey key, bool keyDown)
        {
            KeyInformation info = new KeyInformation();

            info.Key     = key;
            info.KeyDown = keyDown;
            lock (_keyQueue)
            {
                _keyQueue.Clear();
                _keyQueue.Add(info);
                if (info.KeyDown)
                {
                    WriteStatusMessage("Queueing keystroke: " + key.ToString());
                }
            }
            //ProcessKeyInfo(info);
        }
        public void OfflineKeyValidationWithPeriodicTimeCheck()
        {
            var RSAPublicKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

            var keyInfo = new KeyInformation().LoadFromFile("c:\\test\\license2.txt");

            if (keyInfo.HasValidSignature(RSAPublicKey, 3)
                .IsValid())
            {
                // the signature is correct so
                // the program can now launch
                return;
            }
            else
            {
                string key = "";
                if (keyInfo.IsValid())
                {
                    key = keyInfo.Key; // the license key is stored in the activation file.
                }
                else
                {
                    key = "MJAWL-ITPVZ-LKGAN-DLJDN"; // if we are here, ask the user about the key
                }
                var machineCode = SKGL.SKM.getMachineCode(SKGL.SKM.getSHA1);
                keyInfo = SKGL.SKM.KeyActivation("3", "2", "751963", key, machineCode, secure: true, signMid: true, signDate: true);

                if (keyInfo.HasValidSignature(RSAPublicKey).IsValid())
                {
                    // the signature is correct and the key is valid.
                    // save to file.
                    keyInfo.SaveToFile("c:\\test\\license2.txt");

                    // the program can now launch
                    return;
                }
                else
                {
                    // failure. close the program.
                }
            }

            Assert.Fail();
        }
Exemplo n.º 15
0
        public void SaveToFileJSONNormalFormatTest()
        {
            var ki = new KeyInformation()
            {
                CreationDate = DateTime.Today, NewKey = "test", Mid = "123"
            };

            // using binary formatter
            SKM.SaveKeyInformationToFile(ki, "test.txt", json: true);

            var ki2 = new KeyInformation();

            //loading as usual
            ki2 = SKM.LoadKeyInformationFromFile("test.txt", json: true);

            Assert.AreEqual(ki.CreationDate, ki2.CreationDate);
            Assert.AreEqual(ki.NewKey, ki2.NewKey);
            Assert.AreEqual(ki.Mid, ki2.Mid);
        }
Exemplo n.º 16
0
        public void DaysLeft()
        {
            var ki = new KeyInformation()
            {
                CreationDate = DateTime.Today, ExpirationDate = DateTime.Today.AddDays(30)
            };

            Assert.IsTrue(SKM.DaysLeft(ki) == 30);

            ki = new KeyInformation()
            {
                CreationDate = DateTime.Today, ExpirationDate = DateTime.Today
            };
            Assert.IsTrue(SKM.DaysLeft(ki) == 0);

            ki = new KeyInformation()
            {
                CreationDate = DateTime.Today, ExpirationDate = DateTime.Today.AddDays(-3)
            };
            Assert.IsTrue(SKM.DaysLeft(ki) == -3);

            ki = new KeyInformation()
            {
                CreationDate = DateTime.Today, ExpirationDate = DateTime.Today.AddDays(-3)
            };
            Assert.IsTrue(SKM.DaysLeft(ki, true) == 0);

            ki = new KeyInformation()
            {
                CreationDate = DateTime.Today, ExpirationDate = DateTime.Today
            };
            Assert.IsTrue(SKM.DaysLeft(ki, true) == 0);

            ki = new KeyInformation()
            {
                CreationDate = DateTime.Today, ExpirationDate = DateTime.Today.AddDays(-1)
            };
            Assert.IsTrue(SKM.DaysLeft(ki, true) == 0);
        }
Exemplo n.º 17
0
        private void ProcessKeyInfo(KeyInformation info)
        {
            if (info == null)
            {
                return;
            }

            if (info.KeyDown)
            {
                WriteStatusMessage("Processing keystroke: " + info.Key.ToString());

                string focussedWindowTitle;
                string focussedExecutable;
                GetFocussedExecutable(out focussedWindowTitle, out focussedExecutable);

                SettingsKeyboardKeyFocusedApplication application;
                application = info.Key.FocusedApplications.FindByExecutable(focussedWindowTitle, focussedExecutable);
                if (application == null)
                {
                    if (info.Key.FocusedApplications.Count == 0)
                    {
                        return;
                    }
                    application = info.Key.FocusedApplications[0];
                }

                foreach (SettingsKeyboardKeyAction action in application.Actions)
                {
                    try
                    {
                        ProcessAction(action);
                    }
                    catch (Exception e)
                    {
                        WriteStatusMessage("Unexpected error: " + action.ToString() + " : " + e.Message);
                    }
                }
            }
        }
Exemplo n.º 18
0
 public void KeyProcessingThreadProc()
 {
     while (_stopProcessing.WaitOne(10, true) == false)
     {
         try
         {
             KeyInformation info = null;
             lock (_keyQueue)
             {
                 if (_keyQueue.Count > 0)
                 {
                     info = _keyQueue[0];
                     _keyQueue.RemoveAt(0);
                 }
             }
             ProcessKeyInfo(info);
         }
         catch (Exception e)
         {
             Log.LogException(e);
         }
     }
 }
        public void SaveAndLoadFromFile()
        {
            var ki = new KeyInformation()
            {
                CreationDate   = DateTime.Today,
                ExpirationDate = DateTime.Today.AddDays(3)
            };

            ki.SaveToFile("test123.txt");

            ki = null;

            Assert.IsTrue(ki.LoadFromFile("test123.txt")
                          .HasNotExpired()
                          .IsValid());

            ki.SaveToFile("test123.txt", json: true);

            ki.LoadFromFile("test123.txt", json: true);

            Assert.IsTrue(ki.LoadFromFile("test123.txt")
                          .HasNotExpired()
                          .IsValid());
        }
Exemplo n.º 20
0
        private KeyInformation ConvertToKeyInformation(Dvtk.Security.ISecurityItem theISecurityItem)
        {
            KeyInformation theKeyInformation = new KeyInformation();

            try
            {
                theKeyInformation.Issuer = theISecurityItem.Issuer;
            }
            catch (Exception theException)
            {
                theKeyInformation.Issuer = KeyInformation.UNKNOWN;
                _ExceptionText          += "\nIssuer: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.ExpirationDate = theISecurityItem.ExpirationDate.ToString();
            }
            catch (Exception theException)
            {
                theKeyInformation.ExpirationDate = KeyInformation.UNKNOWN;
                _ExceptionText += "\nExpirationDate: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.Version = theISecurityItem.Version.ToString();
            }
            catch (Exception theException)
            {
                theKeyInformation.Version = KeyInformation.UNKNOWN;
                _ExceptionText           += "\nVersion: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.SerialNumber = theISecurityItem.SerialNumber;
            }
            catch (Exception theException)
            {
                theKeyInformation.SerialNumber = KeyInformation.UNKNOWN;
                _ExceptionText += "\nSerialNumber: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.Subject = theISecurityItem.Subject;
            }
            catch (Exception theException)
            {
                theKeyInformation.Subject = KeyInformation.UNKNOWN;
                _ExceptionText           += "\nSubject: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.EffectiveDate = theISecurityItem.EffectiveDate.ToString();
            }
            catch (Exception theException)
            {
                theKeyInformation.EffectiveDate = KeyInformation.UNKNOWN;
                _ExceptionText += "\nEffectiveDate: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.SignatureKeyLength = theISecurityItem.SignatureKeyLength.ToString();
            }
            catch (Exception theException)
            {
                theKeyInformation.SignatureKeyLength = KeyInformation.UNKNOWN;
                _ExceptionText += "\nSignatureKeyLength " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.SignatureAlgorithm = theISecurityItem.SignatureAlgorithm;
            }
            catch (Exception theException)
            {
                theKeyInformation.SignatureAlgorithm = KeyInformation.UNKNOWN;
                _ExceptionText += "\nSignatureAlgorithm: " + theException.Message + "\n";
            }

            return(theKeyInformation);
        }
Exemplo n.º 21
0
 public virtual void HandleKeyPressed(KeyInformation key)
 {
     if (Visible)
     {
     }
 }
Exemplo n.º 22
0
        private KeyInformation ConvertToKeyInformation(Dvtk.Security.ISecurityItem  theISecurityItem)
        {
            KeyInformation theKeyInformation = new KeyInformation();

            try
            {
                theKeyInformation.Issuer = theISecurityItem.Issuer;
            }
            catch(Exception theException)
            {
                theKeyInformation.Issuer = KeyInformation.UNKNOWN;
                _ExceptionText += "\nIssuer: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.ExpirationDate = theISecurityItem.ExpirationDate.ToString();
            }
            catch(Exception theException)
            {
                theKeyInformation.ExpirationDate = KeyInformation.UNKNOWN;
                _ExceptionText += "\nExpirationDate: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.Version = theISecurityItem.Version.ToString();
            }
            catch(Exception theException)
            {
                theKeyInformation.Version = KeyInformation.UNKNOWN;
                _ExceptionText += "\nVersion: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.SerialNumber = theISecurityItem.SerialNumber;
            }
            catch(Exception theException)
            {
                theKeyInformation.SerialNumber = KeyInformation.UNKNOWN;
                _ExceptionText += "\nSerialNumber: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.Subject = theISecurityItem.Subject;
            }
            catch(Exception theException)
            {
                theKeyInformation.Subject = KeyInformation.UNKNOWN;
                _ExceptionText += "\nSubject: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.EffectiveDate = theISecurityItem.EffectiveDate.ToString();
            }
            catch(Exception theException)
            {
                theKeyInformation.EffectiveDate = KeyInformation.UNKNOWN;
                _ExceptionText += "\nEffectiveDate: " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.SignatureKeyLength = theISecurityItem.SignatureKeyLength.ToString();
            }
            catch(Exception theException)
            {
                theKeyInformation.SignatureKeyLength = KeyInformation.UNKNOWN;
                _ExceptionText += "\nSignatureKeyLength " + theException.Message + "\n";
            }

            try
            {
                theKeyInformation.SignatureAlgorithm = theISecurityItem.SignatureAlgorithm;
            }
            catch(Exception theException)
            {
                theKeyInformation.SignatureAlgorithm = KeyInformation.UNKNOWN;
                _ExceptionText += "\nSignatureAlgorithm: " + theException.Message + "\n";
            }

            return(theKeyInformation);
        }
Exemplo n.º 23
0
 // Use this for initialization
 void Start()
 {
     keyInfo = GameObject.Find("Keys").GetComponent <KeyInformation>();
 }