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

illegal base64 data at input byte 'x' for decoding vapid private key #29

Closed
maheshnayer opened this issue Jul 8, 2019 · 4 comments · Fixed by #30
Closed

illegal base64 data at input byte 'x' for decoding vapid private key #29

maheshnayer opened this issue Jul 8, 2019 · 4 comments · Fixed by #30
Labels

Comments

@maheshnayer
Copy link

Hi
I'm experiencing this error while trying to send notifications
My private key has a "+" in the string and the input byte location points to this char. How can I get over this?
My public key also has a "+" in it. Same issue here as well
Any help appreciated
Thank you

@juan88
Copy link

juan88 commented Jul 22, 2019

I'm having the same issue when trying to send notifications.

I have generated the key using openssl like:

  • openssl ecparam -name prime256v1 -genkey -noout -out vapid_private.pem
  • openssl ec -in vapid_private.pem -pubout -out vapid_public.pem

I think that is throwing an error in the function getVAPIDAuthorizationHeader in vapid.go when trying to do:
base64.RawURLEncoding.DecodeString(vapidPrivateKey)

Thanks!

@SherClockHolmes
Copy link
Owner

SherClockHolmes commented Jul 25, 2019

@juan88 Is there a reason you are not using the webpush.GenerateVAPIDKeys() method to generate your vapid keys?

@juan88
Copy link

juan88 commented Jul 26, 2019

Hi!

No there was no specific reasong why. I started with a tutorial from the mozilla's blog and I created the keys in the way I posted.

Then I created a couple of keys with the function you specified and save them to a file. That is the correct way to handle it right? I mean, the keypair generated is supposed to be reused across all the notifications that you sent.

That worked for me. So I think that is an issue with the way that the keys are encoded. If you generate the keys by any other method, the function base64.RawURLEncoding.DecodeString(vapidPrivateKey) may throw that error since it uses a specific way to encode base64 strings. I've found out in the official docs from the package and the corresponding RFC.

@froodian
Copy link
Contributor

froodian commented Sep 4, 2019

in our organization's fork, we have made a change where we decode vapid keys with this method

func decodeVapidKey(key string) ([]byte, error) {
	bytes, err := base64.URLEncoding.DecodeString(key)
	if err == nil {
		return bytes, nil
	}
	return base64.RawURLEncoding.DecodeString(key)
}

which solves this issue for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants