private void RequestTimeStamp()
        {
            try
            {
                X509Certificate2 sslCert  = null;
                string           password = null;

                if (!string.IsNullOrEmpty(this.UserCertPassword.Text))
                {
                    password = this.UserCertPassword.Text;
                }

                if (!string.IsNullOrEmpty(this.UserCert.Text))
                {
                    sslCert = new X509Certificate2(this.UserCert.Text, password);
                }

                NetworkCredential networkCredential = null;
                if (!string.IsNullOrEmpty(this.UserPassword.Text) || !string.IsNullOrEmpty(this.UserName.Text))
                {
                    networkCredential = new NetworkCredential(this.UserName.Text, this.UserPassword.Text);
                }

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

                TimeStampToken token = SharedUtils.RequestTimeStamp(
                    this.ServerAddress.Text,
                    this.SourceFile.Text,
                    ((ComboItemHash)this.HashAlgorithm.SelectedValue).Value,
                    this.RequestedPolicy.Text,
                    this.Nonce.Text,
                    ((ComboItemCertReq)this.TSACertificate.SelectedValue).Value,
                    credentials,
                    new LogDelegate(this.TextAreaLog),
                    this.LogExceptions.Checked);

                SharedUtils.SaveInFormat(this.SourceFile.Text, token, ((ComboItemFormat)this.ResponseFormat.SelectedValue).Format, this.OutFile.Text);
                this.TextAreaLog(string.Format("Response saved in {0}", this.OutFile.Text));
                MessageBox.Show(string.Format("Time-stamp successfully received."), "Info", MessageBoxType.Information);
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("{0}: {1}", e.GetType(), e.Message), "Error", MessageBoxType.Error);
            }
        }
Esempio n. 2
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");
        }