public bool ValidateServerCertficate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                return(true);
            }

            if (m_acceptAll)
            {
                return(true);
            }

            string certHash = null;

            try
            {
                certHash = Utility.ByteArrayAsHexString(cert.GetCertHash());
                if (certHash != null && m_validHashes != null)
                {
                    foreach (var hash in m_validHashes)
                    {
                        if (!string.IsNullOrEmpty(hash) && certHash.Equals(hash, StringComparison.OrdinalIgnoreCase))
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(Strings.SslCertificateValidator.VerifyCertificateHashError(ex, sslPolicyErrors), ex);
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Encodes a URL, like System.Web.HttpUtility.UrlEncode
        /// </summary>
        /// <returns>The encoded URL</returns>
        /// <param name="value">The URL fragment to encode</param>
        /// <param name="encoding">The encoding to use</param>
        public static string UrlEncode(string value, System.Text.Encoding encoding = null, string spacevalue = "+")
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            encoding = encoding ?? System.Text.Encoding.UTF8;

            var encoder  = encoding.GetEncoder();
            var inbuf    = new char[1];
            var outbuf   = new byte[2];
            var shortout = new byte[1];

            return(RE_ESCAPECHAR.Replace(value, (m) => {
                if (m.Value == " ")
                {
                    return spacevalue;
                }

                inbuf[0] = m.Value[0];

                try
                {
                    var len = encoder.GetBytes(inbuf, 0, 1, outbuf, 0, true);
                    if (len == 1)
                    {
                        shortout[0] = outbuf[0];
                        return "%" + Utility.ByteArrayAsHexString(shortout).ToLower();
                    }
                    else if (len == 2)
                    {
                        return "%u" + Utility.ByteArrayAsHexString(outbuf).ToLower();
                    }
                }
                catch
                {
                }

                //Fallback
                return m.Value;
            }));
        }
Esempio n. 3
0
        /// <inheritdoc />
        public string GetFilterHash()
        {
            var hash = MD5HashHelper.GetHash(m_filters?.Select(x => x.Filter));

            return(Utility.ByteArrayAsHexString(hash));
        }
Esempio n. 4
0
 public string GetFinalHashString()
 {
     return(Utility.ByteArrayAsHexString(this.GetFinalHash()));
 }