Esempio n. 1
0
        public static string SanitizePhoneNumber(string displayedPhoneNumber, WebClientConfig cfg)
        {
            if (cfg == null)
            {
                throw new ArgumentNullException("WebClientConfig");
            }
            if (!cfg.SanitizePhoneNumber)
            {
                return(displayedPhoneNumber);
            }
            string msisdn = cfg.SanitizePhoneNumberRegex.Replace(displayedPhoneNumber, cfg.SanitizePhoneNumberReplacement);
            int    len    = msisdn.Length;

            if (len < AuthRequestDto.MIN_MSISDN_DIGITS || len > AuthRequestDto.MAX_MSISDN_DIGITS)
            {
                throw new ArgumentOutOfRangeException("lengthMsisdnSanitized", len.ToString());
            }
            ;
            return(msisdn);
        }
Esempio n. 2
0
        public static WebClientConfig CreateConfig(TextReader cfgStream)
        {
            if (cfgStream == null)
            {
                throw new ArgumentNullException("input stream is null");
            }
            WebClientConfig cfg = new WebClientConfig();

            XmlReaderSettings xmlSetting = new XmlReaderSettings();

            xmlSetting.CloseInput = true;
            xmlSetting.IgnoreProcessingInstructions = true;
            xmlSetting.IgnoreWhitespace             = true;
            using (XmlReader xml = XmlReader.Create(cfgStream, xmlSetting))
            {
                String s;
                while (xml.Read())
                {
                    // we process only the <mobileIdClient .../> element
                    if (xml.Name == "mobileIdClient")
                    {
                        // Warning: Due to input validation, the processing order of the attributes may be important.
                        cfg.ApId       = xml["AP_ID"];
                        cfg.DtbsPrefix = xml["DtbsPrefix"];
                        if (!string.IsNullOrWhiteSpace(s = xml["RequestTimeOutSeconds"]))
                        {
                            cfg.RequestTimeOutSeconds = int.Parse(s);
                        }
                        cfg.ServiceUrlPrefix = xml["ServiceUrlPrefix"];
                        if (!string.IsNullOrEmpty(s = xml["SrvSideValidation"]))
                        {
                            cfg.SrvSideValidation = bool.Parse(s);
                        }
                        cfg.SslCertThumbprint = xml["SslCertThumbprint"];
                        if (!string.IsNullOrEmpty(s = xml["SslKeystore"]))
                        {
                            cfg.SslKeystore = Util.ParseKeyStoreLocation(s);
                        }
                        if (!string.IsNullOrEmpty(s = xml["SslRootCaCertDN"]))
                        {
                            cfg.SslRootCaCertDN = s;
                        }
                        if (!string.IsNullOrEmpty(s = xml["EnableSubscriberInfo"]))
                        {
                            cfg.EnableSubscriberInfo = Boolean.Parse(s);
                        }
                        cfg.SeedApTransId = xml["SeedApTransId"];
                        // PollResponse* must be parsed after RequestTimeOutSeconds due to input validation
                        if (!string.IsNullOrWhiteSpace(s = xml["PollResponseDelaySeconds"]))
                        {
                            cfg.PollResponseDelaySeconds = int.Parse(s);
                        }
                        if (!string.IsNullOrWhiteSpace(s = xml["PollResponseIntervalSeconds"]))
                        {
                            cfg.PollResponseIntervalSeconds = int.Parse(s);
                        }
                        if (!string.IsNullOrWhiteSpace(s = xml["UserSerialNumberPolicy"]))
                        {
                            cfg.UserSerialNumberPolicy = (UserSerialNumberPolicy)Enum.Parse(typeof(UserSerialNumberPolicy), s, true);
                        }
                        if (!string.IsNullOrWhiteSpace(s = xml["DisableSignatureValidation"]))
                        {
                            cfg.DisableSignatureValidation = Boolean.Parse(s);
                        }
                        if (!string.IsNullOrWhiteSpace(s = xml["DisableSignatureCertValidation"]))
                        {
                            cfg.DisableSignatureCertValidation = Boolean.Parse(s);
                        }
                        if ((s = xml["SanitizePhoneNumber"]) != null)
                        {
                            cfg.SanitizePhoneNumber = bool.Parse(s);
                        }
                        if (cfg.SanitizePhoneNumber)
                        {
                            if ((s = xml["SanitizePhoneNumberPattern"]) != null)
                            {
                                cfg.SanitizePhoneNumberPattern = s;
                            }
                            if ((s = xml["SanitizePhoneNumberReplacement"]) != null)
                            {
                                cfg.SanitizePhoneNumberReplacement = s;
                            }
                        }
                        ;
                        // TODO: update on change of properties

                        break;
                    }
                }
                xml.Close();
            }

            return(cfg);
        }