- Timestamp:
- 05/21/09 16:36:02 (3 years ago)
- Location:
- trunk/sandbox/jhb
- Files:
-
- 1 added
- 3 modified
-
mobile/ocwallet.py (modified) (5 diffs)
-
oc2/blowfish.py (added)
-
oc2/storage.py (modified) (2 diffs)
-
oc2/wallet.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sandbox/jhb/mobile/ocwallet.py
r317 r318 262 262 def log_message(self,*args,**kwargs): 263 263 pass 264 264 265 OCHandler.wallet = self.wallet 265 266 self.startInternet() 266 267 267 #hack to open internet268 #r = urllib.urlopen('http://google.com')269 #ip = urllib.urlopen('http://opencoin.org/myownip').read()270 268 self.httpd = StoppableHTTPServer(("",port),OCHandler) 271 269 self.feedback(u'Receiving coins: waiting at %s' % (self.ip),self.stopReceiveCoinsHTTP) … … 287 285 addr,services=btsocket.bt_discover() 288 286 if len(services)>0: 289 #choices=services.keys()290 #choices.sort()291 #choice=appuifw.popup_menu([unicode(services[x])+": "+x for x in choices],u'Choose port:')292 #port=services[choices[choice]]293 287 port = services[u'opencoin'] 294 288 else: … … 490 484 restore=7,right=8,save=9,up=10,zoom=11) 491 485 icons = dict([(k,appuifw.Icon(mediapath+u'ocicons.mbm',v*2,v*2+1)) for k,v in names.items()]) 492 startup('network') 486 487 startup('storage') 488 from oc2 import storage as oc2storage 489 password = '' 490 while 1: 491 password = appuifw.query(u'password','text') 492 493 if password == None: 494 sys.exit() 495 startup('encrypted data') 496 storage = oc2storage.CryptedStorage() 497 storage.setPassword(password) 498 storage.setFilename('wallet.bin') 499 try: 500 storage.restore() 501 break 502 except: 503 pass 504 505 506 startup('netlib') 493 507 import httplib, urllib 494 508 startup('ui') … … 497 511 from key_codes import EKeyLeftArrow, EKeyRightArrow 498 512 499 startup('storage')500 from oc2 import storage501 513 startup('oc wallet') 502 514 from oc2 import wallet … … 512 524 #appuifw.app.screen='full' 513 525 startup('coins') 514 storage = storage.Storage()515 storage.setFilename('wallet.bin')516 storage.restore()517 526 startup('done') 518 527 w = WalletClient(storage) -
trunk/sandbox/jhb/oc2/storage.py
r279 r318 1 import UserDict, cPickle 1 import UserDict, cPickle, blowfish, random, os, base64 2 2 class Storage(UserDict.UserDict): 3 3 … … 17 17 return self 18 18 19 class CryptedStorage(Storage): 20 21 prefix = 'salt' 22 23 def setPassword(self,password): 24 self.password = password 25 26 27 def decrypt(self,password,salt,text): 28 key = str(password+salt) 29 cipher = blowfish.Blowfish(key) 30 cipher.initCTR() 31 return cipher.decryptCTR(text) 32 33 def encrypt(self,password,salt,text): 34 key = str(password+salt) 35 cipher = blowfish.Blowfish(key) 36 cipher.initCTR() 37 return cipher.encryptCTR(text) 38 39 40 def save(self): 41 data = 'opencoin'+base64.b64encode(cPickle.dumps(self.data)) 42 salt = ''.join([str(random.randint(0,9)) for i in range(0,16)]) 43 crypted = self.encrypt(self.password,salt,data) 44 content = '%s%s%s' % (self.prefix,salt,base64.b64encode(crypted)) 45 open(self.filename,'w').write(content) 46 return self 47 48 49 def restore(self): 50 if os.path.exists(self.filename): 51 content = open(self.filename).read() 52 if content.startswith(self.prefix): 53 salt = content[4:20] 54 crypted = base64.b64decode(content[20:]) 55 data = self.decrypt(self.password, salt, crypted) 56 if data.startswith('opencoin'): 57 data = data[8:] 58 else: 59 raise 'wrong password' 60 data = base64.b64decode(data) 61 else: 62 data = content 63 64 self.data = cPickle.loads(data) 65 return self 66 67 68 69 -
trunk/sandbox/jhb/oc2/wallet.py
r306 r318 131 131 if amount != int(orig.amount): 132 132 answer = messages.SpendReject() 133 answer.reason = 'amount of coins does not match announced one '133 answer.reason = 'amount of coins does not match announced one. Announced: %s, got %s' % (orig.amount, amount) 134 134 return answer 135 135 #do exchange
