public void ComprobarNoValidoButton_Click(object sender, EventArgs e)
        {
            //Recuperamos la instancia del cliente
            ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance();

            // Recuperamos el documento a firmar.
            string   path     = Environment.CurrentDirectory;
            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream   fs       = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH);

            byte[] datos_a_firmar = new byte[fs.Length];
            fs.Read(datos_a_firmar, 0, datos_a_firmar.Length);

            // Enviamos a firmar el documento al servidor y nos devuelve el identificador de la firma.
            String idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.PDF, typeFormatSign.PAdES_EPES);

            byte[] firmado1 = clienteViafirma.getDocumentoCustodiado(idFirma);
            //String idFirma2 = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", firmado1, Global.ALIAS, Global.PASS_CERT, typeFile.PDF, typeFormatSign.PAdES_EPES);
            //byte[] firmado2 = clienteViafirma.getDocumentoCustodiado(idFirma2);
            //String idFirma3 = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", firmado2, Global.ALIAS, Global.PASS_CERT, typeFile.PDF, typeFormatSign.PAdES_EPES);
            //byte[] firmado3 = clienteViafirma.getDocumentoCustodiado(idFirma3);

            // Y comprobamos el documento original que no esta firmado para forzar q no sea valido.
            firmaInfoViafirma infoFirma = clienteViafirma.checkSignedDocumentValidityByFileType(firmado1, typeFormatSign.PAdES_EPES);

            if (infoFirma.signed)
            {
                if (infoFirma.otherSigners == null)
                {
                    //Solo tenemos la firma representada por infoFirma
                    int numeroDeFirmas = 1;
                }
                else
                {
                    //El numero de firmas es el numero de otros firmantes más el representado por infoFirma
                    int numeroDeFirmas = infoFirma.otherSigners.Length + 1;
                }
            }
            else
            {
                int numeroDeFirmas = 0;
            }
        }
Example #2
0
        public void ComprobarNoValidoButton_Click(object sender, EventArgs e)
        {
            //Recuperamos la instancia del cliente
            ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance();

            // Recuperamos el documento a firmar.
            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream   fs       = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH);

            byte[] datos_a_firmar = new byte[fs.Length];
            fs.Read(datos_a_firmar, 0, datos_a_firmar.Length);

            // Enviamos a firmar el documento al servidor y nos devuelve el identificador de la firma.
            idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.PDF, typeFormatSign.PDF_PKCS7);


            // Y comprobamos el documento original que no esta firmado para forzar q no sea valido.
            info = clienteViafirma.checkSignedDocumentValidityByFileType(datos_a_firmar, typeFormatSign.PDF_PKCS7);
        }
Example #3
0
        public void ComprobarValidoButton_Click(object sender, EventArgs e)
        {
            //Recuperamos la instancia del cliente
            ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance();

            // Recuperamos el documento a firmar.
            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream   fs       = assembly.GetManifestResourceStream(Global.DEMO_FILE_XML_PATH);

            byte[] datos_a_firmar = new byte[fs.Length];
            fs.Read(datos_a_firmar, 0, datos_a_firmar.Length);

            // Enviamos a firmar el documento al servidor y nos devuelve el identificador de la firma.
            String idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.xml", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.XML, typeFormatSign.XADES_EPES_ENVELOPED);

            // Recuperamos el elemento firmado
            byte[] documento = clienteViafirma.getDocumentoCustodiado(idFirma);
            // Y comprobamos su validez
            infoFirma = clienteViafirma.checkDocumentSigned(documento, idFirma);
        }
Example #4
0
        public void FirmarServerPDFButton_Click(object sender, EventArgs e)
        {
            //Recuperamos la instancia del cliente
            ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance();

            // Recuperamos el documento a firmar.
            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream   fs       = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH);

            byte[] datos_a_firmar = new byte[fs.Length];
            fs.Read(datos_a_firmar, 0, datos_a_firmar.Length);

            // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante
            // Comprobar que efectivamente el servidor de firma está disponible
            System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n");

            //Creamos el objeto documento con los datos a firmar
            typeFormatSign tipoFirma = typeFormatSign.PAdES_BES;
            documento      doc       = new documento();

            doc.nombre         = "PDF_SELLOIMAGEN.pdf";
            doc.datos          = datos_a_firmar;
            doc.typeFormatSign = tipoFirma;
            doc.tipo           = typeFile.PDF;

            //Obtengo la imagen a estampar
            Stream stampImage = assembly.GetManifestResourceStream(Global.DEMO_STAMPER_PATH);

            byte[] image = new byte[stampImage.Length];
            stampImage.Read(image, 0, image.Length);
            String imageB64 = System.Convert.ToBase64String(image);

            //Creamos la politica de firma
            policy pol = PolicyUtil.newPolicy(tipoFirma, typeSign.DETACHED);

            PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_PAGE, "1");
            //Creamos el rectangle
            rectangle r = PolicyUtil.newRectangle(40, 100, 300, 240);

            PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_RECTANGLE, PolicyUtil.rectangleToJson(r));
            PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_IMAGE_STAMPER, imageB64);
            PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_STAMPER_TEXT, "Prueba Firmado por [CN]\ncon DNI [SERIALNUMBER]\ntrabajador de [O]\nen el departamento de [OU]");
            PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_STAMPER_HIDE_STATUS, "true");

            idFirma = clienteViafirma.SignByServerWithPolicy(pol, doc, Global.ALIAS, Global.PASS_CERT);



            //Obtengo la infirmación del documento firmado
            byte[]            signedDoc     = clienteViafirma.getDocumentoCustodiado(idFirma);
            firmaInfoViafirma info          = clienteViafirma.getSignInfo(idFirma);
            string            signTimeStamp = info.signTimeStamp;

            //tsa_cert_notafter
            usuarioGenericoViafirmaEntry[] usersInfo = info.properties;
            foreach (usuarioGenericoViafirmaEntry userInfo in usersInfo)
            {
                if ("tsa_cert_notafter".Equals(userInfo.key))
                {
                    Console.WriteLine(userInfo.value);
                }
            }

            // Generamos la url a la página que gestiona la comunicación con Viafirma.
            // Uri url = new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Response.ApplyAppPathModifier("~/ResultadoFirmaServidor.aspx"));
            // Log.Debug("Redireccionado al usuario a: " + url);

            // Guardamos el Id de Firma
            HttpContext.Current.Session["idFirma"] = idFirma;

            // Redirecciona a la url
            // HttpContext.Current.Response.Redirect(url.AbsoluteUri);
        }
Example #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     idFirma = "";
     info    = null;
 }