Esempio n. 1
0
        /// <summary>
        /// calculate the base keys to initialize the other keys
        /// </summary>
        /// <param name="clientChallenge">the challenge generated by client</param>
        /// <param name="time">the time generated by client</param>
        /// <param name="serverName">the server name from the authenticate packet</param>
        /// <param name="domainName">the domain name from the authenticate packet</param>
        /// <param name="userName">the user name from the authenticate packet</param>
        /// <param name="userPassword">the user password from the authenticate packet</param>
        /// <param name="responseKeyLm">output the lm key</param>
        /// <param name="expectedNtChallengeResponse">output the expected nt challenge response of server</param>
        /// <param name="expectedLmChallengeResponse">output the expected lm challenge response of server</param>
        /// <param name="sessionBaseKey">output the session base key of server</param>
        /// <param name="keyExchangeKey">output the key exchange key of server</param>
        private void CalculateBaseKeys(
            ulong clientChallenge,
            ulong time,
            byte[] serverName,
            string domainName,
            string userName,
            string userPassword,
            out byte[] responseKeyLm,
            out byte[] expectedNtChallengeResponse,
            out byte[] expectedLmChallengeResponse,
            out byte[] sessionBaseKey,
            out byte[] keyExchangeKey)
        {
            // calculate the response key nt and lm
            byte[] responseKeyNt = NlmpUtility.GetResponseKeyNt(this.version, domainName, userName, userPassword);
            responseKeyLm = NlmpUtility.GetResponseKeyLm(this.version, domainName, userName, userPassword);

            // calcute the expected key
            expectedNtChallengeResponse = null;
            expectedLmChallengeResponse = null;
            sessionBaseKey = null;
            NlmpUtility.ComputeResponse(this.version, this.nlmpServer.Context.NegFlg, responseKeyNt, responseKeyLm,
                                        this.challenge.Payload.ServerChallenge, clientChallenge, time, serverName,
                                        out expectedNtChallengeResponse, out expectedLmChallengeResponse, out sessionBaseKey);

            // update session key
            this.nlmpServer.Context.SessionBaseKey = new byte[sessionBaseKey.Length];
            Array.Copy(sessionBaseKey, this.nlmpServer.Context.SessionBaseKey, sessionBaseKey.Length);

            // key exchange key
            keyExchangeKey = NlmpUtility.KXKey(
                this.version, sessionBaseKey,
                this.authenticate.Payload.LmChallengeResponse,
                this.challenge.Payload.ServerChallenge,
                this.nlmpServer.Context.NegFlg, responseKeyLm);
        }