11using Lextm . SharpSnmpLib ;
22using Lextm . SharpSnmpLib . Messaging ;
33using Lextm . SharpSnmpLib . Security ;
4+ using NETworkManager . Utilities ;
45using System ;
56using System . Collections . Generic ;
67using System . Net ;
8+ using System . Security ;
79using System . Threading . Tasks ;
810
911namespace NETworkManager . Models . Network
@@ -53,13 +55,13 @@ protected virtual void OnUserHasCanceled()
5355 #endregion
5456
5557 #region Methods
56- public void GetV1V2CAsync ( SNMPVersion version , IPAddress ipAddress , string community , string oid )
58+ public void GetV1V2CAsync ( SNMPVersion version , IPAddress ipAddress , SecureString community , string oid )
5759 {
5860 Task . Run ( ( ) =>
5961 {
6062 try
6163 {
62- 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 ) )
64+ 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 ) )
6365 OnReceived ( new SNMPReceivedArgs ( result . Id , result . Data ) ) ;
6466
6567 OnComplete ( ) ;
@@ -75,15 +77,15 @@ public void GetV1V2CAsync(SNMPVersion version, IPAddress ipAddress, string commu
7577 } ) ;
7678 }
7779
78- public void WalkV1V2CAsync ( SNMPVersion version , IPAddress ipAddress , string community , string oid , WalkMode walkMode )
80+ public void WalkV1V2CAsync ( SNMPVersion version , IPAddress ipAddress , SecureString community , string oid , WalkMode walkMode )
7981 {
8082 Task . Run ( ( ) =>
8183 {
8284 try
8385 {
8486 IList < Variable > results = new List < Variable > ( ) ;
8587
86- Messenger . Walk ( version == SNMPVersion . V1 ? VersionCode . V1 : VersionCode . V2 , new IPEndPoint ( ipAddress , Port ) , new OctetString ( community ) , new ObjectIdentifier ( oid ) , results , Timeout , walkMode ) ;
88+ Messenger . Walk ( version == SNMPVersion . V1 ? VersionCode . V1 : VersionCode . V2 , new IPEndPoint ( ipAddress , Port ) , new OctetString ( SecureStringHelper . ConvertToString ( community ) ) , new ObjectIdentifier ( oid ) , results , Timeout , walkMode ) ;
8789
8890 foreach ( var result in results )
8991 OnReceived ( new SNMPReceivedArgs ( result . Id , result . Data ) ) ;
@@ -101,13 +103,13 @@ public void WalkV1V2CAsync(SNMPVersion version, IPAddress ipAddress, string comm
101103 } ) ;
102104 }
103105
104- public void SetV1V2CAsync ( SNMPVersion version , IPAddress ipAddress , string communtiy , string oid , string data )
106+ public void SetV1V2CAsync ( SNMPVersion version , IPAddress ipAddress , SecureString communtiy , string oid , string data )
105107 {
106108 Task . Run ( ( ) =>
107109 {
108110 try
109111 {
110- 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 ) ;
112+ 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 ) ;
111113
112114 OnComplete ( ) ;
113115 }
@@ -122,7 +124,7 @@ public void SetV1V2CAsync(SNMPVersion version, IPAddress ipAddress, string commu
122124 } ) ;
123125 }
124126
125- public void Getv3Async ( IPAddress ipAddress , string oid , SNMPV3Security security , string username , SNMPV3AuthenticationProvider authProvider , string auth , SNMPV3PrivacyProvider privProvider , string priv )
127+ public void Getv3Async ( IPAddress ipAddress , string oid , SNMPV3Security security , string username , SNMPV3AuthenticationProvider authProvider , SecureString auth , SNMPV3PrivacyProvider privProvider , SecureString priv )
126128 {
127129 Task . Run ( ( ) =>
128130 {
@@ -139,11 +141,11 @@ public void Getv3Async(IPAddress ipAddress, string oid, SNMPV3Security security,
139141 switch ( security )
140142 {
141143 case SNMPV3Security . AuthPriv :
142- privacy = GetPrivacy ( authProvider , auth , privProvider , priv ) ;
144+ privacy = GetPrivacy ( authProvider , SecureStringHelper . ConvertToString ( auth ) , privProvider , SecureStringHelper . ConvertToString ( priv ) ) ;
143145 break ;
144146 // noAuthNoPriv
145147 case SNMPV3Security . AuthNoPriv :
146- privacy = GetPrivacy ( authProvider , auth ) ;
148+ privacy = GetPrivacy ( authProvider , SecureStringHelper . ConvertToString ( auth ) ) ;
147149 break ;
148150 default :
149151 privacy = GetPrivacy ( ) ;
@@ -170,7 +172,7 @@ public void Getv3Async(IPAddress ipAddress, string oid, SNMPV3Security security,
170172 } ) ;
171173 }
172174
173- public void WalkV3Async ( IPAddress ipAddress , string oid , SNMPV3Security security , string username , SNMPV3AuthenticationProvider authProvider , string auth , SNMPV3PrivacyProvider privProvider , string priv , WalkMode walkMode )
175+ public void WalkV3Async ( IPAddress ipAddress , string oid , SNMPV3Security security , string username , SNMPV3AuthenticationProvider authProvider , SecureString auth , SNMPV3PrivacyProvider privProvider , SecureString priv , WalkMode walkMode )
174176 {
175177 Task . Run ( ( ) =>
176178 {
@@ -187,11 +189,11 @@ public void WalkV3Async(IPAddress ipAddress, string oid, SNMPV3Security security
187189 switch ( security )
188190 {
189191 case SNMPV3Security . AuthPriv :
190- privacy = GetPrivacy ( authProvider , auth , privProvider , priv ) ;
192+ privacy = GetPrivacy ( authProvider , SecureStringHelper . ConvertToString ( auth ) , privProvider , SecureStringHelper . ConvertToString ( priv ) ) ;
191193 break ;
192194 // noAuthNoPriv
193195 case SNMPV3Security . AuthNoPriv :
194- privacy = GetPrivacy ( authProvider , auth ) ;
196+ privacy = GetPrivacy ( authProvider , SecureStringHelper . ConvertToString ( auth ) ) ;
195197 break ;
196198 default :
197199 privacy = GetPrivacy ( ) ;
@@ -218,7 +220,7 @@ public void WalkV3Async(IPAddress ipAddress, string oid, SNMPV3Security security
218220 } ) ;
219221 }
220222
221- public void SetV3Async ( IPAddress ipAddress , string oid , SNMPV3Security security , string username , SNMPV3AuthenticationProvider authProvider , string auth , SNMPV3PrivacyProvider privProvider , string priv , string data )
223+ public void SetV3Async ( IPAddress ipAddress , string oid , SNMPV3Security security , string username , SNMPV3AuthenticationProvider authProvider , SecureString auth , SNMPV3PrivacyProvider privProvider , SecureString priv , string data )
222224 {
223225 Task . Run ( ( ) =>
224226 {
@@ -235,11 +237,11 @@ public void SetV3Async(IPAddress ipAddress, string oid, SNMPV3Security security,
235237 switch ( security )
236238 {
237239 case SNMPV3Security . AuthPriv :
238- privacy = GetPrivacy ( authProvider , auth , privProvider , priv ) ;
240+ privacy = GetPrivacy ( authProvider , SecureStringHelper . ConvertToString ( auth ) , privProvider , SecureStringHelper . ConvertToString ( priv ) ) ;
239241 break ;
240242 // noAuthNoPriv
241243 case SNMPV3Security . AuthNoPriv :
242- privacy = GetPrivacy ( authProvider , auth ) ;
244+ privacy = GetPrivacy ( authProvider , SecureStringHelper . ConvertToString ( auth ) ) ;
243245 break ;
244246 default :
245247 privacy = GetPrivacy ( ) ;
0 commit comments