Comments (11)
After some hit and trial I am able to resolve it.
Issue: When I was working with JDK 1.8 and bcprov-jdk15on-164.jar which is the latest bouncy castle for JDK 1.5 - JDK 1.11, it was working awesome. But bcprov-jdk15on-164.jar doesn't work for JDK 1.7.0_80 and getting "java.security.InvalidKeyException: Not an EC key: ECDH" error.
Solution: While working with JDK 1.7.0_80 please use bcprov-jdk15to18-164.jar provider which is for JDK 1.5 - JDK 1.8.
from webpush-java.
Try adding the following code to your initialisation. This installs the BouncyCastle security provider:
Security.addProvider(new BouncyCastleProvider());
from webpush-java.
I added it without which it's not even working
from webpush-java.
Any update on this issue? I've added the code snippet to add the BouncyCastleProvider but I'm still receiving the same exception: java.security.InvalidKeyException: Not an EC key: ECDH
from webpush-java.
Sorry, no update. I can spend some time on this next weekend, but since I'm not able to reproduce the problem it's very hard to debug. What is your setup (operating system, Java runtime, etc)?
from webpush-java.
Thank you Martijn! I'm running on Mac, Java 1.8 in a Spring application. It's happening on the pushService.send(notification) call.
from webpush-java.
If I recall correctly, Sun's implementation of Java Cryptography Extension (JCE), which is included in the JDK, does not support ECDH. That's the reason I added a dependency on BouncyCastle; they do provide the necessary encryption.
From the stack trace I infer that it is using Sun's implementation instead of BouncyCastle's implementation. I cannot explain why this is happening. Could you try to give BouncyCastle provider highest priority? Instead of just calling addProvider
, you call insertProviderAt
:
Security. insertProviderAt(new BouncyCastleProvider(), 1);
from webpush-java.
The highest priority I was able to give the BouncyCastleProvider without crashing my app was 5, and I still received the same exception :/. It still came before the JCE provider.
For reference, here's the result I get from the Security.getProviders() call:
from webpush-java.
I did the same check and I get a similar result. It's not necessarily bad that it first tries Sun's implementation. In fact, that's what happens on my machine as well. While stepping through the code, the InvalidKeyException: Not an EC key: ECDH
is thrown as well, but the KeyAgreement
class catches the exception and goes on to the next provider (until it arrives at the BouncyCastle implementation).
Could you try stepping through the code and see if something similar happens (or where it goes wrong)?
from webpush-java.
Found out the issue was that the JCE could not authenticate the BouncyCastleProvider, even when explicitly adding the provider via Security.addProvider(new BouncyCastleProvider())
or Security.insertProviderAt(new BouncyCastleProvider(),1)
.
The solution that worked for me can be found here: https://stackoverflow.com/a/17400821, which was to manually add the BouncyCastle jars to the directory: $JAVA_HOME/jre/lib/ext/. Those jars can just be downloaded from the BouncyCastle website: https://www.bouncycastle.org/latest_releases.html
from webpush-java.
I came across this issue as well when I created a fat JAR (a.k.a. uber JAR, shadow JAR). The BouncyCastle JAR is signed and if you create a fat JAR the contents of the BouncyCastle JAR are extracted and put in the fat JAR which breaks the signature. I suspect something similar was happening to you.
When I realised this I updated the build.gradle
to exclude BouncyCastle from the fat JAR and add ../../lib/bcprov-jdk15on-154.jar
to the Class-Path definition MANIFEST.MF
. That way, when you run the generated fat JAR, it adds BouncyCastle to the classpath. Unfortunately, I had to commit lib/bcprov-jdk15on-154.jar
into git.
In practice, developers will be using this project as a library and not as a fat JAR, so they will have to change their build to provide BouncyCastle at runtime. There are many ways to do this:
- Put
bcprov-jdk15on-154.jar
in$JAVA_HOME/jre/lib/ext
, like you suggested. The downside of this approach is that if you need to repeat this if you update your JRE. - Adapt the build system to add BouncyCastle at runtime (similar to how I adapted the
gradle.build
to add a Class-Path to theMANIFEST.MF
). The downside is that you need to commitbcprov-jdk15on-154.jar
into git. - Use a custom class loader that is able to load nested JARs. That way you can put the BouncyCastle JAR in a fat JAR without breaking the signature. The downside is that you need to create and use a custom classloader (Spring Boot provides one, though).
I will update the README with instructions. Thanks for your investigation and feedback!
from webpush-java.
Related Issues (20)
- Why don't you set public and private key after creating the pushService? HOT 3
- Which Firewall rules need to be adjusted?
- not able to make push notifications pop up on screen of android phone HOT 3
- Getting 406 status code - Not Acceptable HOT 2
- How to install in Eclipse? HOT 1
- Dependency Dashboard
- Can I use this Library for my
- Can I use it also in react?
- Post request no pass through proxy when PushAsyncService is used.
- Invalid VAPID token: A value in the vapid claims is either missing or incorrectly specified HOT 15
- Thread leak - too many open files HOT 1
- 403 Forbidden issue on Chrome but working on Firefox HOT 4
- PushAsyncService start an HTTP client but provides no way to shut it down, leaving threads running
- Requires parameters that aren't provided by client side
- please release new version with safe dependencies HOT 1
- Webpush not triggering notifcations to safari HOT 14
- Error 403 for chorme
- Sending web push to APNs (https://web.push.apple.com) responds with 403 Forbidden HOT 5
- 403 Forbidden for Chrome HOT 1
- FCM API will be removed in June 2024 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpush-java.