Skip to content

Keys from webpush-java not compatible #22

Description

@Tree4Free

The keys that I used with the https://github.com/web-push-libs/webpush-java library cannot be used to create a VapidKey object.

Exception in thread "main" java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: DerInputStream.getLength(): lengthTag=28, too big.
	at jdk.crypto.ec/sun.security.ec.ECKeyFactory.engineGeneratePublic(ECKeyFactory.java:158)
	at java.base/java.security.KeyFactory.generatePublic(KeyFactory.java:351)
	at com.interaso.webpush.CryptoKt.generatePublicKeyFromX509(Crypto.kt:81)
	at com.interaso.webpush.VapidKeys$Factory.create(VapidKeys.kt:58)
	at com.example.MainClazz.main(MainClazz.kt:47)
	at com.example.MainClazz.main(MainClazz.kt)
Caused by: java.security.InvalidKeyException: IOException: DerInputStream.getLength(): lengthTag=28, too big.
	at java.base/sun.security.x509.X509Key.decode(X509Key.java:397)
	at java.base/sun.security.x509.X509Key.decode(X509Key.java:402)
	at jdk.crypto.ec/sun.security.ec.ECPublicKeyImpl.<init>(ECPublicKeyImpl.java:74)
	at jdk.crypto.ec/sun.security.ec.ECKeyFactory.implGeneratePublic(ECKeyFactory.java:225)
	at jdk.crypto.ec/sun.security.ec.ECKeyFactory.engineGeneratePublic(ECKeyFactory.java:154)
	... 5 more

For reference I created a new key pair using the following page: https://www.attheminute.com/vapid-key-generator
I am not sure if my keys were originally created with such a page but the format and length of the keys looks similar to mine.

These are the example keys I tried:

val public = "BJwwFRoDoOx2vQPfvbeo-m1fZZHo6lIjtyTlWHjLNSCtHuWdGryZD5xt0LeawVQq7G60ioID1sC33fEoQT8jCzg"
val private = "P5GjTLppISlmUyNiZqZi0HNq7GXFniAdcBECNsKBxfI"

It would be great if there was a way to migrate to this library and keep using my keys like maybe converting them into a format that this library can use. Otherwise all users would have to re-enable the webpush subscription.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions