Move signal scripts in folder and add deprecation notice

This commit is contained in:
Alexander Weidinger
2018-10-05 23:56:28 +02:00
parent af4570b10e
commit d827a96705
3 changed files with 3 additions and 0 deletions

3
signal/README.md Normal file
View File

@@ -0,0 +1,3 @@
# Signal
** deprecated - export functionality is removed by now: https://github.com/signalapp/Signal-Desktop/commit/8eeaad8e18823f83fa2c66b82616552b6d2b04e9**

10
signal/jsonDump.py Executable file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env python3
import json
import sys
content = None
with open(sys.argv[1], 'r') as fh:
content = json.load(fh, encoding='utf-8')
print(json.dumps(content, indent=4, separators=(',', ': '), ensure_ascii=False))

87
signal/signalDesktopDecrypt.py Executable file
View File

@@ -0,0 +1,87 @@
#!/usr/bin/env python3
import hashlib
from Crypto.Cipher import AES
from Crypto.Util import Padding
from Crypto.Hash import HMAC, SHA256
import sys
from getpass import getpass
from docopt import docopt
from os import listdir
IV_LENGTH = 16
NONCE_LENGTH = 16
MAC_LENGTH = 16
iv = bytearray(IV_LENGTH)
FORMAT_STRING = 'window.Signal.Backup.exportToDirectory(\'{0}\', {{\'key\':new Uint8Array({1})}});'
USAGE_STRING = """
Usage:
signalDesktopDecrypt generate --path <path>
signalDesktopDecrypt decrypt --path <path>
"""
def decrypt(cipherkey, ciphertext):
cipher = AES.new(cipherkey, AES.MODE_CBC, iv)
return Padding.unpad(cipher.decrypt(ciphertext), AES.block_size)
def generate_cipherkey(key, nonce):
h = HMAC.new(key, digestmod=SHA256)
h.update(nonce)
return h.digest()
def generate_key(password):
m = hashlib.sha256()
m.update(password)
return m.digest()
def extract_info(filepath):
data = ''
try:
with open(filepath, 'rb') as fh:
data = fh.read()
except FileNotFoundError:
print(filepath + ' was not found, please check --path argument')
sys.exit(1)
# extract none
nonce = data[:NONCE_LENGTH]
# extract ciphertext
ciphertext = data[NONCE_LENGTH:-MAC_LENGTH]
return nonce, ciphertext
def main():
params = docopt(USAGE_STRING)
if params['generate']:
# ask for password
password = getpass()
key = generate_key(password.encode('utf-8'))
# generate string to be pasted in Signal-Desktop
print('Use ctrl+i to open the developer tools in the signal desktop app, switch to console and paste the following text:\n')
print(FORMAT_STRING.format(params['<path>'], [elem for elem in key]))
return
elif params['decrypt']:
# ask for password
password = getpass()
key = generate_key(password.encode('utf-8'))
# extract messages.zip
nonce, ciphertext = extract_info(params['<path>'] + '/messages.zip')
cipherkey = generate_cipherkey(key, nonce)
with open(params['<path>'] + '/messages.zip', 'wb') as fh:
fh.write(decrypt(cipherkey, ciphertext))
# extract attachments
for filename in listdir(params['<path>'] + '/attachments/'):
nonce, ciphertext = extract_info(params['<path>'] + '/attachments/' + filename)
cipherkey = generate_cipherkey(key, nonce)
with open(params['<path>'] + '/attachments/' + filename, 'wb') as fh:
fh.write(decrypt(cipherkey, ciphertext))
if __name__ == '__main__':
main()