@@ -112,7 +112,7 @@ class WebPusher:
112
112
valid_encodings = [
113
113
# "aesgcm128", # this is draft-0, but DO NOT USE.
114
114
"aesgcm" , # draft-httpbis-encryption-encoding-01
115
- "aes128gcm" # draft-httpbis-encryption- encoding-04
115
+ "aes128gcm" # RFC8188 Standard encoding
116
116
]
117
117
118
118
def __init__ (self , subscription_info , requests_session = None ):
@@ -157,17 +157,16 @@ def _repad(self, data):
157
157
"""Add base64 padding to the end of a string, if required"""
158
158
return data + b"====" [:len (data ) % 4 ]
159
159
160
- def encode (self , data , content_encoding = "aesgcm " ):
160
+ def encode (self , data , content_encoding = "aes128gcm " ):
161
161
"""Encrypt the data.
162
162
163
163
:param data: A serialized block of byte data (String, JSON, bit array,
164
164
etc.) Make sure that whatever you send, your client knows how
165
165
to understand it.
166
166
:type data: str
167
167
:param content_encoding: The content_encoding type to use to encrypt
168
- the data. Defaults to draft-01 "aesgcm". Latest draft-04 is
169
- "aes128gcm", however not all clients may be able to use this
170
- format.
168
+ the data. Defaults to RFC8188 "aes128gcm". The previous draft-01 is
169
+ "aesgcm", however this format is now deprecated.
171
170
:type content_encoding: enum("aesgcm", "aes128gcm")
172
171
173
172
"""
@@ -241,7 +240,7 @@ def as_curl(self, endpoint, encoded_data, headers):
241
240
url = endpoint , headers = "" .join (header_list ), data = data ))
242
241
243
242
def send (self , data = None , headers = None , ttl = 0 , gcm_key = None , reg_id = None ,
244
- content_encoding = "aesgcm " , curl = False , timeout = None ):
243
+ content_encoding = "aes128gcm " , curl = False , timeout = None ):
245
244
"""Encode and send the data to the Push Service.
246
245
247
246
:param data: A serialized block of data (see encode() ).
@@ -258,7 +257,7 @@ def send(self, data=None, headers=None, ttl=0, gcm_key=None, reg_id=None,
258
257
:param reg_id: registration id of the recipient. If not provided,
259
258
it will be extracted from the endpoint.
260
259
:type reg_id: str
261
- :param content_encoding: ECE content encoding (defaults to "aesgcm ")
260
+ :param content_encoding: ECE content encoding (defaults to "aes128gcm ")
262
261
:type content_encoding: str
263
262
:param curl: Display output as `curl` command instead of sending
264
263
:type curl: bool
@@ -284,8 +283,11 @@ def send(self, data=None, headers=None, ttl=0, gcm_key=None, reg_id=None,
284
283
headers .update ({
285
284
'crypto-key' : crypto_key ,
286
285
'content-encoding' : content_encoding ,
287
- 'encryption' : "salt=" + encoded ['salt' ].decode ('utf8' ),
288
286
})
287
+ if encoded .get ('salt' ):
288
+ headers .update ({
289
+ 'encryption' : "salt=" + encoded ['salt' ].decode ('utf8' )
290
+ })
289
291
if gcm_key :
290
292
endpoint = 'https://android.googleapis.com/gcm/send'
291
293
reg_ids = []
@@ -324,7 +326,7 @@ def webpush(subscription_info,
324
326
data = None ,
325
327
vapid_private_key = None ,
326
328
vapid_claims = None ,
327
- content_encoding = "aesgcm " ,
329
+ content_encoding = "aes128gcm " ,
328
330
curl = False ,
329
331
timeout = None ,
330
332
ttl = 0 ):
0 commit comments