Beispiel #1
0
        /// <summary>
        /// Main of the current console program
        /// </summary>
        /// <param name="args">Arguments of the current execution</param>
        /// <returns>A negative value if an error occured, 0 otherwise</returns>
        public static int Main(string[] args)
        {
            try
            {
                int result = 0;
                if (args == null || args.Length == 0)
                {
                    Console.WriteLine("Usage : Yubico.Console 'OTP'. You must press on your YubiKey to get the 'OTP' value. Do NOT type the quotes ''.");
                    result = -1;
                }
                else
                {
                    YubicoRequest request = new YubicoRequest();
                    string        otp     = args[0];
                    YubicoAnswer  answer  = request.Validate(otp);
                    Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "Validation status is : {0}", answer.Status.ToString()));
                }

                return(result);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                return(-2);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Validate a given OTP
        /// </summary>
        /// <param name="otp">OTP from pressure on the YubiKey button</param>
        /// <returns>The validation result of the given OTP value</returns>
        public YubicoAnswer Validate(string otp)
        {
            YubicoAnswer result = new YubicoAnswer();
            this.InitializeParameters(otp);
            this.SignParameters();

            StreamReader reader = new StreamReader(this.GetAnswer());
            string currentLine = String.Empty;
            while (!reader.EndOfStream)
            {
                currentLine = reader.ReadLine();
                if (!String.IsNullOrEmpty(currentLine))
                {
                    int indexOfEqual = currentLine.IndexOf('=');
                    result.Parameters.Add(currentLine.Substring(0, indexOfEqual), currentLine.Substring(indexOfEqual + 1, currentLine.Length - (indexOfEqual + 1)));
                }
            }

            result.Validate();
            return result;
        }
        /// <summary>
        /// Validate a given OTP
        /// </summary>
        /// <param name="otp">OTP from pressure on the YubiKey button</param>
        /// <returns>The validation result of the given OTP value</returns>
        public YubicoAnswer Validate(string otp)
        {
            YubicoAnswer result = new YubicoAnswer();

            this.InitializeParameters(otp);
            this.SignParameters();

            StreamReader reader      = new StreamReader(this.GetAnswer());
            string       currentLine = String.Empty;

            while (!reader.EndOfStream)
            {
                currentLine = reader.ReadLine();
                if (!String.IsNullOrEmpty(currentLine))
                {
                    int indexOfEqual = currentLine.IndexOf('=');
                    result.Parameters.Add(currentLine.Substring(0, indexOfEqual), currentLine.Substring(indexOfEqual + 1, currentLine.Length - (indexOfEqual + 1)));
                }
            }

            result.Validate();
            return(result);
        }