Beispiel #1
0
        public AuthResult Authenticate(byte[] passwordHash, string hubName = null)
        {
            if (RandomFromServer == null)
            {
                return new AuthResult {
                           Error = SoftEtherError.ConnectFailed
                }
            }
            ;

            var authPayload = new SoftEtherParameterCollection
            {
                { "method", "admin" },
                { "client_str", "SoftEtherNet" },
                { "client_ver", 1 },
                { "client_build", 0 }
            };

            if (!string.IsNullOrWhiteSpace(hubName))
            {
                authPayload.Add("hubname", hubName);
            }

            var securePassword = CreateSaltedHash(passwordHash, RandomFromServer);

            authPayload.Add("secure_password", securePassword);

            var serializedAuthPayload = SoftEtherProtocol.Serialize(authPayload);

            _socket.SendHttpRequest("POST", "/vpnsvc/vpn.cgi", serializedAuthPayload,
                                    SoftEtherNetwork.GetDefaultHeaders());

            var authResponse = _socket.GetHttpResponse();

            if (authResponse.code != 200)
            {
                return new AuthResult {
                           Error = SoftEtherError.AuthFailed
                }
            }
            ;

            var authDict = SoftEtherProtocol.Deserialize(authResponse.body);

            return(AuthResult.Deserialize(authDict));
        }