comparison sat/plugins/plugin_sec_aesgcm.py @ 3178:98b321234068

plugin aesgcm: use 12 bytes Initialisation Vector: SàT was using 16 bytes IV when sending files withr AES-GCM, due to ChatSecure being only compatible with that. Monal, an other iOS client is only compatible with 12 bytes IV, and ChatSecure has fixed its code to also handle 12 bytes IV, so there is not reason anymore to use 16 bytes, and SàT now uses 12 bytes.
author Goffi <goffi@goffi.org>
date Tue, 18 Feb 2020 18:17:18 +0100
parents c90f27ce52b0
children 84b0c8b4dee0
comparison
equal deleted inserted replaced
3177:f4914ce9d47d 3178:98b321234068
168 168
169 def _uploadTrigger(self, client, options, sat_file, file_producer, slot): 169 def _uploadTrigger(self, client, options, sat_file, file_producer, slot):
170 if options.get('encryption') != C.ENC_AES_GCM: 170 if options.get('encryption') != C.ENC_AES_GCM:
171 return True 171 return True
172 log.debug("encrypting file with AES-GCM") 172 log.debug("encrypting file with AES-GCM")
173 # specification talks about 12 bytes IV, but in practice and for legacy reasons 173 iv = secrets.token_bytes(12)
174 # 16 bytes are used by most clients (and also in the specification example).
175 # It seems that some clients don't handle 12 bytes IV (apparently,
176 # that's the case for ChatSecure).
177 # So we have to follow the de-facto standard and use 16 bytes to be sure
178 # to be compatible with a maximum of clients.
179 iv = secrets.token_bytes(16)
180 key = secrets.token_bytes(32) 174 key = secrets.token_bytes(32)
181 fragment = f'{iv.hex()}{key.hex()}' 175 fragment = f'{iv.hex()}{key.hex()}'
182 ori_url = parse.urlparse(slot.get) 176 ori_url = parse.urlparse(slot.get)
183 # we change the get URL with the one with aesgcm scheme and containing the 177 # we change the get URL with the one with aesgcm scheme and containing the
184 # encoded key + iv 178 # encoded key + iv