Exemplo n.º 1
0
 /// <summary>
 /// Constructor with host attributes
 /// </summary>
 /// <param name="nameAttribute">The name attribute.</param>
 /// <param name="hostAttribute">The remote host attribute.</param>
 /// <param name="portAttribute">The remote port attribute.</param>
 /// <param name="maxNumClientsAttribute">The remote max number clients attribute.</param>
 /// <param name="clientTimeOutAttribute">The remote client timeout attribute.</param>
 /// <param name="pathAttribute">The remote prefix path attribute.</param>
 /// <param name="authenticationAttribute">The authentication attribute.</param>
 public HttpHostElement(String nameAttribute, String hostAttribute, Int32 portAttribute,
                        Int32 maxNumClientsAttribute, Int32 clientTimeOutAttribute, String pathAttribute,
                        System.Net.AuthenticationSchemes authenticationAttribute)
 {
     NameAttribute           = nameAttribute;
     HostAttribute           = hostAttribute;
     PortAttribute           = portAttribute;
     MaxNumClientsAttribute  = maxNumClientsAttribute;
     ClientTimeOutAttribute  = clientTimeOutAttribute;
     PathAttribute           = pathAttribute;
     AuthenticationAttribute = authenticationAttribute;
 }
Exemplo n.º 2
0
        internal void ParseAuthentication(System.Net.AuthenticationSchemes expectedSchemes)
        {
            if (expectedSchemes == System.Net.AuthenticationSchemes.Anonymous)
            {
                return;
            }

            string header = Request.Headers["Authorization"];

            if (string.IsNullOrEmpty(header))
            {
                return;
            }

            if (IsBasicHeader(header))
            {
                _user = ParseBasicAuthentication(header.Substring(AuthenticationTypes.Basic.Length + 1));
            }
        }
Exemplo n.º 3
0
 internal static string AuthorizationHeader(Encoding encoding, RtspMethod method, Uri location, System.Net.AuthenticationSchemes scheme, System.Net.NetworkCredential credential, string qopPart = null, string ncPart = null, string nOncePart = null, string cnOncePart = null, string opaquePart = null, bool rfc2069 = false, string algorithmPart = null, string bodyPart = null)
 {
     return(Http.HttpHeaders.AuthorizationHeader(encoding, method.ToString(), location, scheme, credential, qopPart, ncPart, nOncePart, cnOncePart, opaquePart, rfc2069, algorithmPart, bodyPart));
 }
Exemplo n.º 4
0
        //string method
        internal protected static string AuthorizationHeader(Encoding encoding, string methodString, Uri location, System.Net.AuthenticationSchemes scheme, System.Net.NetworkCredential credential, string qopPart = null, string ncPart = null, string nOncePart = null, string cnOncePart = null, string opaquePart = null, bool rfc2069 = false, string algorithmPart = null, string bodyPart = null)
        {
            string result = string.Empty;

            switch (scheme)
            {
            case System.Net.AuthenticationSchemes.None: break;

            case System.Net.AuthenticationSchemes.Basic:
            {
                //http://en.wikipedia.org/wiki/Basic_access_authentication
                //Don't use the domain.

                //Don't use `basic` because apparently case is REALLY important at this point...
                //result = string.Concat(Http.HeaderFields.Authorization.Basic, new string((char)Common.ASCII.Space, 1), Convert.ToBase64String(encoding.GetBytes(credential.UserName + ':' + credential.Password)));

                result = string.Concat("Basic", new string((char)Common.ASCII.Space, 1), Convert.ToBase64String(encoding.GetBytes(credential.UserName + ':' + credential.Password)));

                break;
            }

            case System.Net.AuthenticationSchemes.Digest:
            {
                //http://www.ietf.org/rfc/rfc2617.txt

                //Example
                //Authorization: Digest username="******", realm="GeoVision", nonce="b923b84614fc11c78c712fb0e88bc525", uri="rtsp://203.11.64.27:8554/CH001.sdp", response="d771e4e5956e3d409ce5747927db10af"\r\n

                //Todo Check that Digest works with Options * or when uriPart is \

                string usernamePart = credential.UserName,
                       realmPart    = credential.Domain ?? "//",
                       uriPart      = location != null && location.IsAbsoluteUri ? location.AbsoluteUri : new String((char)Common.ASCII.BackSlash, 1);

                if (string.IsNullOrWhiteSpace(nOncePart))
                {
                    //Contains two sequential 32 bit units from the Random generator for now
                    nOncePart = ((long)(Utility.Random.Next(int.MaxValue) << 32 | Utility.Random.Next(int.MaxValue))).ToString("X");
                }

                //Need to look at this again
                if (false == string.IsNullOrWhiteSpace(qopPart))
                {
                    if (false == string.IsNullOrWhiteSpace(ncPart))
                    {
                        ncPart = (int.Parse(ncPart) + 1).ToString();
                    }
                    else
                    {
                        ncPart = "00000001";
                    }

                    if (string.IsNullOrWhiteSpace(cnOncePart))
                    {
                        cnOncePart = Utility.Random.Next(int.MaxValue).ToString("X");
                    }
                }

                //http://en.wikipedia.org/wiki/Digest_access_authentication
                //The MD5 hash of the combined username, authentication realm and password is calculated. The result is referred to as HA1.
                byte[] HA1 = Cryptography.MD5.GetHash(encoding.GetBytes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}:{2}", credential.UserName, realmPart, credential.Password)));

                //The MD5 hash of the combined method and digest URI is calculated, e.g. of "GET" and "/dir/index.html". The result is referred to as HA2.
                byte[] HA2 = null;

                //Need to format based on presence of fields qop...
                byte[] ResponseHash;

                //If there is a Quality of Protection
                if (qopPart != null)
                {
                    if (qopPart.Equals(Http.HeaderFields.Authorization.Attributes.qop, StringComparison.OrdinalIgnoreCase))
                    {
                        HA2 = Cryptography.MD5.GetHash(encoding.GetBytes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}", methodString, uriPart)));
                        //The MD5 hash of the combined HA1 result, server nonce (nonce), request counter (nc), client nonce (cnonce), quality of protection code (qop) and HA2 result is calculated. The result is the "response" value provided by the client.
                        ResponseHash = Cryptography.MD5.GetHash(encoding.GetBytes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}:{2}:{3}:{4}:{5}", BitConverter.ToString(HA1).Replace("-", string.Empty).ToLowerInvariant(), nOncePart, BitConverter.ToString(HA2).Replace("-", string.Empty).ToLowerInvariant(), ncPart, cnOncePart, qopPart)));
                        result       = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Digest username=\"{0}\", realm=\"{1}\", nonce=\"{2}\", uri=\"{3}\", qop=\"{4}\" nc=\"{5} cnonce=\"{6}\"", usernamePart, realmPart, nOncePart, uriPart, qopPart, ncPart, cnOncePart);
                        if (false == string.IsNullOrWhiteSpace(opaquePart))
                        {
                            result += "opaque=\"" + opaquePart + '"';
                        }
                    }
                    else if (qopPart.Equals(Http.HeaderFields.Authorization.Attributes.authint, StringComparison.OrdinalIgnoreCase))
                    {
                        HA2 = Cryptography.MD5.GetHash(encoding.GetBytes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}:{2}", methodString, uriPart, Cryptography.MD5.GetHash(encoding.GetBytes(bodyPart)))));
                        //The MD5 hash of the combined HA1 result, server nonce (nonce), request counter (nc), client nonce (cnonce), quality of protection code (qop) and HA2 result is calculated. The result is the "response" value provided by the client.
                        ResponseHash = Cryptography.MD5.GetHash(encoding.GetBytes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}:{2}:{3}:{4}:{5}", BitConverter.ToString(HA1).Replace("-", string.Empty).ToLowerInvariant(), nOncePart, BitConverter.ToString(HA2).Replace("-", string.Empty).ToLowerInvariant(), ncPart, cnOncePart, qopPart)));
                        result       = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Digest username=\"{0}\", realm=\"{1}\", nonce=\"{2}\", uri=\"{3}\", qop=\"{4}\" nc=\"{5} cnonce=\"{6}\"", usernamePart, realmPart, nOncePart, uriPart, qopPart, ncPart, cnOncePart);
                        if (string.IsNullOrWhiteSpace(opaquePart).Equals(false))
                        {
                            result += "opaque=\"" + opaquePart + '"';
                        }
                    }
                    else
                    {
                        throw new NotImplementedException("Quality Of Protection:" + qopPart);
                    }
                }
                else         // No Quality of Protection
                {
                    HA2          = Cryptography.MD5.GetHash(encoding.GetBytes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}", methodString, uriPart)));
                    ResponseHash = Cryptography.MD5.GetHash(encoding.GetBytes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}:{2}", BitConverter.ToString(HA1).Replace("-", string.Empty).ToLowerInvariant(), nOncePart, BitConverter.ToString(HA2).Replace("-", string.Empty).ToLowerInvariant())));
                    result       = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Digest username=\"{0}\", realm=\"{1}\", nonce=\"{2}\", uri=\"{3}\", response=\"{4}\"", usernamePart, realmPart, nOncePart, uriPart, BitConverter.ToString(ResponseHash).Replace("-", string.Empty).ToLowerInvariant());
                }

                break;
            }

            default: throw new ArgumentException("Must be either None, Basic or Digest", "scheme");
            }

            return(result);
        }
Exemplo n.º 5
0
 public void set_AuthenticationSchemes(TestClass testClass, System.Net.AuthenticationSchemes value)
 {
     testClass.authenticationSchemes = value;
 }