- Timestamp:
- 04/12/09 13:56:00 (3 years ago)
- Location:
- trunk/sandbox/jhb/oc2
- Files:
-
- 6 modified
-
documentation.py (modified) (7 diffs)
-
issuer.py (modified) (2 diffs)
-
messages.py (modified) (2 diffs)
-
mint.py (modified) (2 diffs)
-
protocols.py (modified) (2 diffs)
-
testserver.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sandbox/jhb/oc2/documentation.py
r265 r266 355 355 >>> tid = wallet.makeSerial() 356 356 357 >>> int(mkc.denomination) 358 5 359 357 360 ############################################################################### 358 361 … … 419 422 420 423 to issuer service 421 422 * Issuer: if request will not be minted (e.g., "Bad Key ID" if the key_id 423 is not current): 424 425 TRANSFER_TOKEN_REJECT( transaction_id, reason, 426 list( (blind1.key_id, reason1), ... ), (empty list1) ) 427 428 ElseIf minting is done just-in-time, IS answers 429 430 TRANSFER_TOKEN_ACCEPT( transaction_id, message, list_of_signed_blinds) 431 432 Else IS queues blind to the mint and tells wallet to wait 433 434 TRANSFER_TOKEN_DELAY( transaction_id, reason ) 435 436 Session is terminated. 437 438 439 In case of delayed minting, mint processes request (signs blind with key_id) 440 some time later and passes "signed blind"="blind token" back to IS 441 442 443 ############################################################################### 444 445 We first need to setup something to sign the requests for authorization 424 425 426 ############################################################################### 427 428 We first need to setup an authorizer, to (surpise) authorize the request. Nils says 429 the mint should more or less just mint 446 430 447 431 >>> from authorizer import Authorizer … … 450 434 >>> mint.addAuthKey(authpub) 451 435 >>> authorizer.setMKCs(mkcs) 452 453 454 good, lets start the action455 436 >>> clientside = protocols.TransferRequest(transport,tid,'foo',[[mkc.keyId,blind]],[]) 437 438 ############################################################################### 439 440 * Issuer: if request will not be minted (e.g., "Bad Key ID" if the key_id 441 is not current): 442 443 TRANSFER_TOKEN_REJECT( transaction_id, reason, 444 list( (blind1.key_id, reason1), ... ), (empty list1) ) 445 446 ############################################################################### 447 >>> import time 448 >>> time.sleep(1) 449 >>> authorizer.deny = True 456 450 >>> testserver.run_once(port,mint=mint,authorizer=authorizer) 457 451 >>> text,value = clientside.run() 458 452 >>> text 459 u'minted' 453 'TransferReject' 454 455 456 ############################################################################### 457 458 ElseIf minting is done just-in-time, IS answers 459 460 TRANSFER_TOKEN_ACCEPT( transaction_id, message, list_of_signed_blinds) 461 462 ############################################################################### 463 464 >>> authorizer.deny = False 465 >>> testserver.run_once(port,mint=mint,authorizer=authorizer) 466 >>> text,value = clientside.run() 467 >>> text 468 'TransferAccept' 460 469 >>> blindsign = value[0] 461 470 >>> blank.signature = key.unblind(secret,blindsign) … … 464 473 True 465 474 466 ############################################################################### 475 We don't have a transport between mint and issuer yet. Lets have the mint 476 stuff coins directly into the issuer 477 478 >>> mint.addToTransactions = issuer.addToTransactions 479 480 481 ############################################################################### 482 483 Else IS queues blind to the mint and tells wallet to wait 484 485 TRANSFER_TOKEN_DELAY( transaction_id, reason ) 486 487 488 ############################################################################### 489 490 >>> mint.delay = True 491 >>> testserver.run_once(port,mint=mint,authorizer=authorizer) 492 >>> text,value = clientside.run() 493 >>> text 494 'TransferDelay' 495 >>> mint.delay = False 496 497 ############################################################################### 498 499 500 Session is terminated. 501 502 503 In case of delayed minting, mint processes request (signs blind with key_id) 504 some time later and passes "signed blind"="blind token" back to IS 505 506 507 508 509 510 511 467 512 3.5 Wallet gets token back 468 513 … … 480 525 481 526 TRANSFER_TOKEN_DELAY( transaction_id, reason ) 482 527 528 ############################################################################### 529 530 >>> issuer.delay = True 531 >>> clientside = protocols.TransferResume(transport,tid) 532 >>> testserver.run_once(port,issuer=issuer) 533 >>> text,value = clientside.run() 534 >>> text 535 'TransferDelay' 536 >>> issuer.delay = False 537 538 ############################################################################### 539 483 540 (question: what about key expiration while request is in mining queue) 484 541 (oierw thinks: as long as the key is valid for minting when the request is made, we are good) … … 487 544 488 545 TRANSFER_TOKEN_ACCEPT( transaction_id, message, list_of_singed_blinds ) 489 546 547 548 ############################################################################### 549 550 >>> clientside = protocols.TransferResume(transport,tid) 551 >>> testserver.run_once(port,issuer=issuer) 552 >>> text,value = clientside.run() 553 >>> text 554 'TransferAccept' 555 556 ############################################################################### 557 490 558 Session terminates 491 559 … … 495 563 496 564 * Wallet unblinds signed blind and yields token (or reblinds) 565 566 ############################################################################### 567 568 >>> blindsign = value[0] 569 >>> blank.signature = key.unblind(secret,blindsign) 570 >>> coin = blank 571 >>> key.verifyContainerSignature(coin) 572 True 573 574 ############################################################################### 497 575 498 576 -
trunk/sandbox/jhb/oc2/issuer.py
r259 r266 3 3 4 4 class Issuer(Entity): 5 5 6 def __init__(self,storage=None): 7 Entity.__init__(self,storage) 8 self.delay = False 9 6 10 def createMasterKeys(self): 7 11 priv,pub = occrypto.KeyFactory(1024) … … 84 88 def getMKCById(self,keyid,default=None): 85 89 return self.storage.setdefault('keyidlist',{}).get(keyid,default) 90 91 def addToTransactions(self,transactionId,signatures): 92 self.storage.setdefault('transactions',{})[transactionId]=signatures 93 94 def getTransactionResult(self,transactionId): 95 if self.delay: 96 return None 97 else: 98 return self.storage.setdefault('transactions',{}).get(transactionId,None) -
trunk/sandbox/jhb/oc2/messages.py
r265 r266 42 42 class TransferAccept(Message): 43 43 fields = Message.fields + [ 44 Field('text'),45 44 Field('signatures'), 46 45 ] … … 63 62 pass 64 63 64 class TransferDelay(Message): 65 fields = Message.fields + [ 66 Field('transactionId'), 67 Field('reason'), 68 ] 65 69 70 class TransferResume(Message): 71 fields = Message.fields + [ 72 Field('transactionId'), 73 ] 74 75 -
trunk/sandbox/jhb/oc2/mint.py
r265 r266 3 3 class Mint(Entity): 4 4 5 def __init__(self,storage=None): 6 Entity.__init__(self,storage) 7 self.delay = False 5 8 6 9 def setCDD(self,cdd): … … 62 65 signature = priv.sign(blind) 63 66 result.append(signature) 64 65 return ('minted',result)66 67 68 if self.delay: 69 70 self.addToTransactions(message.transactionId,result) 71 return('delayed','mint asked to delay') 72 else: 73 return ('minted',result) 67 74 75 def addToTransactions(self,transactionId,result): 76 self.storage.setdefault('transactions',{})[transactionId]=result -
trunk/sandbox/jhb/oc2/protocols.py
r265 r266 105 105 return ('TransferDelay','') 106 106 elif header == 'TransferAccept': 107 return ( response.text,response.signatures)107 return ('TransferAccept',response.signatures) 108 108 else: 109 109 raise 'unknown thing' … … 128 128 129 129 text,value = response 130 if value:130 if text=='minted': 131 131 answer = messages.TransferAccept() 132 answer.text = text133 132 answer.signatures = value 133 elif text =='delayed': 134 answer = messages.TransferDelay() 135 answer.transactionId = message.transactionId 136 answer.reason = value 134 137 else: 135 138 raise 'something went wrong' 136 139 return answer 137 140 141 class TransferResume(Protocol): 142 143 def __init__(self,transport,transactionId): 144 self.transport = transport 145 self.transactionId = transactionId 146 147 def run(self,message=None): 148 message = messages.TransferResume() 149 message.transactionId = self.transactionId 150 response = self.transport(message) 151 header = response.header 152 if header == 'TransferReject': 153 return ('TransferReject','') 154 elif header == 'TransferDelay': 155 return ('TransferDelay','') 156 elif header == 'TransferAccept': 157 return ('TransferAccept',response.signatures) 158 else: 159 raise 'unknown thing' 160 161 return response.cdd 162 163 class TransferResumeHandling(Protocol): 164 165 def __init__(self,issuer): 166 self.issuer = issuer 167 168 def run(self,message): 169 170 signatures = self.issuer.getTransactionResult(message.transactionId) 171 if signatures: 172 answer = messages.TransferAccept() 173 answer.signatures = signatures 174 else: 175 answer = messages.TransferDelay() 176 answer.transactionId = message.transactionId 177 answer.reason = 'issuer has no coins yet' 178 return answer 179 180 138 181 class CoinsSpendSender(Protocol): 139 182 -
trunk/sandbox/jhb/oc2/testserver.py
r264 r266 19 19 elif message.header == 'TransferRequest': 20 20 protocol = protocols.TransferHandling(self.mint,self.authorizer) 21 elif message.header == 'TransferResume': 22 protocol = protocols.TransferResumeHandling(self.issuer) 23 21 24 answer = protocol.run(message) 22 25 self.send_response(200) … … 26 29 27 30 31 28 32 def run_once(port,issuer=None,mint=None,authorizer=None): 33 import time 34 time.sleep(0.001) 29 35 Handler.issuer = issuer 30 36 Handler.mint = mint
