예제 #1
0
        /// <summary>
        /// Reperimento del TSR del docNumber all'ultima versione
        /// </summary>
        /// <param name="infoUtente"></param>
        /// <param name="docNumer"></param>
        /// <returns></returns>
        private static string getTimeStampForDocNumber(DocsPaVO.utente.InfoUtente infoUtente, string docNumer)
        {
            string retval = null;

            string      versione = BusinessLogic.Documenti.VersioniManager.getLatestVersionID(docNumer, infoUtente);
            FileRequest frTS     = new FileRequest {
                docNumber = docNumer, versionId = versione
            };
            ArrayList tsAL = BusinessLogic.Documenti.TimestampManager.getTimestampsDoc(infoUtente, frTS);

            foreach (DocsPaVO.documento.TimestampDoc ts  in tsAL)
            {
                if (!string.IsNullOrEmpty(ts.TSR_FILE))
                {
                    byte[] tsrBin      = Convert.FromBase64String(ts.TSR_FILE);
                    byte[] fileContent = GetFileDocumento(infoUtente, docNumer).FileContent;
                    bool   match       = new Documenti.DigitalSignature.VerifyTimeStamp().machTSR(tsrBin, fileContent);

                    //Luluciani: per evitare problema Export tsr non valide  Zanotti
                    // if (match)
                    retval = ts.TSR_FILE;
                }
                break;
            }
            return(retval);
        }
예제 #2
0
        /// <summary>
        /// Prova a tovare un match con il TSR verso i file nella cartella
        /// </summary>
        /// <param name="path"></param>
        /// <param name="tsrFileName"></param>
        /// <returns>In caso di associabilità torna true, altrimenti da false</returns>
        public static bool FindTSRMatch(string path, string tsrFileName)
        {
            bool retval = false;

            try
            {
                if (!Path.GetExtension(tsrFileName).ToLowerInvariant().Contains("tsr"))
                {
                    return(false);
                }
                byte[] tsrFile = File.ReadAllBytes(path + "\\" + tsrFileName);

                BusinessLogic.Documenti.DigitalSignature.VerifyTimeStamp vts = new Documenti.DigitalSignature.VerifyTimeStamp();
                string[] Files = Directory.GetFiles(path);

                foreach (string file in Files)
                {
                    if (!Path.GetExtension(file).ToLowerInvariant().Contains("tsr"))
                    {
                        byte[] FileTocheck = File.ReadAllBytes(file);
                        retval = vts.machTSR(tsrFile, FileTocheck);
                        if (retval)
                        {
                            return(retval);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logger.ErrorFormat("Errore Cercando il TSR {0} : {1}", e.Message, e.StackTrace);
            }
            return(retval);
        }
예제 #3
0
        /// <summary>
        /// Associa un TSR a un documento ricevuto
        /// </summary>
        /// <param name="path">path dove sono presenti i file ricevuti in mail</param>
        /// <param name="fr">filerequest</param>
        /// <param name="fd">filedocumento</param>
        /// <param name="infoUtente">infoutente</param>
        /// <returns>False in caso di fallimento</returns>
        public static bool MatchTSR(string path, DocsPaVO.documento.FileRequest fr, DocsPaVO.documento.FileDocumento fd, DocsPaVO.utente.InfoUtente infoUtente)
        {
            bool retval = false;

            string[] tsrFiles = Directory.GetFiles(path, "*.tsr");
            //se non ci sono TSR
            if (tsrFiles.Length == 0)
            {
                return(false);
            }

            if (Path.GetExtension(fr.fileName).ToLowerInvariant() == ".tsr")
            {
                //logger.DebugFormat ("Il file è un TSR, non associo un TSR a un TSR");
                return(false);
            }

            BusinessLogic.Documenti.DigitalSignature.VerifyTimeStamp vts = new Documenti.DigitalSignature.VerifyTimeStamp();
            string fdFileName = path + "\\" + fr.fileName;

            foreach (string file in tsrFiles)
            {
                // byte[] tsrFile = File.ReadAllBytes(file);

                byte[] tsrFile;
                if (fdFileName.ToLowerInvariant().Equals(file.ToLowerInvariant()))
                {
                    tsrFile = fd.content;
                }
                else
                {
                    System.IO.FileStream fsAll = new System.IO.FileStream(file, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read);
                    tsrFile = new byte[fsAll.Length];
                    fsAll.Read(tsrFile, 0, (int)fsAll.Length);
                    fsAll.Close();
                }
                try
                {
                    if (vts.machTSR(tsrFile, fd.content))
                    {
                        logger.DebugFormat("Provo TSR {0}", file);
                        DocsPaVO.areaConservazione.OutputResponseMarca resultMarca = vts.Verify(fd.content, tsrFile);
                        if (resultMarca.esito == "OK")
                        {
                            DocsPaDB.Query_DocsPAWS.TimestampDoc timestampDoc = new DocsPaDB.Query_DocsPAWS.TimestampDoc();
                            timestampDoc.saveTSR(infoUtente, resultMarca, fr);
                            logger.DebugFormat("Associato TSR al documento {0} {1}", fr.docNumber, fr.versionId);
                            retval = true;
                        }
                    }
                }
                catch (Exception e1)
                {
                    logger.ErrorFormat("Errore Cercando di associare il TSR {0} : {1}", e1.Message, e1.StackTrace);
                }
            }
            return(retval);
        }
예제 #4
0
 public static bool MatchTSR(byte[] tsrFile, byte[] content)
 {
     try
     {
         BusinessLogic.Documenti.DigitalSignature.VerifyTimeStamp vts = new Documenti.DigitalSignature.VerifyTimeStamp();
         if (vts.machTSR(tsrFile, content))
         {
             DocsPaVO.areaConservazione.OutputResponseMarca resultMarca = vts.Verify(content, tsrFile);
             if (resultMarca.esito == "OK")
             {
                 return(true);
             }
         }
     }
     catch (Exception e)
     {
         logger.ErrorFormat("Errore verificando il TSR {0} {1}", e.Message, e.StackTrace);
     }
     return(false);
 }
예제 #5
0
        /// <summary>
        /// Metodo per il download di un file associato ad un documento
        /// </summary>
        /// <param name="documentInfo">Informazioni sul documento</param>
        /// <param name="senderAdministrationId">Id dell'amministrazione</param>
        /// <param name="fileRequest">Informazioni sul file richiesto</param>
        /// <param name="userInfo">Informazioni sull'utente con cui recuperare il file</param>
        /// <param name="senderFileManagerUrl">Url del servizio per la gestione dei file</param>
        public static void DownloadFile(DocumentInfo documentInfo, String senderAdministrationId, FileRequest fileRequest, InfoUtente userInfo, String senderFileManagerUrl, out string errPutFile)
        {
            logger.Debug("BEGIN");
            // Reperimento del file
            InteroperabilityController interoperabilityController = new InteroperabilityController();

            Interoperability.Service.Library.FileServiceReference.RemoteFileInfo fileResponse = interoperabilityController.DownloadFile(
                new Interoperability.Service.Library.FileServiceReference.SendFileRequest(
                    senderAdministrationId,
                    documentInfo.DocumentNumber,
                    documentInfo.DocumentServerLocation,
                    documentInfo.FileName,
                    documentInfo.FilePath,
                    documentInfo.Version,
                    documentInfo.VersionId,
                    documentInfo.VersionLabel),
                senderFileManagerUrl);

            // Caricamento del file in DocsPa
            byte[] documentContent = ReadFileContent(fileResponse.FileData, (int)fileResponse.FileTransferInfo.FileLength);

            FileDocumento fileDocument = new FileDocumento()
            {
                content = documentContent,
                length  = (int)fileResponse.FileTransferInfo.FileLength,
                name    = fileResponse.FileTransferInfo.FileName
            };

            String err = String.Empty;

            //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.


            DocsPaVO.areaConservazione.OutputResponseMarca resultMarca = null;
            if (Path.GetExtension(fileDocument.name) == ".TSDis")
            {
                try
                {
                    Documenti.DigitalSignature.PKCS_Utils.tsd tsdMgr = new Documenti.DigitalSignature.PKCS_Utils.tsd();
                    tsdMgr.explode(fileDocument.content);
                    fileDocument.content = tsdMgr.Data.Content;
                    fileDocument.length  = (int)fileDocument.content.Length;
                    fileDocument.name    = fileDocument.name.Replace(".TSDis", string.Empty);
                    Documenti.DigitalSignature.VerifyTimeStamp vts = new Documenti.DigitalSignature.VerifyTimeStamp();
                    byte[] tsrFile = tsdMgr.TSR.FirstOrDefault().Content;
                    if (vts.machTSR(tsrFile, fileDocument.content))
                    {
                        resultMarca = vts.Verify(fileDocument.content, tsrFile);
                    }
                }
                catch (Exception e)
                {
                    logger.ErrorFormat("Errore gestendo il TSDis {0} {1}", e.Message, e.StackTrace);
                    //manca il loggher pdpdpdpdp
                }
            }

            FileManager.putFile(ref fileRequest, fileDocument, userInfo, out errPutFile, false);
            if (resultMarca != null && resultMarca.esito == "OK")
            {
                DocsPaDB.Query_DocsPAWS.TimestampDoc timestampDoc = new DocsPaDB.Query_DocsPAWS.TimestampDoc();
                timestampDoc.saveTSR(userInfo, resultMarca, fileRequest);
            }

            logger.Debug("END");
        }