예제 #1
0
        /// <summary>
        /// Generates an XML file (either generates the full XML or an incremental file).
        /// </summary>
        /// <param name="nextTransactionId">Indicates if a full XML file should be generated
        /// or just a partial incremental file.</param>
        /// <returns>Returns an XML stream of the file content.</returns>
        public ParsePollRequestResult GenerateRecordEnsemble(string nextTransactionId)
        {
            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "Begin - SyncManager - GenerateRecordEnsemble transaction ID :" + nextTransactionId);
            ParsePollRequestResult pollResult = new ParsePollRequestResult();
            XmlDocument            xmldoc     = null;

            // get data from azure tables
            NextTransactionID reqTransId = this.dalcDbSync.GetRequestorTransactionId(nextTransactionId);

            // Bad Request
            if (reqTransId == null)
            {
                pollResult.RTResponseCode = PollStatus.BadRequest;
            }
            else if (reqTransId.Timestamp.AddHours(72) >= DateTime.Now)
            {
                // Transaction ID not older than 72 hour - ok
                try
                {
                    xmldoc = this.BuildRecordEnsumble(DbSyncScope.INC, reqTransId, "External");
                }
                catch
                {
                    throw;
                }

                xmldoc = XmlCryptography.SignXmlDcoument(Utils.GetFilePathForConfigKey("SignCertificate"), xmldoc);
                pollResult.ResponseData = xmldoc.OuterXml;
                XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmldoc.NameTable);
                namespaceManager.AddNamespace("ren", xmldoc.DocumentElement.NamespaceURI);

                XmlNodeList nodelist = xmldoc.SelectNodes("//ren:Registration", namespaceManager);
                if (nodelist != null && nodelist.Count > 0)
                {
                    this.VerifyRecordEnsembleGenerated(xmldoc);

                    pollResult.RTResponseCode    = PollStatus.Success;
                    pollResult.ResponseData      = xmldoc.OuterXml;
                    pollResult.NextTransactionId = xmldoc.SelectSingleNode("//ren:NextTransactionID", namespaceManager).InnerXml;
                }
                else
                {
                    pollResult.RTResponseCode    = PollStatus.NoNewRecords;
                    pollResult.NextTransactionId = xmldoc.SelectSingleNode("//ren:NextTransactionID", namespaceManager).InnerXml;
                }
            }
            else if (reqTransId.Timestamp.AddHours(72) < DateTime.Now)
            {
                // Transaction ID Stale > 72 hours
                pollResult.RTResponseCode = PollStatus.TransactionIDStale;
            }

            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "End - SyncManager - GenerateRecordEnsemble transaction ID :" + nextTransactionId);
            return(pollResult);
        }
예제 #2
0
 /// <summary>
 ///  validates xml file for signature and schema
 /// </summary>
 /// <param name="xmlDoc">xml document to be verified</param>
 private void VerifyRecordEnsembleGenerated(XmlDocument xmlDoc)
 {
     if (!XmlCryptography.IsXmlSignValidByFile(xmlDoc, Utils.GetFilePathForConfigKey("PrivateCertificate")))
     {
         this.logger.Log(TraceEventType.Error, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:, SyncManager.VerifyRecordEnsembleGenerated - XML signature mismatched and not verified with the certificate. please check the xml file received.");
         throw new CryptographicException("Xml signature is not matching.");
     }
     else if (!this.IsXmlValidWithSchema(xmlDoc))
     {
         this.logger.Log(TraceEventType.Error, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:, SyncManager.VerifyRecordEnsembleGenerated - XML file is invalid. please check the xml file received.");
         throw new XmlException("Xml file schema validaion failed.");
     }
 }
예제 #3
0
        /// <summary>
        /// Validates the xml signature of the xml document.
        /// </summary>
        /// <param name="doc"> xml document containing the xml signature to be validated</param>
        /// <param name="key">public key of the administrator</param>
        /// <returns> Returns boolean </returns>
        public bool IsXMLSignatureValid(XmlDocument doc, string key)
        {
            bool success = false;

            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "Begin - SyncManager - IsXMLSignatureValid - Xml Documents signature verification");
            try
            {
                success = XmlCryptography.IsXmlSignValid(doc, key);
            }
            catch (CryptographicException e)
            {
                this.logger.Log(TraceEventType.Critical, LoggingMessageId.DBSyncPollerGenericMessage, e.ToString());
            }

            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "End - SyncManager - IsXMLSignatureValid - Xml Documents signature verification");
            return(success);
        }
예제 #4
0
        /// <summary>
        /// Generates an XML file (either generates the full XML).
        /// </summary>
        /// <param name="scope">Indicates if a full XML file should be generated
        /// or just a partial incremental file.</param>
        /// <returns>Returns an XML string of the file content.</returns>
        public string GenerateRecordEnsemble(DbSyncScope scope)
        {
            string wsdba = Utils.Configuration[Constants.ConfigSettingWSDBAName];

            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "Begin - SyncManager - GenerateRecordEnsemble scope :" + scope);
            XmlDocument xmlDocAll            = new XmlDocument();
            string      signedOutputFilePath = null;

            try
            {
                NextTransactionID reqTransId = this.dalcDbSync.GetRequestorTransactionId(wsdba, scope);

                // generating xml Doc
                xmlDocAll = this.BuildRecordEnsumble(scope, reqTransId, wsdba);

                // Registrations count check
                if (this.registrationExist)
                {
                    // Signing the XML
                    xmlDocAll = XmlCryptography.SignXmlDcoument(Utils.GetFilePathForConfigKey("SignCertificate"), xmlDocAll);
                    this.VerifyRecordEnsembleGenerated(xmlDocAll);

                    // <n1:NextTransactionID/>
                    string timeStamp            = "F" + DateTime.Now.ToFileTime() + "\\";
                    string signedOutPutFileName = Utils.Configuration["Registrar"] + ".V" + Utils.Configuration["DBSyncVersionNo"] + "." + scope.ToString() + "." + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "T" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "Z";
                    if (!Directory.Exists(Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp))
                    {
                        Directory.CreateDirectory(Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp);
                    }

                    signedOutputFilePath = Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp + signedOutPutFileName + ".xml";

                    XmlTextWriter writer = null;

                    // Saving signed xml to file
                    using (writer = new XmlTextWriter(signedOutputFilePath, null))
                    {
                        writer.Formatting = Formatting.Indented;
                        xmlDocAll.Save(writer);
                    }

                    // compressing the xml file
                    this.CreateZipFile(Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp + signedOutPutFileName + ".xml", Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp + signedOutPutFileName + ".zip", signedOutPutFileName + ".xml");
                    if (scope == DbSyncScope.ALL)
                    {
                        this.dalcDbSync.UploadAllRegistrationsFile(Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp + signedOutPutFileName + ".zip", Utils.Configuration["ALLFileBlobContainer"], signedOutPutFileName + ".zip");
                    }
                    else
                    {
                        this.dalcDbSync.UploadINCRegistrationsFile(Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp + signedOutPutFileName + ".zip", Utils.Configuration["INCFileBlobContainer"], signedOutPutFileName + ".zip");
                    }
                }
                else
                {
                    // No Records found case.
                    this.auditor.Audit(AuditId.DBSyncFileGenerated, AuditStatus.Success, 0, "File Service : No Records Found");
                    return("No Records Found");
                }
            }
            catch
            {
                throw;
            }

            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "End - SyncManager - GenerateRecordEnsemble scope :" + scope);
            return(signedOutputFilePath);
        }