Пример #1
0
        public static CredentialsRequest Parse(XmlReader reader)
        {
            CredentialsRequest credentialsRequest = new CredentialsRequest();

            reader.MoveToContent();
            credentialsRequest.CredentialsRequestID = reader.GetAttribute(@"credentialsRequestID");

            reader.Read();
            reader.MoveToContent();
            credentialsRequest.Identity =
                reader.ReadElementContentAsString(@"identity", @"http://schemas.microsoft.com/2006/09/sip/mrasp");

            if (reader.IsStartElement(@"location"))
            {
                credentialsRequest.Location = Common.ParseLocation(reader.ReadElementContentAsString());
            }

            if (reader.IsStartElement(@"duration"))
            {
                credentialsRequest.Duration = (uint)reader.ReadElementContentAsInt();
            }

            reader.MoveToContent();
            reader.ReadEndElement();

            return(credentialsRequest);
        }
Пример #2
0
        public static Request Parse(XmlReader reader)
        {
            try
            {
                Request request = new Request();

                if (reader.IsStartElement(@"request") == false)
                {
                    throw new MrasException();
                }

                request.RequestId = reader.GetAttribute(@"requestID");
                request.Version   = reader.GetAttribute(@"version");
                request.To        = reader.GetAttribute(@"to");
                request.From      = reader.GetAttribute(@"from");
                request.Route     = Common.ParseRoute(reader.GetAttribute(@"route"));

                request.CredentialsRequests = new List <CredentialsRequest>();

                reader.Read();
                while (CredentialsRequest.CanParse(reader))
                {
                    request.CredentialsRequests.Add(CredentialsRequest.Parse(reader));
                }

                if (request.CredentialsRequests.Count <= 0)
                {
                    throw new MrasException();
                }
                if (request.CredentialsRequests.Count > 100)
                {
                    throw new MrasException(ReasonPhrase.RequestTooLarge);
                }

                return(request);
            }
            catch (XmlException ex)
            {
                throw WrapException(ex);
            }
            catch (InvalidOperationException ex)
            {
                throw WrapException(ex);
            }
            catch (ArgumentException ex)
            {
                throw WrapException(ex);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
		public static CredentialsRequest Parse(XmlReader reader)
		{
			CredentialsRequest credentialsRequest = new CredentialsRequest();

			reader.MoveToContent();
			credentialsRequest.CredentialsRequestID = reader.GetAttribute(@"credentialsRequestID");

			reader.Read();
			reader.MoveToContent();
			credentialsRequest.Identity =
				reader.ReadElementContentAsString(@"identity", @"http://schemas.microsoft.com/2006/09/sip/mrasp");

			if (reader.IsStartElement(@"location"))
				credentialsRequest.Location = Common.ParseLocation(reader.ReadElementContentAsString());

			if (reader.IsStartElement(@"duration"))
				credentialsRequest.Duration = (uint)reader.ReadElementContentAsInt();

			reader.MoveToContent();
			reader.ReadEndElement();

			return credentialsRequest;
		}
Пример #4
0
		private CredentialsResponse Process(CredentialsRequest credentialsRequest, int versionMajor)
		{
			TokenBlob1 tokenBlob = (versionMajor == 1) ? new TokenBlob1() : new TokenBlob2();

			using (HMACSHA1 sha1 = new HMACSHA1(key0))
			{
				UTF8Encoding utf8 = new UTF8Encoding();
				tokenBlob.ClientID = sha1.ComputeHash(utf8.GetBytes(credentialsRequest.Identity));
			}

			byte[] username = Username.GetBytes(Key1, tokenBlob);
			byte[] password = Password.GetBytes(Key2, username);

			IEnumerable<MediaRelay> mediaRelays1 = null, mediaRelays2 = null;

			if (credentialsRequest.Location == null || credentialsRequest.Location == Location.Intranet)
				mediaRelays2 = intranetServers.Select<TurnServerInfo, MediaRelay>(
					turnServer => new MediaRelay()
					{
						Location = Location.Intranet,
						HostName = turnServer.Fqdn,
						TcpPort = turnServer.TcpPort,
						UdpPort = turnServer.UdpPort,
					});

			if (credentialsRequest.Location == null || credentialsRequest.Location == Location.Internet)
				mediaRelays2 = internetServers.Select <TurnServerInfo, MediaRelay>(
					turnServer => new MediaRelay()
					{
						Location = Location.Internet,
						HostName = turnServer.Fqdn,
						TcpPort = turnServer.TcpPort,
						UdpPort = turnServer.UdpPort,
					});


			return new CredentialsResponse()
			{
				CredentialsRequestID = credentialsRequest.CredentialsRequestID,
				Duration = Math.Min(credentialsRequest.Duration, Duration),
				Username = Convert.ToBase64String(username),
				Password = Convert.ToBase64String(password),
				MediaRelays1 = mediaRelays1,
				MediaRelays2 = mediaRelays2,
			};
		}