combox

split and encrypted files between online file storage providers
git clone git://git.ricketyspace.net/combox.git
Log | Files | Refs

commit ff9f0ada050d1b3d13862786a099a060f38c9169
parent 30cf34bef72df235be4ada2e7b15afbeeb84dd23
Author: Siddharth Ravikumar <sravik@bgsu.edu>
Date:   Tue, 13 Jan 2015 23:15:12 -0500

combox/crypto.py: wrote split_and_encrypt & decrypt_and_glue functions

Diffstat:
combox/crypto.py | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+), 0 deletions(-)

diff --git a/combox/crypto.py b/combox/crypto.py @@ -21,7 +21,13 @@ import base64 import os +from combox.config import get_nodedirs +from combox.file import (read_file, write_file, + read_shards, write_shards, + split_data, glue_data) + from Crypto.Cipher import AES +from os import path BLOCK_SIZE = 32 PAD_CHAR = '#' @@ -82,3 +88,58 @@ def decrypt_shards(ciphers, secret): shards.append(shard) return shards + + +def split_and_encrypt(fpath, config): + """ + Splits the file, encrypts the shards and writes them to the nodes. + + fpath: The path to file that has to be split. + config: The dictonary containing the combox configuration information. + """ + + # no. of shards = no. of nodes. + SHARDS = len(config['nodes_info'].keys()) + + f = path.abspath(fpath) + f_content = read_file(f) + f_shards = split_data(f_content, SHARDS) + + # encrypt shards + ciphered_shards = encrypt_shards(f_shards, config['topsecret']) + + + # write ciphered shards to disk + f_basename = path.basename(f) + # gets the list of node' directories. + nodes = get_nodedirs(config) + + write_shards(ciphered_shards, nodes, f_basename) + + +def decrypt_and_glue(fpath, config): + + """ + Reads encrypted shards, decrypts and glues them. + + fpath: The path to file that has to be decrypted & glued from the nodes. + config: The dictonary containing the combox configuration information. + + """ + + f = path.abspath(fpath) + f_basename = path.basename(f) + # gets the list of node' directories. + nodes = get_nodedirs(config) + + ciphered_shards = read_shards(nodes, f_basename) + + # decrypt shards + f_parts = decrypt_shards(ciphered_shards, config['topsecret']) + + # glue them together + f_content = glue_data(f_parts) + + # write the glued content to fpath + write_file(f, f_content) +.