Skip to content

Commit

Permalink
Merge pull request #40 from jimsch/SignGroup
Browse files Browse the repository at this point in the history
Sign group
  • Loading branch information
jimsch authored Apr 1, 2018
2 parents 4147107 + 6795f1e commit 92ddf8d
Show file tree
Hide file tree
Showing 34 changed files with 798 additions and 420 deletions.
10 changes: 3 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
# see travis-ci.org for details

language: csharp
dist: trusty
os:
- linux
- osx

env:
# - SLN=CoAP.NET40.2010.sln
# TARGET=NET40
# VERSION=Release
- SLN=CoAP.NET45.sln
TARGET=NET45
VERSION=Release
# - SLN=CoAP.NET45.sln
# TARGET=NET45
# VERSION=Debug

install:
- curl -L -o nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
Expand Down
3 changes: 0 additions & 3 deletions CoAP.Example/CoAP.Client/CoAP.Client.NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
<HintPath>..\..\packages\Portable.BouncyCastle.1.8.1.3\lib\net40\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="CBOR, Version=3.0.0.0, Culture=neutral, PublicKeyToken=9cd62db60ea5554c, processorArchitecture=MSIL">
<HintPath>..\..\packages\PeterO.Cbor.3.0.0\lib\netstandard1.0\CBOR.dll</HintPath>
</Reference>
Expand Down
4 changes: 2 additions & 2 deletions CoAP.Example/CoAP.Client/ExampleClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void Main(String[] args)
}
else if (arg.StartsWith("-oscoap=")) {
if (contextSet == null) {
Console.WriteLine("Must have -oscoap-data bevore -oscoap");
Console.WriteLine("Must have -oscoap-data before -oscoap");
Environment.Exit(1);
}

Expand Down Expand Up @@ -286,7 +286,7 @@ private static SecurityContextSet LoadContextSet(string fileName)
else if (usage == "oscoap-group") {
SecurityContext ctx = SecurityContext.DeriveGroupContext(key[CoseKeyParameterKeys.Octet_k].GetByteString(), key[CBORObject.FromObject(2)].GetByteString(), key[CBORObject.FromObject("SenderID")].GetByteString(), null, null, key[CoseKeyKeys.Algorithm]);
foreach (CBORObject recipient in key[CBORObject.FromObject("recipients")].Values) {
ctx.AddRecipient(recipient[CBORObject.FromObject("RecipID")].GetByteString());
ctx.AddRecipient(recipient[CBORObject.FromObject("RecipID")].GetByteString(), new OneKey( recipient[CBORObject.FromObject("sign")]));
}
SecurityContextSet.AllContexts.Add(ctx);
}
Expand Down
13 changes: 9 additions & 4 deletions CoAP.Example/CoAP.Client/ServerKeys.cbor
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
��EKey#0 cKDFgdir+kdfgRecipIDFclienthSenderIDFserver X#
 !"#eusagefoscoap�EKey#1 cKDFgdir+kdfgRecipIDFclienthSenderIDFserver X#
 "$&(*,.02468:<>@BDFeusagefoscoap�EKey#2 cKDFgdir+kdfgRecipIDFclienthSenderIDFserver X# !$'*-0369<?BEHKNQTWZ]`cfieusagefoscoap�EKey#2 cKDFgdir+kdfgRecipIDFclienthSenderIDFserver X#  $(,048<@DHLPTX\`dhlptx|����eusagefoscoap�Fclien cKDFgdir+kdfgRecipIDFclienhSenderIDFserver X#  $(,048<@DHLPTX\`dhlptx|����eusageeedhoc�Fclient cKDFgdir+kdfgRecipIDFclienthSenderIDFserver X#
 !"#eusagefoscoap�Hmember01 hSenderIDHmember02 X$  $(,048<@DHLPTX\`dhlptx|������eusageloscoap-groupjrecipients��gRecipIDHmember01�gRecipIDHmember03
��EKey#0
cKDFgdir+kdfgRecipIDFclienthSenderIDFserver X#
 !"#eusagefoscoap�EKey#1
cKDFgdir+kdfgRecipIDFclienthSenderIDFserver X#
 "$&(*,.02468:<>@BDFeusagefoscoap�EKey#2
cKDFgdir+kdfgRecipIDFclienthSenderIDFserver X# !$'*-0369<?BEHKNQTWZ]`cfieusagefoscoap�EKey#2cKDFgdir+kdfgRecipIDFclienthSenderIDFserver X#  $(,048<@DHLPTX\`dhlptx|����eusagefoscoap�FcliencKDFgdir+kdfgRecipIDFclienhSenderIDFserver X#  $(,048<@DHLPTX\`dhlptx|����eusageeedhoc�Fclient
cKDFgdir+kdfgRecipIDFclienthSenderIDFserver X#
 !"#eusagefoscoap�Hmember01
hSenderIDHmember02 X$  $(,048<@DHLPTX\`dhlptx|������eusageloscoap-groupjrecipients��gRecipIDHmember01�gRecipIDHmember03
Expand Down
14 changes: 7 additions & 7 deletions CoAP.Example/CoAP.Client/ServerKeys.diag
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[
{1: 4, 2: h'4b65792330', 3: 12, "KDF": "dir+kdf", "RecipID": h'636c69656e74', "SenderID": h'736572766572', -1: h'0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223', "usage":"oscoap"},
{1: 4, 2: h'4b65792331', 3: 12, "KDF": "dir+kdf", "RecipID": h'636c69656e74', "SenderID": h'736572766572', -1: h'020406080a0c0e10121416181a1c1e20222426282a2c2e30323436383a3c3e40424446', "usage":"oscoap"},
{1: 4, 2: h'4b65792332', 3: 12, "KDF": "dir+kdf", "RecipID": h'636c69656e74', "SenderID": h'736572766572', -1: h'0306090c0f1215181b1e2124272a2d303336393c3f4245484b4e5154575a5d60636669', "usage":"oscoap"},
{1: 4, 2: h'4b65792332', 3: 32, "KDF": "dir+kdf", "RecipID": h'636c69656e74', "SenderID": h'736572766572', -1: h'04080c1014181c2024282c3034383c4044484c5054585c6064686c7074787c8084888c', "usage":"oscoap"},
{1: 4, 2: h'636c69656e7F', 3: 32, "KDF": "dir+kdf", "RecipID": h'636c69656e7F', "SenderID": h'736572766572', -1: h'04080c1014181c2024282c3034383c4044484c5054585c6064686c7074787c8084888c', "usage":"edhoc"},
{1: 4, 2: h'636c69656e74', 3: 12, "KDF": "dir+kdf", "RecipID": h'636c69656e74', "SenderID": h'736572766572', -1: h'0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223', "usage":"oscoap"},
{1: 4, 2: h'6d656d6265723031', 3: 12, "SenderID": h'6d656d6265723032', -1: h'080c1014181c2024282c3034383c4044484c5054585c6064686c7074787c8084888c8992', "usage":"oscoap-group",
{1: 4, 2: h'4b65792330', 3: 10, "KDF": "dir+kdf", "RecipID": h'636c69656e74', "SenderID": h'736572766572', -1: h'0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223', "usage":"oscoap"},
{1: 4, 2: h'4b65792331', 3: 10, "KDF": "dir+kdf", "RecipID": h'636c69656e74', "SenderID": h'736572766572', -1: h'020406080a0c0e10121416181a1c1e20222426282a2c2e30323436383a3c3e40424446', "usage":"oscoap"},
{1: 4, 2: h'4b65792332', 3: 10, "KDF": "dir+kdf", "RecipID": h'636c69656e74', "SenderID": h'736572766572', -1: h'0306090c0f1215181b1e2124272a2d303336393c3f4245484b4e5154575a5d60636669', "usage":"oscoap"},
{1: 4, 2: h'4b65792332', 3: 30, "KDF": "dir+kdf", "RecipID": h'636c69656e74', "SenderID": h'736572766572', -1: h'04080c1014181c2024282c3034383c4044484c5054585c6064686c7074787c8084888c', "usage":"oscoap"},
{1: 4, 2: h'636c69656e7F', 3: 30, "KDF": "dir+kdf", "RecipID": h'636c69656e7F', "SenderID": h'736572766572', -1: h'04080c1014181c2024282c3034383c4044484c5054585c6064686c7074787c8084888c', "usage":"edhoc"},
{1: 4, 2: h'636c69656e74', 3: 10, "KDF": "dir+kdf", "RecipID": h'636c69656e74', "SenderID": h'736572766572', -1: h'0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223', "usage":"oscoap"},
{1: 4, 2: h'6d656d6265723031', 3: 10, "SenderID": h'6d656d6265723032', -1: h'080c1014181c2024282c3034383c4044484c5054585c6064686c7074787c8084888c8992', "usage":"oscoap-group",
"recipients":[{"RecipID": h'6d656d6265723031'}, {"RecipID": h'6d656d6265723033'}]}

]
1 change: 0 additions & 1 deletion CoAP.Example/CoAP.Client/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle" version="1.8.1" targetFramework="net40" />
<package id="Com.AugustCellars.COSE" version="1.1.0" targetFramework="net45" />
<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net45" />
<package id="NETStandard.Library" version="1.6.1" targetFramework="net45" />
Expand Down
10 changes: 10 additions & 0 deletions CoAP.NET/Channel/IChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public interface IChannel : IDisposable
/// </summary>
void Stop();
/// <summary>
/// Abort the session - may not be clean.
/// </summary>
/// <param name="session">Session to abort</param>
void Abort(ISession session);
/// <summary>
/// Clean shutdown for the session
/// </summary>
/// <param name="session">Session to shutdown</param>
void Release(ISession session);
/// <summary>
/// Sends data through this channel. This method should be non-blocking.
/// </summary>
/// <param name="data">the bytes to send</param>
Expand Down
28 changes: 28 additions & 0 deletions CoAP.NET/Channel/UDPChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ public System.Net.EndPoint LocalEndPoint
/// </summary>
public Int32 ReceivePacketSize { get; set; } = DefaultReceivePacketSize;

/// <summary>
/// True means that it is supported, False means that it may be supported.
/// </summary>
public bool BlockTransfer { get; set; } = false;

/// <summary>
/// Max message size
/// </summary>
public int MaxSendSize { get; set; }

/// <inheritdoc/>
public void Start()
{
Expand Down Expand Up @@ -184,6 +194,24 @@ public void Stop()
}
}

/// <summary>
/// We don't do anything for this right now because we don't have sessions.
/// </summary>
/// <param name="session"></param>
public void Abort(ISession session)
{
return;
}

/// <summary>
/// We don't do anything for this right now because we don't have sessions.
/// </summary>
/// <param name="session"></param>
public void Release(ISession session)
{
return;
}

/// <inheritdoc/>
public void Send(Byte[] data, ISession sessionReceive, System.Net.EndPoint ep)
{
Expand Down
5 changes: 3 additions & 2 deletions CoAP.NET/CoAP.NET45.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -164,6 +164,7 @@
<Compile Include="Server\Resources\TimerResource.cs" />
<Compile Include="Server\ServerMessageDeliverer.cs" />
<Compile Include="SessionEventArgs.cs" />
<Compile Include="SignalMessage.cs" />
<Compile Include="Spec.cs" />
<Compile Include="Stack\AbstractLayer.cs" />
<Compile Include="Stack\BlockwiseLayer.cs" />
Expand Down Expand Up @@ -204,4 +205,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
3 changes: 2 additions & 1 deletion CoAP.NET/CoapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public CoapClient(Uri uri, ICoapConfig config)

/// <summary>
/// Gets or sets the timeout how long synchronous method calls will wait
/// until they give up and return anyways. The default value is <see cref="System.Threading.Timeout.Infinite"/>.
/// until they give up and return anyways. Time is in milliseconds.
/// The default value is <see cref="System.Threading.Timeout.Infinite"/>.
/// </summary>
public Int32 Timeout { get; set; } = System.Threading.Timeout.Infinite;

Expand Down
33 changes: 31 additions & 2 deletions CoAP.NET/Code.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ public static string ToString(int code)
return $"Unknown Response [code {code}]";
}
else {
return $"Reserved [code {code}]";
return $"Reserved [code {code/32}.{code%32}]";
}
}
else {
return $"Invalid Message [code {code}]";
return $"Invalid Message [code {code/32}.{code%32}]";
}
}
}
Expand Down Expand Up @@ -519,4 +519,33 @@ public enum StatusCode
/// </summary>
ProxyingNotSupported = 165
}

public enum SignalCode
{
/// <summary>
/// 7.01 Capabilities and Signaling Message
/// </summary>
CSM = 225,

/// <summary>
/// 7.02 Ping request
/// </summary>
Ping = 226,

/// <summary>
/// 7.03 Pong response
/// </summary>
Pong = 227,

/// <summary>
/// 7.04 Release connection request
/// </summary>
Release = 228,

/// <summary>
/// 7.05 Abort connection
/// </summary>
Abort = 229

}
}
5 changes: 5 additions & 0 deletions CoAP.NET/Codec/IMessageDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public interface IMessageDecoder
/// <returns>the decoded empty message</returns>
EmptyMessage DecodeEmptyMessage();
/// <summary>
/// Decodes as a <see cref="SignalMessage"/>
/// </summary>
/// <returns>the decoded signal</returns>
SignalMessage DecodeSignal();
/// <summary>
/// Decodes as a CoAP message.
/// </summary>
/// <returns>the decoded message, or null if not be recognized.</returns>
Expand Down
12 changes: 12 additions & 0 deletions CoAP.NET/Codec/MessageDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ public EmptyMessage DecodeEmptyMessage()
return message;
}

/// <inheritdoc/>
public SignalMessage DecodeSignal()
{
System.Diagnostics.Debug.Assert(IsSignal);
SignalMessage signal = new SignalMessage((SignalCode)m_code) {
Type = m_type,
ID = m_id
};
ParseMessage(signal);
return signal;
}

/// <inheritdoc/>
public Message Decode()
{
Expand Down
11 changes: 11 additions & 0 deletions CoAP.NET/Codec/MessageEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public Byte[] Encode(EmptyMessage message)
return writer.ToByteArray();
}

/// <inheritdoc/>
public byte[] Encode(SignalMessage message)
{
DatagramWriter writer = new DatagramWriter();
Serialize(writer, message, message.Code);
return writer.ToByteArray();
}

/// <inheritdoc/>
public Byte[] Encode(Message message)
{
Expand All @@ -51,6 +59,9 @@ public Byte[] Encode(Message message)
return Encode((Response)message);
else if (message is EmptyMessage)
return Encode((EmptyMessage)message);
else if (message is SignalMessage) {
return Encode((SignalMessage)message);
}
else
return null;
}
Expand Down
18 changes: 18 additions & 0 deletions CoAP.NET/DTLS/DTLSChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ public void Stop()
_udpChannel.Stop();
}

/// <summary>
/// We don't do anything for this right now because we don't have sessions.
/// </summary>
/// <param name="session"></param>
public void Abort(ISession session)
{
return;
}

/// <summary>
/// We don't do anything for this right now because we don't have sessions.
/// </summary>
/// <param name="session"></param>
public void Release(ISession session)
{
return;
}

public void Dispose()
{
_udpChannel.Dispose();
Expand Down
18 changes: 18 additions & 0 deletions CoAP.NET/DTLS/DTLSClientChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ public void Stop()
_udpChannel.Stop();
}

/// <summary>
/// We don't do anything for this right now because we don't have sessions.
/// </summary>
/// <param name="session"></param>
public void Abort(ISession session)
{
return;
}

/// <summary>
/// We don't do anything for this right now because we don't have sessions.
/// </summary>
/// <param name="session"></param>
public void Release(ISession session)
{
return;
}

/// <summary>
/// Tell the channel to release all of it's resources
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions CoAP.NET/DTLS/DTLSSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public bool IsReliable
get => false;
}

/// <summary>
/// True means that it is supported, False means that it may be supported.
/// </summary>
public bool BlockTransfer { get; set; } = true;

/// <summary>
/// Max message size
/// </summary>
public int MaxSendSize { get; set; } = 1152;

/// <summary>
/// Queue of items to be written on the session.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions CoAP.NET/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@ public interface ISession
/// Is the session reliable?
/// </summary>
bool IsReliable { get; }

/// <summary>
/// True means that it is supported, False means that it may be supported.
/// </summary>
bool BlockTransfer { get; set; }

/// <summary>
/// Size of maximum message the other size is able to process
/// </summary>
int MaxSendSize { get; set; }


}
}
6 changes: 3 additions & 3 deletions CoAP.NET/LinkFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static class LinkFormat
private static readonly ILogger _Log = LogManager.GetLogger(typeof(LinkFormat));

// Mapping defined in the RFC
private static readonly Dictionary<string, CBORObject> _CborAttributeKeys = new Dictionary<string, CBORObject>() {
public static readonly Dictionary<string, CBORObject> _CborAttributeKeys = new Dictionary<string, CBORObject>() {
["href"] = CBORObject.FromObject(1),
["rel"] = CBORObject.FromObject(2),
["anchor"] = CBORObject.FromObject(3),
Expand Down Expand Up @@ -329,7 +329,7 @@ private static void SerializeTree(IResource resource, List<string> queries, CBOR
}
}

private static void SerializeResource(IResource resource, StringBuilder sb)
public static void SerializeResource(IResource resource, StringBuilder sb)
{
sb.Append("<")
.Append(resource.Path)
Expand All @@ -338,7 +338,7 @@ private static void SerializeResource(IResource resource, StringBuilder sb)
SerializeAttributes(resource.Attributes, sb);
}

private static void SerializeResource(IResource resource, CBORObject cbor, Dictionary<string, CBORObject> dictionary)
public static void SerializeResource(IResource resource, CBORObject cbor, Dictionary<string, CBORObject> dictionary)
{
CBORObject obj = CBORObject.NewMap();

Expand Down
Loading

0 comments on commit 92ddf8d

Please sign in to comment.