Example #1
0
        //andrebbe chiamato all'open della maschera se presenti i dati alias e dominio essi verrano PRE popolati
        private void popolaCampiMemento()
        {
            RemoteDigitalSignManager dsm = new RemoteDigitalSignManager();

            try
            {
                RemoteDigitalSignManager.Memento m = dsm.HSM_GetMementoForUser();
                if (m != null)
                {
                    this.txtUseerName.Text = m.Alias;
                    this.txtDominio.Text   = m.Dominio;
                }
            }
            catch (System.Exception ex)
            {
                return;
            }
        }
Example #2
0
        protected void btnFirma_OnClick(object sender, EventArgs e)
        {
            // Da valutare i campi Obbligatori
            if (!string.IsNullOrEmpty(this.txtUseerName.Text)
                //&& !string.IsNullOrEmpty(this.txtDominio.Text)
                && !string.IsNullOrEmpty(this.txtPassword.Text) &&
                !string.IsNullOrEmpty(this.txtOTP.Text) &&
                (this.rbPades.Checked || this.rbCades.Checked))
            {
                string alias   = this.txtUseerName.Text;
                string dominio = this.txtDominio.Text;
                string pin     = this.txtPassword.Text;
                string otp     = this.txtOTP.Text;

                DocsPaWR.FileRequest fileReq = null;

                fileReq = FileManager.getSelectedFile();

                bool isPdf = (FileManager.getEstensioneIntoSignedFile(this.Page, fileReq.fileName).ToUpper() == "PDF");

                string msgError = CheckSign(fileReq, isPdf);
                if (!string.IsNullOrEmpty(msgError))
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "ajaxDialogModal", "alert('" + msgError + "');", true);
                }
                else
                {
                    RemoteDigitalSignManager dsm = new RemoteDigitalSignManager();

                    // attenzione mancano questi dati in maschera, vanno popolati come quelli sopra, prendendo i valori corretti.
                    bool cofirma = this.rbCofirma.Checked; //prendere dalla checkbox cofirma
                    //bool timestamp = this.HsmCheckMarkTemporal.Checked; //prendere dalla checkbox timestamp
                    bool timestamp = false;
                    RemoteDigitalSignManager.tipoFirma tipoFirma = new RemoteDigitalSignManager.tipoFirma();
                    if (this.rbPades.Checked)
                    {
                        tipoFirma = RemoteDigitalSignManager.tipoFirma.PADES;
                    }
                    else
                    {
                        tipoFirma = RemoteDigitalSignManager.tipoFirma.CADES;
                    }


                    try
                    {
                        RemoteDigitalSignManager.Memento m = new RemoteDigitalSignManager.Memento {
                            Alias = alias, Dominio = dominio
                        };
                        //Intanto salvo il memento
                        dsm.HSM_SetMementoForUser(m);
                    }
                    catch (System.Exception ex)
                    {
                        // Non è stato possibile salvare il mememnto
                        return;
                    }

                    bool retval  = false;
                    bool convert = !isPdf && this.chkConverti.Checked;
                    try
                    {
                        //System.Threading.Thread.Sleep(3000);
                        //retval = true;
                        retval = dsm.HSM_Sign(fileReq, cofirma, timestamp, tipoFirma, alias, dominio, otp, pin, convert);
                    }
                    catch (System.Exception ex)
                    {
                        //ScriptManager.RegisterStartupScript(this, this.GetType(), "alertFirmaKO", "alert('Attenzione, errore durante l'operazione di firma HSM');", true);
                    }

                    if (retval)
                    {
                        // Ricarico il dettaglio della scheda documento
                        DocsPaWR.SchedaDocumento sd = DocumentManager.getDocumentoSelezionato(this);
                        DocsPaWR.SchedaDocumento schedaDocumento = DocumentManager.getDettaglioDocumento(this, sd.systemId, sd.docNumber);
                        DocumentManager.setDocumentoSelezionato(this, schedaDocumento);

                        //ScriptManager.RegisterStartupScript(this, this.GetType(), "alertFirmaOK", "alert(Operazione di firma HSM avvenuta con successo');", true);
                        ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "ajaxDialogModal", "alert('Operazione di firma HSM avvenuta con successo');", true);
                    }
                    else
                    {
                        // è accaduto un inconveniente.. la firma non è andata a buon fine...
                        //ScriptManager.RegisterStartupScript(this, this.GetType(), "alertFirmaKO", "alert('Attenzione, errore durante l'operazione di firma HSM');", true);
                        ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "ajaxDialogModal", "alert('Attenzione, errore durante la firma HSM');", true);
                    }

                    if (retval)
                    {
                        // Chiude la finestra
                        //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "closeWindows", "window.close();", true);
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "closeWindows", "CloseWindow();", true);
                    }
                }
            }
            else
            {
                //ScriptManager.RegisterStartupScript(this, this.GetType(), "ajaxDialogModal", "alert('Attenzione, inserire alias utente, password e otp');", true);
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "ajaxDialogModal", "alert('Attenzione, inserire alias utente, password e otp');", true);
            }

            //// Chiude la finestra
            //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "closeWindows", "window.close();", true);
        }