Ejemplo n.º 1
0
        /// <summary>
        /// Crea una nuova versione da un documento acquisito, se è associato un TSR, verrà unito al documento per creare un TSD
        /// </summary>
        /// <param name="infoUtente"></param>
        /// <param name="fileRequest"></param>
        /// <returns></returns>
        public static DocsPaVO.documento.FileRequest CreateTSDVersion(DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.documento.FileRequest fileRequest)
        {
            byte [] lastTSR = BusinessLogic.Interoperabilità.InteroperabilitaUtils.GetTSRForDocument(infoUtente, fileRequest);
            if (lastTSR == null)
            {
                return(null);
            }

            //Conversione in TSD
            DocsPaVO.documento.FileDocumento docFile = FileManager.getFileFirmato(fileRequest, infoUtente, false);
            BusinessLogic.Documenti.DigitalSignature.VerifyTimeStamp vts = new DigitalSignature.VerifyTimeStamp();
            if (vts.Verify(docFile.content, lastTSR).esito != "OK")
            {
                return(null);
            }

            try
            {
                BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.tsd        tsdMgr = new BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.tsd();
                BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile file   = new BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile {
                    Content = docFile.content, Name = docFile.name, MessageFileType = BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.fileType.Binary
                };
                List <BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile> tsrLst  = new List <BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile>();
                BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile        tsrfile = new BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile {
                    Content = lastTSR, MessageFileType = BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.fileType.Binary
                };
                tsrLst.Add(tsrfile);
                docFile.content        = tsdMgr.create(file, tsrLst.ToArray()).Content;
                docFile.estensioneFile = "tsd";
                docFile.fullName       = docFile.fullName + ".tsd";
                docFile.length         = (int)docFile.content.Length;
                docFile.name           = docFile.name + ".tsd";
                docFile.nomeOriginale  = docFile.nomeOriginale + ".tsd";
            }
            catch (Exception e)
            {
                logger.ErrorFormat("Errore creando il TSD!! {0},{1}", e.Message, e.StackTrace);
                return(null);
            }
            DocsPaVO.documento.FileRequest tsdFileReq;
            if (fileRequest.GetType() == typeof(DocsPaVO.documento.Allegato))
            {
                tsdFileReq = new DocsPaVO.documento.Allegato();
                (tsdFileReq as DocsPaVO.documento.Allegato).numeroPagine = (fileRequest as DocsPaVO.documento.Allegato).numeroPagine;
            }
            else
            {
                tsdFileReq = new DocsPaVO.documento.Documento();
            }

            tsdFileReq.docNumber   = fileRequest.docNumber;
            tsdFileReq.descrizione = "Versione creata per conversione in TSD";
            tsdFileReq.firmato     = fileRequest.firmato;
            tsdFileReq             = BusinessLogic.Documenti.VersioniManager.addVersion(tsdFileReq, infoUtente, false);

            if (tsdFileReq != null)
            {
                BusinessLogic.UserLog.UserLog.WriteLog(infoUtente, "DOCUMENTOAGGIUNGIVERSIONE", tsdFileReq.docNumber, string.Format("{0}{1}{2}{3}", "Aggiunta al N.ro Doc.: ", tsdFileReq.docNumber, " la Ver. ", tsdFileReq.version + " di tipo TSD"), DocsPaVO.Logger.CodAzione.Esito.OK);
            }

            else
            {
                BusinessLogic.UserLog.UserLog.WriteLog(infoUtente, "DOCUMENTOAGGIUNGIVERSIONE", tsdFileReq.docNumber, string.Format("{0}{1}{2}{3}", "Aggiunta al N.ro Doc.: ", tsdFileReq.docNumber, " la Ver. ", tsdFileReq.version + " di tipo TSD"), DocsPaVO.Logger.CodAzione.Esito.KO);
            }


            tsdFileReq = BusinessLogic.Documenti.FileManager.putFile(tsdFileReq, docFile, infoUtente);

            List <DocsPaVO.LibroFirma.FirmaElettronica> firmaE = LibroFirma.LibroFirmaManager.GetFirmaElettronicaDaFileRequest(fileRequest);
            bool isFirmatoElettonicamente = firmaE != null && firmaE.Count > 0;

            if (isFirmatoElettonicamente)
            {
                string impronta = string.Empty;
                DocsPaDB.Query_DocsPAWS.Documenti docInfoDB = new DocsPaDB.Query_DocsPAWS.Documenti();
                docInfoDB.GetImpronta(out impronta, tsdFileReq.versionId, tsdFileReq.docNumber);

                foreach (DocsPaVO.LibroFirma.FirmaElettronica firma in firmaE)
                {
                    firma.UpdateXml(impronta, tsdFileReq.versionId, tsdFileReq.version);
                    LibroFirma.LibroFirmaManager.InserisciFirmaElettronica(firma);
                }
            }

            return(tsdFileReq);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Metodo per il download di un file
        /// </summary>
        /// <param name="request">Informazioni sul file da scricare</param>
        /// <returns>Informazioni sul file scaricato e riferimento all'oggetto responsabile della gestione dello streaming dati</returns>
        RemoteFileInfo IFileManager.DownloadFile(SendFileRequest request)
        {
            logger.Debug("BEGIN");
            DocsPaVO.utente.InfoUtente infoUtente = new DocsPaVO.utente.InfoUtente()
            {
                idAmministrazione = request.AdministrationId
            };
            FileRequest fr = new FileRequest()
            {
                docServerLoc = request.DocumentServerLocation,
                path         = request.FilePath,
                fileName     = request.FileName,
                docNumber    = request.DocumentNumber,
                versionId    = request.VersionId,
                versionLabel = request.VersionLabel,
                version      = request.Version
            };

            byte[] lastTSR = null;
            try
            {
                lastTSR = BusinessLogic.Interoperabilità.InteroperabilitaUtils.GetTSRForDocument(infoUtente, fr);
            }
            catch
            { }

            FileDocumento docFile = BusinessLogic.Documenti.FileManager.getFileFirmato(
                fr,
                infoUtente,
                false);

            if (lastTSR != null)
            {
                logger.Debug("TSR presente, incapsulo in TSDiS");
                //controllo il match
                if (!BusinessLogic.Interoperabilità.InteroperabilitaUtils.MatchTSR(lastTSR, docFile.content))
                {
                    lastTSR = null;
                }

                //Gestione TSDis (DOC+TSR)
                //Siccome non si possono mandare piu file allo stesso tempo, ne è possibile alterare la struttura
                //si è pensato:

                //In fase di invio, in caso di documenti con TSR associato, l'invio dello stesso un formato
                //TSD, come marca verrà presa l'ultima disponibile, e unita al documento, creadno un file con estensione TSDis

                //In fase di ricezione il TsdIs, sarà poi spacchettato, il TSR messo in DPA_TIMESTAMP dopo verifica hash e
                //infine il payload messo in documentale con la putfile.



                //tsr presente, combino il tutto per creare un TSDis
                if (lastTSR != null)
                {
                    try
                    {
                        BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.tsd        tsdMgr = new BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.tsd();
                        BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile file   = new BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile {
                            Content = docFile.content, Name = docFile.name, MessageFileType = BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.fileType.Binary
                        };
                        List <BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile> tsrLst  = new List <BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile>();
                        BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile        tsrfile = new BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.CryptoFile {
                            Content = lastTSR, MessageFileType = BusinessLogic.Documenti.DigitalSignature.PKCS_Utils.fileType.Binary
                        };
                        tsrLst.Add(tsrfile);
                        docFile.content  = tsdMgr.create(file, tsrLst.ToArray()).Content;
                        request.FileName = request.FileName + ".TSDis";
                    }
                    catch (Exception e)
                    {
                        logger.ErrorFormat("Error creating TSDID {0} {1}", e.Message, e.StackTrace);
                        //Manca il logger pdpdpdpdp
                    }
                }
            }
            //FileDocumento docFile = BusinessLogic.Documenti.FileManager.getFileFirmato(
            //    new FileRequest()
            //    {
            //        docServerLoc = request.DocumentServerLocation,
            //        path = request.FilePath,
            //        fileName = request.FileName,
            //        docNumber = request.DocumentNumber,
            //        versionId = request.VersionId,
            //        versionLabel = request.VersionLabel
            //    },
            //    new DocsPaVO.utente.InfoUtente()
            //    {
            //        idAmministrazione = request.AdministrationId
            //    },
            //    false);
            logger.Debug("END");
            return(new RemoteFileInfo
            {
                FileData = new MemoryStream(docFile.content, false),
                FileTransferInfo = new FileTransferInfo()
                {
                    FileName = request.FileName,
                    FileLength = docFile.content.Length
                }
            });
        }