def nextTurnCheck(i, state): if i['game_name'] not in state: print('19') return False board=state[i['game_name']] if len(state.keys())==0: print('2') return False # print('state: ' +str(state)) # print('board: ' +str(board)) if board['whos_turn']=='white': pubkey=board['pubkey_white'] else: pubkey=board['pubkey_black'] if board['move_number'] != i['move_number']: return False if not pt.ecdsa_verify(blockchain.message2signObject(i, nextturn_sig_list), i['signature'], pubkey): print('i: ' +str(i)) print('state: ' +str(state)) print('14') return False n=next_board(copy.deepcopy(board), i['where'], state['length']) if (len(n['black'])+len(n['white']))<=(len(board['black'])+len(board['white'])):#if it kills, then it lives # error('here') return True return valid_board(board, i)
def checkSig(dic): print('in func checksig') bad_password_page=empty_page.format(''' The signature that you gave: {} <br /> Does not match the command that you gave: {}{}''') command=dic['command'] signature=unpackage(dic['signature']) dic=unpackage(dic['command']) if pt.ecdsa_verify(command, signature, str(dic['user'])): print('1') user=users_load(str(dic['user'])) if 'cmd_num_biggest' not in user: user['cmd_num_biggest']=-1 if int(dic['cmd_num']) > int(user['cmd_num_biggest']): user['cmd_num_biggest']=dic['cmd_num'] users_save(str(dic['user']), user) print('2') out=execute_command(dic) print('2') else: return package({'type':'cmd_num_error', 'cmd_num':user['cmd_num_biggest']}) else: out=package({'type':'error','message':bad_password_page.format(signature, command, '{}')}) print('in func checksig') return out
def spend_check(tx, state): if tx['id'] not in state.keys(): print("you can't spend money from a non-existant account") return False if 'amount' not in tx: print('how much did you want to spend?') return False if type(tx['amount']) != type(5): print('you can only spend integer amounts of money') return False if tx['amount'] <= 1000: print( 'the minimum amount to spend is 1000 base units = 0.01 CryptGo coin.' ) return False if not enough_funds(state, tx['id'], tx['amount']): print('not enough money to spend in this account') return False if 'signature' not in tx: print("spend transactions must be signed") return False # try: if not pt.ecdsa_verify(message2signObject(tx, spend_list), tx['signature'], tx['id']): print("bad signature") return False # except: # print('Weird error when checking the signature of a transaction') # return False return True
def checkSig(dic): print('in func checksig') bad_password_page = empty_page.format(''' The signature that you gave: {} <br /> Does not match the command that you gave: {}{}''') command = dic['command'] signature = unpackage(dic['signature']) dic = unpackage(dic['command']) if pt.ecdsa_verify(command, signature, str(dic['user'])): print('1') user = users_load(str(dic['user'])) if 'cmd_num_biggest' not in user: user['cmd_num_biggest'] = -1 if int(dic['cmd_num']) > int(user['cmd_num_biggest']): user['cmd_num_biggest'] = dic['cmd_num'] users_save(str(dic['user']), user) print('2') out = execute_command(dic) print('2') else: return package({ 'type': 'cmd_num_error', 'cmd_num': user['cmd_num_biggest'] }) else: out = package({ 'type': 'error', 'message': bad_password_page.format(signature, command, '{}') }) print('in func checksig') return out
def spend_check(tx, state): if tx['id'] not in state.keys(): print("you can't spend money from a non-existant account") return False if 'amount' not in tx: print('how much did you want to spend?') return False if type(tx['amount']) != type(5): print('you can only spend integer amounts of money') return False if tx['amount']<=1000: print('the minimum amount to spend is 1000 base units = 0.01 CryptGo coin.') return False if not enough_funds(state, tx['id'], tx['amount']): print('not enough money to spend in this account') return False if 'signature' not in tx: print("spend transactions must be signed") return False try: if not pt.ecdsa_verify(message2signObject(tx, spend_list), tx['signature'], tx['id'] ): print("bad signature") return False except: print('Weird error when checking the signature of a transaction') return False return True
def spend_check(tx, state): if not spend_check_1(tx, state): return False signed_properties=['type','pubkey','amount', 'count'] if not pt.ecdsa_verify(message2signObject(tx, ['type','pubkey','amount', 'count']), tx['signature'], tx['id'] ): print("bad signature") return False return True
def newGameCheck(i, state): if len(i['game_name'])>129: print('name too long') return False if not 'pubkey_white' in i or not 'pubkey_black' in i: print('13') return False if i['whos_turn'] not in ['white', 'black']: print('4') return False for j in i['white']+i['black']: # print('j: ' +str(j)) if type(j)!=type([1,2]) or len(j)!=2: print('5') return False if 'time' not in i or 'size' not in i or 'white' not in i or 'black' not in i: print('12') return False if (type(i['time']) != type(3)): print('7') return False if type(i['size']) != type(3) or i['size']<3 or i['size']>30: print('8') return False if type(i['white']) != type([1,2]) or type(['black']) != type([1,2]): print('6') return False if 'amount' not in i: print('bet error') return False if type(i['amount'])!=type(10): print('bet error 2') return False sign=blockchain.message2signObject(i, newgame_sig_list) if not pt.ecdsa_verify(sign, i['signature'], i['pubkey_black']): print('i: ' +str(i)) print('signature error') return False if i['amount']>0 and not pt.ecdsa_verify(sign, i['signature_white'], pubkey_white): print('signature error 2') return False return True
def deserialize_wait_timer(cls, serialized_timer, signature): with cls._lock: # Verify the signature before trying to deserialize if not pybitcointools.ecdsa_verify(serialized_timer, signature, cls._poet_public_key): return None return \ EnclaveWaitTimer.wait_timer_from_serialized( serialized_timer=serialized_timer, signature=signature)
def deserialize_wait_timer(cls, serialized_timer, signature): with cls._lock: # Verify the signature before trying to deserialize if not pybitcointools.ecdsa_verify( serialized_timer, signature, cls._poet_public_key): return None return \ EnclaveWaitTimer.wait_timer_from_serialized( serialized_timer=serialized_timer, signature=signature)
def nextTurnCheck(i, state): if i['game_name'] not in state: print('19') return False board = state[i['game_name']] if len(state.keys()) == 0: print('2') return False # print('state: ' +str(state)) # print('board: ' +str(board)) if board['whos_turn'] == 'white': pubkey = board['pubkey_white'] else: pubkey = board['pubkey_black'] if board['move_number'] != i['move_number']: return False try: #so that invalid pubkeys don't break anything. if not pt.ecdsa_verify(message2signObject(i, nextturn_sig_list), i['signature'], pubkey): print('i: ' + str(i)) print('state: ' + str(state)) print('14') return False except: print('invalid pubkey error') return False if type(i['where']) != type([1, 2]) or len(i['where']) != 2: print('move type eerror') return False if i['where'] in board['white'] + board['black']: print('spot taken error') return False if i['where'][0] < 0 or i['where'][1] < 0: print('off board error') return False if i['where'][0] >= board['size'] or i['where'][1] >= board['size']: print('off board error') return False n = next_board(copy.deepcopy(board), i['where'], state['length']) if (len(n['black']) + len(n['white'])) <= (len(board['black']) + len( board['white'])): #if it kills, then it lives # error('here') return True return valid_board(board, i)
def verify_signup_info(cls, signup_info, originator_public_key_hash, most_recent_wait_certificate_id): # Verify the attestation verification report signature proof_data = json2dict(signup_info.proof_data) verification_report = proof_data.get('verification_report') if verification_report is None: raise \ SignupInfoError( 'Verification report is missing from proof data') if not pybitcointools.ecdsa_verify(verification_report, proof_data.get('signature'), cls._report_public_key): raise \ SignupInfoError('Verification report signature is invalid') # Verify that the report data field in the report contains the SHA256 # digest of the originator's public key SHA 256 digest and the PoET # public key. verification_report_dict = json2dict(verification_report) enclave_quote = verification_report_dict.get('enclave_quote') if enclave_quote is None: raise \ SignupInfoError( 'Verification report does not contain an enclave quote') report = json2dict(pybitcointools.base64.b64decode(enclave_quote)) report_data = report.get('report_data') if report_data is None: raise \ SignupInfoError('Enclave quote does not contain report data') target_report_data = { 'originator_public_key_hash': originator_public_key_hash.upper(), 'poet_public_key': signup_info.poet_public_key.upper() } target_report_data_digest = \ pybitcointools.sha256(dict2json(target_report_data)) if report_data != target_report_data_digest: raise SignupInfoError('Enclave quote report data is invalid')
def nextTurnCheck(i, state): if i['game_name'] not in state: print('19') return False board=state[i['game_name']] if len(state.keys())==0: print('2') return False # print('state: ' +str(state)) # print('board: ' +str(board)) if board['whos_turn']=='white': pubkey=board['pubkey_white'] else: pubkey=board['pubkey_black'] if board['move_number'] != i['move_number']: return False try:#so that invalid pubkeys don't break anything. if not pt.ecdsa_verify(message2signObject(i, nextturn_sig_list), i['signature'], pubkey): print('i: ' +str(i)) print('state: ' +str(state)) print('14') return False except: print('invalid pubkey error') return False if type(i['where']) != type([1,2]) or len(i['where'])!=2: print('move type eerror') return False if i['where'] in board['white']+board['black']: print('spot taken error') return False if i['where'][0]<0 or i['where'][1]<0: print('off board error') return False if i['where'][0]>=board['size'] or i['where'][1]>=board['size']: print('off board error') return False n=next_board(copy.deepcopy(board), i['where'], state['length']) if (len(n['black'])+len(n['white']))<=(len(board['black'])+len(board['white'])):#if it kills, then it lives # error('here') return True return valid_board(board, i)
def nextTurnCheck(i, state): if i['game_name'] not in state: print('19') return False board=state[i['game_name']] if len(state.keys())==0: print('2') return False if board['whos_turn']=='white': pubkey=board['pubkey_white'] else: pubkey=board['pubkey_black'] if 'move_number' not in i: print('no move number error') return False if board['move_number'] != i['move_number']: print('wrong move number error') return False try:#so that invalid pubkeys don't break anything. if not pt.ecdsa_verify(message2signObject(i, nextturn_sig_list), i['signature'], pubkey): print('i: ' +str(i)) print('state: ' +str(state)) print('14') return False except: print('invalid pubkey error') return False if type(i['where'])!= type([1,2]) or len(i['where'])!=2: print('move type eerror') return False if i['where'] in board['white']+board['black']: print('spot taken error') return False if i['where'][0]<0 or i['where'][1]<0: return False if i['where'][0]>=board['size'] or i['where'][1]>=board['size']: return False return True
def verify(message, signature, pubkey): return pybitcointools.ecdsa_verify(message, signature, pubkey)
def newGameCheck(i, state): if 'pubkey_black' not in i.keys(): i['pubkey_black']=i['id'] if 'pubkey_white' not in i.keys() or type(i['pubkey_white']) not in [type('string'), type(u'unicode')] or len(i['pubkey_white'])!=130: print('type: ' +str(type(i['pubkey_white']))) print('badly formated newgame white pubkey') return False if not enough_funds(state, i['pubkey_black'], 25000): print('you need at least 1/4 of a CryptGo coin in order to play.') return False if 'game_name' not in i.keys(): print('the game needs a name') return False if len(i['game_name'])>129: print('name too long') return False if not 'pubkey_white' in i or not 'pubkey_black' in i: print('13') return False if 'whose_turn' not in i: i['whos_turn']='black' if i['whos_turn'] not in ['white', 'black']: print('4') return False if type(i['white']) != type([1,2]): return False if type(i['black']) != type([1,2]): return False for j in i['white']+i['black']: # print('j: ' +str(j)) if type(j)!=type([1,2]) or len(j)!=2: print('5') return False if 'time' not in i: i['time']=5 if 'size' not in i: i['size']=13 if 'white' not in i: i['white']=[] if 'black' not in i: i['black']=[] if (type(i['time']) != type(3)): print('7') return False if type(i['size']) != type(3) or i['size']<3 or i['size']>30: print('8') return False if type(i['white']) != type([1,2]) or type(['black']) != type([1,2]): print('6') return False if 'amount' not in i: i['amount']=0 if type(i['amount'])!=type(10): print('bet error') return False sign=message2signObject(i, newgame_sig_list) if not pt.ecdsa_verify(sign, i['signature'], i['pubkey_black']): print('i: ' +str(i)) print('signature error') return False if i['amount']>0 and 'signature_white' not in i: print('both people need to consent, if you want to bet') return False if i['amount']>0 and not pt.ecdsa_verify(sign, i['signature_white'], pubkey_white): print('signature error 2') return False return True
def newGameCheck(i, state): if 'pubkey_black' not in i.keys(): i['pubkey_black'] = i['id'] if 'pubkey_white' not in i.keys() or type(i['pubkey_white']) not in [ type('string'), type(u'unicode') ] or len(i['pubkey_white']) != 130: print('type: ' + str(type(i['pubkey_white']))) print('badly formated newgame white pubkey') return False if not enough_funds(state, i['pubkey_black'], 25000): print('you need at least 1/4 of a CryptGo coin in order to play.') return False if 'game_name' not in i.keys(): print('the game needs a name') return False if len(i['game_name']) > 129: print('name too long') return False if not 'pubkey_white' in i or not 'pubkey_black' in i: print('13') return False if 'whose_turn' not in i: i['whos_turn'] = 'black' if i['whos_turn'] not in ['white', 'black']: print('4') return False if type(i['white']) != type([1, 2]): return False if type(i['black']) != type([1, 2]): return False for j in i['white'] + i['black']: # print('j: ' +str(j)) if type(j) != type([1, 2]) or len(j) != 2: print('5') return False if 'time' not in i: i['time'] = 5 if 'size' not in i: i['size'] = 13 if 'white' not in i: i['white'] = [] if 'black' not in i: i['black'] = [] if (type(i['time']) != type(3)): print('7') return False if type(i['size']) != type(3) or i['size'] < 3 or i['size'] > 30: print('8') return False if type(i['white']) != type([1, 2]) or type(['black']) != type([1, 2]): print('6') return False if 'amount' not in i: i['amount'] = 0 if type(i['amount']) != type(10): print('bet error') return False sign = message2signObject(i, newgame_sig_list) if not pt.ecdsa_verify(sign, i['signature'], i['pubkey_black']): print('i: ' + str(i)) print('signature error') return False if i['amount'] > 0 and 'signature_white' not in i: print('both people need to consent, if you want to bet') return False if i['amount'] > 0 and not pt.ecdsa_verify(sign, i['signature_white'], pubkey_white): print('signature error 2') return False return True
def verify_signup_info(cls, signup_info, originator_public_key, validator_network_basename, most_recent_wait_certificate_id): # Verify the attestation verification report signature attestation_verification_report = \ signup_info.proof_data.get('attestation_verification_report') if attestation_verification_report is None: raise \ SignupInfoError( 'Attestation verification report is missing from proof ' 'data') if not pybitcointools.ecdsa_verify( dict2json(attestation_verification_report), signup_info.proof_data.get('signature'), cls._report_public_key): raise \ SignupInfoError( 'Attestation verification report signature is invalid') # Verify the presence of the anti-Sybil ID anti_sybil_id = attestation_verification_report.get('anti_sybil_id') if anti_sybil_id is None: raise \ SignupInfoError( 'Attestation verification report does not contain an ' 'anti-Sybil ID') # Verify that the report data field in the report contains the SHA256 # digest of the originator's public key SHA 256 digest and the PoET # public key. attestation_evidence_payload = \ attestation_verification_report.get( 'attestation_evidence_payload') if attestation_evidence_payload is None: raise \ SignupInfoError( 'Attestation verification report does not contain ' 'attestation evidence payload') enclave_quote = attestation_evidence_payload.get('enclave_quote') if enclave_quote is None: raise \ SignupInfoError( 'Attestation evidence payload does not contain an ' 'enclave quote') report = json2dict(pybitcointools.base64.b64decode(enclave_quote)) report_data = report.get('report_data') if report_data is None: raise \ SignupInfoError('Enclave quote does not contain report data') target_report_data = { 'originator_public_key_hash': pybitcointools.sha256( pybitcointools.encode_pubkey( originator_public_key, 'hex')), 'poet_public_key': signup_info.poet_public_key } target_report_data_digest = \ pybitcointools.sha256(dict2json(target_report_data)) if report_data != target_report_data_digest: raise SignupInfoError('Enclave quote report data is invalid') # Verify that the validator base name in the enclave quote report # matches the provided validator network basename validator_net_basename = report.get('validator_network_basename') if validator_net_basename is None: raise \ SignupInfoError( 'Enclave quote report does not have a validator network ' 'basename') if validator_net_basename != validator_network_basename: raise \ SignupInfoError( 'Enclave quote report validator network basename [{0}] ' 'does not match [{1}]'.format( validator_net_basename, validator_network_basename))