public void UserNameMachineCodeTest()
        {
            string machineCode  = SKM.getMachineCode(SKM.getSHA1);
            string machineCode2 = SKM.getMachineCode(SKM.getSHA1, true);

            Assert.AreNotEqual(machineCode, machineCode2);
        }
예제 #2
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();
            }
        }
        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());
        }
예제 #4
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);
        }
예제 #5
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);
        }