Created
May 16, 2018 13:08
-
-
Save qstokkink/b35e2d2ccde3093db651cb0a7bfdaf06 to your computer and use it in GitHub Desktop.
IDEMIA verification with phone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from base64 import b64encode | |
from json import loads | |
from urllib import quote | |
from twisted.internet import reactor | |
from twisted.internet.defer import inlineCallbacks, returnValue | |
from twisted.internet.task import deferLater | |
from roles import initialize_peer, make_request, sleep, stop_peers | |
print "Initializing peers" | |
verifier, verifier_restapi = initialize_peer("verifier") | |
@inlineCallbacks | |
def wait_for_peers(idowner_restapi): | |
# Wait a second, if we fail to find peers: repeat, otherwise: return the result | |
peers = yield make_request(idowner_restapi, 'GET', { | |
'type': 'peers' | |
}) | |
if peers != "[]": | |
returnValue(peers) | |
else: | |
print "No peers have connected yet, waiting for 4 seconds!" | |
peers = yield deferLater(reactor, 4.0, wait_for_peers, idowner_restapi) | |
returnValue(peers) | |
@inlineCallbacks | |
def make_attribute(): | |
global verifier, verifier_restapi | |
try: | |
value = yield wait_for_peers(verifier_restapi) | |
print "Known peers:", value | |
identifier = loads(value)[0] | |
yield sleep(2) | |
value = yield make_request(verifier_restapi, 'GET', { | |
'type': 'attributes', | |
'mid': str(identifier).replace("+", "%2B") | |
}) | |
attributes = loads(value) | |
print attributes | |
yield make_request(verifier_restapi, 'POST', { | |
'type': 'verify', | |
'mid': str(identifier).replace("+", "%2B"), | |
'attribute_hash': quote(str(attributes[0][1])), | |
'attribute_values': quote(b64encode('binarydata')).replace("+", "%2B") | |
}) | |
while True: | |
yield sleep(4) | |
value = yield make_request(verifier_restapi, 'GET', { | |
'type': 'verification_output' | |
}) | |
verifications = loads(value) | |
print "Verifications:", verifications | |
except: | |
import traceback | |
traceback.print_exc() | |
deferLater(reactor, 0.5, make_attribute) | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment