@@ -80,31 +80,7 @@ function encryptOld(userPublicKey, payload) {
80
80
} ;
81
81
}
82
82
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+.
108
84
function encrypt ( userPublicKey , userAuth , payload ) {
109
85
var localCurve = crypto . createECDH ( 'prime256v1' ) ;
110
86
var localPublicKey = localCurve . generateKeys ( ) ;
@@ -169,18 +145,11 @@ function sendNotification(endpoint, params) {
169
145
if ( userAuth ) {
170
146
useCryptoKey = true ;
171
147
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' ;
182
151
} 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).
184
153
encrypted = encryptOld ( userPublicKey , new Buffer ( payload ) ) ;
185
154
encodingHeader = 'aesgcm128' ;
186
155
}
0 commit comments