Ejemplo n.º 1
0
        public void Run(string[] args)
        {
            if (args.Length <= 0)
            {
                Console.WriteLine("Invalid call");
                ShowHelp();
                return;
            }

            if (args[0].Equals("-h"))
            {
                ShowHelp();
                return;
            }

            if (args[0].Equals("-f"))
            {
                if (args.Length != 2)
                {
                    Console.WriteLine("No file specified");
                    ShowHelp();
                    return;
                }

                var filePath = args[1];
                if (!File.Exists(filePath))
                {
                    Console.WriteLine("specified file doesn't exist");
                    return;
                }

                var keyContainer = PSKCHelper.ToKeyContainer(filePath);
                ToConsole(keyContainer);
            }
        }
Ejemplo n.º 2
0
        public void File_To_KeyContainer(string path)
        {
            var container = PSKCHelper.ToKeyContainer(path);

            Assert.True(container.KeyPackages.Count == 2);
        }
Ejemplo n.º 3
0
 public void Hexstring_To_Base64_Binary_Invalid_Input(string hex)
 {
     Assert.Throws <FormatException>(() => PSKCHelper.HexToBase64EncodedBinary(hex));
 }
Ejemplo n.º 4
0
 public void Hexstring_To_Base64_Binary_Invalid_Length(string hex)
 {
     Assert.Throws <ArgumentException>(() => PSKCHelper.HexToBase64EncodedBinary(hex));
 }
Ejemplo n.º 5
0
 public void Hexstring_To_Base64_Binary_Null_Input(string hex)
 {
     Assert.Throws <ArgumentNullException>(() => PSKCHelper.HexToBase64EncodedBinary(hex));
 }
Ejemplo n.º 6
0
        public void Hexstring_To_Base64_Binary(string hex, string expected)
        {
            var result = PSKCHelper.HexToBase64EncodedBinary(hex);

            Assert.Equal(expected, result);
        }
Ejemplo n.º 7
0
 public void Base64_Binary_To_Hexstring_Invalid_Input(string b64string)
 {
     Assert.Throws <FormatException>(() => PSKCHelper.Base64EncodedBinaryToHex(b64string));
 }
Ejemplo n.º 8
0
 public void Base64_Binary_To_Hexstring_Null_Input(string b64string)
 {
     Assert.Throws <ArgumentNullException>(() => PSKCHelper.Base64EncodedBinaryToHex(b64string));
 }
Ejemplo n.º 9
0
        public void Base64_Binary_To_Hexstring(string b64string, string expected)
        {
            var result = PSKCHelper.Base64EncodedBinaryToHex(b64string);

            Assert.Equal(expected, result);
        }
Ejemplo n.º 10
0
        private void ToConsole(KeyContainer keyContainer)
        {
            if (keyContainer.KeyPackages.Count <= 0)
            {
                Console.WriteLine("No KeyPackages found");
                return;
            }

            foreach (var keyPackage in keyContainer.KeyPackages)
            {
                if (keyPackage.DeviceInfo != null)
                {
                    if (!string.IsNullOrWhiteSpace(keyPackage.DeviceInfo.Manufacturer))
                    {
                        Console.WriteLine($"Device Manufacturer: {keyPackage.DeviceInfo.Manufacturer}");
                    }
                    if (!string.IsNullOrWhiteSpace(keyPackage.DeviceInfo.SerialNo))
                    {
                        Console.WriteLine($"Device SerialNo: {keyPackage.DeviceInfo.SerialNo}");
                    }
                }

                var key = keyPackage.Key;
                if (key != null)
                {
                    if (!string.IsNullOrWhiteSpace(key.Id))
                    {
                        Console.WriteLine($"Key Id: {key.Id}");
                    }
                    if (!string.IsNullOrWhiteSpace(key.Algorithm))
                    {
                        Console.WriteLine($"Key Algorithm: {key.Algorithm}");
                    }

                    var algorithmParameters = key.AlgorithmParameters;
                    if (!string.IsNullOrWhiteSpace(algorithmParameters?.ResponseFormat?.Encoding))
                    {
                        Console.WriteLine($"Key AlgorithmParameters ResponseFormat Encoding: {algorithmParameters.ResponseFormat.Encoding}");
                    }

                    if (!string.IsNullOrWhiteSpace(algorithmParameters?.ResponseFormat?.Length))
                    {
                        Console.WriteLine($"Key AlgorithmParameters ResponseFormat Length: {algorithmParameters.ResponseFormat.Length}");
                    }

                    if (!string.IsNullOrWhiteSpace(key.Data?.Secret?.PlainValue))
                    {
                        var hex = PSKCHelper.Base64EncodedBinaryToHex(key.Data.Secret.PlainValue);
                        Console.WriteLine($"Key Data Secret PlainValue (B64): {key.Data.Secret.PlainValue}");
                        Console.WriteLine($"Key Data Secret PlainValue (Hex): {hex}");
                    }

                    if (!string.IsNullOrWhiteSpace(key.Data?.Counter?.PlainValue))
                    {
                        Console.WriteLine($"Key Data Counter PlainValue: {key.Data.Counter.PlainValue}");
                    }

                    Console.WriteLine();
                }
            }
        }