Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong order of sender and receiver keys in context #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/nl/martijndwars/webpush/HttpEce.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(publicKey), lengthPrefix(senderPubKey));
byte[] context = concat(labels.get(keyid).getBytes(UTF_8), new byte[1], lengthPrefix(receiverPubKey), lengthPrefix(senderPubKey));

return new byte[][]{
secret,
Expand Down