Skip to content

Commit d866291

Browse files
author
Kyle Baley
authored
Standardize encryption key headers (#379)
1 parent 006a292 commit d866291

6 files changed

Lines changed: 10 additions & 17 deletions

src/AcceptanceTests/When_using_Aes_without_incoming_key_identifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class RemoveKeyIdentifierHeaderMutator : IMutateIncomingTransportMessages
9191
{
9292
public Task MutateIncoming(MutateIncomingTransportMessageContext context)
9393
{
94-
context.Headers.Remove(EncryptionHeaders.AesKeyIdentifier);
94+
context.Headers.Remove(EncryptionHeaders.EncryptionKeyIdentifier);
9595
return Task.FromResult(0);
9696
}
9797
}

src/AcceptanceTests/When_using_Rijndael_without_incoming_key_identifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class RemoveKeyIdentifierHeaderMutator : IMutateIncomingTransportMessages
9595
{
9696
public Task MutateIncoming(MutateIncomingTransportMessageContext context)
9797
{
98-
context.Headers.Remove(EncryptionHeaders.RijndaelKeyIdentifier);
98+
context.Headers.Remove(EncryptionHeaders.EncryptionKeyIdentifier);
9999
return Task.FromResult(0);
100100
}
101101
}

src/MessageProperty/AesEncryptionService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageCont
111111
{
112112
return DecryptUsingKeyIdentifier(encryptedValue, keyIdentifier);
113113
}
114-
Log.Warn($"Encrypted message has no '{EncryptionHeaders.AesKeyIdentifier}' header. Possibility of data corruption. Upgrade endpoints that send message with encrypted properties.");
114+
Log.Warn($"Encrypted message has no '{EncryptionHeaders.EncryptionKeyIdentifier}' header. Possibility of data corruption. Upgrade endpoints that send message with encrypted properties.");
115115
return DecryptUsingAllKeys(encryptedValue);
116116
}
117117

@@ -252,16 +252,15 @@ static bool IsValidKey(byte[] key)
252252
/// </summary>
253253
protected internal virtual void AddKeyIdentifierHeader(IOutgoingLogicalMessageContext context)
254254
{
255-
context.Headers[EncryptionHeaders.AesKeyIdentifier] = encryptionKeyIdentifier;
256-
context.Headers[EncryptionHeaders.RijndaelKeyIdentifier] = encryptionKeyIdentifier;
255+
context.Headers[EncryptionHeaders.EncryptionKeyIdentifier] = encryptionKeyIdentifier;
257256
}
258257

259258
/// <summary>
260259
/// Tries to locate an encryption key identifier from an incoming message.
261260
/// </summary>
262261
protected internal virtual bool TryGetKeyIdentifierHeader(out string keyIdentifier, IIncomingLogicalMessageContext context)
263262
{
264-
return context.Headers.TryGetValue(EncryptionHeaders.AesKeyIdentifier, out keyIdentifier);
263+
return context.Headers.TryGetValue(EncryptionHeaders.EncryptionKeyIdentifier, out keyIdentifier);
265264
}
266265

267266
/// <summary>

src/MessageProperty/EncryptionHeaders.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ public static class EncryptionHeaders
88
/// <summary>
99
/// The identifier to lookup the key to decrypt the encrypted data.
1010
/// </summary>
11-
public const string RijndaelKeyIdentifier = "NServiceBus.RijndaelKeyIdentifier";
12-
/// <summary>
13-
/// The AES identifier to lookup the key to decrypt the encrypted data.
14-
/// </summary>
15-
public const string AesKeyIdentifier = "NServiceBus.AesKeyIdentifier";
11+
public const string EncryptionKeyIdentifier = "NServiceBus.RijndaelKeyIdentifier";
1612
}
1713
}

src/MessageProperty/RijndaelEncryptionService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageCont
114114
{
115115
return DecryptUsingKeyIdentifier(encryptedValue, keyIdentifier);
116116
}
117-
Log.Warn($"Encrypted message has no '{EncryptionHeaders.RijndaelKeyIdentifier}' header. Possibility of data corruption. Upgrade endpoints that send message with encrypted properties.");
117+
Log.Warn($"Encrypted message has no '{EncryptionHeaders.EncryptionKeyIdentifier}' header. Possibility of data corruption. Upgrade endpoints that send message with encrypted properties.");
118118
return DecryptUsingAllKeys(encryptedValue);
119119
}
120120

@@ -262,16 +262,15 @@ static bool IsValidKey(byte[] key)
262262
/// </summary>
263263
protected internal virtual void AddKeyIdentifierHeader(IOutgoingLogicalMessageContext context)
264264
{
265-
context.Headers[EncryptionHeaders.RijndaelKeyIdentifier] = encryptionKeyIdentifier;
266-
context.Headers[EncryptionHeaders.AesKeyIdentifier] = encryptionKeyIdentifier;
265+
context.Headers[EncryptionHeaders.EncryptionKeyIdentifier] = encryptionKeyIdentifier;
267266
}
268267

269268
/// <summary>
270269
/// Tries to locate an encryption key identfier from an incoming message.
271270
/// </summary>
272271
protected internal virtual bool TryGetKeyIdentifierHeader(out string keyIdentifier, IIncomingLogicalMessageContext context)
273272
{
274-
return context.Headers.TryGetValue(EncryptionHeaders.RijndaelKeyIdentifier, out keyIdentifier);
273+
return context.Headers.TryGetValue(EncryptionHeaders.EncryptionKeyIdentifier, out keyIdentifier);
275274
}
276275

277276
/// <summary>

src/Tests/ApprovalFiles/APIApprovals.Approve.approved.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ namespace NServiceBus.Encryption.MessageProperty
3939
}
4040
public static class EncryptionHeaders
4141
{
42-
public const string AesKeyIdentifier = "NServiceBus.AesKeyIdentifier";
43-
public const string RijndaelKeyIdentifier = "NServiceBus.RijndaelKeyIdentifier";
42+
public const string EncryptionKeyIdentifier = "NServiceBus.RijndaelKeyIdentifier";
4443
}
4544
public interface IEncryptionService
4645
{

0 commit comments

Comments
 (0)