Beispiel #1
0
    // Test that a valid key passes the key validation function - needs changes to
    //  OTPgenerator to work properly
    public int[] testGoodDecrypt()
    {
        int[] passed = new int[2];
        passed[1] = 1;

        string seed = "A021E0A80264A33C08B6C2884AC0685C";
        string key  = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";

        key = VerifyKeys.removeHexPrefix(key);
        byte[] otp          = new byte[32];
        byte[] seedByte     = new byte[14];
        byte[] encryptedKey = new byte[34];
        byte[] keyByte      = Encoding.ASCII.GetBytes(key);
        seedByte = Encoding.ASCII.GetBytes(seed);
        byte[] goodKey      = OTPworker.OTPxor(seedByte, keyByte);
        byte[] decryptedKey = OTPworker.decryptFromBlob(seed, Convert.ToBase64String(goodKey));
        string finalKey     = Encoding.ASCII.GetString(keyByte);

        if (finalKey == key)
        {
            passed[0] = 1;
        }

        return(passed);
    }
Beispiel #2
0
    // Test that an invalid key fails the key validation function
    public void testBadDecrypt()
    {
        string seed    = "A021E0A80264A33C08B6C2884AC0685C";
        string badBlob = "aaaabbbbaaaabbbbaaaabbbbaaaabbbb";

        byte[] keyByte  = OTPworker.decryptFromBlob(seed, badBlob);
        string finalKey = Encoding.ASCII.GetString(keyByte);

        Debug.Log("Bad decrypted key: " + finalKey);
    }
Beispiel #3
0
    // Test decrypting a key from a didery blob - needs the bug fix for OTPgenerator to work
    public int[] testDecryptFromBlob()
    {
        int[] passed = new int[2];
        passed[1] = 1;

        byte[] key           = new byte[16];
        byte[] seed          = new byte[16];
        byte[] encryptedKey  = new byte[16];
        byte[] decryptedKey  = new byte[16];
        byte[] decryptedBlob = new byte[16];
        byte[] otp           = new byte[32];

        for (int i = 0; i < key.Length; i++)
        {
            key[i] = (byte)(i + 1);
        }
        for (int i = 0; i < seed.Length; i++)
        {
            seed[i] = (byte)(i + 1);
        }

        OTPworker.OTPGenerator(otp, 32, seed);
        encryptedKey = OTPworker.OTPxor(key, otp);
        decryptedKey = OTPworker.OTPxor(encryptedKey, otp);

        string seedString      = OTPworker.ByteArrayToHex(seed);
        string keyString       = OTPworker.ByteArrayToHex(key);
        string decryptedString = OTPworker.ByteArrayToHex(decryptedKey);

        if (keyString == decryptedString)
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Decrypt key test failed. Key: " + OTPworker.ByteArrayToHex(key));
            Debug.Log("Decrypted key: " + OTPworker.ByteArrayToHex(decryptedKey));
        }

        decryptedBlob = OTPworker.decryptFromBlob(seedString, Convert.ToBase64String(encryptedKey));
        passed[1]    += 1;

        if (keyString == OTPworker.ByteArrayToHex(decryptedBlob))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Decrypt blob test failed. Key string: " + keyString + " decrypted blob: " + OTPworker.ByteArrayToHex(decryptedBlob));
        }

        //Debug.Log("Decrypted blob: " + OTPworker.ByteArrayToHex(decryptedBlob));

        return(passed);
    }
Beispiel #4
0
    public void testDecrypt()
    {
        string seed = SeedManager.InputSeed;

        Debug.Log("Seed: " + seed);
        byte[] keyByte  = OTPworker.decryptFromBlob(seed, DideryDemoManager.DemoBlob);
        string finalKey = Encoding.ASCII.GetString(keyByte);

        keyString.text = finalKey;
        Debug.Log("Decrypted key: " + finalKey);
    }
Beispiel #5
0
    public int[] testHexToByte()
    {
        int[] passed = new int[2];
        passed[1] = 1;

        string even = "abdc";
        string odd  = "abc";

        byte[] evenArray = OTPworker.HexStringToByteArray(even);
        byte[] oddArray  = OTPworker.HexStringToByteArray(odd);

        // If it's gotten this far, it works
        passed[0] = 1;
        return(passed);
    }
Beispiel #6
0
    // Takes a string for a key as input, encrypts it, and returns a byte[] of the encrypted key
    public byte[] encryptKey(string inputKey)
    {
        byte[] otp          = new byte[32];
        byte[] seed         = new byte[16];
        byte[] encryptedKey = new byte[34];
        byte[] key          = Encoding.ASCII.GetBytes(inputKey);

        int size = 32;

        seed = OTPworker.randomSeedGenerator(seed);
        OTPworker.OTPGenerator(otp, size, seed);
        encryptedKey = OTPworker.OTPxor(key, otp);

        return(encryptedKey);
    }
Beispiel #7
0
    // Decrypt the key from DideryDemoManager.demoBlob
    public void decryptKey()
    {
        if (DideryDemoManager.IsDemo)
        {
            keyString.text = DideryDemoManager.DemoBlob;
        }
        else
        {
            byte[] keyByte = OTPworker.decryptFromBlob(SeedManager.RecoveredSeed, dideryDemoManager.demoBlob);
            finalKey       = Encoding.ASCII.GetString(keyByte);
            keyString.text = finalKey;
        }

        //copyButton.SetActive(true);
    }
Beispiel #8
0
    // To be finished at a later date
    public int[] testRandomSeedGenerator()
    {
        int[] passed = new int[2];
        passed[1] = 1;

        byte[] testSeed1 = new byte[10];
        byte[] testSeed2 = new byte[10];
        testSeed1 = OTPworker.randomSeedGenerator(testSeed1);
        testSeed2 = OTPworker.randomSeedGenerator(testSeed2);

        Debug.Log("RandomSeedGenerator() test passed");

        // if no errors have happened by here, the test has passed
        passed[0] = 1;
        return(passed);
    }
Beispiel #9
0
    // To do
    public int[] testDecryptKey()
    {
        int[] passed = new int[2];
        passed[1] = 1;
        int size = 32;

        byte[] key  = new byte[size];
        byte[] eKey = new byte[size];
        byte[] dKey = new byte[size];
        byte[] seed = new byte[size];
        byte[] otp  = new byte[size];
        bool   same = true;

        for (int i = 0; i < key.Length; i++)
        {
            key[i] = (byte)i;
        }

        for (int i = 0; i < seed.Length; i++)
        {
            seed[i] = (byte)i;
        }

        OTPworker.OTPGenerator(otp, size, seed);
        eKey = OTPworker.OTPxor(key, otp);
        dKey = OTPworker.OTPxor(eKey, otp);

        for (int i = 0; i < key.Length; i++)
        {
            if (key[i] != dKey[i])
            {
                same = false;
            }
        }

        if (same)
        {
            passed[0] = 1;
        }
        else
        {
            Debug.Log("Test for encryption and decryption failed");
            Debug.Log("Values: " + key[0] + "-" + dKey[0] + " " + key[1] + "-" + dKey[1]);
        }

        return(passed);
    }
Beispiel #10
0
    // Test that a valid key passes the key validation function
    public void testGoodDecrypt()
    {
        string seed = "A021E0A80264A33C08B6C2884AC0685C";
        string key  = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";

        key = VerifyKeys.removeHexPrefix(key);
        byte[] otp          = new byte[32];
        byte[] seedByte     = new byte[14];
        byte[] encryptedKey = new byte[34];
        byte[] keyByte      = Encoding.ASCII.GetBytes(key);
        seedByte = Encoding.ASCII.GetBytes(seed);
        byte[] goodKey      = OTPworker.OTPxor(seedByte, keyByte);
        byte[] decryptedKey = OTPworker.decryptFromBlob(seed, Convert.ToBase64String(goodKey));
        string finalKey     = Encoding.ASCII.GetString(keyByte);

        Debug.Log("Bad decrypted key: " + finalKey);
    }
Beispiel #11
0
    // Test that an invalid key fails the key validation function
    public int[] testBadDecrypt()
    {
        int[] passed = new int[2];
        passed[1] = 1;

        string seed    = "A021E0A80264A33C08B6C2884AC0685C";
        string badBlob = "aaaabbbbaaaabbbbaaaabbbbaaaabbbb";

        byte[] keyByte  = OTPworker.decryptFromBlob(seed, badBlob);
        string finalKey = Encoding.ASCII.GetString(keyByte);

        //Debug.Log("Bad decrypted key: " + finalKey);

        // if the function has gotten to this point, and hasn't crashed, it's passed
        passed[0] = 1;
        return(passed);
    }
Beispiel #12
0
    // Checks to see if the seed is within demo parameters. For demo use only
    public byte[] checkSeed(byte[] seed)
    {
        int checkVal = OTPworker.checkValidSeed(seedToByte.getActionsFromBytes(seed));

        while (checkVal > 1)
        {
            Debug.Log("Generating new seed");
            for (int i = 0; i < seed.Length; i++)
            {
                if (seed[i] > 0)
                {
                    seed[i] -= 1;
                }
            }
            checkVal = OTPworker.checkValidSeed(seedToByte.getActionsFromBytes(seed));
        }
        return(seed);
    }
Beispiel #13
0
    // Takes a key as input, encrypts the key, sends it to didery in a POST request
    public void demoEncryptKey(string inputKey, string url = null)
    {
        inputKey = VerifyKeys.removeHexPrefix(inputKey);
        if (url == null)
        {
            url = urlAddress;
        }
        int size = 32;

        string[] dideryData;

        byte[] otp = new byte[32];
        //byte[] seed = new byte[16]; // used for 128 bit seed
        byte[] seed         = new byte[14]; // used for 108 bit seed
        byte[] encryptedKey = new byte[34];
        byte[] key          = Encoding.ASCII.GetBytes(inputKey);

        seed = OTPworker.randomSeedGenerator(seed);

        // Used for demo puroses - required if trying to use 108 bit seed
        if (seed[13] > 7)
        {
            seed[13] = (byte)((int)seed[13] % 7);
        }

        OTPworker.OTPGenerator(otp, size, seed);

        encryptedKey = OTPworker.OTPxor(key, otp);

        dideryData = DideryInterface.makePost(encryptedKey, seed);

        string did       = dideryData[0];
        string signature = dideryData[1];
        string postBody  = dideryData[2];

        //Debug.Log("Did: " + did + " signature: " + " postBody: " + postBody);
        SeedManager.InputSeed     = OTPworker.ByteArrayToHex(seed);
        DideryDemoManager.DemoDid = did;
        Debug.Log("Did: " + DideryDemoManager.DemoDid);

        postRequest(url, postBody, signature);
    }
Beispiel #14
0
    // Test the OTP generator to make sure it outputs the same pad given the same seed
    public int[] testOtpGenerator2()
    {
        int[]  passed  = new int[2];
        int    size    = 16;
        string s       = "a";
        string result1 = "";
        string result2 = "";

        byte[] seed = OTPworker.HexStringToByteArray(s);

        byte[] output = new byte[size];

        for (int i = 0; i < 1000; i++)
        {
            passed[1] += 1;
            if (s.Length < 30)
            {
                int rand = Random.Range(0, 9);
                s += rand.ToString();
            }
            else
            {
                s = "b";
            }

            OTPworker.OTPGenerator(output, size, seed);
            result1 = OTPworker.ByteArrayToHex(output);
            result2 = OTPworker.ByteArrayToHex(output);

            if (result1 == result2)
            {
                passed[0] += 1;
            }
            else
            {
                Debug.Log("OTP generator test failed. Seed: " + result1 + " Result: " + result2);
            }
        }

        return(passed);
    }
Beispiel #15
0
    void testRun2()
    {
        byte[] testRunSeed = new byte[14];
        testRunSeed = OTPworker.randomSeedGenerator(testRunSeed);

        if (testRunSeed[13] > 15)
        {
            testRunSeed[13] = (byte)((int)testRunSeed[13] % 7);
        }

        List <int> tempList = customList(3, 4, 2, 4, 4);

        BitArray seedBits = byteToBits(testRunSeed);

        int[] actions = bitConverter(seedBits, tempList);

        byte[] finalSeed = seed108Converter(actions, tempList);

        Debug.Log("Initial seed: " + byteToSeed(testRunSeed));
        Debug.Log("Final  seed: " + byteToSeed(finalSeed));
    }
Beispiel #16
0
    public void Start()
    {
        copied      = GameObject.FindGameObjectWithTag("Copied Text").GetComponent <TextMeshProUGUI>();
        copied.text = "";
        copied.gameObject.SetActive(false);
        if (DideryDemoManager.IsDemo)
        {
            keyString.text = DideryDemoManager.DemoBlob;
        }
        else
        {
            byte[] keyByte = OTPworker.decryptFromBlob(SeedManager.RecoveredSeed, dideryDemoManager.demoBlob);
            finalKey       = Encoding.ASCII.GetString(keyByte);
            keyString.text = finalKey;
        }
        copy.onClick.AddListener(onClickCopyKey);
        menu.onClick.AddListener(onClickMainMenu);
        quit.onClick.AddListener(onClickQuit);

        //PathManager.ResetPathManager();
        //copyButton.SetActive(false);
    }
Beispiel #17
0
    // Takes a key as input, encrypts the key, sends it to didery in a POST request
    public void demoEncryptKey(string inputKey)
    {
        int size = 32;

        string[] dideryData;

        byte[] otp = new byte[32];
        //byte[] seed = new byte[16];
        byte[] seed         = new byte[14];
        byte[] encryptedKey = new byte[34];
        byte[] key          = Encoding.ASCII.GetBytes(inputKey);

        seed = OTPworker.randomSeedGenerator(seed);
        seed = checkSeed(seed);

        // Used for demo puroses
        if (seed[13] > 7)
        {
            seed[13] = (byte)((int)seed[13] % 7);
        }
        //seed = HexStringToByteArray("4040C1A90886218984850151AC123249");

        OTPworker.OTPGenerator(otp, size, seed);

        encryptedKey = OTPworker.OTPxor(key, otp);

        dideryData = DideryInterface.makePost(encryptedKey);

        string did       = dideryData[0];
        string signature = dideryData[1];
        string postBody  = dideryData[2];

        //Debug.Log("Did: " + did + " signature: " + " postBody: " + postBody);
        SeedManager.InputSeed     = OTPworker.ByteArrayToHex(seed);
        DideryDemoManager.DemoDid = did;
        Debug.Log("Did: " + DideryDemoManager.DemoDid);

        postRequest(url, postBody, signature);
    }
Beispiel #18
0
    // Test decrypting a key from a didery blob
    public int[] testDecrypt()
    {
        int[] passed = new int[2];
        passed[1] = 1;

        byte[] key          = new byte[16];
        byte[] seed         = new byte[16];
        byte[] encryptedKey = new byte[16];
        byte[] decryptedKey = new byte[16];
        byte[] otp          = new byte[32];

        for (int i = 0; i < key.Length; i++)
        {
            key[i] = (byte)(i + 1);
        }
        for (int i = 0; i < seed.Length; i++)
        {
            seed[i] = (byte)(i + 1);
        }

        OTPworker.OTPGenerator(otp, 32, seed);
        encryptedKey = OTPworker.OTPxor(key, otp);
        decryptedKey = OTPworker.OTPxor(encryptedKey, otp);

        string keyString       = OTPworker.ByteArrayToHex(key);
        string decryptedString = OTPworker.ByteArrayToHex(decryptedKey);

        if (keyString == decryptedString)
        {
            passed[0] = 1;
        }
        else
        {
            Debug.Log("testDecrypt() failed.");
        }

        return(passed);
    }
Beispiel #19
0
    public int[] testMultipleSizeSeeds()
    {
        int[] passed = new int[2];

        string testHex = "FFFFAAAAFFFFAAAAFFFFDDDDFFFF";

        byte[] testHexSeed = SeedToByte.HexStringToByteArray(testHex);
        byte[] testRunSeed = new byte[14];
        testRunSeed = OTPworker.randomSeedGenerator(testRunSeed);

        List <int> tempList1 = SeedToByte.customList(4, 4, 2, 4, 4);
        List <int> tempList2 = SeedToByte.customList(3, 4, 2, 4, 4);

        BitArray seedBits1 = seedToByte.byteToBits(testRunSeed);
        BitArray seedBits2 = seedToByte.byteToBits(testHexSeed);

        int[] actions1 = seedToByte.bitToActions(seedBits1, tempList1);
        int[] actions2 = seedToByte.bitToActions(seedBits2, tempList1);

        byte[] finalSeed1 = SeedToByte.seedConverterUniversal(actions1, tempList1);
        byte[] finalSeed2 = SeedToByte.seedConverterUniversal(actions2, tempList1);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testRunSeed) == seedToByte.byteToSeed(finalSeed1))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test 1 for converting 112 bit seed to action list and back failed");
        }

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed2))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test 2 for converting 112 bit seed to action list and back failed");
        }

        testHexSeed = new byte[14];
        testRunSeed = OTPworker.randomSeedGenerator(testRunSeed);

        if (testRunSeed[13] > 7)
        {
            testRunSeed[13] = (byte)((int)testRunSeed[13] % 7);
        }

        BitArray seedBits = seedToByte.byteToBits(testHexSeed);

        int[] actions3 = seedToByte.bitToActions(seedBits, tempList2);

        byte[] finalSeed3 = SeedToByte.seedConverterUniversal(actions3, tempList2);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed3))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test for converting 108 bit seed to action list and back failed");
        }

        return(passed);
    }
Beispiel #20
0
    // Test the OTP generator to make sure it outputs the same pad given the same seed
    public int[] testOtpGenerator()
    {
        int[] passed = new int[2];
        int   size   = 16;

        string s1 = "9876abcdef";
        string s2 = "1234567890";
        string s3 = "0245789bce";

        byte[] seed1 = OTPworker.HexStringToByteArray(s1);
        byte[] seed2 = OTPworker.HexStringToByteArray(s2);
        byte[] seed3 = OTPworker.HexStringToByteArray(s3);

        byte[]        output  = new byte[size];
        List <string> result1 = new List <string>();
        List <string> result2 = new List <string>();
        List <string> result3 = new List <string>();

        for (int i = 0; i < 10; i++)
        {
            OTPworker.OTPGenerator(output, size, seed1);
            result1.Add(OTPworker.ByteArrayToHex(output));
        }

        for (int i = 0; i < 10; i++)
        {
            OTPworker.OTPGenerator(output, size, seed2);
            result2.Add(OTPworker.ByteArrayToHex(output));
        }

        for (int i = 0; i < 10; i++)
        {
            OTPworker.OTPGenerator(output, size, seed3);
            result3.Add(OTPworker.ByteArrayToHex(output));
        }

        for (int i = 1; i < result1.Count; i++)
        {
            passed[1] += 3;
            if (result1[0] != result1[i])
            {
                Debug.Log("String mismatch in result1");
                Debug.Log("RandomBytesDeterministic test failed");
            }
            else
            {
                passed[0] += 1;
            }
            if (result2[0] != result2[i])
            {
                Debug.Log("String mismatch in result2");
                Debug.Log("RandomBytesDeterministic test failed");
            }
            else
            {
                passed[0] += 1;
            }
            if (result3[0] != result3[i])
            {
                Debug.Log("String mismatch in result3");
                Debug.Log("RandomBytesDeterministic test failed");
            }
            else
            {
                passed[0] += 1;
            }
        }

        return(passed);
    }