Exemplo n.º 1
0
        public void AddLtv(String src, String dest, IOcspClient ocsp, ICrlClient crl, ITSAClient tsa)
        {
            PdfReader       r       = new PdfReader(src);
            FileStream      fos     = new FileStream(dest, FileMode.Create);
            PdfStamper      stp     = PdfStamper.CreateSignature(r, fos, '\0', null, true);
            LtvVerification v       = stp.LtvVerification;
            AcroFields      fields  = stp.AcroFields;
            List <String>   names   = fields.GetSignatureNames();
            String          sigName = names[names.Count - 1];
            PdfPKCS7        pkcs7   = fields.VerifySignature(sigName);

            if (pkcs7.IsTsp)
            {
                v.AddVerification(sigName, ocsp, crl, LtvVerification.CertificateOption.SIGNING_CERTIFICATE, LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.NO);
            }
            else
            {
                foreach (String name in names)
                {
                    v.AddVerification(name, ocsp, crl, LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.NO);
                }
            }
            PdfSignatureAppearance sap = stp.SignatureAppearance;

            LtvTimestamp.Timestamp(sap, tsa, null);
        }
Exemplo n.º 2
0
        void Button4Click(object sender, EventArgs e)
        {
            if (!tsaCbx.Checked || TSAUrlTextBox.Text == "")
            {
                MessageBox.Show("Marca temporale non selezionata, oppure server non definito");
                return;
            }

            string TSA_URL   = TSAUrlTextBox.Text;
            string TSA_ACCNT = tsaLogin.Text;
            string TSA_PASSW = tsaPwd.Text;

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                string   foldername = fbd.SelectedPath;
                string[] files      = Directory.GetFiles(foldername, "*.pdf");
                pb.Minimum = 0;
                pb.Maximum = files.Length;
                pb.Visible = true;
                lb2.Items.Clear();
                foreach (string s in files)
                {
                    //just filename
                    try {
                        string ext = s.Substring(1 + s.LastIndexOf(@".")).ToLowerInvariant();
                        if (ext == "pdf" || ext == "PDF")
                        {
                            //ricreo il percorso con il nome del nuovo file
                            string          file      = s.Substring(1 + s.LastIndexOf(@"\"));
                            string          NuovoFile = s.Substring(0, s.LastIndexOf(@"\") + 1) + file.Substring(0, file.LastIndexOf(".")) + "_validato_" + DateTime.Now.ToFileTime() + ".pdf";
                            PdfReader       r         = new PdfReader(s);
                            FileStream      fout      = new FileStream(NuovoFile, FileMode.Create);
                            PdfStamper      stp       = PdfStamper.CreateSignature(r, fout, '\0', null, true);
                            LtvVerification v         = stp.LtvVerification;
                            AcroFields      af        = stp.AcroFields;
                            foreach (string sigName in af.GetSignatureNames())
                            {
                                v.AddVerification(sigName, new OcspClientBouncyCastle(), new CrlClientImp(), LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.NO);
                            }
                            PdfSignatureAppearance sap = stp.SignatureAppearance;
                            TSAClientBouncyCastle  tsa = new TSAClientBouncyCastle(TSA_URL, TSA_ACCNT, TSA_PASSW, 6500, "sha256");
                            LtvTimestamp.Timestamp(sap, tsa, null);
                            lb2.Items.Add(NuovoFile);
                            lb2.Refresh();
                            pb.Increment(1);
                        }
                    }
                    catch (Exception ex) {
                        MessageBox.Show(ex.ToString());
                        pb.Visible = false;
                        return;
                    }
                }
                MessageBox.Show(pb.Maximum.ToString() + " file firmati correttamente", "Operazione Completata");
                pb.Visible = false;
            }
        }
Exemplo n.º 3
0
        private void AdicionarLtv(PdfStamper stamper, PdfSignatureAppearance appearance)
        {
            Log.Application.Info("Validacao iniciado");
            var v      = stamper.LtvVerification;
            var fields = stamper.AcroFields;
            var names  = fields.GetSignatureNames();

            Log.Application.Info("fields-" + fields.TotalRevisions);
            Log.Application.Info("names-" + names.Count);

            var sigName = names[names.Count - 1];
            var pkcs7   = fields.VerifySignature(sigName);

            Log.Application.Info("verificando tsp");

            if (pkcs7.IsTsp)
            {
                Log.Application.Info("Adicionando verificacao para " + sigName);

                v.AddVerification(
                    sigName,
                    this.ocspClient,
                    new CrlClientOnline(this.cadeiaTempo),
                    LtvVerification.CertificateOption.SIGNING_CERTIFICATE,
                    LtvVerification.Level.OCSP_CRL,
                    LtvVerification.CertificateInclusion.YES);
            }
            else
            {
                foreach (var name in names)
                {
                    Log.Application.Info("Adicionando verificacao para nomes" + name);
                    v.AddVerification(
                        name,
                        this.ocspClient,
                        new CrlClientOnline(this.cadeiaTempo),
                        LtvVerification.CertificateOption.WHOLE_CHAIN,
                        LtvVerification.Level.OCSP_CRL,
                        LtvVerification.CertificateInclusion.YES);
                }
            }

            LtvTimestamp.Timestamp(appearance, this.tsaClient, null);
        }