Skip to content

Commit

Permalink
Support for >REMOTE/remote interaction added
Browse files Browse the repository at this point in the history
  • Loading branch information
rozmansi committed Sep 15, 2017
1 parent 6aaf56b commit 2215ef3
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 1 deletion.
9 changes: 9 additions & 0 deletions eduOpenVPN/Management/ISessionNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ public interface ISessionNotifications
/// <param name="realm">Realm title</param>
void OnAuthenticationFailed(string realm);

/// <summary>
/// Called when remote endpoint is needed
/// </summary>
/// <param name="host">Hostname or IP address</param>
/// <param name="port">IP Port</param>
/// <param name="protocol">Protocol</param>
/// <returns></returns>
RemoteAction OnRemote(string host, int port, ProtoType protocol);

/// <summary>
/// Called when RSA data signing is required
/// </summary>
Expand Down
24 changes: 24 additions & 0 deletions eduOpenVPN/Management/RemoteAcceptAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
eduOpenVPN - OpenVPN Management Library for eduVPN (and beyond)
Copyright: 2017, The Commons Conservancy eduVPN Programme
SPDX-License-Identifier: GPL-3.0+
*/

namespace eduOpenVPN.Management
{
/// <summary>
/// OpenVPN Management session remote "ACCEPT" command action
/// </summary>
public class RemoteAcceptAction : RemoteAction
{
#region Methods

public override string ToString()
{
return "ACCEPT";
}

#endregion
}
}
16 changes: 16 additions & 0 deletions eduOpenVPN/Management/RemoteAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
eduOpenVPN - OpenVPN Management Library for eduVPN (and beyond)
Copyright: 2017, The Commons Conservancy eduVPN Programme
SPDX-License-Identifier: GPL-3.0+
*/

namespace eduOpenVPN.Management
{
/// <summary>
/// OpenVPN Management session "remote" command action base class
/// </summary>
public class RemoteAction
{
}
}
53 changes: 53 additions & 0 deletions eduOpenVPN/Management/RemoteModAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
eduOpenVPN - OpenVPN Management Library for eduVPN (and beyond)
Copyright: 2017, The Commons Conservancy eduVPN Programme
SPDX-License-Identifier: GPL-3.0+
*/

namespace eduOpenVPN.Management
{
/// <summary>
/// OpenVPN Management session remote "MOD" command action
/// </summary>
public class RemoteModAction : RemoteAction
{
#region Properties

/// <summary>
/// Hostname or IP address
/// </summary>
public string Host { get; }

/// <summary>
/// IP port
/// </summary>
public int Port { get; }

#endregion

#region Constructors

/// <summary>
/// Constructs a command action
/// </summary>
/// <param name="host">Hostname or IP address</param>
/// <param name="port">IP port</param>
public RemoteModAction(string host, int port)
{
Host = host;
Port = port;
}

#endregion

#region Methods

public override string ToString()
{
return string.Format("MOD {0} {1:D}", Configuration.EscapeParamValue(Host), Port);
}

#endregion
}
}
24 changes: 24 additions & 0 deletions eduOpenVPN/Management/RemoteSkipAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
eduOpenVPN - OpenVPN Management Library for eduVPN (and beyond)
Copyright: 2017, The Commons Conservancy eduVPN Programme
SPDX-License-Identifier: GPL-3.0+
*/

namespace eduOpenVPN.Management
{
/// <summary>
/// OpenVPN Management session remote "SKIP" command action
/// </summary>
public class RemoteSkipAction : RemoteAction
{
#region Methods

public override string ToString()
{
return "SKIP";
}

#endregion
}
}
17 changes: 16 additions & 1 deletion eduOpenVPN/Management/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,27 @@ public override void ProcessData(byte[] data, ISessionNotifications event_sink)
}
break;
case "PKCS11ID-COUNT":
// TODO: Implement.
break;
case "PROXY":
// TODO: Implement.
break;
case "REMOTE":
// TODO: Implement.
{
// Get action.
var fields = Encoding.ASCII.GetString(queue.SubArray(data_start, msg_end - data_start)).Split(new char[] { ',' }, 3 + 1);
var action = event_sink.OnRemote(
fields.Length >= 1 ? fields[0].Trim() : null,
fields.Length >= 2 && int.TryParse(fields[1].Trim(), out var port) ? port : 0,
fields.Length >= 3 && ParameterValueAttribute.TryGetEnumByParameterValueAttribute<ProtoType>(fields[2].Trim(), out var proto) ? proto : ProtoType.UDP);
// Send reply message.
SendCommand("remote " + action.ToString(), new SingleCommand(), ct);
}
break;
case "RSA_SIGN":
Expand Down
30 changes: 30 additions & 0 deletions eduOpenVPN/ProtoType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
eduOpenVPN - OpenVPN Management Library for eduVPN (and beyond)
Copyright: 2017, The Commons Conservancy eduVPN Programme
SPDX-License-Identifier: GPL-3.0+
*/

namespace eduOpenVPN
{
public enum ProtoType
{
/// <summary>
/// UDP
/// </summary>
[ParameterValue("udp")]
UDP = 0,

/// <summary>
/// TCP client
/// </summary>
[ParameterValue("tcp-client")]
TCPClient,

/// <summary>
/// TCP server
/// </summary>
[ParameterValue("tcp-server")]
TCPServer,
}
}
5 changes: 5 additions & 0 deletions eduOpenVPN/eduOpenVPN.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<Reference Include="System.ServiceProcess" />
</ItemGroup>
<ItemGroup>
<Compile Include="Management\RemoteModAction.cs" />
<Compile Include="Management\RemoteAcceptAction.cs" />
<Compile Include="Management\RemoteAction.cs" />
<Compile Include="Management\RemoteSkipAction.cs" />
<Compile Include="ProtoType.cs" />
<Compile Include="AuthRetryType.cs" />
<Compile Include="Configuration.cs" />
<Compile Include="InteractiveService\Session.cs" />
Expand Down

0 comments on commit 2215ef3

Please sign in to comment.