Files
PBinCLI/pbincli/actions.py

36 lines
1.3 KiB
Python
Raw Normal View History

2017-02-18 21:00:40 +03:00
"""Action functions for argparser"""
2017-02-19 09:40:04 +03:00
import base64
2017-02-18 21:00:40 +03:00
import pbincli.actions
2017-02-19 09:40:04 +03:00
from Crypto.Hash import SHA256
from Crypto.Random import get_random_bytes
from pbincli.sjcl_gcm import SJCL
2017-02-19 13:26:22 +03:00
from pbincli.transports import privatebin
2017-02-18 21:00:40 +03:00
from pbincli.utils import PBinCLIException, check_readable, check_writable
2017-02-19 09:40:04 +03:00
from zlib import compress
2017-02-19 06:48:10 -05:00
import json
2017-02-18 21:00:40 +03:00
def send(args):
2017-02-19 09:40:04 +03:00
""" Sub-command for sending paste """
check_readable(args.filename)
with open(args.filename, "rb") as f:
contents = f.read()
file = base64.b64encode(compress(contents))
passphrase = base64.b64encode(get_random_bytes(32))
if not args.password:
password = passphrase
else:
p = SHA256.new()
p.update(args.password.encode("UTF-8"))
password = passphrase + p.hexdigest().encode("UTF-8")
data = SJCL().encrypt(file, password)
2017-02-19 06:48:10 -05:00
#request = "data={}&expire={}&formatter={}&burnafterreading={}&opendiscussion={}".format(json.dumps(data, ensure_ascii=False), args.expire, args.format, int(args.burn), int(args.discus))
request = {'data':json.dumps(data, ensure_ascii=False),'expire':args.expire,'formatter':args.format,'burnafterreading':int(args.burn),'opendiscussion':int(args.discus)
}
print(request)
2017-02-19 09:40:04 +03:00
'''Here we must run function post from pbincli.transports'''
2017-02-19 13:26:22 +03:00
print(request)
privatebin().post(request)