コード例 #1
0
            public Builder Clear()
            {
                _uri    = null;
                _method = RtspMethod.UNKNOWN;

                _headers.Clear();

                return(this);
            }
コード例 #2
0
        protected override bool OnAuthenticationRequired(IIPCameraClient client, RtspMethod method)
        {
            //if (method != RtspMethod.DESCRIBE)
            //    return false;

            Log.Write("Authentication required " + method);

            return(base.OnAuthenticationRequired(client, method));
        }
コード例 #3
0
        public RtspRequestMessage(RtspMethod method, Uri connectionUri, Version protocolVersion, Func <uint> cSeqProvider,
                                  string userAgent, string session)
            : base(cSeqProvider(), protocolVersion)
        {
            Method        = method;
            ConnectionUri = connectionUri;
            _cSeqProvider = cSeqProvider;
            UserAgent     = userAgent;

            if (!string.IsNullOrEmpty(session))
            {
                Headers.Add("Session", session);
            }
        }
コード例 #4
0
        public static void Pack(Conversation conversation, Frame frame, MessageType type, String content)
        {
            if (null == conversation)
            {
                throw new ArgumentNullException("conversation");
            }

            if (null == frame)
            {
                throw new ArgumentNullException("frame");
            }

            content = TSharkHelper.GetFrameWithoutHeader(content);

            String[] lines   = content.SplitToLines();
            String   cSeqStr = lines.FirstOrDefault(item => item.Contains("CSeq"));

            if (null == cSeqStr)
            {
                return;
            }

            cSeqStr = cSeqStr.Substring(cSeqStr.IndexOf(":", StringComparison.Ordinal) + 1).Trim();
            int cSeq = int.Parse(cSeqStr);

            switch (type)
            {
            case MessageType.Request:
                RtspMethod method = GetMethod(lines.First(item => item.Contains("Method")));
                conversation.Add(new RequestResponsePair(new RtspRequest(frame, conversation, cSeq, method), null, frame.FoundInTrace, conversation, ContentType.Rtsp));
                break;

            case MessageType.Response:
                var pair = conversation.GetMessages(ContentType.Rtsp).FirstOrDefault(item => item.GetRequest <RtspRequest>().CSeq == cSeq && item.Response.IsEmpty);

                if (null != pair)
                {
                    pair.SetResponse(new RtspResponse(frame, conversation, cSeq));
                }
                break;
            }

            String filename = FrameHelper.GetFrameFilename(conversation, frame, type);

            File.WriteAllText(filename, content);
        }
コード例 #5
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));
 }
コード例 #6
0
 public static string DigestAuthorizationHeader(Encoding encoding, RtspMethod method, Uri location, 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(AuthorizationHeader(encoding, method, location, System.Net.AuthenticationSchemes.Digest, credential, qopPart, ncPart, nOncePart, cnOncePart, opaquePart, rfc2069, algorithmPart, bodyPart));
 }
コード例 #7
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)
        {
            if (scheme != System.Net.AuthenticationSchemes.Basic && scheme != System.Net.AuthenticationSchemes.Digest)
            {
                throw new ArgumentException("Must be either None, Basic or Digest", "scheme");
            }
            string result = string.Empty;

            //Basic
            if (scheme == System.Net.AuthenticationSchemes.Basic)
            {
                //http://en.wikipedia.org/wiki/Basic_access_authentication
                //Don't use the domain.
                result = "Basic " + Convert.ToBase64String(encoding.GetBytes(credential.UserName + ':' + credential.Password));
            }
            else if (scheme == System.Net.AuthenticationSchemes.Digest) //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 == "auth")
                    {
                        HA2 = Cryptography.MD5.GetHash(encoding.GetBytes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}", method, 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 == "auth-int")
                    {
                        HA2 = Cryptography.MD5.GetHash(encoding.GetBytes(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}:{2}", method, 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 (false == string.IsNullOrWhiteSpace(opaquePart))
                        {
                            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}", method, 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());
                }
            }

            return(result);
        }
コード例 #8
0
 internal RtspRequest(RtspMethod method, Uri uri) : base(RtspVersion.RTSP_1_0)
 {
     URI    = uri;
     Method = method;
 }
コード例 #9
0
            public Builder Method(RtspMethod method)
            {
                _method = method;

                return(this);
            }
コード例 #10
0
 public bool TryAddRequestHandler(RtspMethod method, RtspRequestHandler handler)
 {
     Exception any;
     if (false == Common.Collections.DictionaryExtensions.TryAdd(m_RequestHandlers, method, handler, out any))
     {
         try { Media.Common.Extensions.Exception.ExceptionExtensions.RaiseTaggedException(this, "Custom Handler already registered", any); }
         catch (Exception ex) { if (Logger != null) Logger.LogException(ex); }
         return false;
     }
     return true;
 }
コード例 #11
0
        protected override bool OnAuthenticationRequired(IIPCameraClient client, RtspMethod method)
        {
            //if (method != RtspMethod.DESCRIBE)
            //    return false;

            Log.Write("Authentication required " + method);

            return base.OnAuthenticationRequired(client, method);
        }
コード例 #12
0
ファイル: RtspRequest.cs プロジェクト: kudrinyaroslav/ON-0110
 public RtspRequest(Frame frame, Conversation conversation, int cSeq, RtspMethod method)
     : base(frame, conversation, cSeq, MessageType.Request)
 {
     Method = method;
 }