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 20:15:26 +03:00
import json
import os
2017-02-18 21:00:40 +03:00
import pbincli.actions
2017-02-19 20:15:26 +03:00
'''from pbincli.sjcl_gcm import SJCL'''
import pbincli.sjcl_simple
from base64 import b64encode
2017-02-19 09:40:04 +03:00
from Crypto.Hash import SHA256
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-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()
2017-02-19 20:15:26 +03:00
file = b64encode(compress(contents))
2017-02-19 09:40:04 +03:00
2017-02-19 20:15:26 +03:00
passphrase = os.urandom(32)
print("Passphrase: {}".format(passphrase))
if args.password:
2017-02-19 09:40:04 +03:00
p = SHA256.new()
p.update(args.password.encode("UTF-8"))
2017-02-19 20:15:26 +03:00
passphrase = passphrase + p.hexdigest().encode("UTF-8")
print("Password: {}".format(password))
print(args.password)
2017-02-19 09:40:04 +03:00
2017-02-19 20:15:26 +03:00
'''data = SJCL().encrypt(file, password.decode("UTF-8"))'''
data = pbincli.sjcl_simple.encrypt(password, file)
2017-02-19 06:48:10 -05:00
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 20:15:26 +03:00
privatebin().post(request, passphrase)