From a66ff138347ce3e7bf0ccd48e66d130965c9d68b Mon Sep 17 00:00:00 2001 From: Antochi Anton Date: Thu, 15 Feb 2024 23:29:58 +0400 Subject: [PATCH 1/2] Fix wrong order of keys in context --- src/main/java/nl/martijndwars/webpush/HttpEce.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/nl/martijndwars/webpush/HttpEce.java b/src/main/java/nl/martijndwars/webpush/HttpEce.java index b9e9436..bd25b8e 100644 --- a/src/main/java/nl/martijndwars/webpush/HttpEce.java +++ b/src/main/java/nl/martijndwars/webpush/HttpEce.java @@ -362,7 +362,7 @@ private byte[][] extractDH(String keyid, ECPublicKey publicKey) throws NoSuchAl keyAgreement.doPhase(publicKey, true); byte[] secret = keyAgreement.generateSecret(); - byte[] context = concat(labels.get(keyid).getBytes(UTF_8), new byte[1], lengthPrefix(publicKey), lengthPrefix(senderPubKey)); + byte[] context = concat(labels.get(keyid).getBytes(UTF_8), new byte[1], lengthPrefix(senderPubKey), lengthPrefix(publicKey)); return new byte[][]{ secret, From c609e0b6d68ed9644f5f227d66c15ec7946b863f Mon Sep 17 00:00:00 2001 From: Antochi Anton Date: Fri, 16 Feb 2024 00:14:07 +0400 Subject: [PATCH 2/2] Update HttpEce.java --- src/main/java/nl/martijndwars/webpush/HttpEce.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/nl/martijndwars/webpush/HttpEce.java b/src/main/java/nl/martijndwars/webpush/HttpEce.java index bd25b8e..d2dc009 100644 --- a/src/main/java/nl/martijndwars/webpush/HttpEce.java +++ b/src/main/java/nl/martijndwars/webpush/HttpEce.java @@ -354,15 +354,15 @@ public byte[] webpushSecret(String keyId, ECPublicKey dh, byte[] authSecret, int * @param publicKey * @return */ - private byte[][] extractDH(String keyid, ECPublicKey publicKey) throws NoSuchAlgorithmException, InvalidKeyException { - ECPublicKey senderPubKey = getPublicKey(keyid); + private byte[][] extractDH(String keyid, ECPublicKey senderPubKey) throws NoSuchAlgorithmException, InvalidKeyException { + ECPublicKey receiverPubKey = getPublicKey(keyid); KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH"); keyAgreement.init(getPrivateKey(keyid)); - keyAgreement.doPhase(publicKey, true); + keyAgreement.doPhase(senderPubKey, true); byte[] secret = keyAgreement.generateSecret(); - byte[] context = concat(labels.get(keyid).getBytes(UTF_8), new byte[1], lengthPrefix(senderPubKey), lengthPrefix(publicKey)); + byte[] context = concat(labels.get(keyid).getBytes(UTF_8), new byte[1], lengthPrefix(receiverPubKey), lengthPrefix(senderPubKey)); return new byte[][]{ secret,