Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions Source/NETworkManager.Models/Network/SNMP.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Lextm.SharpSnmpLib;
using Lextm.SharpSnmpLib.Messaging;
using Lextm.SharpSnmpLib.Security;
using NETworkManager.Utilities;
using System;
using System.Collections.Generic;
using System.Net;
using System.Security;
using System.Threading.Tasks;

namespace NETworkManager.Models.Network
Expand Down Expand Up @@ -53,13 +55,13 @@ protected virtual void OnUserHasCanceled()
#endregion

#region Methods
public void GetV1V2CAsync(SNMPVersion version, IPAddress ipAddress, string community, string oid)
public void GetV1V2CAsync(SNMPVersion version, IPAddress ipAddress, SecureString community, string oid)
{
Task.Run(() =>
{
try
{
foreach (var result in Messenger.Get(version == SNMPVersion.V1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, Port), new OctetString(community), new List<Variable> { new Variable(new ObjectIdentifier(oid)) }, Timeout))
foreach (var result in Messenger.Get(version == SNMPVersion.V1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, Port), new OctetString(SecureStringHelper.ConvertToString(community)), new List<Variable> { new Variable(new ObjectIdentifier(oid)) }, Timeout))
OnReceived(new SNMPReceivedArgs(result.Id, result.Data));

OnComplete();
Expand All @@ -75,15 +77,15 @@ public void GetV1V2CAsync(SNMPVersion version, IPAddress ipAddress, string commu
});
}

public void WalkV1V2CAsync(SNMPVersion version, IPAddress ipAddress, string community, string oid, WalkMode walkMode)
public void WalkV1V2CAsync(SNMPVersion version, IPAddress ipAddress, SecureString community, string oid, WalkMode walkMode)
{
Task.Run(() =>
{
try
{
IList<Variable> results = new List<Variable>();

Messenger.Walk(version == SNMPVersion.V1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, Port), new OctetString(community), new ObjectIdentifier(oid), results, Timeout, walkMode);
Messenger.Walk(version == SNMPVersion.V1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, Port), new OctetString(SecureStringHelper.ConvertToString(community)), new ObjectIdentifier(oid), results, Timeout, walkMode);

foreach (var result in results)
OnReceived(new SNMPReceivedArgs(result.Id, result.Data));
Expand All @@ -101,13 +103,13 @@ public void WalkV1V2CAsync(SNMPVersion version, IPAddress ipAddress, string comm
});
}

public void SetV1V2CAsync(SNMPVersion version, IPAddress ipAddress, string communtiy, string oid, string data)
public void SetV1V2CAsync(SNMPVersion version, IPAddress ipAddress, SecureString communtiy, string oid, string data)
{
Task.Run(() =>
{
try
{
Messenger.Set(version == SNMPVersion.V1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, Port), new OctetString(communtiy), new List<Variable> { new Variable(new ObjectIdentifier(oid), new OctetString(data)) }, Timeout);
Messenger.Set(version == SNMPVersion.V1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, Port), new OctetString(SecureStringHelper.ConvertToString(communtiy)), new List<Variable> { new Variable(new ObjectIdentifier(oid), new OctetString(data)) }, Timeout);

OnComplete();
}
Expand All @@ -122,7 +124,7 @@ public void SetV1V2CAsync(SNMPVersion version, IPAddress ipAddress, string commu
});
}

public void Getv3Async(IPAddress ipAddress, string oid, SNMPV3Security security, string username, SNMPV3AuthenticationProvider authProvider, string auth, SNMPV3PrivacyProvider privProvider, string priv)
public void Getv3Async(IPAddress ipAddress, string oid, SNMPV3Security security, string username, SNMPV3AuthenticationProvider authProvider, SecureString auth, SNMPV3PrivacyProvider privProvider, SecureString priv)
{
Task.Run(() =>
{
Expand All @@ -139,11 +141,11 @@ public void Getv3Async(IPAddress ipAddress, string oid, SNMPV3Security security,
switch (security)
{
case SNMPV3Security.AuthPriv:
privacy = GetPrivacy(authProvider, auth, privProvider, priv);
privacy = GetPrivacy(authProvider, SecureStringHelper.ConvertToString(auth), privProvider, SecureStringHelper.ConvertToString(priv));
break;
// noAuthNoPriv
case SNMPV3Security.AuthNoPriv:
privacy = GetPrivacy(authProvider, auth);
privacy = GetPrivacy(authProvider, SecureStringHelper.ConvertToString(auth));
break;
default:
privacy = GetPrivacy();
Expand All @@ -170,7 +172,7 @@ public void Getv3Async(IPAddress ipAddress, string oid, SNMPV3Security security,
});
}

public void WalkV3Async(IPAddress ipAddress, string oid, SNMPV3Security security, string username, SNMPV3AuthenticationProvider authProvider, string auth, SNMPV3PrivacyProvider privProvider, string priv, WalkMode walkMode)
public void WalkV3Async(IPAddress ipAddress, string oid, SNMPV3Security security, string username, SNMPV3AuthenticationProvider authProvider, SecureString auth, SNMPV3PrivacyProvider privProvider, SecureString priv, WalkMode walkMode)
{
Task.Run(() =>
{
Expand All @@ -187,11 +189,11 @@ public void WalkV3Async(IPAddress ipAddress, string oid, SNMPV3Security security
switch (security)
{
case SNMPV3Security.AuthPriv:
privacy = GetPrivacy(authProvider, auth, privProvider, priv);
privacy = GetPrivacy(authProvider, SecureStringHelper.ConvertToString(auth), privProvider, SecureStringHelper.ConvertToString(priv));
break;
// noAuthNoPriv
case SNMPV3Security.AuthNoPriv:
privacy = GetPrivacy(authProvider, auth);
privacy = GetPrivacy(authProvider, SecureStringHelper.ConvertToString(auth));
break;
default:
privacy = GetPrivacy();
Expand All @@ -218,7 +220,7 @@ public void WalkV3Async(IPAddress ipAddress, string oid, SNMPV3Security security
});
}

public void SetV3Async(IPAddress ipAddress, string oid, SNMPV3Security security, string username, SNMPV3AuthenticationProvider authProvider, string auth, SNMPV3PrivacyProvider privProvider, string priv, string data)
public void SetV3Async(IPAddress ipAddress, string oid, SNMPV3Security security, string username, SNMPV3AuthenticationProvider authProvider, SecureString auth, SNMPV3PrivacyProvider privProvider, SecureString priv, string data)
{
Task.Run(() =>
{
Expand All @@ -235,11 +237,11 @@ public void SetV3Async(IPAddress ipAddress, string oid, SNMPV3Security security,
switch (security)
{
case SNMPV3Security.AuthPriv:
privacy = GetPrivacy(authProvider, auth, privProvider, priv);
privacy = GetPrivacy(authProvider, SecureStringHelper.ConvertToString(auth), privProvider, SecureStringHelper.ConvertToString(priv));
break;
// noAuthNoPriv
case SNMPV3Security.AuthNoPriv:
privacy = GetPrivacy(authProvider, auth);
privacy = GetPrivacy(authProvider, SecureStringHelper.ConvertToString(auth));
break;
default:
privacy = GetPrivacy();
Expand Down
13 changes: 0 additions & 13 deletions Source/NETworkManager.Validators/PrivacyAESValidator.cs

This file was deleted.

81 changes: 70 additions & 11 deletions Source/NETworkManager/ViewModels/SNMPViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
Expand All @@ -21,6 +19,7 @@
using MahApps.Metro.Controls.Dialogs;
using NETworkManager.Models.Export;
using NETworkManager.Views;
using System.Security;

namespace NETworkManager.ViewModels
{
Expand Down Expand Up @@ -122,15 +121,35 @@ public SNMPV3Security Security
}
}

private string _community;
public string Community
private bool _isCommunityEmpty = true; // Initial it's empty
public bool IsCommunityEmpty
{
get => _isCommunityEmpty;
set
{
if (value == _isCommunityEmpty)
return;

_isCommunityEmpty = value;
OnPropertyChanged();
}
}

private SecureString _community;
public SecureString Community
{
get => _community;
set
{
if (value == _community)
return;

// Validate the community string
if (value == null)
IsCommunityEmpty = true;
else
IsCommunityEmpty = string.IsNullOrEmpty(SecureStringHelper.ConvertToString(value));

_community = value;
OnPropertyChanged();
}
Expand Down Expand Up @@ -169,15 +188,35 @@ public SNMPV3AuthenticationProvider AuthenticationProvider
}
}

private string _auth;
public string Auth
private bool _isAuthEmpty = true; // Initial it's empty
public bool IsAuthEmpty
{
get => _isAuthEmpty;
set
{
if (value == _isAuthEmpty)
return;

_isAuthEmpty = value;
OnPropertyChanged();
}
}

private SecureString _auth;
public SecureString Auth
{
get => _auth;
set
{
if (value == _auth)
return;

// Validate the auth string
if (value == null)
IsAuthEmpty = true;
else
IsAuthEmpty = string.IsNullOrEmpty(SecureStringHelper.ConvertToString(value));

_auth = value;
OnPropertyChanged();
}
Expand All @@ -202,15 +241,35 @@ public SNMPV3PrivacyProvider PrivacyProvider
}
}

private string _priv;
public string Priv
private bool _isPrivEmpty = true; // Initial it's empty
public bool IsPrivEmpty
{
get => _isPrivEmpty;
set
{
if (value == _isPrivEmpty)
return;

_isPrivEmpty = value;
OnPropertyChanged();
}
}

private SecureString _priv;
public SecureString Priv
{
get => _priv;
set
{
if (value == _priv)
return;

// Validate the auth string
if (value == null)
IsPrivEmpty = true;
else
IsPrivEmpty = string.IsNullOrEmpty(SecureStringHelper.ConvertToString(value));

_priv = value;
OnPropertyChanged();
}
Expand Down Expand Up @@ -323,7 +382,7 @@ public SNMPViewModel(IDialogCoordinator instance, int tabId, string host)
_isLoading = true;

_dialogCoordinator = instance;

TabId = tabId;
Host = host;

Expand Down Expand Up @@ -454,7 +513,7 @@ private async void Work()
}

if (ipAddress == null)
{
{
Finished();

StatusMessage = string.Format(Localization.Resources.Strings.CouldNotResolveIPAddressFor, Host);
Expand Down Expand Up @@ -548,7 +607,7 @@ private void Snmp_Received(object sender, SNMPReceivedArgs e)
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
{
//lock (QueryResults)
QueryResults.Add(snmpReceivedInfo);
QueryResults.Add(snmpReceivedInfo);
}));
}

Expand Down
Loading