Exemplo n.º 1
0
        /// <summary>
        /// Add a password to a serialized GovTalkMessage
        /// </summary>
        /// <param name="inputXDocument"></param>
        /// <param name="userPassword"></param>
        /// <param name="passwordMethod"></param>
        /// <returns></returns>
        public XDocument AddPassword(XDocument inputXDocument, string userPassword, string passwordMethod = "")
        {
            _loggingService.LogInfo(this, "Adding input password via Xml.Linq");

            bool MD5Password = false;

            if ((passwordMethod == "MD5" || _configurationRepository.GetConfigurationValue <string>("SenderAuthenticationMethod") == "MD5") && passwordMethod.ToLower() != "clear")
            {
                MD5Password = true;
                CommonUtilityHelper helper = new CommonUtilityHelper(_configurationRepository, _loggingService);
                userPassword = helper.MD5Hash(userPassword);
            }
            else
            {
                MD5Password = false;
            }

            XElement   root    = XElement.Parse(inputXDocument.ToString(), LoadOptions.PreserveWhitespace);
            XNamespace GovTalk = "http://www.govtalk.gov.uk/CM/envelope";

            //The name of the password element is 'value'.
            // The full path is /GovTalkMessage/Header/SenderDetails/IDAuthentication/Authentication/Value .

            IEnumerable <XElement> PasswordTree =
                (from el in root.Descendants(GovTalk + "Value")
                 select el);

            if (PasswordTree.Count() == 0 || PasswordTree.ElementAt(0).Name.LocalName != "Value")
            {
                _loggingService.LogWarning(this, "Password element not found.");
                return(inputXDocument);
            }

            XElement Password    = PasswordTree.ElementAt(0);
            XElement NewPassword = new XElement(GovTalk + "Value", userPassword);

            Password.ReplaceWith(NewPassword);

            IEnumerable <XElement> MethodTree =
                (from el in root.Descendants(GovTalk + "Method")
                 select el);
            XElement PassMethod = MethodTree.ElementAt(0);
            XElement NewMethod  = MD5Password ? new XElement(GovTalk + "Method", "MD5") : new XElement(GovTalk + "Method", "clear");

            PassMethod.ReplaceWith(NewMethod);

            XDocument outputXDocument = new XDocument(new XDeclaration(inputXDocument.Declaration), root);

            _loggingService.LogInfo(this, "Password added to XDocument.");

            return(outputXDocument);
        }
Exemplo n.º 2
0
        public static string DecompressData(byte[] inputXml)
        {
            //var bytes = Encoding.UTF8.GetBytes(inputXml);

            using (var msi = new MemoryStream(inputXml))
                using (var mso = new MemoryStream())
                {
                    using (var gs = new GZipStream(msi, CompressionMode.Decompress))
                    {
                        CommonUtilityHelper.CopyTo(gs, mso);
                    }

                    return(Encoding.UTF8.GetString(mso.ToArray()));
                }
        }
Exemplo n.º 3
0
        public override string ToString()
        {
            string filename = string.Concat(FilePath, Environment, MessageIntention, Timestamp, CorrelationId, MessageQualifier, CustomNamePart, FILE_EXT);

            // if there are any SEPARATOR chars, remove the last one
            if (filename.Contains(SEPARATOR))
            {
                filename = CommonUtilityHelper.ReverseString(filename);
                filename = CommonUtilityHelper.ReplaceFirst(filename, SEPARATOR, String.Empty);
                filename = CommonUtilityHelper.ReverseString(filename);
            }

            return(validateFileName(filename));
            //return base.ToString();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add a password to a serialized GovTalkMessage
        /// </summary>
        /// <param name="inputXDocument"></param>
        /// <param name="userPassword"></param>
        /// <param name="passwordMethod"></param>
        /// <returns></returns>
        public XDocument AddPassword( XDocument inputXDocument, string userPassword, string passwordMethod = "")
        {
            _loggingService.LogInfo(this, "Adding input password via Xml.Linq");

            bool MD5Password = false;

            if ((passwordMethod == "MD5" || _configurationRepository.GetConfigurationValue<string>("SenderAuthenticationMethod") == "MD5") && passwordMethod.ToLower() != "clear")
            {
                MD5Password = true;
                CommonUtilityHelper helper = new CommonUtilityHelper(_configurationRepository, _loggingService);
                userPassword = helper.MD5Hash(userPassword);
            }
            else
            {
                MD5Password = false;
            }

            XElement root = XElement.Parse(inputXDocument.ToString(), LoadOptions.PreserveWhitespace);
            XNamespace GovTalk = "http://www.govtalk.gov.uk/CM/envelope";

            //The name of the password element is 'value'.
            // The full path is /GovTalkMessage/Header/SenderDetails/IDAuthentication/Authentication/Value .

            IEnumerable<XElement> PasswordTree =
                    (from el in root.Descendants(GovTalk + "Value")
                     select el);
            if (PasswordTree.Count() == 0 || PasswordTree.ElementAt(0).Name.LocalName != "Value")
            {
                _loggingService.LogWarning(this, "Password element not found.");
                return inputXDocument;
            }

            XElement Password = PasswordTree.ElementAt(0);
            XElement NewPassword = new XElement(GovTalk + "Value", userPassword);
            Password.ReplaceWith(NewPassword);

            IEnumerable<XElement> MethodTree =
                    (from el in root.Descendants(GovTalk + "Method")
                     select el);
            XElement PassMethod = MethodTree.ElementAt(0);
            XElement NewMethod = MD5Password ? new XElement(GovTalk + "Method", "MD5") : new XElement(GovTalk + "Method", "clear");
            PassMethod.ReplaceWith(NewMethod);

            XDocument outputXDocument = new XDocument(new XDeclaration(inputXDocument.Declaration), root);
            _loggingService.LogInfo(this, "Password added to XDocument.");

            return outputXDocument;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set a password within a GovTalkMessage object
        /// </summary>
        /// <param name="govTalkMessage"></param>
        /// <param name="userPassword"></param>
        /// <param name="passwordMethod"></param>
        public void SetPassword(GovTalkMessage govTalkMessage, string userPassword, string passwordMethod = "")
        {
            _loggingService.LogInfo(this, "Setting password.");

            if ((passwordMethod == "MD5" || _configurationRepository.GetConfigurationValue <string>("SenderAuthenticationMethod") == "MD5") && passwordMethod.ToLower() != "clear")
            {
                CommonUtilityHelper helper = new CommonUtilityHelper(_configurationRepository, _loggingService);

                govTalkMessage.Header.SenderDetails.IDAuthentication.Authentication[0].Method = GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthenticationMethod.MD5;

                userPassword = helper.MD5Hash(userPassword);

                _loggingService.LogDebug(this, "MD5 Hashed password.");
            }
            if (passwordMethod.ToLower() == "clear")
            {
                govTalkMessage.Header.SenderDetails.IDAuthentication.Authentication[0].Method = GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthenticationMethod.clear;
            }

            govTalkMessage.Header.SenderDetails.IDAuthentication.Authentication[0].Item = userPassword;

            _loggingService.LogInfo(this, "Password set.");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Set a password within a GovTalkMessage object
        /// </summary>
        /// <param name="govTalkMessage"></param>
        /// <param name="userPassword"></param>
        /// <param name="passwordMethod"></param>
        public void SetPassword(GovTalkMessage govTalkMessage, string userPassword, string passwordMethod = "")
        {
            _loggingService.LogInfo(this, "Setting password.");

            if((passwordMethod == "MD5" || _configurationRepository.GetConfigurationValue<string>("SenderAuthenticationMethod") == "MD5") && passwordMethod.ToLower() != "clear")
            {
                CommonUtilityHelper helper = new CommonUtilityHelper(_configurationRepository,_loggingService);

                govTalkMessage.Header.SenderDetails.IDAuthentication.Authentication[0].Method = GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthenticationMethod.MD5;

                userPassword = helper.MD5Hash(userPassword);

                _loggingService.LogDebug(this, "MD5 Hashed password.");
            }
            if(passwordMethod.ToLower() == "clear")
            {
                govTalkMessage.Header.SenderDetails.IDAuthentication.Authentication[0].Method = GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthenticationMethod.clear;
            }

            govTalkMessage.Header.SenderDetails.IDAuthentication.Authentication[0].Item = userPassword;

            _loggingService.LogInfo(this, "Password set.");
        }