-
Notifications
You must be signed in to change notification settings - Fork 306
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
Fix for the #786 #812
Closed
Closed
Fix for the #786 #812
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2db6afe
migrate urlsafe-base64 to be internal to web-push
hikarunoryoma c84f172
move nyc dependancy back
hikarunoryoma 654ff6a
missed variable rename
hikarunoryoma 7d08d83
logging
haouarihk b41442a
ignore testing junk
haouarihk b10a9c0
decode fix
haouarihk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
coverage/ | ||
node_modules/ | ||
test/output/ | ||
|
||
# ignore nyc output | ||
.nyc_output | ||
|
||
# ignore history | ||
.history | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Largely ported from https://github.com/RGBboy/urlsafe-base64 | ||
|
||
'use strict'; | ||
|
||
function encode(buffer) { | ||
return buffer.toString('base64') | ||
.replace(/\+/g, '-') // Convert '+' to '-' | ||
.replace(/\//g, '_') // Convert '/' to '_' | ||
.replace(/=+$/, ''); // Remove ending '=' | ||
} | ||
|
||
function decode(base64) { | ||
// Add removed at end '=' | ||
base64 += Array(5 - (base64.length % 4)).join('='); | ||
|
||
base64 = base64 | ||
.replace(/-/g, '+') // Convert '-' to '+' | ||
.replace(/_/g, '/'); // Convert '_' to '/' | ||
|
||
// change from urlsafe-base64 since new Buffer() is deprecated | ||
return Buffer.from(base64, 'base64'); | ||
} | ||
|
||
function validate(base64) { | ||
return /^[A-Za-z0-9\-_]+$/.test(base64); | ||
} | ||
|
||
module.exports = { | ||
encode: encode, | ||
decode: decode, | ||
validate: validate | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,12 +1,12 @@ | ||||||
'use strict'; | ||||||
|
||||||
const crypto = require('crypto'); | ||||||
const urlBase64 = require('urlsafe-base64'); | ||||||
const asn1 = require('asn1.js'); | ||||||
const jws = require('jws'); | ||||||
const { URL } = require('url'); | ||||||
|
||||||
const WebPushConstants = require('./web-push-constants.js'); | ||||||
const urlBase64Helper = require('./urlsafe-base64-helper'); | ||||||
|
||||||
/** | ||||||
* DEFAULT_EXPIRATION is set to seconds in 12 hours | ||||||
|
@@ -60,8 +60,8 @@ function generateVAPIDKeys() { | |||||
} | ||||||
|
||||||
return { | ||||||
publicKey: urlBase64.encode(publicKeyBuffer), | ||||||
privateKey: urlBase64.encode(privateKeyBuffer) | ||||||
publicKey: urlBase64Helper.encode(publicKeyBuffer), | ||||||
privateKey: urlBase64Helper.encode(privateKeyBuffer) | ||||||
}; | ||||||
} | ||||||
|
||||||
|
@@ -100,14 +100,14 @@ function validatePublicKey(publicKey) { | |||||
+ 'encoded string.'); | ||||||
} | ||||||
|
||||||
if (!urlBase64.validate(publicKey)) { | ||||||
if (!urlBase64Helper.validate(publicKey)) { | ||||||
throw new Error('Vapid public key must be a URL safe Base 64 (without "=")'); | ||||||
} | ||||||
|
||||||
publicKey = urlBase64.decode(publicKey); | ||||||
publicKey = urlBase64Helper.decode(publicKey); | ||||||
|
||||||
if (publicKey.length !== 65) { | ||||||
throw new Error('Vapid public key should be 65 bytes long when decoded.'); | ||||||
throw new Error(`Vapid public key should be 65 bytes long when decoded. got (${publicKey.length}) ${publicKey}`); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -121,11 +121,11 @@ function validatePrivateKey(privateKey) { | |||||
+ 'encoded string.'); | ||||||
} | ||||||
|
||||||
if (!urlBase64.validate(privateKey)) { | ||||||
if (!urlBase64Helper.validate(privateKey)) { | ||||||
throw new Error('Vapid private key must be a URL safe Base 64 (without "=")'); | ||||||
} | ||||||
|
||||||
privateKey = urlBase64.decode(privateKey); | ||||||
privateKey = urlBase64Helper.decode(privateKey); | ||||||
|
||||||
if (privateKey.length !== 32) { | ||||||
throw new Error('Vapid private key should be 32 bytes long when decoded.'); | ||||||
|
@@ -203,7 +203,7 @@ function getVapidHeaders(audience, subject, publicKey, privateKey, contentEncodi | |||||
validatePublicKey(publicKey); | ||||||
validatePrivateKey(privateKey); | ||||||
|
||||||
privateKey = urlBase64.decode(privateKey); | ||||||
privateKey = urlBase64Helper.decode(privateKey); | ||||||
|
||||||
if (expiration) { | ||||||
validateExpiration(expiration); | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes in .gitignore are OK, but can you create a separate PR for them? I prefer to have self-contained PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see sorry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, thank you for working on the PR!
BTW, you don't need to close and create a new one, you can also just update an existing PR.