Skip to content

Commit

Permalink
Merge branch 'hotfix-3.3.11' into support-3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Aug 20, 2014
2 parents b71c4ac + 1e52830 commit fa02e4e
Show file tree
Hide file tree
Showing 15 changed files with 651 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/repositories.config
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<repository path="..\src\testing\packages.config" />
<repository path="..\src\timeout\NServiceBus.Timeout.Core\packages.config" />
<repository path="..\src\timeout\NServiceBus.Timeout.Hosting.Windows\packages.config" />
<repository path="..\src\impl\encryption\NServiceBus.Encryption.Rijndael.Tests\packages.config" />
<repository path="..\tests\core\NServiceBus.Core.Tests\packages.config" />
<repository path="..\tests\encryption\NServiceBus.Encryption.Tests\packages.config" />
<repository path="..\tests\timeout\NServiceBus.Timeout.Tests\packages.config" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.Logging;
using NServiceBus.Config;
using NServiceBus.Encryption;
using NServiceBus.Encryption.Rijndael;
using NServiceBus.ObjectBuilder;

namespace NServiceBus
{
Expand All @@ -24,13 +27,48 @@ public static Configure RijndaelEncryptionService(this Configure config)
Logger.Warn("Could not find configuration section for Rijndael Encryption Service.");

var encryptConfig = config.Configurer.ConfigureComponent<EncryptionService>(DependencyLifecycle.SingleInstance);

if (section != null)
{
if (string.IsNullOrWhiteSpace(section.Key))
{
throw new Exception("The RijndaelEncryptionServiceConfig has an empty 'Key' attribute.");
}
encryptConfig.ConfigureProperty(s => s.Key, Encoding.ASCII.GetBytes(section.Key));
var expiredKeys = ExtractExpiredKeysFromConfigSection(section);
if (expiredKeys != null)
{
encryptConfig.ConfigureProperty(s => s.ExpiredKeys, expiredKeys.Select(x => Encoding.ASCII.GetBytes(x)).ToList());
}
}

return config;
}

internal static List<string> ExtractExpiredKeysFromConfigSection(RijndaelEncryptionServiceConfig section)
{
if (section.ExpiredKeys == null)
{
return new List<string>();
}
var encryptionKeys = section.ExpiredKeys
.Cast<RijndaelExpiredKey>()
.Select(x => x.Key)
.ToList();
if (encryptionKeys.Any(string.IsNullOrWhiteSpace))
{
throw new Exception("The RijndaelEncryptionServiceConfig has a 'ExpiredKeys' property defined however some keys have no data.");
}
if (encryptionKeys.Any(x => x == section.Key))
{
throw new Exception("The RijndaelEncryptionServiceConfig has a 'Key' that is also defined inside the 'ExpiredKeys'.");
}

if (encryptionKeys.Count != encryptionKeys.Distinct().Count())
{
throw new Exception("The RijndaelEncryptionServiceConfig has overlapping ExpiredKeys defined. Please ensure that no keys overlap in the 'ExpiredKeys' property.");
}
return encryptionKeys;
}
private static readonly ILog Logger = LogManager.GetLogger(typeof(RijndaelEncryptionServiceConfig));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@
</Reference>
</ItemGroup>
<ItemGroup>

<Compile Include="ConfigureRijndaelEncryptionService.cs" />
<Compile Include="RijndaelEncryptionServiceConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RijndaelExpiredKey.cs" />
<Compile Include="RijndaelExpiredKeyCollection.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NServiceBus.Encryption.Rijndael\NServiceBus.Encryption.Rijndael.csproj">
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace NServiceBus.Config
{

public class RijndaelEncryptionServiceConfig : ConfigurationSection
{
/// <summary>
Expand All @@ -19,5 +20,21 @@ public string Key
this["Key"] = value;
}
}

/// <summary>
/// Contains the expired decryptions that are currently being phased out.
/// </summary>
[ConfigurationProperty("ExpiredKeys", IsRequired = false)]
public RijndaelExpiredKeyCollection ExpiredKeys
{
get
{
return this["ExpiredKeys"] as RijndaelExpiredKeyCollection;
}
set
{
this["ExpiredKeys"] = value;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Configuration;

namespace NServiceBus.Config
{
/// <summary>
/// A configuration element representing a Rijndael encryption key.
/// </summary>
public class RijndaelExpiredKey : ConfigurationElement, IComparable<RijndaelExpiredKey>
{

/// <summary>
/// The keys value.
/// </summary>
[ConfigurationProperty("Key", IsRequired = true)]
public string Key
{
get
{
return (string)this["Key"];
}
set
{
this["Key"] = value;
}
}


int IComparable<RijndaelExpiredKey>.CompareTo(RijndaelExpiredKey other)
{
return String.Compare(Key, other.Key, StringComparison.Ordinal);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.Configuration;

namespace NServiceBus.Config
{
/// <summary>
/// A configuration element collection of <see cref="RijndaelExpiredKey"/>s.
/// </summary>
public class RijndaelExpiredKeyCollection : ConfigurationElementCollection
{
/// <summary>
/// Returns AddRemoveClearMap.
/// </summary>
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.AddRemoveClearMap;
}
}

/// <summary>
/// Creates a new <see cref="RijndaelExpiredKey"/>.
/// </summary>
protected override ConfigurationElement CreateNewElement()
{
return new RijndaelExpiredKey();
}

/// <summary>
/// Creates a new <see cref="RijndaelExpiredKey"/>, setting its <see cref="RijndaelExpiredKey.Key"/> property to the given value.
/// </summary>
protected override ConfigurationElement CreateNewElement(string elementName)
{
return new RijndaelExpiredKey
{
Key = elementName
};
}

/// <summary>
/// Returns the Messages property of the given <see cref="RijndaelExpiredKey"/> element.
/// </summary>
protected override Object GetElementKey(ConfigurationElement element)
{
var encryptionKey = (RijndaelExpiredKey)element;

return encryptionKey.Key;
}

/// <summary>
/// Gets/sets the <see cref="RijndaelExpiredKey"/> at the given index.
/// </summary>
public RijndaelExpiredKey this[int index]
{
get
{
return (RijndaelExpiredKey)BaseGet(index);
}
set
{
if (BaseGet(index) != null)
{
BaseRemoveAt(index);
}
BaseAdd(index, value);
}
}

/// <summary>
/// Gets the <see cref="RijndaelExpiredKey"/> for the given key.
/// </summary>
new public RijndaelExpiredKey this[string key]
{
get
{
return (RijndaelExpiredKey)BaseGet(key);
}
}

/// <summary>
/// Calls BaseIndexOf on the given <see cref="RijndaelExpiredKey"/>.
/// </summary>
public int IndexOf(RijndaelExpiredKey encryptionKey)
{
return BaseIndexOf(encryptionKey);
}

/// <summary>
/// Calls BaseAdd.
/// </summary>
public void Add(RijndaelExpiredKey encryptionKey)
{
BaseAdd(encryptionKey);
}

/// <summary>
/// Calls BaseAdd with true as the additional parameter.
/// </summary>
protected override void BaseAdd(ConfigurationElement element)
{
BaseAdd(element, true);
}

/// <summary>
/// If the key exists, calls BaseRemove on it.
/// </summary>
public void Remove(RijndaelExpiredKey encryptionKey)
{
if (BaseIndexOf(encryptionKey) >= 0)
{
BaseRemove(encryptionKey.Key);
}
}

/// <summary>
/// Calls BaseRemoveAt.
/// </summary>
public void RemoveAt(int index)
{
BaseRemoveAt(index);
}

/// <summary>
/// Calls BaseRemove.
/// </summary>
public void Remove(string name)
{
BaseRemove(name);
}

/// <summary>
/// Calls BaseClear.
/// </summary>
public void Clear()
{
BaseClear();
}

/// <summary>
/// True if the collection is readonly
/// </summary>
public override bool IsReadOnly()
{
return false;
}
}
}
Loading

0 comments on commit fa02e4e

Please sign in to comment.