CreateResponseAuthenticator() public static method

Generates an "Authenticator" value used in a RADIUS response packet sent by the server to client.
public static CreateResponseAuthenticator ( string sharedSecret, RadiusPacket requestPacket, RadiusPacket responsePacket ) : byte[]
sharedSecret string The shared secret key.
requestPacket RadiusPacket RADIUS packet sent from client to server.
responsePacket RadiusPacket RADIUS packet sent from server to client.
return byte[]
コード例 #1
0
ファイル: RadiusClient.cs プロジェクト: xj0229/gsf
        /// <summary>
        /// Send a request to the server and waits for a response back.
        /// </summary>
        /// <param name="request">Request to be sent to the server.</param>
        /// <returns>Response packet if a valid response is received from the server; otherwise Nothing.</returns>
        public RadiusPacket ProcessRequest(RadiusPacket request)
        {
            CheckDisposed();

            // We wait indefinitely for the connection to establish. But since this is UDP, the connection
            // will always be successful (locally we're binding to any available UDP port).
            if (m_udpClient.CurrentState != ClientState.Connected)
            {
                return(null);
            }

            RadiusPacket response = null;

            // We have a UDP socket we can use for exchanging packets.
            DateTime stopTime;

            for (int i = 1; i <= m_requestAttempts; i++)
            {
                m_responseBytes = null;
                m_udpClient.Send(request.BinaryImage());

                stopTime = DateTime.UtcNow.AddMilliseconds(m_reponseTimeout);

                while (true)
                {
                    Thread.Sleep(1);

                    // Stay in the loop until:
                    // 1) We receive a response OR
                    // 2) We exceed the response timeout duration
                    if ((object)m_responseBytes != null || DateTime.UtcNow > stopTime)
                    {
                        break;
                    }
                }

                if ((object)m_responseBytes != null)
                {
                    // The server sent a response.
                    response = new RadiusPacket(m_responseBytes, 0, m_responseBytes.Length);

                    if (response.Identifier == request.Identifier && response.Authenticator.CompareTo(RadiusPacket.CreateResponseAuthenticator(m_sharedSecret, request, response)) == 0)
                    {
                        break;
                    }

                    // The response failed the verification, so we'll silently discard it.
                    response = null;
                }
            }

            return(response);
        }