Files
PBinCLI/pbincli/actions.py

40 lines
1.4 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 """
2017-02-19 23:27:37 +03:00
#check_readable(args.filename)
#with open(args.filename, "rb") as f:
# contents = f.read()
#file = b64encode(compress(contents))
data = b'Test!'
2017-02-19 09:40:04 +03:00
2017-02-19 20:15:26 +03:00
passphrase = os.urandom(32)
2017-02-19 23:27:37 +03:00
#print("Passphrase: {}".format(passphrase))
2017-02-19 20:15:26 +03:00
if args.password:
2017-02-19 23:27:37 +03:00
#print("Password: {}".format(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")
2017-02-19 09:40:04 +03:00
2017-02-19 23:27:37 +03:00
#data = SJCL().encrypt(file, password.decode("UTF-8"))
"""Sending text from 'data' string"""
#cipher = pbincli.sjcl_simple.encrypt(b64encode(passphrase), file)
cipher = pbincli.sjcl_simple.encrypt(b64encode(passphrase), data)
request = {'data':json.dumps(cipher, ensure_ascii=False),'expire':args.expire,'formatter':args.format,'burnafterreading':int(args.burn),'opendiscussion':int(args.discus)
2017-02-19 06:48:10 -05:00
}
print(request)
2017-02-19 23:27:37 +03:00
'''Here we run function post from pbincli.transports'''
privatebin().post(request, b64encode(passphrase))