예제 #1
0
        public static byte[] GetBytes(byte[] key1, TokenBlob1 blob1)
        {
            using (HMACSHA1 sha1 = new HMACSHA1(key1))
            {
                byte[] username = blob1.GetBytes(sha1.HashSize / 8);

                sha1.ComputeHash(username, 0, blob1.Size);

                Array.Copy(sha1.Hash, 0, username, blob1.Size, sha1.HashSize / 8);

                return(username);
            }
        }
예제 #2
0
		public static byte[] GetBytes(byte[] key1, TokenBlob1 blob1)
		{
			using (HMACSHA1 sha1 = new HMACSHA1(key1))
			{
				byte[] username = blob1.GetBytes(sha1.HashSize / 8);

				sha1.ComputeHash(username, 0, blob1.Size);

				Array.Copy(sha1.Hash, 0, username, blob1.Size, sha1.HashSize / 8);

				return username;
			}
		}
예제 #3
0
파일: Mras.cs 프로젝트: KhaledSMQ/SipServer
        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,
            });
        }