예제 #1
0
        public static void Main(string[] args)
        {
            try
            {
                string fileName          = null;
                string tsa               = null;
                string hash              = null;
                string policy            = null;
                string nonce             = null;
                bool   cert              = false;
                string outFile           = null;
                string sslClientCertFile = null;
                string sslClientCertPass = null;
                string httpAuthLogin     = null;
                string httpAuthPass      = null;
                bool   isAsics           = false;

                if (args == null)
                {
                    return;
                }

                int i = 0;
                if (0 >= args.Length)
                {
                    ExitWithHelp(string.Empty);
                }

                while (i < args.Length)
                {
                    switch (args[i])
                    {
                    case "--file":
                        fileName = args[++i];
                        break;

                    case "--tsa":
                        tsa = args[++i];
                        break;

                    case "--out":
                        outFile = args[++i];
                        break;

                    case "--hash":
                        hash = args[++i];
                        break;

                    case "--policy":
                        policy = args[++i];
                        break;

                    case "--nonce":
                        nonce = args[++i];
                        break;

                    case "--cert-req":
                        cert = true;
                        break;

                    case "--ssl-client-cert-file":
                        sslClientCertFile = args[++i];
                        break;

                    case "--ssl-client-cert-pass":
                        sslClientCertPass = args[++i];
                        break;

                    case "--http-auth-login":
                        httpAuthLogin = args[++i];
                        break;

                    case "--http-auth-pass":
                        httpAuthPass = args[++i];
                        break;

                    case "--asics":
                        isAsics = true;
                        break;

                    default:
                        ExitWithHelp("Invalid argument: " + args[i]);
                        break;
                    }

                    i++;
                }

                X509Certificate2 sslCert = null;
                if (!string.IsNullOrEmpty(sslClientCertFile))
                {
                    sslCert = new X509Certificate2(sslClientCertFile, sslClientCertPass);
                }

                NetworkCredential networkCredential = null;
                if (!string.IsNullOrEmpty(httpAuthLogin) && !string.IsNullOrEmpty(httpAuthPass))
                {
                    networkCredential = new NetworkCredential(httpAuthLogin, httpAuthPass);
                }

                UserCredentials credentials = null;
                if (networkCredential != null || sslCert != null)
                {
                    credentials = new UserCredentials(sslCert, networkCredential);
                }

                TimeStampToken token = SharedUtils.RequestTimeStamp(tsa, fileName, hash, policy, nonce, cert, credentials, new LogDelegate(LogMessage), true);
                if (isAsics)
                {
                    SharedUtils.SaveToAsicSimple(fileName, token, outFile);
                }
                else
                {
                    SharedUtils.SaveResponse(outFile, token);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                ExitWithHelp(null);
            }

            Console.WriteLine("Success");
        }