web-push-libs / webpush-java

Web Push library for Java
MIT License
315 stars 113 forks source link

Update HttpEce to use BC provider when calling KeyAgreement #205

Open frmans opened 1 year ago

frmans commented 1 year ago

Since there already is a dependency to BouncyCastle in Utils.java it doesn't add any more restrictions doing this, also this solves the following issue https://github.com/web-push-libs/webpush-java/issues/5

dofs197 commented 1 year ago

This is useful patch. It helped me to reveal the problem under wildfly: https://issues.redhat.com/browse/WFLY-4576

java.security.NoSuchProviderException: JCE cannot authenticate the provider BC
    at javax.crypto.JceSecurity.getInstance(JceSecurity.java:105)
    at javax.crypto.KeyAgreement.getInstance(KeyAgreement.java:230)
    at nl.martijndwars.webpush.HttpEce.extractDH(HttpEce.java:360)
...
Caused by: java.lang.SecurityException: Cannot verify jar:vfs:/content/runawfe.ear/lib/bcprov-debug-jdk18on-1.73.jar!/
    at javax.crypto.JarVerifier.verifySingleJar(JarVerifier.java:448)
...
Caused by: java.security.PrivilegedActionException: java.util.zip.ZipException: zip file is empty
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.crypto.JarVerifier.verifySingleJar(JarVerifier.java:426)
    ... 75 more
Caused by: java.util.zip.ZipException: zip file is empty
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:225)
    ... 77 more
    Suppressed: java.nio.file.NoSuchFileException: /tmp/jar_cache2337284540188290599.tmp
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
        ... 86 more