Exemplo n.º 1
0
            public byte[] CalculateHa1(ByteArrayPart username, ByteArrayPart realm,
                                       bool isMd5SessAlgorithm, ByteArrayPart nonce, ByteArrayPart cnonce, ByteArrayPart password)
            {
                md5.Initialize();

                md5.TransformBlock(username);
                md5.TransformBlock(Colon);
                md5.TransformBlock(realm);
                md5.TransformBlock(Colon);
                md5.TransformFinalBlock(password);

                if (isMd5SessAlgorithm)
                {
                    var ha1 = md5.Hash;

                    md5.Initialize();
                    md5.TransformBlock(ha1);
                    md5.TransformBlock(Colon);
                    md5.TransformBlock(nonce);
                    md5.TransformBlock(Colon);
                    md5.TransformFinalBlock(cnonce);
                }

                return(md5.Hash);
            }
Exemplo n.º 2
0
        public void It_should_test_equality_by_value()
        {
            var part1 = new ByteArrayPart(@"1234567890");
            var part2 = new ByteArrayPart(@"1234567890");
            var part3 = new ByteArrayPart(@"123456789-");
            var part4 = new ByteArrayPart(@"123456789");
            var part5 = new ByteArrayPart(@"12345678901");

            Assert.IsTrue(part1.IsEqualValue(part2));
            Assert.IsFalse(part1.IsEqualValue(part3));
            Assert.IsFalse(part1.IsEqualValue(part4));
            Assert.IsFalse(part1.IsEqualValue(part5));

            Assert.IsTrue(part1 == part2);
            Assert.IsTrue(part1 != part3);
            Assert.IsTrue(part1 != part4);
            Assert.IsTrue(part1 != part5);

            var bytes2 = Encoding.UTF8.GetBytes(@"1234567890");
            var bytes3 = Encoding.UTF8.GetBytes(@"123456789-");
            var bytes4 = Encoding.UTF8.GetBytes(@"123456789");
            var bytes5 = Encoding.UTF8.GetBytes(@"12345678901");

            Assert.IsTrue(part1.Equals(bytes2));
            Assert.IsFalse(part1.Equals(bytes3));
            Assert.IsFalse(part1.Equals(bytes4));
            Assert.IsFalse(part1.Equals(bytes5));
        }
Exemplo n.º 3
0
        public void WriteContact(ByteArrayPart user, IPEndPoint endPoint, Transports transport, ByteArrayPart sipInstance)
        {
            Write(C.Contact, C.HCOLON, C.SP, C.LAQUOT, C.sip, C.HCOLON);

            if (user.IsValid)
            {
                Write(user, C.At);
            }

            Write(endPoint, transport);

            if (transport != Transports.None)
            {
                Write(C.SEMI, C.transport, C.EQUAL);
                Write(transport.ToTransportParamUtf8Bytes());
            }

            Write(C.RAQUOT);

            if (sipInstance.IsValid)
            {
                Write(C.__sip_instance___, sipInstance, C.RAQUOT, C.DQUOTE);
            }

            Write(C.CRLF);
        }
Exemplo n.º 4
0
        public void It_should_trim_sws_at_begin()
        {
            var part1 = new ByteArrayPart("\r\n X");

            part1.TrimStartSws();

            var part2 = new ByteArrayPart(" \r\n X");

            part2.TrimStartSws();

            var part3 = new ByteArrayPart("  \r\n      X");

            part3.TrimStartSws();

            var part4 = new ByteArrayPart("  \r\n ");

            part4.TrimStartSws();

            var part5 = new ByteArrayPart("  \r\n      ");

            part5.TrimStartSws();

            var part6 = new ByteArrayPart("  X");

            part6.TrimStartSws();

            Assert.AreEqual("X", part1.ToString());
            Assert.AreEqual("X", part2.ToString());
            Assert.AreEqual("X", part3.ToString());
            Assert.AreEqual("", part4.ToString());
            Assert.AreEqual("", part5.ToString());
            Assert.AreEqual("X", part6.ToString());
        }
Exemplo n.º 5
0
            public byte[] CalculateResponse(ByteArrayPart nonce, ByteArrayPart qop,
                                            ByteArrayPart nonceCountBytes, ByteArrayPart cnonce, byte[] ha1, byte[] ha2)
            {
                md5.Initialize();

                HexEncoding.GetLowerHexChars(ha1, bytes32);
                md5.TransformBlock(bytes32);
                md5.TransformBlock(Colon);
                md5.TransformBlock(nonce);
                md5.TransformBlock(Colon);

                if (qop.IsValid)
                {
                    md5.TransformBlock(nonceCountBytes);
                    md5.TransformBlock(Colon);
                    md5.TransformBlock(cnonce);
                    md5.TransformBlock(Colon);
                    md5.TransformBlock(qop);
                    md5.TransformBlock(Colon);
                }

                HexEncoding.GetLowerHexChars(ha2, bytes32);
                md5.TransformFinalBlock(bytes32);

                return(md5.Hash);
            }
Exemplo n.º 6
0
        /// <inheritdoc />
        public virtual Task <HttpResponseMessage> UploadBytesPart(ByteArrayPart bytes)
        {
            var arguments = new object[] { bytes };
            var func      = requestBuilder.BuildRestResultFuncForMethod("UploadBytesPart", new Type[] { typeof(ByteArrayPart) });

            return((Task <HttpResponseMessage>)func(Client, arguments));
        }
Exemplo n.º 7
0
		protected override HttpMessageWriter IsAuthorized(BaseHttpConnection c, ByteArrayPart realm, int agentIndex)
		{
			HttpMessageWriter writer;
			authorization.IsAuthorized(c.HttpReader, c.Content, realm, agentIndex, out writer);

			return writer;
		}
Exemplo n.º 8
0
            public byte[] CalculateHa2(ByteArrayPart qop, ByteArrayPart digestUri, ByteArrayPart method, ArraySegment <byte> body)
            {
                byte[] bodyHash = null;
                //	if (messageQop.IsValid == true && messageQop.IsEqualValue(AuthInt))
                if (qop.Equals(AuthInt))
                {
                    if (body.Array != null && body.Count > 0)
                    {
                        bodyHash = md5.ComputeHash(body.Array, body.Offset, body.Count);
                    }
                }

                md5.Initialize();
                md5.TransformBlock(method);
                md5.TransformBlock(Colon);

                if (bodyHash != null)
                {
                    md5.TransformBlock(digestUri);
                    md5.TransformBlock(Colon);
                    HexEncoding.GetLowerHexChars(bodyHash, bytes32);
                    md5.TransformFinalBlock(bytes32);
                }
                else
                {
                    md5.TransformFinalBlock(digestUri);
                }

                return(md5.Hash);
            }
Exemplo n.º 9
0
        //public void WriteMsAuthentication(HeaderNames header, AuthSchemes scheme, ByteArrayPart targetname, ByteArrayPart realm, bool version, bool crlf)
        //{
        //    ByteArrayPart name;

        //    switch (header)
        //    {
        //        case HeaderNames.ProxyAuthenticate:
        //            name = C.Proxy_Authenticate;
        //            break;

        //        case HeaderNames.WwwAuthenticate:
        //            name = C.WWW_Authenticate;
        //            break;

        //        case HeaderNames.AuthenticationInfo:
        //            name = C.Authentication_Info;
        //            break;

        //        case HeaderNames.ProxyAuthenticationInfo:
        //            name = C.Proxy_Authentication_Info;
        //            break;

        //        default:
        //            throw new ArgumentException();
        //    }

        //    Write(name, C.HCOLON, C.SP, scheme == AuthSchemes.Ntlm ? C.NTLM : C.Kerberos, C.SP);

        //    if (scheme == AuthSchemes.Kerberos)
        //        Write(C.targetname, C.EQUAL, C.DQUOTE, C.sip, C.SLASH, targetname, C.DQUOTE, C.COMMA);
        //    else
        //        Write(C.targetname, C.EQUAL, C.DQUOTE, targetname, C.DQUOTE, C.COMMA);

        //    Write(C.realm, C.EQUAL, C.DQUOTE, realm, C.DQUOTE);

        //    if (version == true)
        //        Write(C.COMMA, C.version, C.EQUAL, 3);

        //    Write(crlf == true ? C.CRLF : C.COMMA);
        //}

        //public void WriteMsAuthenticationInfo(ByteArrayPart opaque, int snum, ByteArrayPart srand, ByteArrayPart rspauth)
        //{
        //    Write(C.opaque, C.EQUAL, C.DQUOTE, opaque, C.DQUOTE, C.COMMA);
        //    Write(C.qop, C.EQUAL, C.DQUOTE, C.auth, C.DQUOTE, C.COMMA);
        //    Write(C.snum, C.EQUAL, C.DQUOTE, snum, C.DQUOTE, C.COMMA);
        //    Write(C.srand, C.EQUAL, C.DQUOTE, srand, C.DQUOTE, C.COMMA);
        //    Write(C.rspauth, C.EQUAL, C.DQUOTE, rspauth, C.DQUOTE, C.CRLF);
        //}

        //public void WriteMsAuthentication(ByteArrayPart opaque, ByteArrayPart gssapiData)
        //{
        //    Write(C.opaque, C.EQUAL, C.DQUOTE, opaque, C.DQUOTE, C.COMMA);
        //    Write(C.gssapi_data, C.EQUAL, C.DQUOTE, gssapiData, C.DQUOTE, C.CRLF);
        //}

        public void WriteAuthenticationInfo(bool proxy, AuthSchemes scheme, ByteArrayPart targetname, ByteArrayPart realm, int opaque, int snum, int srand, ArraySegment <byte> rspauth)
        {
            Write(proxy ? C.Proxy_Authentication_Info : C.Authentication_Info, C.HCOLON, C.SP,
                  scheme == AuthSchemes.Ntlm ? C.NTLM : C.Kerberos, C.SP);

            Write(C.targetname, C.EQUAL, C.DQUOTE);
            if (scheme == AuthSchemes.Kerberos)
            {
                Write(C.sip, C.SLASH);
            }
            Write(targetname, C.DQUOTE, C.COMMA);

            Write(C.realm, C.EQUAL, C.DQUOTE, realm, C.DQUOTE);

            Write(C.COMMA, C.opaque, C.EQUAL, C.DQUOTE);
            WriteAsHex8(opaque);
            Write(C.DQUOTE);

            Write(C.COMMA, C.qop, C.EQUAL, C.DQUOTE, C.auth, C.DQUOTE);

            Write(C._snum__, snum, C.DQUOTE);

            Write(C._srand__);
            WriteAsHex8(srand);
            Write(C.DQUOTE);

            Write(C._rspauth__);
            WriteAsHex(rspauth);
            Write(C.DQUOTE);

            Write(C.CRLF);
        }
Exemplo n.º 10
0
        //public void WriteAuthenticateDigest(bool proxy, ByteArrayPart realm, ByteArrayPart nonce, bool authint, bool stale, ByteArrayPart opaque)
        //{
        //    Write(proxy ? C.Proxy_Authenticate : C.WWW_Authenticate, C.HCOLON, C.SP, C.Digest, C.SP);

        //    Write(C.realm, C.EQUAL, C.DQUOTE, realm, C.DQUOTE, C.COMMA);
        //    Write(C.nonce, C.EQUAL, C.DQUOTE, nonce, C.DQUOTE, C.COMMA);
        //    Write(C.qop, C.EQUAL, C.DQUOTE, C.auth);
        //    if (authint)
        //        Write(C.COMMA, C.auth_int);
        //    Write(C.DQUOTE, C.COMMA);
        //    Write(C.algorithm, C.EQUAL, C.MD5, C.COMMA);
        //    Write(C.stale, C.EQUAL, stale ? C._true : C._false, C.COMMA);
        //    Write(C.opaque, C.EQUAL, C.DQUOTE, opaque, C.DQUOTE);

        //    Write(C.CRLF);
        //}

        public void WriteAuthenticateDigest(bool proxy, ByteArrayPart realm, int nonce1, int nonce2, int nonce3, int nonce4, bool authint, bool stale, int opaque)
        {
            Write(proxy ? C.Proxy_Authenticate : C.WWW_Authenticate, C.HCOLON, C.SP, C.Digest, C.SP);

            Write(C.realm, C.EQUAL, C.DQUOTE, realm, C.DQUOTE, C.COMMA);
            Write(C.nonce, C.EQUAL, C.DQUOTE);
            WriteAsHex8(nonce1);
            WriteAsHex8(nonce2);
            WriteAsHex8(nonce3);
            WriteAsHex8(nonce4);
            Write(C.DQUOTE, C.COMMA);
            Write(C.qop, C.EQUAL, C.DQUOTE, C.auth);
            if (authint)
            {
                Write(C.COMMA, C.auth_int);
            }
            Write(C.DQUOTE, C.COMMA);
            Write(C.algorithm, C.EQUAL, C.MD5, C.COMMA);
            Write(C.stale, C.EQUAL, stale ? C._true : C._false, C.COMMA);
            Write(C.opaque, C.EQUAL, C.DQUOTE);
            WriteAsHex8(opaque);
            Write(C.DQUOTE);

            Write(C.CRLF);
        }
Exemplo n.º 11
0
 public void WriteTo(Header header, ByteArrayPart tag, ByteArrayPart ctag)
 {
     if (header.Name.IsValid == true)
     {
         Write(header.Name, C.HCOLON);
         if (ctag.IsValid == true)
         {
             Write(new ByteArrayPart()
             {
                 Bytes = header.Value.Bytes,
                 Begin = header.Value.Begin,
                 End   = ctag.Begin
             },
                   tag,
                   new ByteArrayPart()
             {
                 Bytes = header.Value.Bytes,
                 Begin = ctag.End,
                 End   = header.Value.End
             });
         }
         else
         {
             Write(header.Value);
             if (tag.IsValid == true)
             {
                 Write(C.SEMI, C.tag, C.EQUAL, tag);
             }
         }
         Write(C.CRLF);
     }
 }
Exemplo n.º 12
0
		public void It_should_trim_sws_at_end()
		{
			var part1 = new ByteArrayPart("X\r\n ");
			part1.TrimEndSws();

			var part2 = new ByteArrayPart("X \r\n ");
			part2.TrimEndSws();

			var part3 = new ByteArrayPart("X  \r\n      ");
			part3.TrimEndSws();

			var part4 = new ByteArrayPart("  \r\n ");
			part4.TrimEndSws();

			var part5 = new ByteArrayPart("  \r\n      ");
			part5.TrimEndSws();

			var part6 = new ByteArrayPart("X  ");
			part6.TrimEndSws();

			var part7 = new ByteArrayPart("");
			part7.TrimEndSws();

			Assert.AreEqual("X", part1.ToString());
			Assert.AreEqual("X", part2.ToString());
			Assert.AreEqual("X", part3.ToString());
			Assert.AreEqual("", part4.ToString());
			Assert.AreEqual("", part5.ToString());
			Assert.AreEqual("X", part6.ToString());
			Assert.AreEqual("", part7.ToString());
		}
Exemplo n.º 13
0
		public override HttpMessageWriter ProcessPutItem(ByteArrayPart username, ByteArrayPart domain, HttpMessageReader reader, ArraySegment<byte> content)
		{
			var statusCode = StatusCodes.OK;

			int sipIfMatch = simpleModule.InvalidEtag;
			if (reader.Count.IfMatches > 0)
			{
				if (HexEncoding.TryParseHex8(reader.IfMatches[0].Bytes, reader.IfMatches[0].Begin, out sipIfMatch) == false)
					statusCode = StatusCodes.PreconditionFailed;
			}

			if (statusCode == StatusCodes.OK)
			{
				if (simpleModule.Publish(username.ToString() + "@" + domain.ToString(), ref sipIfMatch, 60, content) == false)
					statusCode = StatusCodes.BadRequest;
			}

			HttpMessageWriter response;
			if (statusCode != StatusCodes.OK)
			{
				response = CreateResponse(statusCode);
			}
			else
			{
				response = CreateNotFinishedResponse(statusCode, ContentType.None);

				response.WriteEtag(sipIfMatch);
				response.WriteCRLF();
			}

			return response;
		}
Exemplo n.º 14
0
        public bool TryGetCredentialsByTargetname(AuthSchemes scheme, ByteArrayPart targetname, out Credentials credentials, out bool proxy)
        {
            int length = targetname.Length + ((scheme == AuthSchemes.Kerberos) ? 4 : 0);

            for (int i = 0; i < Count.AuthorizationCount; i++)
            {
                if (Authorization[i].AuthScheme == scheme)
                {
                    if (Authorization[i].Targetname.Length == length && Authorization[i].Targetname.EndWith(targetname))
                    {
                        credentials = Authorization[i];
                        proxy       = false;
                        return(true);
                    }
                }
            }

            for (int i = 0; i < Count.ProxyAuthorizationCount; i++)
            {
                if (ProxyAuthorization[i].AuthScheme == scheme)
                {
                    if (ProxyAuthorization[i].Targetname.Length == length && ProxyAuthorization[i].Targetname.EndWith(targetname))
                    {
                        credentials = ProxyAuthorization[i];
                        proxy       = true;
                        return(true);
                    }
                }
            }

            credentials = new Credentials();
            proxy       = false;
            return(false);
        }
Exemplo n.º 15
0
 public void MultiPartConstructorShouldThrowArgumentNullExceptionWhenNoFileName()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var byteArrayPart = new ByteArrayPart(new byte[0], null, "application/pdf");
     });
 }
Exemplo n.º 16
0
        public Trunk(string displayName, string hostname, string username, Transports transport, IPEndPoint localEndPoint, string outgoingProxy, string authId, string password, string localUri, int registerAfterErrorTimeout)
        {
            sync  = new object();
            state = States.Initiliazed;
            nonce.SetDefaultValue();
            opaque.SetDefaultValue();
            errorMessage = "Connecting...";

            Username      = username;
            Hostname      = hostname;
            OutgoingProxy = string.IsNullOrEmpty(outgoingProxy) ? hostname : outgoingProxy;

            DisplayName               = new ByteArrayPart(string.IsNullOrEmpty(displayName) ? username : displayName);
            Domain                    = new ByteArrayPart(hostname);
            Realm                     = Domain;
            Uri                       = new ByteArrayPart("sip:" + username + "@" + hostname);
            RequestUri                = new ByteArrayPart("sip:" + hostname);
            Transport                 = transport;
            LocalEndPoint             = (localEndPoint.Address == IPAddress.None) ? new IPEndPoint(IPAddress.Any, 0) : localEndPoint;
            AuthenticationId          = new ByteArrayPart(string.IsNullOrEmpty(authId) ? username : authId);
            Password                  = new ByteArrayPart(password);
            RegisterDuration          = 600;
            RegisterAfterErrorTimeout = registerAfterErrorTimeout;

            ForwardCallToUri = new ByteArrayPart(localUri);

            usedCSeqs = new UsedCSeq[128];

            //dialogs = new Dictionary<int, Dialogs>();
            dialogs1 = new Dictionary <int, Dialog>();
            dialogs2 = new Dictionary <int, Dialog>();
        }
Exemplo n.º 17
0
        private ByteArrayPart GetAor(ByteArrayPart user, ByteArrayPart domainName)
        {
            if (user.IsInvalid || domainName.IsInvalid)
            {
                return(ByteArrayPart.Invalid);
            }

            int length = scheme.Length + 1 + user.Length + 1 + domainName.Length;

            if (tempAor == null || tempAor.Length < length)
            {
                tempAor = new byte[Math.Max(length, 256)];
            }

            Buffer.BlockCopy(scheme, 0, tempAor, 0, scheme.Length);
            Buffer.BlockCopy(user.Bytes, user.Offset, tempAor, scheme.Length + 1, user.Length);
            Buffer.BlockCopy(domainName.Bytes, domainName.Offset, tempAor, scheme.Length + 1 + user.Length + 1, domainName.Length);

            tempAor[scheme.Length] = 0x3a;
            tempAor[scheme.Length + 1 + user.Length] = 0x40;

            return(new ByteArrayPart()
            {
                Bytes = tempAor, Begin = 0, End = length
            });
        }
Exemplo n.º 18
0
		public void It_should_test_equality_by_value()
		{
			var part1 = new ByteArrayPart(@"1234567890");
			var part2 = new ByteArrayPart(@"1234567890");
			var part3 = new ByteArrayPart(@"123456789-");
			var part4 = new ByteArrayPart(@"123456789");
			var part5 = new ByteArrayPart(@"12345678901");

			Assert.IsTrue(part1.IsEqualValue(part2));
			Assert.IsFalse(part1.IsEqualValue(part3));
			Assert.IsFalse(part1.IsEqualValue(part4));
			Assert.IsFalse(part1.IsEqualValue(part5));

			Assert.IsTrue(part1 == part2);
			Assert.IsTrue(part1 != part3);
			Assert.IsTrue(part1 != part4);
			Assert.IsTrue(part1 != part5);

			var bytes2 = Encoding.UTF8.GetBytes(@"1234567890");
			var bytes3 = Encoding.UTF8.GetBytes(@"123456789-");
			var bytes4 = Encoding.UTF8.GetBytes(@"123456789");
			var bytes5 = Encoding.UTF8.GetBytes(@"12345678901");

			Assert.IsTrue(part1.Equals(bytes2));
			Assert.IsFalse(part1.Equals(bytes3));
			Assert.IsFalse(part1.Equals(bytes4));
			Assert.IsFalse(part1.Equals(bytes5));
		}
        private static ByteArrayPart[] CreateErrorMessages()
        {
            var errors = new ByteArrayPart[Enum.GetValues(typeof(ErrorCodes)).Length];

            errors[(int)ErrorCodes.Ok]                  = new ByteArrayPart(@"No error");
            errors[(int)ErrorCodes.EpidNotFound]        = new ByteArrayPart(@"Epid not found");
            errors[(int)ErrorCodes.QopNotSupported]     = new ByteArrayPart(@"Qop not supported");
            errors[(int)ErrorCodes.UnexpectedOpaque]    = new ByteArrayPart(@"Unexpected opaque");
            errors[(int)ErrorCodes.VersionNotSupported] = new ByteArrayPart(@"Version not supported");
            errors[(int)ErrorCodes.NoGssapiData]        = new ByteArrayPart(@"No gssapi data");
            errors[(int)ErrorCodes.SecurityViolation]   = new ByteArrayPart(@"Security violation");
            errors[(int)ErrorCodes.Continue]            = new ByteArrayPart(@"Continue");
            errors[(int)ErrorCodes.NoResponse]          = new ByteArrayPart(@"No MS auth header");
            errors[(int)ErrorCodes.InvalidSignature]    = new ByteArrayPart(@"Invalid Signature");
            errors[(int)ErrorCodes.CrandRequired]       = new ByteArrayPart(@"Crand Required");
            errors[(int)ErrorCodes.CnumRequired]        = new ByteArrayPart(@"Cnum Required");
            errors[(int)ErrorCodes.ResponseRequired]    = new ByteArrayPart(@"Response Required");
            errors[(int)ErrorCodes.QueryContextAttributesForSizesFailed]    = new ByteArrayPart(@"QueryContextAttributes for sizes failed");
            errors[(int)ErrorCodes.QueryContextAttributesForUsernameFailed] = new ByteArrayPart(@"QueryContextAttributes for username failed");
            errors[(int)ErrorCodes.UsernameNotMatch] = new ByteArrayPart(@"From username not match to security username");
            errors[(int)ErrorCodes.ResponseHasInvalidHexEncoding] = new ByteArrayPart(@"Response has invalid hex encoding");
            errors[(int)ErrorCodes.NotAuthenticated] = new ByteArrayPart(@"Authentication not completed, signature unexpected");
            errors[(int)ErrorCodes.NotAuthorized]    = new ByteArrayPart(@"User pass authentication, but user outside authorized group");

            foreach (var error in errors)
            {
                if (error.Bytes == null)
                {
                    throw new InvalidProgramException(@"Not all errors defined");
                }
            }

            return(errors);
        }
Exemplo n.º 20
0
        private static ByteArrayPart GetDialogId(SipMessageReader message)
        {
            if (Dialog.HasValidId(message) == false)
            {
                return(ByteArrayPart.Invalid);
            }

            int length = Dialog.GetIdLength(message);

            if (dialogIdBytes == null || dialogIdBytes.Length < length)
            {
                dialogIdBytes = new byte[length];
            }

            var part = new ByteArrayPart()
            {
                Bytes = dialogIdBytes,
                Begin = 0,
                End   = length,
            };

            Dialog.GenerateId(message, part.Bytes);

            return(part);
        }
Exemplo n.º 21
0
		public MrasTU(Mras1 mras)
		{
			this.type = new ByteArrayPart("application");
			this.subtype = new ByteArrayPart("msrtc-media-relay-auth+xml");
			this.userPrefix = Encoding.UTF8.GetBytes("MRASLoc.");

			this.mras = mras;
		}
Exemplo n.º 22
0
		public void WriteResponse(SipMessageReader request, StatusCodes statusCode, ByteArrayPart localTag)
		{
			WriteStatusLine(statusCode);
			CopyViaToFromCallIdRecordRouteCSeq(request, statusCode, localTag);
			WriteContentLength(0);
			WriteCustomHeaders();
			WriteCRLF();
		}
Exemplo n.º 23
0
 private Range CreateRange(ByteArrayPart part, int headerBegin)
 {
     if (part.IsValid)
     {
         return(new Range(end + part.Begin - headerBegin, part.Length));
     }
     return(new Range());
 }
Exemplo n.º 24
0
		public DirectorySearchTU(IAccounts accounts, ServiceSoap1 serviceSoap, IUserz userz)
		{
			this.type = new ByteArrayPart("application");
			this.subtype = new ByteArrayPart("SOAP+xml");
			this.accounts = accounts;
			this.serviceSoap = serviceSoap;
			this.userz = userz;
		}
Exemplo n.º 25
0
        public void WriteRequestLine(Methods method, UriSchemes scheme, ByteArrayPart user, ByteArrayPart domain)
        {
            Method = method;

            Write(method.ToByteArrayPart(), C.SP);
            Write(scheme.ToByteArrayPart(), C.HCOLON, user, C.At, domain);
            Write(C.SP, C.SIP_2_0, C.CRLF);
        }
Exemplo n.º 26
0
 public void WriteHeaderName(ByteArrayPart name, bool sp)
 {
     Write(name, C.HCOLON);
     if (sp == true)
     {
         Write(C.SP);
     }
 }
Exemplo n.º 27
0
 public DirectorySearchTU(IAccounts accounts, ServiceSoap1 serviceSoap, IUserz userz)
 {
     this.type        = new ByteArrayPart("application");
     this.subtype     = new ByteArrayPart("SOAP+xml");
     this.accounts    = accounts;
     this.serviceSoap = serviceSoap;
     this.userz       = userz;
 }
Exemplo n.º 28
0
        protected override HttpMessageWriter IsAuthorized(BaseHttpConnection c, ByteArrayPart realm, int agentIndex)
        {
            HttpMessageWriter writer;

            authorization.IsAuthorized(c.HttpReader, c.Content, realm, agentIndex, out writer);

            return(writer);
        }
Exemplo n.º 29
0
        public MrasTU(Mras1 mras)
        {
            this.type       = new ByteArrayPart("application");
            this.subtype    = new ByteArrayPart("msrtc-media-relay-auth+xml");
            this.userPrefix = Encoding.UTF8.GetBytes("MRASLoc.");

            this.mras = mras;
        }
Exemplo n.º 30
0
        //public void WriteVia(Header header, SipMessageReader.ViaStruct via)
        //{
        //    if (header.Name.IsValid == true)
        //    {
        //        Write(header.Name, C.HCOLON, header.Value);
        //        if (via.ReceivedIP != IPAddress.None)
        //        {
        //            Write(C.SEMI, C.received, C.EQUAL, via.ReceivedIP);
        //        }
        //        if (via.MsReceivedPort != int.MinValue)
        //        {
        //            Write(C.SEMI, C.ms_received_port, C.EQUAL);
        //            Write(via.MsReceivedPort);
        //        }
        //        if (via.MsReceivedCid.IsValid == true && via.MsReceivedCid.Bytes != null)
        //        {
        //            Write(C.SEMI, C.ms_received_cid, C.EQUAL);
        //            Write(via.MsReceivedCid);
        //        }
        //        Write(C.CRLF);
        //    }
        //}

        public void WriteVia(Transports transport, ByteArrayPart host, int port, ByteArrayPart branch)
        {
            Write(C.Via, C.HCOLON, C.SP, C.SIP_2_0, C.SLASH);
            Write(transport.ToUtf8Bytes());
            Write(C.SP, host, C.HCOLON);
            Write(port);
            Write(C.SEMI, C.branch, C.EQUAL, branch, C.CRLF);
        }
Exemplo n.º 31
0
 public void WriteResponse(SipMessageReader request, StatusCodes statusCode, ByteArrayPart localTag)
 {
     WriteStatusLine(statusCode);
     CopyViaToFromCallIdRecordRouteCSeq(request, statusCode, localTag);
     WriteContentLength(0);
     WriteCustomHeaders();
     WriteCRLF();
 }
Exemplo n.º 32
0
        public Credentials GetCredentialsByTargetname(AuthSchemes scheme, ByteArrayPart targetname, out bool proxy)
        {
            Credentials credentials;

            TryGetCredentialsByTargetname(scheme, targetname, out credentials, out proxy);

            return(credentials);
        }
Exemplo n.º 33
0
        public Credentials GetCredentialsByRealm(AuthSchemes scheme, ByteArrayPart realm)
        {
            Credentials credentials;

            TryGetCredentialsByRealm(scheme, realm, out credentials);

            return(credentials);
        }
Exemplo n.º 34
0
		public static int CopyFrom(this byte[] bytes, ByteArrayPart part, int offset)
		{
			int length = part.Length;

			if (length > 0)
				Buffer.BlockCopy(part.Bytes, part.Begin, bytes, offset, length);

			return offset + length;
		}
Exemplo n.º 35
0
 public void WriteStatusLineToTop(StatusCodes statusCode, ByteArrayPart reason)
 {
     WriteToTop(C.CRLF);
     WriteToTop(reason, 100);
     WriteToTop(C.SP);
     WriteToTop((uint)statusCode);
     WriteToTop(C.SP);
     WriteToTop(C.SIP_2_0);
 }
Exemplo n.º 36
0
		public static IProxie Create(int transactionId, Trunk trunk, ByteArrayPart toTag)
		{
			int tag;
			Dialog dialog1 = null;
			if (HexEncoding.TryParseHex8(toTag, out tag))
				dialog1 = trunk.GetDialog1(tag);

			return (dialog1 == null) ? null : new TrunkDialogProxie(transactionId, trunk, tag, dialog1);
		}
Exemplo n.º 37
0
 public void WriteFrom(ByteArrayPart uri, int tag)
 {
     Write(C.From__, C.LAQUOT);
     fromAddrspec = new Range(end, uri.Length);
     Write(uri, C.RAQUOT, C._tag_);
     fromTag = new Range(end, 8);
     WriteAsHex8(tag);
     Write(C.CRLF);
 }
Exemplo n.º 38
0
 public void WriteTo2(ByteArrayPart user, ByteArrayPart domain, ByteArrayPart tag)
 {
     Write(C.To__, C.LAQUOT, C.sip, C.HCOLON, user, C.At, domain, C.RAQUOT);
     if (tag.IsValid)
     {
         Write(C._tag_, tag);
     }
     Write(C.CRLF);
 }
Exemplo n.º 39
0
 public void WriteTo(ByteArrayPart uri, ByteArrayPart tag)
 {
     Write(C.To__, C.LAQUOT, uri, C.RAQUOT);
     if (tag.IsValid)
     {
         Write(C._tag_, tag);
     }
     Write(C.CRLF);
 }
Exemplo n.º 40
0
		public void WriteStatusLineToTop(StatusCodes statusCode, ByteArrayPart reason)
		{
			WriteToTop(C.CRLF);
			WriteToTop(reason, 100);
			WriteToTop(C.SP);
			WriteToTop((uint)statusCode);
			WriteToTop(C.SP);
			WriteToTop(C.SIP_2_0);
		}
Exemplo n.º 41
0
		public void RemoveAllBindings(ByteArrayPart user, ByteArrayPart domain)
		{
			Bindings bindings = GetBindings(GetAor(user, domain));

			if (bindings != null)
			{
				if (bindings.TryRemoveAll(ContactRemovedHandler))
					RemoveStaleBindings(bindings);
			}
		}
Exemplo n.º 42
0
 public Trunk GetTrunkByDomain(ByteArrayPart host)
 {
     lock (sync)
     {
         for (int i = 0; i < trunks.Count; i++)
             if (trunks[i].Domain.Equals(host))
                 return trunks[i].IsConnected ? trunks[i] : null;
         return null;
     }
 }
Exemplo n.º 43
0
		public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment<byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
		{
			dialog2 = new Dialog(reader, tag, fromConnectionAddress);
			//trunk.AddDialog2(tag, dialog2);

			/////////////////////////////////////////////////////////////////////////////////

			writer.WriteRequestLine(reader.Method, dialog1.RemoteUri);

			//var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
			//writer.WriteVia(dialog1.Transport, dialog1.LocalEndPoint, TransactionId, msReceivedCid);
			writer.WriteVia(dialog1.Transport, dialog1.LocalEndPoint, TransactionId);

			for (int i = 0; i < reader.Count.HeaderCount; i++)
			{
				switch (reader.Headers[i].HeaderName)
				{
					case HeaderNames.MaxForwards:
						writer.WriteMaxForwards((reader.MaxForwards == int.MinValue) ? 69 : reader.MaxForwards - 1);
						break;

					case HeaderNames.Contact:
						writer.WriteContact(dialog1.LocalEndPoint, dialog1.Transport);
						break;

					case HeaderNames.To:
						writer.WriteTo(dialog1.RemoteUri, dialog1.RemoteTag);
						break;

					case HeaderNames.From:
						writer.WriteFrom(reader.From.AddrSpec.Value, tag);
						break;

					case HeaderNames.Authorization:
						break;

					default:
						writer.WriteHeader(reader, i);
						break;

					case HeaderNames.Via:
						via = reader.Headers[i].Value.DeepCopy();
						break;
				}
			}

			if (reader.ContentLength == int.MinValue)
				writer.WriteContentLength(content.Count);

			writer.WriteCustomHeaders();
			writer.WriteCRLF();

			writer.Write(content);
		}
Exemplo n.º 44
0
		public HttpMessageWriter ProcessGetItem(ByteArrayPart username, ByteArrayPart domain)
		{
			var writer = base.CreateNotFinishedResponse(StatusCodes.OK, ContentType.ApplicationResourceListsXml);

			var content = CreateResourceList(GetEntries(username, domain));

			writer.WriteContentLength(content.Length);
			writer.WriteCRLF();
			writer.Write(content);

			return writer;
		}
Exemplo n.º 45
0
	public static byte ParseHex2(ByteArrayPart part, int offset)
	{
		byte result = 0xff;

		if (part.IsValid && part.Length - offset >= 2)
		{
			result = AsciiCodeToHex[part.Bytes[part.Offset + offset]];
			result <<= 4;
			result |= AsciiCodeToHex[part.Bytes[part.Offset + offset + 1]];
		}

		return result;
	}
Exemplo n.º 46
0
		public bool UpdateBindings(ByteArrayPart user, ByteArrayPart domain, IncomingMessageEx request, int defaultExpires)
		{
			bool isNewData;
			Bindings bindings;

			do
			{
				bindings = GetOrAddBindings(GetAor(user, domain));

			} while (bindings.TryUpdate(request, defaultExpires, out isNewData, ContactAddedHandler, ContactRemovedHandler) == false);

			RemoveStaleBindings(bindings);

			return isNewData;
		}
Exemplo n.º 47
0
		public override HttpMessageWriter ProcessGetItem(ByteArrayPart username, ByteArrayPart domain)
		{
			var document = simpleModule.GetDocument(username.ToString() + "@" + domain.ToString());

			if (document == null)
			{
				return base.CreateResponse(StatusCodes.NotFound);
			}
			else
			{
				var response = base.CreateNotFinishedResponse(StatusCodes.OK, ContentType.ApplicationPidfXml);

				document.WriteLenghtAndContent(response);

				return response;
			}
		}
Exemplo n.º 48
0
	public static bool TryParseHex2(ByteArrayPart part, int offset, out byte result)
	{
		if (part.IsValid && part.Length - offset >= 2)
		{
			byte b1 = AsciiCodeToHex[part.Bytes[part.Offset + offset]];
			byte b2 = AsciiCodeToHex[part.Bytes[part.Offset + offset + 1]];

			if (b1 != 0xff && b2 != 0xff)
			{
				result = b1;
				result <<= 4;
				result |= b2;
				return true;
			}
		}

		result = 0;
		return false;
	}
Exemplo n.º 49
0
		protected override IEnumerable<Entry> GetEntries(ByteArrayPart username, ByteArrayPart domain)
		{
			var account = accounts.GetAccount(domain);

			if (account != null)
			{
				for (int i = 0; i < userz.Count; i++)
				{
					int count = userz[i].GetCount(account.Id);
					var users = userz[i].GetUsers(account.Id, 0, count);

					for (int j = 0; j < users.Count; j++)
					{
						var user = users[j];

						yield return new Entry("sip:" + user.Name + "@" + account.DomainName, user.DisplayName);
					}
				}
			}
		}
Exemplo n.º 50
0
		public IAccount GetAccount(ByteArrayPart domain)
		{
			return domain.IsInvalid ? null : accounts2.GetValue(domain.ToString());
		}
Exemplo n.º 51
0
		public bool HasDomain(ByteArrayPart domain)
		{
			return domain.IsValid && accounts2.ContainsKey(domain.ToString());
		}
Exemplo n.º 52
0
			public bool IsNewData(ByteArrayPart callId, int cseq1)
			{
				return CallId != callId || cseq < cseq1;
			}
Exemplo n.º 53
0
		private void LocationService_AorRemoved(ByteArrayPart aor)
		{
			enhancedPresence.UserUnregistered(aor.ToString());
		}
Exemplo n.º 54
0
		/// <summary>
		/// Обработчик события evRegisteredAORContact от Location Service.
		/// </summary>
		private void LocationService_ContactAdded(ByteArrayPart aor1, LocationService.Binding contact, SipMessageReader request)
		{
			var aor = aor1.ToString();
			bool ep = false;

			for (var i = 0; i < request.Count.SupportedCount; i++)
			{
				if (request.Supported[i].Option.ToString() == @"msrtc-event-categories")
				{
					ep = true;
					break;
				}
			}

			enhancedPresence.EndpointRegistered(aor, contact.SipInstance.Length != 0 ? contact.SipInstance.ToString() : contact.AddrSpec.ToString(), ep);
		}
Exemplo n.º 55
0
		public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment<byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
		{
			//dialog2 = new Dialog(reader, fromTag, fromConnectionAddress);

			Dialog dialog1 = null;
			if (HexEncoding.TryParseHex8(reader.To.Tag, out tag))
				dialog1 = trunk.GetDialog1(tag);
			else
				tag = DialogManager.NewLocalTag();

			dialog2 = new Dialog(reader, tag, fromConnectionAddress);
			trunk.AddDialog2(tag, dialog2);

			/////////////////////////////////////////////////////////////////////////////////

			writer.WriteRequestLine(reader.Method, binding.AddrSpec);

			//var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
			//writer.WriteVia(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, TransactionId, msReceivedCid);
			writer.WriteVia(binding.ConnectionAddresses.Transport, binding.ConnectionAddresses.LocalEndPoint, TransactionId);

			for (int i = 0; i < reader.Count.HeaderCount; i++)
			{
				switch (reader.Headers[i].HeaderName)
				{
					case HeaderNames.MaxForwards:
						writer.WriteMaxForwards((reader.MaxForwards == int.MinValue) ? 69 : reader.MaxForwards - 1);
						break;

					case HeaderNames.Contact:
						writer.WriteContact(binding.ConnectionAddresses.LocalEndPoint, binding.ConnectionAddresses.Transport);
						break;

					case HeaderNames.To:
						writer.WriteTo(trunk.ForwardCallToUri, (dialog1 != null) ? dialog1.RemoteTag : ByteArrayPart.Invalid);
						break;

					case HeaderNames.From:
						writer.WriteFrom(reader.From.AddrSpec.Value, tag);
						break;

					case HeaderNames.Authorization:
						break;

					default:
						writer.WriteHeader(reader, i);
						break;

					case HeaderNames.Via:
						via = reader.Headers[i].Value.DeepCopy();
						break;
				}
			}

			if (reader.ContentLength == int.MinValue)
				writer.WriteContentLength(content.Count);

			writer.WriteCustomHeaders();
			writer.WriteCRLF();

			writer.Write(content);
		}
Exemplo n.º 56
0
		private void LocationService_ContactRemoved(ByteArrayPart aor1, LocationService.Binding binding)
		{
			enhancedPresence.EndpointUnregistered(aor1.ToString(),
				binding.SipInstance.IsValid ? binding.SipInstance.ToString() : binding.AddrSpec.ToString());
		}
Exemplo n.º 57
0
		private static ByteArrayPart GetDialogId(SipMessageReader message)
		{
			if (Dialog.HasValidId(message) == false)
				return ByteArrayPart.Invalid;

			int length = Dialog.GetIdLength(message);

			if (dialogIdBytes == null || dialogIdBytes.Length < length)
				dialogIdBytes = new byte[length];

			var part = new ByteArrayPart()
			{
				Bytes = dialogIdBytes,
				Begin = 0,
				End = length,
			};

			Dialog.GenerateId(message, part.Bytes);

			return part;
		}
Exemplo n.º 58
0
		public void Remove(ByteArrayPart dialogId)
		{
			dictionary.Remove(dialogId);
		}
Exemplo n.º 59
0
		public override HttpMessageWriter ProcessGetItem(ByteArrayPart item)
		{
			throw new NotImplementedException();
		}
Exemplo n.º 60
0
		public Dialog Get(ByteArrayPart dialogId)
		{
			return dictionary.TryGetValue(dialogId);
		}