Changeset 266 for trunk

Show
Ignore:
Timestamp:
04/12/09 13:56:00 (3 years ago)
Author:
ocjhb
Message:

work I did on the train

Location:
trunk/sandbox/jhb/oc2
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/sandbox/jhb/oc2/documentation.py

    r265 r266  
    355355>>> tid = wallet.makeSerial() 
    356356 
     357>>> int(mkc.denomination) 
     3585 
     359 
    357360############################################################################### 
    358361 
     
    419422 
    420423  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 
     428We first need to setup an authorizer, to (surpise) authorize the request. Nils says 
     429the mint should more or less just mint 
    446430 
    447431>>> from authorizer import Authorizer 
     
    450434>>> mint.addAuthKey(authpub) 
    451435>>> authorizer.setMKCs(mkcs) 
    452  
    453  
    454 good, lets start the action 
    455436>>> 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 
    456450>>> testserver.run_once(port,mint=mint,authorizer=authorizer) 
    457451>>> text,value =  clientside.run() 
    458452>>> 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' 
    460469>>> blindsign = value[0] 
    461470>>> blank.signature = key.unblind(secret,blindsign) 
     
    464473True 
    465474 
    466 ############################################################################### 
     475We don't have a transport between mint and issuer yet. Lets have the mint 
     476stuff 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 
    4675123.5 Wallet gets token back 
    468513 
     
    480525 
    481526        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 
    483540  (question: what about key expiration while request is in mining queue) 
    484541  (oierw thinks: as long as the key is valid for minting when the request is made, we are good) 
     
    487544 
    488545        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 
    490558  Session terminates 
    491559 
     
    495563 
    496564* 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) 
     572True 
     573 
     574############################################################################### 
    497575 
    498576 
  • trunk/sandbox/jhb/oc2/issuer.py

    r259 r266  
    33 
    44class Issuer(Entity): 
    5   
     5 
     6    def __init__(self,storage=None): 
     7        Entity.__init__(self,storage) 
     8        self.delay = False 
     9 
    610    def createMasterKeys(self): 
    711        priv,pub = occrypto.KeyFactory(1024) 
     
    8488    def getMKCById(self,keyid,default=None): 
    8589        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  
    4242class TransferAccept(Message): 
    4343    fields = Message.fields + [ 
    44         Field('text'), 
    4544        Field('signatures'), 
    4645    ] 
     
    6362    pass 
    6463 
     64class TransferDelay(Message): 
     65     fields = Message.fields + [ 
     66        Field('transactionId'), 
     67        Field('reason'), 
     68    ] 
    6569 
     70class TransferResume(Message): 
     71     fields = Message.fields + [ 
     72        Field('transactionId'), 
     73    ] 
     74 
     75 
  • trunk/sandbox/jhb/oc2/mint.py

    r265 r266  
    33class Mint(Entity): 
    44 
     5    def __init__(self,storage=None): 
     6        Entity.__init__(self,storage) 
     7        self.delay = False 
    58 
    69    def setCDD(self,cdd): 
     
    6265            signature = priv.sign(blind) 
    6366            result.append(signature) 
    64                      
    65         return ('minted',result) 
    6667 
     68        if self.delay: 
     69             
     70            self.addToTransactions(message.transactionId,result) 
     71            return('delayed','mint asked to delay') 
     72        else:             
     73            return ('minted',result) 
    6774 
     75    def addToTransactions(self,transactionId,result): 
     76        self.storage.setdefault('transactions',{})[transactionId]=result 
  • trunk/sandbox/jhb/oc2/protocols.py

    r265 r266  
    105105            return ('TransferDelay','') 
    106106        elif header == 'TransferAccept': 
    107             return (response.text,response.signatures) 
     107            return ('TransferAccept',response.signatures) 
    108108        else: 
    109109            raise 'unknown thing' 
     
    128128 
    129129            text,value = response 
    130             if value: 
     130            if text=='minted': 
    131131                answer = messages.TransferAccept() 
    132                 answer.text = text 
    133132                answer.signatures = value 
     133            elif text =='delayed': 
     134                answer = messages.TransferDelay() 
     135                answer.transactionId = message.transactionId 
     136                answer.reason = value 
    134137            else: 
    135138                raise 'something went wrong' 
    136139        return answer     
    137140 
     141class 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 
     163class 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 
    138181class CoinsSpendSender(Protocol): 
    139182 
  • trunk/sandbox/jhb/oc2/testserver.py

    r264 r266  
    1919        elif message.header == 'TransferRequest': 
    2020            protocol = protocols.TransferHandling(self.mint,self.authorizer) 
     21        elif message.header == 'TransferResume': 
     22            protocol = protocols.TransferResumeHandling(self.issuer) 
     23  
    2124        answer = protocol.run(message) 
    2225        self.send_response(200) 
     
    2629 
    2730 
     31 
    2832def run_once(port,issuer=None,mint=None,authorizer=None): 
     33    import time 
     34    time.sleep(0.001) 
    2935    Handler.issuer = issuer 
    3036    Handler.mint = mint