CalcM2() 공개 정적인 메소드

M2 is Server's proof of K.
public static CalcM2 ( NetBigInteger A, Byte M, Byte K ) : Byte[]
A NetBigInteger
M Byte
K Byte
리턴 Byte[]
예제 #1
0
        /// <summary>
        /// Actually verifies received verification data (initiated remotely) + generates response
        /// </summary>
        /// <param name="verification"></param>
        private NetSRP.Verification VerificationOfActiveParty(NetSRP.Verification verification)
        {
            if ((Handshake.State.AllowVerificating & this.HandshakeState) != this.HandshakeState)
            {
                return(_verification); // double
            }
            // Set State
            this.HandshakeState = Handshake.State.Verificating;

            // Hello I am the one that is being connected to. So let's generate
            // the value M I should have in the SRPPackedData Object.
            Byte[] M = NetSRP.CalcM(N, g, _request.Username, _response.Salt, _request.A, _cache.B, _cache.K);

            // Compare
            if (!NetUtility.ArraysEqual(M, verification.M))
            {
                this.HandshakeState = Handshake.State.Denied | State.Failed;
                throw new NetSRP.HandShakeException("Invalid proof of Key. Username or password invalid.", new InvalidOperationException("Generated M does not match received M"));
            }

            // Ok, so their verification passed. Now let's proof that mine will to.
            _verification = new NetSRP.Verification(NetSRP.CalcM2(_request.A, verification.M, _cache.K));

            // Check expiration (maybe use timer?)
            if (_cache.ExpirationTime.CompareTo(DateTime.Now) < 0)
            {
                this.HandshakeState = Handshake.State.Expired;
                throw new NetSRP.HandShakeException("Hand was not shaken before it expired.");
            }

            return(_verification);
        }
예제 #2
0
        /// <summary>
        /// Actually verifies received verification data (initiated locally)
        /// </summary>
        /// <param name="verification"></param>
        private Boolean VerificationOfPassiveParty(NetSRP.Verification verification)
        {
            if ((Handshake.State.AllowVerification & this.HandshakeState) != this.HandshakeState)
            {
                return(false);
            }

            // Hello I am the one that tries to connect. So let's generate the
            // value M2 I should have in the SRPPackedData Object.
            Byte[] M2 = NetSRP.CalcM2(_cache.A, _verification.M, _cache.K);

            // Compare
            if (!NetUtility.ArraysEqual(M2, verification.M2))
            {
                this.HandshakeState = Handshake.State.Failed;
                throw new NetSRP.HandShakeException("Username or password invalid.", new ArgumentException("Generated M2 does not match received M2"));
            }

            // Check expiration
            if (_cache.ExpirationTime.CompareTo(DateTime.Now) < 0)
            {
                this.HandshakeState = Handshake.State.Expired;
                throw new NetSRP.HandShakeException("Hand was not shaken before it expired.");
            }

            return(true);
        }