Changeset 319

Show
Ignore:
Timestamp:
05/23/09 02:06:34 (3 years ago)
Author:
ocjhb
Message:

when storing: removed b64, added zlib

Location:
trunk/sandbox/jhb
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/sandbox/jhb/mobile/ocwallet.py

    r318 r319  
    4848        appuifw.app.title = u'opencoin wallet\nall currencies' 
    4949        appuifw.app.menu = [(u'add currency',self.addCurrency), 
    50                             (u'delete currency',self.delCurrency)] 
     50                            (u'delete currency',self.delCurrency), 
     51                            (u'new password',self.newPassword),] 
    5152 
    5253    def displayActionMenu(self): 
     
    426427            self.ip = s.getsockname()[0] 
    427428 
     429     
    428430 
    429431    def stopInternet(self): 
    430432        pass 
     433 
     434 
     435    def newPassword(self): 
     436        password = appuifw.query(u'new password','text') 
     437        if password != None: 
     438            self.storage.setPassword(password) 
     439            appuifw.note(u'new password set','conf') 
     440 
     441 
     442 
     443 
    431444 
    432445def filmIt(foo=None): 
     
    459472 
    460473############################### main code ############################         
     474 
     475#what port do we listen on? 
    461476walletport = 9091 
     477 
     478#setting up the environment 
    462479app_lock = e32.Ao_lock() 
    463480appuifw.app.screen='normal' 
     481 
     482#this will return normal control to the main code once the exit key is pressed 
    464483appuifw.app.exit_key_handler = app_lock.signal 
     484 
    465485import oc2 
    466486import sys 
     487 
     488#finding out where we are, in order to get the icons 
    467489oc2path = oc2.__file__ 
    468490if sys.platform == 'symbian_s60': 
     
    474496        #standalone app 
    475497        mediapath = u'%s\\private\\%s\\' % (basedrive,appuifw.app.uid()) 
     498    storagepath=u'e:\\' 
    476499else: 
    477500    mediapath = u'' 
     501    storagepath=u'' 
    478502         
    479503#only for documenting it 
     
    481505#filmIt() 
    482506 
     507#set up the icons 
    483508names = dict(coin=0,opencoin=1,coins=2,detail=3,down=4,left=5,refresh=6, 
    484509             restore=7,right=8,save=9,up=10,zoom=11) 
     
    487512startup('storage') 
    488513from oc2 import storage as oc2storage 
     514 
     515#Try to use a password on the data file. Repeat till its sucessfully loaded 
    489516password = '' 
    490517while 1: 
     
    493520    if password == None: 
    494521        sys.exit()    
    495     startup('encrypted data') 
     522    startup('data...') 
    496523    storage = oc2storage.CryptedStorage() 
    497524    storage.setPassword(password) 
    498     storage.setFilename('wallet.bin') 
     525    storage.setFilename(storagepath+'wallet.bin') 
    499526    try: 
    500527        storage.restore() 
    501528        break 
    502529    except: 
     530        appuifw.note(u'wrong password','error') 
    503531        pass 
    504532 
    505  
     533#Load the rest of the libs 
    506534startup('netlib') 
    507535import httplib, urllib 
     
    516544from oc2 import transports 
    517545startup('media') 
    518  
    519  
    520  
    521546coinsound = audio.Sound.open(mediapath+u'coinsound.wav') 
    522  
    523  
    524 #appuifw.app.screen='full' 
    525 startup('coins') 
    526547startup('done') 
     548 
     549#Ok, fire up the real wallet 
    527550w = WalletClient(storage) 
    528 import time 
     551 
     552#this makes the app running till a signal (by the exit key) is given 
    529553app_lock.wait() 
     554 
     555#Saving the data (encrypting it on the fly) 
    530556status('Shut down:saving data...',icons['save']) 
    531557storage.save() 
    532558status('Shut down:exit',icons['save']) 
     559 
     560#give a bit of time to read the last message 
     561import time 
    533562time.sleep(1) 
  • trunk/sandbox/jhb/oc2/blowfish.py

    r318 r319  
    573573    cipher.initCTR() 
    574574    text = "The quick brown fox jumps over the lazy dog" 
    575     print "\tText:\t\t", text 
     575    text = 'h' * 100000 
     576    #print "\tText:\t\t", text 
    576577    crypted = cipher.encryptCTR(text) 
    577     print "\tEncrypted:\t", crypted 
     578    #print "\tEncrypted:\t", crypted 
    578579    cipher.initCTR() 
    579580    decrypted = cipher.decryptCTR(crypted) 
    580     print "\tDecrypted:\t", decrypted 
     581    #print "\tDecrypted:\t", decrypted 
  • trunk/sandbox/jhb/oc2/documentation.py

    r299 r319  
    186186Traceback (most recent call last): 
    187187    .... 
    188 SpendReject: amount of coins does not match announced one 
     188SpendReject: amount of coins does not match announced one. Announced: 5, got 0 
    189189 
    190190>>> alice.requestSpend(bob.listenSpend, alicetid, [coin])  
  • trunk/sandbox/jhb/oc2/storage.py

    r318 r319  
    1 import UserDict, cPickle, blowfish, random, os, base64 
     1import UserDict, cPickle, blowfish, random, os, base64, zlib 
    22class Storage(UserDict.UserDict): 
    33 
     
    1717        return self 
    1818 
     19class EmptyStorage(Storage): 
     20    def save(self): 
     21        pass 
     22    def restore(self): 
     23        pass 
     24 
     25 
    1926class CryptedStorage(Storage): 
    2027 
     
    2330    def setPassword(self,password): 
    2431        self.password = password 
    25  
     32        return self 
    2633 
    2734    def decrypt(self,password,salt,text): 
     
    3946 
    4047    def save(self): 
    41         data = 'opencoin'+base64.b64encode(cPickle.dumps(self.data)) 
     48        #data = 'opencoin'+base64.b64encode(cPickle.dumps(self.data)) 
     49        data = 'opencoin'+zlib.compress(cPickle.dumps(self.data),9) 
    4250        salt = ''.join([str(random.randint(0,9)) for i in range(0,16)]) 
    4351        crypted = self.encrypt(self.password,salt,data) 
    44         content = '%s%s%s' % (self.prefix,salt,base64.b64encode(crypted)) 
     52        #content = '%s%s%s' % (self.prefix,salt,base64.b64encode(crypted)) 
     53        content = '%s%s%s' % (self.prefix,salt,crypted) 
    4554        open(self.filename,'w').write(content) 
    4655        return self 
     
    5261            if content.startswith(self.prefix): 
    5362                salt = content[4:20] 
    54                 crypted = base64.b64decode(content[20:]) 
     63                #crypted = base64.b64decode(content[20:]) 
     64                crypted = content[20:] 
    5565                data = self.decrypt(self.password, salt, crypted) 
    5666                if data.startswith('opencoin'): 
    57                     data = data[8:] 
     67                    data = zlib.decompress(data[8:]) 
    5868                else: 
    59                     raise 'wrong password' 
    60                 data = base64.b64decode(data)                     
     69                    raise Exception, 'wrong password' 
     70                #data = base64.b64decode(data)                     
    6171            else: 
    6272                data = content 
  • trunk/sandbox/jhb/oc2/transports.py

    r301 r319  
    6565        return response             
    6666                     
     67class TestTransport(object): 
    6768 
     69    def __init__(self, *args): 
     70        self.results = list(args) 
     71 
     72    def __call__(self,message): 
     73        result = self.results.pop(0) 
     74         
     75        if type(result) == type([]) or type(result) == type(()): 
     76            method = result[0] 
     77            args = list(result[1:]) 
     78            args.append(message) 
     79            return method(*args) 
     80         
     81        elif callable(result): 
     82            return result(message)         
     83         
     84        else: 
     85            return result 
     86 
  • trunk/sandbox/jhb/oc2/wallet.py

    r318 r319  
    195195 
    196196    def feedback(self,message): 
    197         print message 
     197        #print message 
     198        pass 
    198199 
    199200#################################higher level############################# 
     
    212213        tid = self.makeSerial() 
    213214        secrets,data = self.prepareBlanks(transport,cdd,tokenized) 
    214         response = self.requestTransfer(transport,tid,target,data,[])                          
     215        response = self.requestTransfer(transport,tid,target,data,[]) 
    215216        signatures = response.signatures 
    216217        currency['coins'].extend(self.unblindWithSignatures(secrets,signatures))