Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNMPv3 over DTLS #133

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
210a3be
Merge pull request #1 from lextudio/master
kdurkin77 Nov 15, 2019
33d89e3
Merge pull request #2 from lextudio/master
kdurkin77 Dec 5, 2019
375dca0
Updated to use DTLS2.Net to allow for SNMPv3 over DTLS
kdurkin77 Dec 5, 2019
98a183d
Merge branch 'master' of https://github.com/kmiller77/sharpsnmplib
kdurkin77 Dec 5, 2019
ccb8536
Removed the project reference to DTLS2.Net and added the nuget package
kdurkin77 Dec 5, 2019
328f898
Forgot to remove my test project
kdurkin77 Dec 5, 2019
900037d
Removed the default keyword to allow for the Mac version to build pro…
kdurkin77 Dec 5, 2019
7007b74
Created a static Empty to use instead of the empty ctor for SecurityP…
kdurkin77 Dec 6, 2019
8319b80
Removed the Listeners and ListenerBindings (this needs to be moved in…
kdurkin77 Dec 6, 2019
2b42aa7
Added some unit testing and removed incorrect parameter comment in Ge…
kdurkin77 Dec 6, 2019
a11571a
Updating DTLS2.Net Version
kdurkin77 Dec 11, 2019
221da76
Updated GetBulkRequestMessage, GetNextRequestMessage, and SetRequestM…
kdurkin77 Dec 11, 2019
817c5b2
Forgot to update the test - will add more tests for the other message…
kdurkin77 Dec 11, 2019
2c47b81
Updated DTLS2.Net package - that update includes a timeout when conne…
kdurkin77 Dec 19, 2019
1927f5a
Added a timeout to connecting to the server in GetSecureResponse
kdurkin77 Jan 3, 2020
0d3b7a8
Created separate timeout for connection and response
kdurkin77 Jan 7, 2020
a7e33ce
Updated to the new DTLS2.Net library
kdurkin77 Jan 9, 2020
a4488c8
Upgraded DTLS2.Net library - using async
kdurkin77 Jan 14, 2020
c1e0a27
Merge branch 'master' of https://github.com/lextudio/sharpsnmplib
kdurkin77 Jan 14, 2020
cb8914b
Fixed from merge
kdurkin77 Jan 14, 2020
f10b0e9
Merge pull request #4 from lextudio/master
kdurkin77 Jan 16, 2020
5a9ef97
Updated DTLS2.Net
kdurkin77 Jan 17, 2020
2c50ccc
Merge pull request #5 from lextudio/master
kdurkin77 Jan 17, 2020
14c6417
Updated DTLS2.Net project
kdurkin77 Jan 17, 2020
44efc4c
Updating DTLS2.Net and no longer calling StopAsync since Client is no…
kdurkin77 Jan 20, 2020
8dee6aa
Updated the async functions to have the Async suffix
kdurkin77 Jan 28, 2020
bff3913
Updating DTLS library
kdurkin77 Jan 28, 2020
89f378c
Updated the DTLS2.Net library in an effort to help with high CPU with…
kdurkin77 Feb 3, 2020
39457b2
Merge pull request #6 from lextudio/master
kdurkin77 Feb 3, 2020
5adcd46
Added support for standard 2.1 and upgraded DTLS2.Net
kdurkin77 Feb 4, 2020
d27a0ec
Merge pull request #7 from lextudio/master
kdurkin77 Jun 11, 2020
fb4d8cf
Updated DTLS2.NET
kdurkin77 Jun 11, 2020
d849c60
Upgraded DLTS2.Net and added in missing .ConfigureAwait(false)
kdurkin77 Aug 12, 2020
18c2c72
Added ability to use TimeSpan for timeouts as well as int for millise…
kdurkin77 Aug 24, 2020
59ce5d9
Updated packages
kdurkin77 Aug 28, 2020
3d33735
Updated DTLS2.Net
kdurkin77 Sep 15, 2020
b677193
Updated DTLS.Net library
kdurkin77 Jul 1, 2021
4933bc7
Merge branch 'master' of https://github.com/lextudio/sharpsnmplib int…
kdurkin77 Feb 16, 2022
af04e83
Some cleanup based on warnings
kdurkin77 Feb 16, 2022
c9cc316
merged from upstream master
kdurkin77 May 10, 2024
dfed035
corrected the target frameworks and added net8.0
kdurkin77 May 10, 2024
a4c181d
updated packages
kdurkin77 May 10, 2024
2a55df2
Updated TargetFrameworks and Microsoft.SourceLink.GitHub and SonarAna…
kdurkin77 May 13, 2024
ed31d91
updated DTLS2.Net
kdurkin77 May 29, 2024
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
4 changes: 2 additions & 2 deletions SharpSnmpLib/Messaging/SecureDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public SecureDiscovery(int messageId, int requestId, int maxMessageSize)
/// <param name="responseTimeout">The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.</param>
/// <param name="receiver">The receiver.</param>
/// <returns></returns>
public ReportMessage GetResponse(int connectionTimeout, int responseTimeout, IPEndPoint receiver, Client client)
public async Task<ReportMessage> GetResponse(int connectionTimeout, int responseTimeout, IPEndPoint receiver, Client client)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you should rename it to GetResponseAsync.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update

{
if (receiver == null)
{
throw new ArgumentNullException(nameof(receiver));
}

return (ReportMessage)_discovery.GetSecureResponse(connectionTimeout, responseTimeout, receiver, client, Empty);
return (ReportMessage) (await _discovery.GetSecureResponse(connectionTimeout, responseTimeout, receiver, client, Empty));
}

/// <summary>
Expand Down
14 changes: 8 additions & 6 deletions SharpSnmpLib/Messaging/SecureMessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
using System.Globalization;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

namespace Lextm.SharpSnmpLib.Messaging
{
public static class SecureMessageExtensions
{
public static ISnmpMessage GetSecureResponse(this ISnmpMessage request, int connectionTimeout, int responseTimeout, IPEndPoint receiver, Client client)
public static async Task<ISnmpMessage> GetSecureResponse(this ISnmpMessage request, int connectionTimeout, int responseTimeout, IPEndPoint receiver, Client client)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be changed to GetSecureResponseAsync.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update

{
if (request is null)
{
Expand All @@ -32,7 +33,7 @@ public static ISnmpMessage GetSecureResponse(this ISnmpMessage request, int conn
// registry.Add(request.Parameters.UserName, request.Privacy);
//}

return request.GetSecureResponse(connectionTimeout, responseTimeout, receiver, client, registry);
return await request.GetSecureResponse(connectionTimeout, responseTimeout, receiver, client, registry);
}

/// <summary>
Expand All @@ -44,7 +45,7 @@ public static ISnmpMessage GetSecureResponse(this ISnmpMessage request, int conn
/// <param name="udpSocket">The UDP <see cref="Socket"/> to use to send/receive.</param>
/// <param name="registry">The user registry.</param>
/// <returns></returns>
public static ISnmpMessage GetSecureResponse(this ISnmpMessage request, int connectionTimeout, int responseTimeout, IPEndPoint receiver, Client client, UserRegistry registry)
public static async Task<ISnmpMessage> GetSecureResponse(this ISnmpMessage request, int connectionTimeout, int responseTimeout, IPEndPoint receiver, Client client, UserRegistry registry)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be GetSecureResponseAsync.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update

{
if (request == null)
{
Expand Down Expand Up @@ -83,14 +84,15 @@ public static ISnmpMessage GetSecureResponse(this ISnmpMessage request, int conn
reply = buffer;
manualReset.Set();
};
client.Send(bytes);

_ = Task.Run(() => client.SendAsync(bytes));
if (!manualReset.WaitOne(responseTimeout))
{
client.Stop();
await client.StopAsync();
throw new TimeoutException();
}

client.Stop();
await client.StopAsync();

// Passing 'count' is not necessary because ParseMessages should ignore it, but it offer extra safety (and would avoid an issue if parsing >1 response).
var response = MessageFactory.ParseMessages(reply, 0, reply.Length, registry)[0];
Expand Down
6 changes: 3 additions & 3 deletions SharpSnmpLib/SharpSnmpLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<PropertyGroup>
<AssemblyName>SharpSnmpLib</AssemblyName>
<RootNamespace>Lextm.SharpSnmpLib</RootNamespace>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netcoreapp2.1;netstandard1.3;net452;xamarin.ios10;monoandroid80</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.1;netstandard1.3</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netcoreapp2.1;netstandard1.3;netstandard2.1;net452;xamarin.ios10;monoandroid80</TargetFrameworks>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need netstandard2.1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have sworn you added 2.1 in master, i think i updated this to 2.0. Will double check that everything matches what you already have.
Out of curiosity, why are you using netcoreapp versions instead of netstandard since it's a library?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certain encryption algorithms are only available in a few .NET Core releases, but not in .NET Standard. So to make sure end users of the library get less platform not supported exceptions, we have to treat such platforms separately.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I may actually be experiencing something similar with a net472 project consuming this library as net standard. Standard and framework seem to see the keys inside an X509Certificate2 differently. Standard sees it as RSACng and framework sees RSA CryptoServiceProvider. Would it be okay if I added support for net472 so it doesn't try to use standard instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release 12.0 and above will by default support net471, and a net472 project will consume that copy. So we don't need to specify net472 explictly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I think I actually do need .NET Standard 2.1. There is much better Socket handling in 2.1 including the ability to cancel during send/receive. I'm seeing some issues with high CPU that being able to cancel the send/receive in DTLS2.Net seems to help with

<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.1;netstandard1.3;netstandard2.1;</TargetFrameworks>
<PackageId>Lextm.SharpSnmpLib</PackageId>
<Title>#SNMP Library</Title>
<NeutralLanguage>en-US</NeutralLanguage>
Expand Down Expand Up @@ -34,7 +34,7 @@
<AndroidUseIntermediateDesignerFile>False</AndroidUseIntermediateDesignerFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DTLS2.Net" Version="1.0.6" />
<PackageReference Include="DTLS2.Net" Version="1.0.7" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netstandard1.3' OR '$(TargetFramework)'=='netcoreapp2.1'">
Expand Down