コード例 #1
0
    def process_file(self, filename):
        """
        attempts to store a file into CSDM
        """
        #attempt to open file
        if os.path.exists(filename):
            with open(filename, 'rb') as f:
                data = f.read()
        else:
            print('C: file does not exist...')
            return

        print('C: checking for public key...')

        #make sure public key exists
        if os.path.exists('public.ecc'):
            with open('public.ecc', 'rb') as f:
                epub = f.read()
        else:
            print('C: public ecc key does not exist...')
            print('C: please run: client.py gen-key <passphrase>')
            return

        #setup ecc object
        print('C: encrypting...')
        epgp = ECCPGP()
        epgp._epub = epub
        pack = epgp.encrypt(data, filename)

        #process the file into an eccpgp pack
        print('C: processing file...')
        fi = Filer()
        manifest = fi.process_data(pack['payload'].encode())
        manifest['header'] = pack['header']

        #encrypt the manifest
        manstr = json.dumps(manifest['manifest'])
        manenc = b64enc(epgp.raw_enc(manstr.encode(), epub))
        manifest['manifest'] = manenc

        #write manifest to disk
        with open(MANIFESTDIR + manifest['hash'], 'wb') as f:
            f.write(json.dumps(manifest).encode())

        print('C: chunks and manifest created...')
コード例 #2
0
ファイル: client.py プロジェクト: xevrem/csdm
    def process_file(self, filename):
        """
        attempts to store a file into CSDM
        """
        #attempt to open file
        if os.path.exists(filename):
            with open(filename, 'rb') as f:
                data = f.read()
        else:
            print('C: file does not exist...')
            return

        print('C: checking for public key...')

        #make sure public key exists
        if os.path.exists('public.ecc'):
            with open('public.ecc', 'rb') as f:
                epub = f.read()
        else:
            print('C: public ecc key does not exist...')
            print('C: please run: client.py gen-key <passphrase>')
            return

        #setup ecc object
        print('C: encrypting...')
        epgp = ECCPGP()
        epgp._epub = epub
        pack = epgp.encrypt(data, filename)

        #process the file into an eccpgp pack
        print('C: processing file...')
        fi = Filer()
        manifest = fi.process_data(pack['payload'].encode())
        manifest['header'] = pack['header']

        #encrypt the manifest
        manstr = json.dumps(manifest['manifest'])
        manenc = b64enc(epgp.raw_enc(manstr.encode(), epub))
        manifest['manifest'] = manenc

        #write manifest to disk
        with open(MANIFESTDIR+manifest['hash'], 'wb') as f:
            f.write(json.dumps(manifest).encode())

        print('C: chunks and manifest created...')