Skip to content

Commit ffa83eb

Browse files
committed
Merge branch '3.2.8'
2 parents c4d1162 + da55d59 commit ffa83eb

13 files changed

+565
-226
lines changed

Samples/Encryption/Client/App.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</MessageEndpointMappings>
2020
</UnicastBusConfig>
2121

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

2424
<appSettings>
2525
</appSettings>

Samples/Encryption/Client/Client.cs

+18-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
using Messages;
44

55
namespace Client
6-
{
6+
{
7+
using System.Collections.Generic;
8+
using NServiceBus.Encryption.Config;
9+
710
public class EndpointConfig : IConfigureThisEndpoint, AsA_Client {}
811

912
public class SecurityConfig : IWantCustomInitialization
1013
{
11-
public void Init()
12-
{
13-
Configure.Instance.RijndaelEncryptionService();
14+
public void Init()
15+
{
16+
Configure.Instance.RijndaelEncryptionService();
17+
//.DisableCompatibilityWithNSB2();//uncomment this line to turn off compatibility with2.X endpoints
1418
}
1519
}
1620

@@ -21,7 +25,16 @@ public void Run()
2125
Console.WriteLine("Press 'Enter' to send a message.");
2226
while (Console.ReadLine() != null)
2327
{
24-
Bus.Send<MessageWithSecretData>(m => m.Secret = "betcha can't guess my secret");
28+
Bus.Send<MessageWithSecretData>(m =>
29+
{
30+
m.Secret = "betcha can't guess my secret";
31+
m.SubProperty = new MySecretSubProperty {Secret = "My sub secret"};
32+
m.CreditCards = new List<CreditCardDetails>
33+
{
34+
new CreditCardDetails{ValidTo = DateTime.UtcNow.AddYears(1), Number = "312312312312312"},
35+
new CreditCardDetails{ValidTo = DateTime.UtcNow.AddYears(2), Number = "543645546546456"}
36+
};
37+
});
2538
}
2639
}
2740

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
using NServiceBus;
22

33
namespace Messages
4-
{
4+
{
5+
using System;
6+
using System.Collections.Generic;
7+
58
public class MessageWithSecretData : IMessage
69
{
710
public WireEncryptedString Secret { get; set; }
8-
}
11+
public MySecretSubProperty SubProperty{ get; set; }
12+
public List<CreditCardDetails> CreditCards { get; set; }
13+
}
14+
15+
public class CreditCardDetails
16+
{
17+
public DateTime ValidTo { get; set; }
18+
public WireEncryptedString Number { get; set; }
19+
}
20+
21+
public class MySecretSubProperty
22+
{
23+
public WireEncryptedString Secret { get; set; }
24+
}
925
}

Samples/Encryption/Server/App.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

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

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

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

Samples/Encryption/Server/Server.cs

+32-24
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
using System;
2-
using Messages;
3-
using NServiceBus;
4-
5-
namespace Server
6-
{
7-
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
8-
{
9-
public void Init()
10-
{
11-
Configure.With()
12-
.StructureMapBuilder()
13-
.RijndaelEncryptionService();
14-
}
15-
}
16-
17-
public class Handler : IHandleMessages<MessageWithSecretData>
18-
{
19-
public void Handle(MessageWithSecretData message)
20-
{
21-
Console.WriteLine("I know your secret - it's '" + message.Secret + "'.");
22-
}
23-
}
24-
}
1+
using System;
2+
using Messages;
3+
using NServiceBus;
4+
5+
namespace Server
6+
{
7+
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
8+
{
9+
public void Init()
10+
{
11+
Configure.With()
12+
.StructureMapBuilder()
13+
.RijndaelEncryptionService();
14+
}
15+
}
16+
17+
public class Handler : IHandleMessages<MessageWithSecretData>
18+
{
19+
public void Handle(MessageWithSecretData message)
20+
{
21+
Console.Out.WriteLine("I know your secret - it's '" + message.Secret + "'");
22+
23+
if (message.SubProperty != null)
24+
Console.Out.WriteLine("SubSecret: " + message.SubProperty.Secret);
25+
26+
27+
if (message.CreditCards != null)
28+
foreach (var creditCard in message.CreditCards)
29+
Console.Out.WriteLine("CreditCard: {0} is valid to {1}", creditCard.Number.Value, creditCard.ValidTo);
30+
}
31+
}
32+
}

src/core/NServiceBus/WireEncryptedString.cs

+42-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,47 @@ public WireEncryptedString(SerializationInfo info, StreamingContext context)
3232
/// <summary>
3333
/// The encrypted value of this string
3434
/// </summary>
35-
public EncryptedValue EncryptedValue { get; set; }
35+
public EncryptedValue EncryptedValue
36+
{
37+
get
38+
{
39+
if (encryptedValue != null)
40+
return encryptedValue;
41+
42+
if(EncryptedBase64Value != null)
43+
return new EncryptedValue
44+
{
45+
EncryptedBase64Value = EncryptedBase64Value,
46+
Base64Iv = Base64Iv
47+
};
48+
return null;
49+
}
50+
set
51+
{
52+
encryptedValue = value;
53+
54+
if(encryptedValue != null)
55+
{
56+
EncryptedBase64Value = encryptedValue.EncryptedBase64Value;
57+
Base64Iv = encryptedValue.Base64Iv;
58+
}
59+
}
60+
}
61+
EncryptedValue encryptedValue;
62+
63+
//**** we need to duplicate to make versions > 3.2.7 backwards compatible with 2.X
64+
65+
/// <summary>
66+
/// Only keept for backwards compatibility reasons
67+
/// </summary>
68+
public string EncryptedBase64Value { get; set; }
69+
70+
/// <summary>
71+
/// Only keept for backwards compatibility reasons
72+
/// </summary>
73+
public string Base64Iv { get; set; }
74+
75+
//****
3676

3777
/// <summary>
3878
/// Gets the string value from the WireEncryptedString.
@@ -61,7 +101,7 @@ public static implicit operator WireEncryptedString(string s)
61101
/// <param name="context"></param>
62102
public void GetObjectData(SerializationInfo info, StreamingContext context)
63103
{
64-
info.AddValue("EncryptedValue", EncryptedValue);
104+
info.AddValue("EncryptedValue", EncryptedValue);
65105
}
66106
}
67107

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace NServiceBus.Encryption.Config
2+
{
3+
public static class ConfigureEncryption
4+
{
5+
static ConfigureEncryption()
6+
{
7+
EnsureCompatibilityWithNSB2 = true;
8+
}
9+
10+
/// <summary>
11+
/// Causes the endpoint to no longer send extra data to make encryption compatible with NSB 2.X
12+
/// </summary>
13+
/// <returns></returns>
14+
public static Configure DisableCompatibilityWithNSB2(this Configure config)
15+
{
16+
EnsureCompatibilityWithNSB2 = false;
17+
return config;
18+
}
19+
20+
public static bool EnsureCompatibilityWithNSB2 { get; set; }
21+
}
22+
}

0 commit comments

Comments
 (0)