From 8014c386aceca9f03f89aff643909445d518d2f2 Mon Sep 17 00:00:00 2001 From: r4sas Date: Sun, 19 Feb 2017 09:40:04 +0300 Subject: [PATCH] partly realised send command --- pbincli.py | 2 +- pbincli/actions.py | 24 ++++++++++++++++++++++-- pbincli/sjcl_gcm.py | 12 +++--------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/pbincli.py b/pbincli.py index b3851ad..e4c1eef 100755 --- a/pbincli.py +++ b/pbincli.py @@ -20,7 +20,7 @@ def main(): send_parser.add_argument("-e", "--expire", default="1day", action="store", help="expiration of paste (default: 1day)") send_parser.add_argument("-f", "--format", default="plaintext", action="store", help="format of paste (default: plaintext)") send_parser.add_argument("-p", "--password", default=None, help="password for crypting paste") - send_parser.add_argument("filename", type=argparse.FileType('r'), help="filename (example: image.jpg)") + send_parser.add_argument("filename", help="filename (example: image.jpg)") send_parser.set_defaults(func=pbincli.actions.send) # parse arguments diff --git a/pbincli/actions.py b/pbincli/actions.py index 3c229e9..5e67f28 100644 --- a/pbincli/actions.py +++ b/pbincli/actions.py @@ -1,7 +1,27 @@ """Action functions for argparser""" -import pbincli.sjcl_gcm +import base64 import pbincli.actions +from Crypto.Hash import SHA256 +from Crypto.Random import get_random_bytes +from pbincli.sjcl_gcm import SJCL from pbincli.utils import PBinCLIException, check_readable, check_writable +from zlib import compress def send(args): - print("Meow!") + """ 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) + '''Here we must run function post from pbincli.transports''' + print(data) diff --git a/pbincli/sjcl_gcm.py b/pbincli/sjcl_gcm.py index ad1b8e1..1a5b7c7 100644 --- a/pbincli/sjcl_gcm.py +++ b/pbincli/sjcl_gcm.py @@ -2,19 +2,13 @@ # -*- coding: utf-8 -*- """ - - Edited SJCL.py library (https://github.com/berlincode/sjcl/) - for AES.MODE_GCM support, work begin. +for AES.MODE_GCM support, work begin. - pip3.5 install pycryptodome - - - +pip3.5 install pycryptodome """ from Crypto.Hash import SHA256, HMAC -#pip3.5 install pycryptodome from Crypto.Protocol.KDF import PBKDF2 from Crypto.Cipher import AES from Crypto.Random import get_random_bytes @@ -112,7 +106,7 @@ class SJCL(object): return plaintext - def encrypt(self, plaintext, passphrase, count=1000, dkLen=16): + def encrypt(self, plaintext, passphrase, count=10000, dkLen=32): # dkLen = key length in bytes check_mode_gcm() # check gcm support