Skip to content

Commit

Permalink
Merge branch '3.2.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasohlund committed Aug 29, 2012
2 parents c4d1162 + da55d59 commit ffa83eb
Show file tree
Hide file tree
Showing 13 changed files with 565 additions and 226 deletions.
2 changes: 1 addition & 1 deletion Samples/Encryption/Client/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</MessageEndpointMappings>
</UnicastBusConfig>

<RijndaelEncryptionServiceConfig Key="gdDbqRpqdRbTs3mhdZh8qCaDaxJXl+e7"/>
<RijndaelEncryptionServiceConfig Key="gdDbqRpqdRbTs3mhdZh9qCaDaxJXl+e6"/>

<appSettings>
</appSettings>
Expand Down
23 changes: 18 additions & 5 deletions Samples/Encryption/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
using Messages;

namespace Client
{
{
using System.Collections.Generic;
using NServiceBus.Encryption.Config;

public class EndpointConfig : IConfigureThisEndpoint, AsA_Client {}

public class SecurityConfig : IWantCustomInitialization
{
public void Init()
{
Configure.Instance.RijndaelEncryptionService();
public void Init()
{
Configure.Instance.RijndaelEncryptionService();
//.DisableCompatibilityWithNSB2();//uncomment this line to turn off compatibility with2.X endpoints
}
}

Expand All @@ -21,7 +25,16 @@ public void Run()
Console.WriteLine("Press 'Enter' to send a message.");
while (Console.ReadLine() != null)
{
Bus.Send<MessageWithSecretData>(m => m.Secret = "betcha can't guess my secret");
Bus.Send<MessageWithSecretData>(m =>
{
m.Secret = "betcha can't guess my secret";
m.SubProperty = new MySecretSubProperty {Secret = "My sub secret"};
m.CreditCards = new List<CreditCardDetails>
{
new CreditCardDetails{ValidTo = DateTime.UtcNow.AddYears(1), Number = "312312312312312"},
new CreditCardDetails{ValidTo = DateTime.UtcNow.AddYears(2), Number = "543645546546456"}
};
});
}
}

Expand Down
20 changes: 18 additions & 2 deletions Samples/Encryption/Messages/MessageWithSecretData.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
using NServiceBus;

namespace Messages
{
{
using System;
using System.Collections.Generic;

public class MessageWithSecretData : IMessage
{
public WireEncryptedString Secret { get; set; }
}
public MySecretSubProperty SubProperty{ get; set; }
public List<CreditCardDetails> CreditCards { get; set; }
}

public class CreditCardDetails
{
public DateTime ValidTo { get; set; }
public WireEncryptedString Number { get; set; }
}

public class MySecretSubProperty
{
public WireEncryptedString Secret { get; set; }
}
}
2 changes: 1 addition & 1 deletion Samples/Encryption/Server/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="" />

<RijndaelEncryptionServiceConfig Key="gdDbqRpqdRbTs3mhdZh8qCaDaxJXl+e7"/>
<RijndaelEncryptionServiceConfig Key="gdDbqRpqdRbTs3mhdZh9qCaDaxJXl+e6"/>

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>

Expand Down
56 changes: 32 additions & 24 deletions Samples/Encryption/Server/Server.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
using System;
using Messages;
using NServiceBus;

namespace Server
{
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
public void Init()
{
Configure.With()
.StructureMapBuilder()
.RijndaelEncryptionService();
}
}

public class Handler : IHandleMessages<MessageWithSecretData>
{
public void Handle(MessageWithSecretData message)
{
Console.WriteLine("I know your secret - it's '" + message.Secret + "'.");
}
}
}
using System;
using Messages;
using NServiceBus;

namespace Server
{
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
public void Init()
{
Configure.With()
.StructureMapBuilder()
.RijndaelEncryptionService();
}
}

public class Handler : IHandleMessages<MessageWithSecretData>
{
public void Handle(MessageWithSecretData message)
{
Console.Out.WriteLine("I know your secret - it's '" + message.Secret + "'");

if (message.SubProperty != null)
Console.Out.WriteLine("SubSecret: " + message.SubProperty.Secret);


if (message.CreditCards != null)
foreach (var creditCard in message.CreditCards)
Console.Out.WriteLine("CreditCard: {0} is valid to {1}", creditCard.Number.Value, creditCard.ValidTo);
}
}
}
44 changes: 42 additions & 2 deletions src/core/NServiceBus/WireEncryptedString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,47 @@ public WireEncryptedString(SerializationInfo info, StreamingContext context)
/// <summary>
/// The encrypted value of this string
/// </summary>
public EncryptedValue EncryptedValue { get; set; }
public EncryptedValue EncryptedValue
{
get
{
if (encryptedValue != null)
return encryptedValue;

if(EncryptedBase64Value != null)
return new EncryptedValue
{
EncryptedBase64Value = EncryptedBase64Value,
Base64Iv = Base64Iv
};
return null;
}
set
{
encryptedValue = value;

if(encryptedValue != null)
{
EncryptedBase64Value = encryptedValue.EncryptedBase64Value;
Base64Iv = encryptedValue.Base64Iv;
}
}
}
EncryptedValue encryptedValue;

//**** we need to duplicate to make versions > 3.2.7 backwards compatible with 2.X

/// <summary>
/// Only keept for backwards compatibility reasons
/// </summary>
public string EncryptedBase64Value { get; set; }

/// <summary>
/// Only keept for backwards compatibility reasons
/// </summary>
public string Base64Iv { get; set; }

//****

/// <summary>
/// Gets the string value from the WireEncryptedString.
Expand Down Expand Up @@ -61,7 +101,7 @@ public static implicit operator WireEncryptedString(string s)
/// <param name="context"></param>
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("EncryptedValue", EncryptedValue);
info.AddValue("EncryptedValue", EncryptedValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace NServiceBus.Encryption.Config
{
public static class ConfigureEncryption
{
static ConfigureEncryption()
{
EnsureCompatibilityWithNSB2 = true;
}

/// <summary>
/// Causes the endpoint to no longer send extra data to make encryption compatible with NSB 2.X
/// </summary>
/// <returns></returns>
public static Configure DisableCompatibilityWithNSB2(this Configure config)
{
EnsureCompatibilityWithNSB2 = false;
return config;
}

public static bool EnsureCompatibilityWithNSB2 { get; set; }
}
}
Loading

0 comments on commit ffa83eb

Please sign in to comment.