- Timestamp:
- 05/23/09 02:06:34 (3 years ago)
- Location:
- trunk/sandbox/jhb
- Files:
-
- 6 modified
-
mobile/ocwallet.py (modified) (8 diffs)
-
oc2/blowfish.py (modified) (1 diff)
-
oc2/documentation.py (modified) (1 diff)
-
oc2/storage.py (modified) (5 diffs)
-
oc2/transports.py (modified) (1 diff)
-
oc2/wallet.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sandbox/jhb/mobile/ocwallet.py
r318 r319 48 48 appuifw.app.title = u'opencoin wallet\nall currencies' 49 49 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),] 51 52 52 53 def displayActionMenu(self): … … 426 427 self.ip = s.getsockname()[0] 427 428 429 428 430 429 431 def stopInternet(self): 430 432 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 431 444 432 445 def filmIt(foo=None): … … 459 472 460 473 ############################### main code ############################ 474 475 #what port do we listen on? 461 476 walletport = 9091 477 478 #setting up the environment 462 479 app_lock = e32.Ao_lock() 463 480 appuifw.app.screen='normal' 481 482 #this will return normal control to the main code once the exit key is pressed 464 483 appuifw.app.exit_key_handler = app_lock.signal 484 465 485 import oc2 466 486 import sys 487 488 #finding out where we are, in order to get the icons 467 489 oc2path = oc2.__file__ 468 490 if sys.platform == 'symbian_s60': … … 474 496 #standalone app 475 497 mediapath = u'%s\\private\\%s\\' % (basedrive,appuifw.app.uid()) 498 storagepath=u'e:\\' 476 499 else: 477 500 mediapath = u'' 501 storagepath=u'' 478 502 479 503 #only for documenting it … … 481 505 #filmIt() 482 506 507 #set up the icons 483 508 names = dict(coin=0,opencoin=1,coins=2,detail=3,down=4,left=5,refresh=6, 484 509 restore=7,right=8,save=9,up=10,zoom=11) … … 487 512 startup('storage') 488 513 from oc2 import storage as oc2storage 514 515 #Try to use a password on the data file. Repeat till its sucessfully loaded 489 516 password = '' 490 517 while 1: … … 493 520 if password == None: 494 521 sys.exit() 495 startup(' encrypted data')522 startup('data...') 496 523 storage = oc2storage.CryptedStorage() 497 524 storage.setPassword(password) 498 storage.setFilename( 'wallet.bin')525 storage.setFilename(storagepath+'wallet.bin') 499 526 try: 500 527 storage.restore() 501 528 break 502 529 except: 530 appuifw.note(u'wrong password','error') 503 531 pass 504 532 505 533 #Load the rest of the libs 506 534 startup('netlib') 507 535 import httplib, urllib … … 516 544 from oc2 import transports 517 545 startup('media') 518 519 520 521 546 coinsound = audio.Sound.open(mediapath+u'coinsound.wav') 522 523 524 #appuifw.app.screen='full'525 startup('coins')526 547 startup('done') 548 549 #Ok, fire up the real wallet 527 550 w = WalletClient(storage) 528 import time 551 552 #this makes the app running till a signal (by the exit key) is given 529 553 app_lock.wait() 554 555 #Saving the data (encrypting it on the fly) 530 556 status('Shut down:saving data...',icons['save']) 531 557 storage.save() 532 558 status('Shut down:exit',icons['save']) 559 560 #give a bit of time to read the last message 561 import time 533 562 time.sleep(1) -
trunk/sandbox/jhb/oc2/blowfish.py
r318 r319 573 573 cipher.initCTR() 574 574 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 576 577 crypted = cipher.encryptCTR(text) 577 print "\tEncrypted:\t", crypted578 #print "\tEncrypted:\t", crypted 578 579 cipher.initCTR() 579 580 decrypted = cipher.decryptCTR(crypted) 580 print "\tDecrypted:\t", decrypted581 #print "\tDecrypted:\t", decrypted -
trunk/sandbox/jhb/oc2/documentation.py
r299 r319 186 186 Traceback (most recent call last): 187 187 .... 188 SpendReject: amount of coins does not match announced one 188 SpendReject: amount of coins does not match announced one. Announced: 5, got 0 189 189 190 190 >>> alice.requestSpend(bob.listenSpend, alicetid, [coin]) -
trunk/sandbox/jhb/oc2/storage.py
r318 r319 1 import UserDict, cPickle, blowfish, random, os, base64 1 import UserDict, cPickle, blowfish, random, os, base64, zlib 2 2 class Storage(UserDict.UserDict): 3 3 … … 17 17 return self 18 18 19 class EmptyStorage(Storage): 20 def save(self): 21 pass 22 def restore(self): 23 pass 24 25 19 26 class CryptedStorage(Storage): 20 27 … … 23 30 def setPassword(self,password): 24 31 self.password = password 25 32 return self 26 33 27 34 def decrypt(self,password,salt,text): … … 39 46 40 47 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) 42 50 salt = ''.join([str(random.randint(0,9)) for i in range(0,16)]) 43 51 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) 45 54 open(self.filename,'w').write(content) 46 55 return self … … 52 61 if content.startswith(self.prefix): 53 62 salt = content[4:20] 54 crypted = base64.b64decode(content[20:]) 63 #crypted = base64.b64decode(content[20:]) 64 crypted = content[20:] 55 65 data = self.decrypt(self.password, salt, crypted) 56 66 if data.startswith('opencoin'): 57 data = data[8:]67 data = zlib.decompress(data[8:]) 58 68 else: 59 raise 'wrong password'60 data = base64.b64decode(data)69 raise Exception, 'wrong password' 70 #data = base64.b64decode(data) 61 71 else: 62 72 data = content -
trunk/sandbox/jhb/oc2/transports.py
r301 r319 65 65 return response 66 66 67 class TestTransport(object): 67 68 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 195 195 196 196 def feedback(self,message): 197 print message 197 #print message 198 pass 198 199 199 200 #################################higher level############################# … … 212 213 tid = self.makeSerial() 213 214 secrets,data = self.prepareBlanks(transport,cdd,tokenized) 214 response = self.requestTransfer(transport,tid,target,data,[]) 215 response = self.requestTransfer(transport,tid,target,data,[]) 215 216 signatures = response.signatures 216 217 currency['coins'].extend(self.unblindWithSignatures(secrets,signatures))
