Skip to content

Commit 9af0bb3

Browse files
committed
Remove intermediate standard implementation
1 parent 73ceb2f commit 9af0bb3

File tree

1 file changed

+5
-36
lines changed

1 file changed

+5
-36
lines changed

index.js

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,7 @@ function encryptOld(userPublicKey, payload) {
8080
};
8181
}
8282

83-
// Intermediate standard, Firefox 46.
84-
function encryptIntermediate(userPublicKey, userAuth, payload) {
85-
var localCurve = crypto.createECDH('prime256v1');
86-
var localPublicKey = localCurve.generateKeys();
87-
88-
var salt = urlBase64.encode(crypto.randomBytes(16));
89-
90-
ece.saveKey('webpushKey', localCurve, 'P-256');
91-
92-
var cipherText = ece.encrypt(payload, {
93-
keyid: 'webpushKey',
94-
dh: userPublicKey,
95-
salt: salt,
96-
authSecret: userAuth,
97-
padSize: 1,
98-
});
99-
100-
return {
101-
localPublicKey: localPublicKey,
102-
salt: salt,
103-
cipherText: cipherText,
104-
};
105-
}
106-
107-
// New standard, Firefox 47+ and Chrome 50+.
83+
// New standard, Firefox 46+ and Chrome 50+.
10884
function encrypt(userPublicKey, userAuth, payload) {
10985
var localCurve = crypto.createECDH('prime256v1');
11086
var localPublicKey = localCurve.generateKeys();
@@ -169,18 +145,11 @@ function sendNotification(endpoint, params) {
169145
if (userAuth) {
170146
useCryptoKey = true;
171147

172-
var userAuthBuf = urlBase64.decode(userAuth);
173-
if (userAuthBuf.length === 16) {
174-
// Use the new standard if userAuth is defined and is 16 bytes long (Firefox 47+ and Chrome 50+).
175-
encrypted = encrypt(userPublicKey, userAuth, new Buffer(payload));
176-
encodingHeader = 'aesgcm';
177-
} else {
178-
// Use the intermediate standard if userAuth is defined and is 12 bytes long (Firefox 46).
179-
encrypted = encryptIntermediate(userPublicKey, userAuth, new Buffer(payload));
180-
encodingHeader = 'aesgcm128';
181-
}
148+
// Use the new standard if userAuth is defined (Firefox 46+ and Chrome 50+).
149+
encrypted = encrypt(userPublicKey, userAuth, new Buffer(payload));
150+
encodingHeader = 'aesgcm';
182151
} else {
183-
// Use the old standard if userAuth isn't defined (Firefox 45).
152+
// Use the old standard if userAuth isn't defined (up to Firefox 45).
184153
encrypted = encryptOld(userPublicKey, new Buffer(payload));
185154
encodingHeader = 'aesgcm128';
186155
}

0 commit comments

Comments
 (0)