Share
nvents

.NET events across the network

Encryption, handlers and filters in version 0.3

Some background on encryption in WCF

The NetTcpBinding (used in nvents) in WCF supports both Transport- and Message-level security. It’s highly recommended to use this functionality when you need to secure a WCF service.

However to enable one of these you need to use Windows authentication or a certificate. See more information in patterns & practices Improving Web Services Security (Chapter 7 - Message and Transport Security).

Encryption in nvents

Windows authentication and certificates does not fit well with the goal of nvents (being simple in it’s nature). We should only need to set the encryption key string and be done with it.

Events.Service = new AutoNetworkService("encryption-key");

Why isn’t the encryption key just a static property on Events?

  • We would like to keep the Events members to a minimum
  • Not all services supports encryption (it makes no sense for the InProcessService to support encryption)
  • We can create and consummate multiple nvents services in the same application, some of these might require encryption when others don’t

How is the encryption applied?

A custom serializer that’s using NetDataContractSerializer under the hood for the serialization. Before the serialized event are written there is a check if encryption should be applied and the bytes are encrypted using .NET AES implementation with the specified encryption key, likewise the data is decrypted before deserialization occurs.

Note that if a malicious user get a hold of your encryption key (by decompiling your assemblies) and has the ability to monitor your network your data may still be compromised.

Event handlers

In addition to subscribing directly to events it’s now possible to register event handlers to separate event handling further.

using System; using Nvents; namespace NventsHandlerSample { class Program { static void Main(string[] args) { var handler = new MyEventHandler(); Events.RegisterHandler(handler); Events.Publish(new MyEvent { Bar = "FooBar" }); Console.ReadLine(); } } public class MyEvent : IEvent { public string Bar { get; set; } } public class MyEventHandler : IHandler<MyEvent> { public void Handle(MyEvent @event) { Console.WriteLine(@event.Bar); } } }

Filters

Filters is a simple way to only subscribe to events that meets some specific demands.

using System; using Nvents; namespace NventsFilterSample { class Program { static void Main(string[] args) { Events.Subscribe<FooEvent>( e => Console.WriteLine("Unfiltered: " + e.Bar)); Events.Subscribe<FooEvent>( e => Console.WriteLine("Filtered: " + e.Bar), e => e.Bar.Contains("Foo")); Events.Publish(new FooEvent { Bar = "FooBar" }); Events.Publish(new FooEvent { Bar = "JustBar" }); Console.ReadLine(); } } public class FooEvent : IEvent { public string Bar { get; set; } } }

Download the latest version or view the nvents page.

 
Fork me on GitHub