public ConnectResult Connect() { _socket.SendHttpRequest("POST", "/vpnsvc/connect.cgi", Encoding.ASCII.GetBytes("VPNCONNECT"), SoftEtherNetwork.GetDefaultHeaders()); var connectResponse = _socket.GetHttpResponse(); if (connectResponse.code != 200) { return new ConnectResult { Error = SoftEtherError.ConnectFailed } } ; var connectDict = SoftEtherProtocol.Deserialize(connectResponse.body); var connectResult = ConnectResult.Deserialize(connectDict); if (connectResult.Valid()) { RandomFromServer = connectResult.random; } return(connectResult); }
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)); }