-
Notifications
You must be signed in to change notification settings - Fork 150
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
base: master
Are you sure you want to change the base?
SNMPv3 over DTLS #133
Changes from 1 commit
210a3be
33d89e3
375dca0
98a183d
ccb8536
328f898
900037d
7007b74
8319b80
2b42aa7
a11571a
221da76
817c5b2
2c47b81
1927f5a
0d3b7a8
a7e33ce
a4488c8
c1e0a27
cb8914b
f10b0e9
5a9ef97
2c50ccc
14c6417
44efc4c
8dee6aa
bff3913
89f378c
39457b2
5adcd46
d27a0ec
fb4d8cf
d849c60
18c2c72
59ce5d9
3d33735
b677193
4933bc7
af04e83
c9cc316
dfed035
a4c181d
2a55df2
ed31d91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be changed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will update |
||
{ | ||
if (request is null) | ||
{ | ||
|
@@ -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> | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will update |
||
{ | ||
if (request == null) | ||
{ | ||
|
@@ -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]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
@@ -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'"> | ||
|
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update