web-push-libs / webpush-java

Web Push library for Java
MIT License
318 stars 112 forks source link

Migration from old versions to the latest one #120

Closed KirillSBarsukov closed 4 years ago

KirillSBarsukov commented 4 years ago

Good evening! Long time ago, one of our ex- employee used that library to implement Web Push notifications. Right now, we have 3.1.0 version of the library. Is there any guides how to migrate to the newest version? Right now, when I am trying to use 3.1.0 version, I got Error 403. Thank you!

martijndwars commented 4 years ago

I never maintained a changelog (but should start doing so) and I cannot explain the 403 error you are getting. Could you try picking up the latest version, update any broken API calls, and see if you can still subscribe and subsequently receive a notification?

If you were not using VAPID before, you should start using VAPID. If you were using VAPID before, make sure to keep using the same key pair, otherwise you won't be able to send notifications to existing subscriptions.

I'll close this issue, but feel free to leave a comment if something is unclear.

KirillSBarsukov commented 4 years ago

Thank you for the answer! If you do not mind, I will ask another question about that method

   public PublicKey getUserPublicKey() throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
        KeyFactory kf = KeyFactory.getInstance("ECDH", BouncyCastleProvider.PROVIDER_NAME);
        ECNamedCurveParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp256r1");
        ECPoint point = ecSpec.getCurve().decodePoint(getKeyAsBytes());
        ECPublicKeySpec pubSpec = new ECPublicKeySpec(point, ecSpec);

        return kf.generatePublic(pubSpec);
    }

The line before last, ECPublicKeySpec pubSpec = new ECPublicKeySpec(point, ecSpec); We are passing two arguments into ECPublicKeySpec: ECPoint and ECNamedCurveParameterSpec. However, ECPublicKeySpec accepts only ECPoint and ECParameterSpec here the Oracle link.

Am I doing something wrong?

Thank you and appreciate your time!

martijndwars commented 4 years ago

I guess that snippet comes from the Wiki. I see that the imports are missing, but probably these classes come from the BouncyCastle API, not the Oracle API:

I also have a small Spring Boot project that demonstrates how to integrate the library -- might be useful. Let me know if there's anything else 😉