This object holds the local cache for generated values of the private and public key and for the username/password, session key and keybytes.
Пример #1
0
        /// <summary>
        /// Creates a new Handshake
        /// </summary>
        /// <param name="active">Is active party</param>
        /// <param name="keySize">keysize</param>
        /// <param name="logonManager">logonManager (only needed if passive)</param>
        internal Handshake(Boolean active, Int32 keySize, ILogonManager logonManager)
        {
            // Local Data setup
            _cache = new NetSRP.State();
            _keySize = keySize;
            _logonManager = logonManager ?? _defaultLogonManager;

            if (!active && _defaultLogonManager == null)
                _defaultLogonManager = logonManager;

            // We calculate N and G for this insance. I choose to do so, so you can
            // have different keysizes throughout your program and are not stuck with one
            N = NetSRP.GetNandG(_keySize, out g);
            k = NetSRP.Calck(N, g);

            // Set as NotInitialized
            this.HandshakeState = Handshake.State.NotInitialized;

            if (!active && _logonManager == null)
                throw new InvalidOperationException("Receiving handshakes need a logonManager");

            if (keySize == 0 || N == null || g == null || k == null)
                throw new InvalidOperationException("Handshake not intialized");

            // NOTE: this is caused by the length of the hailmessage - larger then 4096 goes over the MTU
            if (keySize < 1024 || keySize > 4096)
                throw new NetException("SRP6Keysize is not supported by Lidgren.Network",
                    new ArgumentOutOfRangeException("keySize"));
        }
Пример #2
0
        /// <summary>
        /// Creates a completed handshake
        /// </summary>
        /// <param name="username"></param>
        /// <param name="key"></param>
        public Handshake(String username, Byte[] key)
        {
            _cache = new NetSRP.State();
            _cache.K = key;
            _request = new NetSRP.Request(username, null);

            this.HandshakeState = State.Succeeded;
        }
Пример #3
0
        /// <summary>
        /// Creates a completed handshake
        /// </summary>
        /// <param name="username"></param>
        /// <param name="key"></param>
        public Handshake(String username, Byte[] key)
        {
            _cache   = new NetSRP.State();
            _cache.K = key;
            _request = new NetSRP.Request(username, null);

            this.HandshakeState = State.Succeeded;
        }
Пример #4
0
        /// <summary>
        /// Creates a new Handshake
        /// </summary>
        /// <param name="active">Is active party</param>
        /// <param name="keySize">keysize</param>
        /// <param name="logonManager">logonManager (only needed if passive)</param>
        internal Handshake(Boolean active, Int32 keySize, ILogonManager logonManager)
        {
            // Local Data setup
            _cache        = new NetSRP.State();
            _keySize      = keySize;
            _logonManager = logonManager ?? _defaultLogonManager;

            if (!active && _defaultLogonManager == null)
            {
                _defaultLogonManager = logonManager;
            }

            // We calculate N and G for this insance. I choose to do so, so you can
            // have different keysizes throughout your program and are not stuck with one
            N = NetSRP.GetNandG(_keySize, out g);
            k = NetSRP.Calck(N, g);

            // Set as NotInitialized
            this.HandshakeState = Handshake.State.NotInitialized;

            if (!active && _logonManager == null)
            {
                throw new InvalidOperationException("Receiving handshakes need a logonManager");
            }

            if (keySize == 0 || N == null || g == null || k == null)
            {
                throw new InvalidOperationException("Handshake not intialized");
            }

            // NOTE: this is caused by the length of the hailmessage - larger then 4096 goes over the MTU
            if (keySize < 1024 || keySize > 4096)
            {
                throw new NetException("SRP6Keysize is not supported by Lidgren.Network",
                                       new ArgumentOutOfRangeException("keySize"));
            }
        }