Skip to content

Commit b2b9eeb

Browse files
committed
Make client keys handling case insensitive (#26)
1 parent ab0df61 commit b2b9eeb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Lib.Net.Http.WebPush/PushServiceClient.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,18 @@ private static HttpRequestMessage SetContent(HttpRequestMessage pushMessageDeliv
291291
}
292292
else
293293
{
294+
string p256dhKey = subscription.GetKey(PushEncryptionKeyName.P256DH);
295+
string authKey = subscription.GetKey(PushEncryptionKeyName.Auth);
296+
297+
if (String.IsNullOrWhiteSpace(p256dhKey) || String.IsNullOrWhiteSpace(authKey))
298+
{
299+
throw new InvalidOperationException("The client P-256 public key or authentication secret is not available");
300+
}
301+
294302
ECDHAgreement keyAgreement = ECDHAgreementCalculator.CalculateAgreement
295303
(
296-
UrlBase64Converter.FromUrlBase64String(subscription.GetKey(PushEncryptionKeyName.P256DH)),
297-
UrlBase64Converter.FromUrlBase64String(subscription.GetKey(PushEncryptionKeyName.Auth))
304+
UrlBase64Converter.FromUrlBase64String(p256dhKey),
305+
UrlBase64Converter.FromUrlBase64String(authKey)
298306
);
299307

300308
pushMessageDeliveryRequest.Content = new Aes128GcmEncodedContent(

src/Lib.Net.Http.WebPush/PushSubscription.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Linq;
3+
using System.Collections.Generic;
24

35
namespace Lib.Net.Http.WebPush
46
{
@@ -37,6 +39,10 @@ public string GetKey(PushEncryptionKeyName keyName)
3739
{
3840
key = Keys[keyNameStringified];
3941
}
42+
else
43+
{
44+
key = Keys.SingleOrDefault(x => String.Equals(x.Key, keyNameStringified, StringComparison.OrdinalIgnoreCase)).Value;
45+
}
4046
}
4147

4248
return key;

0 commit comments

Comments
 (0)