本文整理匯總了Python中linotp.lib.ocra.OcraSuite.compute方法的典型用法代碼示例。如果您正苦於以下問題:Python OcraSuite.compute方法的具體用法?Python OcraSuite.compute怎麽用?Python OcraSuite.compute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類linotp.lib.ocra.OcraSuite
的用法示例。
在下文中一共展示了OcraSuite.compute方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _getChallenge
# 需要導入模塊: from linotp.lib.ocra import OcraSuite [as 別名]
# 或者: from linotp.lib.ocra.OcraSuite import compute [as 別名]
def _getChallenge(self, ocrasuite, bkey, serial, ocrapin="", data=None, count=0, ttime=None):
otp1 = None
p = {"serial": serial, "data": "0105037311 Konto 50150850 BLZ 1752,03 Eur"}
if data != None:
p[data] = data
response = self.app.get(genUrl(controller="ocra", action="request"), params=p)
log.info("response %s\n", response)
assert '"value": true' in response
""" -2b- from the response get the challenge """
jresp = json.loads(response.body)
challenge1 = str(jresp.get("detail").get("challenge"))
transid1 = str(jresp.get("detail").get("transactionid"))
now = datetime.now()
if ttime != None:
now = ttime
stime = now.strftime("%s")
itime = int(stime)
param = {}
param["C"] = count
param["Q"] = challenge1
param["P"] = ocrapin
param["S"] = ""
param["T"] = itime
ocra = OcraSuite(ocrasuite)
data = ocra.combineData(**param)
otp1 = ocra.compute(data, bkey)
return (otp1, transid1)
示例2: verify_challenge_is_valid
# 需要導入模塊: from linotp.lib.ocra import OcraSuite [as 別名]
# 或者: from linotp.lib.ocra.OcraSuite import compute [as 別名]
def verify_challenge_is_valid(self, challenge, session):
'''
verify, if a challenge is valid according to the ocrasuite definition
of the token
'''
ret = True
counter = self.getOtpCount()
secretHOtp = self.token.getHOtpKey()
ocraSuite = OcraSuite(self.getOcraSuiteSuite(), secretHOtp)
## set the pin onyl in the compliant hashed mode
pin = ''
if ocraSuite.P is not None:
pinObj = self.token.getUserPin()
pin = pinObj.getKey()
try:
param = {}
param['C'] = counter
param['Q'] = challenge
param['P'] = pin
param['S'] = session
if ocraSuite.T is not None:
now = datetime.datetime.now()
stime = now.strftime("%s")
itime = int(stime)
param['T'] = itime
''' verify that the data is compliant with the OcraSuitesuite
and the client is able to calc the otp
'''
c_data = ocraSuite.combineData(**param)
ocraSuite.compute(c_data)
except Exception as ex:
log.error("[Ocra2TokenClass] challenge verification failed: "
"%s,%r: " % (challenge, ex))
log.error("[Ocra2TokenClass] %r" % (traceback.format_exc()))
ret = False
return ret
示例3: _getChallenge
# 需要導入模塊: from linotp.lib.ocra import OcraSuite [as 別名]
# 或者: from linotp.lib.ocra.OcraSuite import compute [as 別名]
def _getChallenge(self, ocrasuite, bkey, serial, ocrapin='', data=None, count=0, ttime=None):
otp1 = None
p = {"serial" : serial,
"data" : "0105037311 Konto 50150850 BLZ 1752,03 Eur"
}
if data != None:
p[data] = data
response = self.app.get(genUrl(controller='ocra', action='request'), params=p)
log.info("response %s\n", response)
assert '"value": true' in response
''' -2b- from the response get the challenge '''
jresp = json.loads(response.body)
challenge1 = str(jresp.get('detail').get('challenge'))
transid1 = str(jresp.get('detail').get('transactionid'))
now = datetime.now()
if ttime != None:
now = ttime
stime = now.strftime("%s")
itime = int(stime)
param = {}
param['C'] = count
param['Q'] = challenge1
param['P'] = ocrapin
param['S'] = ''
param['T'] = itime
ocra = OcraSuite(ocrasuite)
data = ocra.combineData(**param)
otp1 = ocra.compute(data, bkey)
return (otp1, transid1)
示例4: ptest_OCRA_token_failcounterInc
# 需要導入模塊: from linotp.lib.ocra import OcraSuite [as 別名]
# 或者: from linotp.lib.ocra.OcraSuite import compute [as 別名]
def ptest_OCRA_token_failcounterInc(self, tid=1):
'''
test_OCRA_token_failcounterInc: failcounter increment
description:
for all ocrasuites:
create and enroll token
verify the first otp
get some challenges
4 times:
verify a wrong otp
verify a wrong transaction
check status and if fail counter has incremented
'''
tcount = 0
for test in self.tests:
ocrasuite = test['ocrasuite']
key = test['keyh']
bkey = test['key']
ocrapin = 'myocrapin'
tid = tid
serial = "QR_One_%r_%r_%r_%r" % (tid, tcount, int(time.time()), random.randint(0, 100))
log.info("## serial: %s" % serial)
count = 0
tcount = tcount + 1
ocra = OcraSuite(ocrasuite)
pinlen = ocra.truncation
''' -1- create an ocra token '''
parameters = {
"serial" : serial,
"user" : "root",
"pin" : "pin",
"description" : "first QRToken",
'type' : 'ocra',
'ocrapin' : ocrapin,
'otpkey' : key,
'ocrasuite' : ocrasuite
}
response = self.app.get(genUrl(controller='admin', action='init'), params=parameters)
assert '"value": true' in response
## verify that the token is usable
''' -2- fetch the challenge '''
p = {"serial" : serial,
"data" : "0105037311 Konto 50150850 BLZ 1752,03 Eur"
}
response = self.app.get(genUrl(controller='ocra', action='request'), params=p)
log.info("response %s\n", response)
if '"value": true' not in response:
assert '"value": true' in response
''' -3.a- from the response get the challenge '''
jresp = json.loads(response.body)
challenge = str(jresp.get('detail').get('challenge'))
transid = str(jresp.get('detail').get('transactionid'))
param = {}
param['C'] = count
param['Q'] = challenge
param['P'] = ocrapin
param['S'] = ''
if ocra.T != None:
''' Default value for G is 1M, i.e., time-step size is one minute and the
T represents the number of minutes since epoch time [UT].
'''
now = datetime.now()
stime = now.strftime("%s")
itime = int(stime)
param['T'] = itime
ocra = OcraSuite(ocrasuite)
data = ocra.combineData(**param)
otp = ocra.compute(data, bkey)
ppin = 'pin' + otp
''' -3.b- verify the correct otp value '''
parameters = {"transactionid" : transid,
"pass" : ppin,
}
response = self.app.get(genUrl(controller='ocra', action='check_t'), params=parameters)
log.info("response %s\n", response)
if '"result": true' not in response:
assert '"result": true' in response
# verify that the failcounter increments (max is 10)
fcount = 0
for count in range(1, 3):
## create more than one challenge
chals = random.randint(2, 5)
for cc in range(1, chals):
''' -2- fetch the challenge '''
p = {"serial" : serial,
"data" : "0105037311 Konto 50150850 BLZ 1752,03 Eur"
}
response = self.app.get(genUrl(controller='ocra', action='request'), params=p)
log.info("response %s\n", response)
#.........這裏部分代碼省略.........
示例5: OcraOtp
# 需要導入模塊: from linotp.lib.ocra import OcraSuite [as 別名]
# 或者: from linotp.lib.ocra.OcraSuite import compute [as 別名]
#.........這裏部分代碼省略.........
jresp = json.loads(response.body)
app_import = str(jresp.get('detail').get('app_import'))
self.sharedsecret = str(jresp.get('detail').get('sharedsecret'))
self.serial = str(jresp.get('detail').get('serial'))
''' now parse the appurl for the ocrasuite '''
uri = urlparse(app_import.replace('lseqr://', 'http://'))
qs = uri.query
qdict = parse_qs(qs)
ocrasuite = qdict.get('os', None)
if ocrasuite != None and len(ocrasuite) > 0:
ocrasuite = ocrasuite[0]
self.ocrasuite = ocrasuite
return (self.ocrasuite, self.sharedsecret, self.serial)
def init_2(self, response, activationKey):
self.activationkey = activationKey
jresp = json.loads(response.body)
self.nonce = str(jresp.get('detail').get('nonce'))
self.transid = str(jresp.get('detail').get('transactionid'))
app_import = str(jresp.get('detail').get('app_import'))
''' now parse the appurl for the ocrasuite '''
uri = urlparse(app_import.replace('lseqr://', 'http://'))
qs = uri.query
qdict = parse_qs(qs)
nonce = qdict.get('no', None)
if nonce != None and len(nonce) > 0:
nonce = nonce[0]
challenge = qdict.get('ch', None)
if challenge != None and len(challenge) > 0:
challenge = challenge[0]
self.challenge = challenge
self.ocra = None
self.bkey = None
return (self.challenge, self.transid)
def _setup_(self):
if self.ocra != None and self.bkey != None:
return
key_len = 20
if self.ocrasuite.find('-SHA256'):
key_len = 32
elif self.ocrasuite.find('-SHA512'):
key_len = 64
self.bkey = kdf2(self.sharedsecret, self.nonce, self.activationkey, len=key_len)
self.ocra = OcraSuite(self.ocrasuite)
self.counter = 0
return
def callcOtp(self, challenge=None, ocrapin=None, counter= -1):
if self.ocra == None:
self._setup_()
if ocrapin == None:
ocrapin = self.ocrapin
if challenge == None:
challenge = self.challenge
if counter == -1:
counter = self.counter
param = {}
param['C'] = counter
param['Q'] = challenge
param['P'] = ocrapin
param['S'] = ''
if self.ocra.T != None:
''' Default value for G is 1M, i.e., time-step size is one minute and the
T represents the number of minutes since epoch time [UT].
'''
now = datetime.now()
stime = now.strftime("%s")
itime = int(stime)
param['T'] = itime
data = self.ocra.combineData(**param)
otp = self.ocra.compute(data, self.bkey)
if counter == -1:
self.counter += 1
return otp
示例6: calculateOtp
# 需要導入模塊: from linotp.lib.ocra import OcraSuite [as 別名]
# 或者: from linotp.lib.ocra.OcraSuite import compute [as 別名]
#.........這裏部分代碼省略.........
qs = uri.query
qdict = parse_qs(qs)
ocrasuite2 = qdict.get('os', None)
if ocrasuite2 is not None and len(ocrasuite2) > 0:
ocrasuite2 = ocrasuite2[0]
if ocrasuite is None:
ocrasuite = ocrasuite2
sharedsecret2 = qdict.get('sh', None)
if sharedsecret2 is not None and len(sharedsecret2) > 0:
sharedsecret2 = sharedsecret2[0]
if sharedsecret is None:
sharedsecret = sharedsecret2
## parse init1
if init2 is not None:
## now parse the appurl for the ocrasuite
uri = urlparse(init2.replace('lseqr://', 'http://'))
qs = uri.query
qdict = parse_qs(qs)
challenge2 = qdict.get('ch', None)
if challenge2 is not None and len(challenge2) > 0:
challenge2 = challenge2[0]
if challenge is None:
challenge = challenge2
nonce2 = qdict.get('no', None)
if nonce2 is not None and len(nonce2) > 0:
nonce2 = nonce2[0]
if nonce is None:
nonce = nonce2
if ocrapin is None:
ocrapin = ''
if counter is None:
counter = 0
if nonce3 is not None:
nonce = unicode(nonce3)
if ocrasuite3 is not None:
ocrasuite = unicode(ocrasuite3)
## now we have all in place for the key derivation to create the new key
## sharedsecret, activationcode and nonce
key_len = 20
if ocrasuite.find('-SHA256'):
key_len = 32
elif ocrasuite.find('-SHA512'):
key_len = 64
if sharedsecret is not None:
sharedsecret = unicode(sharedsecret)
if nonce is not None:
nonce = unicode(nonce)
if activationcode is not None:
activationcode = unicode(activationcode)
newkey = kdf2(sharedsecret, nonce, activationcode, len=key_len)
## hnewkey = binascii.hexlify(newkey)
ocra = OcraSuite(ocrasuite)
param = {}
param['C'] = int(counter)
param['Q'] = unicode(challenge)
param['P'] = unicode(ocrapin)
param['S'] = ''
if ocra.T is not None:
## Default value for G is 1M, i.e., time-step size is one minute and the
## T represents the number of minutes since epoch time [UT].
now = datetime.now()
stime = now.strftime("%s")
itime = int(stime)
param['T'] = itime
data = ocra.combineData(**param)
otp = ocra.compute(data, newkey)
res = {'otp':otp}
Session.commit()
return sendResult(response, res, 1)
except PolicyException as pe:
log.exception("[ocra/calculateOtp] policy failed: %r" % pe)
Session.rollback()
return sendError(response, pe)
except Exception as e:
log.exception("[ocra/calculateOtp] failed: %r" % e)
Session.rollback()
return sendError(response, unicode(e), 0)
finally:
Session.close()
log.debug('[ocra/calculateOtp] done')
示例7: challenge
# 需要導入模塊: from linotp.lib.ocra import OcraSuite [as 別名]
# 或者: from linotp.lib.ocra.OcraSuite import compute [as 別名]
def challenge(self, data, session='', typ='raw', challenge=None):
'''
the challenge method is for creating an transaction / challenge object
remark: the transaction has a maximum lifetime and a reference to
the OcraSuite token (serial)
:param data: data, which is the base for the challenge or None
:type data: string or None
:param session: session support for ocratokens
:type session: string
:type typ: define, which kind of challenge base should be used
could be raw - take the data input as is
(extract chars accordind challenge definition Q)
or random - will generate a random input
or hased - will take the hash of the input data
:return: challenge response containing the transcation id and the
challenge for the ocrasuite
:rtype : tuple of (transId(string), challenge(string))
'''
log.debug('[challenge] %r: %r: %r' % (data, session, challenge))
secretHOtp = self.token.getHOtpKey()
ocraSuite = OcraSuite(self.getOcraSuiteSuite(), secretHOtp)
if data is None or len(data) == 0:
typ = 'random'
if challenge is None:
if typ == 'raw':
challenge = ocraSuite.data2rawChallenge(data)
elif typ == 'random':
challenge = ocraSuite.data2randomChallenge(data)
elif typ == 'hash':
challenge = ocraSuite.data2hashChallenge(data)
log.debug('[Ocra2TokenClass] challenge: %r ' % (challenge))
counter = self.getOtpCount()
## set the pin onyl in the compliant hashed mode
pin = ''
if ocraSuite.P is not None:
pinObj = self.token.getUserPin()
pin = pinObj.getKey()
try:
param = {}
param['C'] = counter
param['Q'] = challenge
param['P'] = pin
param['S'] = session
if ocraSuite.T is not None:
now = datetime.datetime.now()
stime = now.strftime("%s")
itime = int(stime)
param['T'] = itime
''' verify that the data is compliant with the OcraSuitesuite
and the client is able to calc the otp
'''
c_data = ocraSuite.combineData(**param)
ocraSuite.compute(c_data)
except Exception as ex:
log.error("[Ocra2TokenClass] %r" % (traceback.format_exc()))
raise Exception('[Ocra2TokenClass] Failed to create ocrasuite '
'challenge: %r' % (ex))
## create a non exisiting challenge
try:
(res, opt) = create_challenge(self, options={'messgae': data})
transid = opt.get('transactionid')
challenge = opt.get('challenge')
except Exception as ex:
## this might happen if we have a db problem or
## the uniqnes constrain does not fit
log.error("[Ocra2TokenClass] %r" % (traceback.format_exc()))
raise Exception('[Ocra2TokenClass] Failed to create '
'challenge object: %s' % (ex))
realm = None
realms = self.token.getRealms()
if len(realms) > 0:
realm = realms[0]
url = ''
if realm is not None:
url = get_qrtan_url(realm.name)
log.debug('[challenge]: %r: %r: %r' % (transid, challenge, url))
return (transid, challenge, True, url)
示例8: ptest_OCRA_token_failcounterInc
# 需要導入模塊: from linotp.lib.ocra import OcraSuite [as 別名]
# 或者: from linotp.lib.ocra.OcraSuite import compute [as 別名]
def ptest_OCRA_token_failcounterInc(self, tid=1):
"""
test_OCRA_token_failcounterInc: failcounter increment
description:
for all ocrasuites:
create and enroll token
verify the first otp
get some challenges
4 times:
verify a wrong otp
verify a wrong transaction
check status and if fail counter has incremented
"""
tcount = 0
for test in self.tests:
ocrasuite = test["ocrasuite"]
key = test["keyh"]
bkey = test["key"]
ocrapin = "myocrapin"
tid = tid
serial = "QR_One_%r_%r_%r_%r" % (tid, tcount, int(time.time()), random.randint(0, 100))
log.info("## serial: %s" % serial)
count = 0
tcount = tcount + 1
ocra = OcraSuite(ocrasuite)
pinlen = ocra.truncation
""" -1- create an ocra token """
parameters = {
"serial": serial,
"user": "root",
"pin": "pin",
"description": "first QRToken",
"type": "ocra",
"ocrapin": ocrapin,
"otpkey": key,
"ocrasuite": ocrasuite,
}
response = self.app.get(genUrl(controller="admin", action="init"), params=parameters)
assert '"value": true' in response
## verify that the token is usable
""" -2- fetch the challenge """
p = {"serial": serial, "data": "0105037311 Konto 50150850 BLZ 1752,03 Eur"}
response = self.app.get(genUrl(controller="ocra", action="request"), params=p)
log.info("response %s\n", response)
if '"value": true' not in response:
assert '"value": true' in response
""" -3.a- from the response get the challenge """
jresp = json.loads(response.body)
challenge = str(jresp.get("detail").get("challenge"))
transid = str(jresp.get("detail").get("transactionid"))
param = {}
param["C"] = count
param["Q"] = challenge
param["P"] = ocrapin
param["S"] = ""
if ocra.T != None:
""" Default value for G is 1M, i.e., time-step size is one minute and the
T represents the number of minutes since epoch time [UT].
"""
now = datetime.now()
stime = now.strftime("%s")
itime = int(stime)
param["T"] = itime
ocra = OcraSuite(ocrasuite)
data = ocra.combineData(**param)
otp = ocra.compute(data, bkey)
ppin = "pin" + otp
""" -3.b- verify the correct otp value """
parameters = {"transactionid": transid, "pass": ppin}
response = self.app.get(genUrl(controller="ocra", action="check_t"), params=parameters)
log.info("response %s\n", response)
if '"result": true' not in response:
assert '"result": true' in response
# verify that the failcounter increments (max is 10)
fcount = 0
for count in range(1, 3):
## create more than one challenge
chals = random.randint(2, 5)
for cc in range(1, chals):
""" -2- fetch the challenge """
p = {"serial": serial, "data": "0105037311 Konto 50150850 BLZ 1752,03 Eur"}
response = self.app.get(genUrl(controller="ocra", action="request"), params=p)
log.info("response %s\n", response)
if '"value": true' not in response:
assert '"value": true' in response
""" -3.a- from the response get the challenge """
jresp = json.loads(response.body)
challenge = str(jresp.get("detail").get("challenge"))
#.........這裏部分代碼省略.........
示例9: OcraOtp
# 需要導入模塊: from linotp.lib.ocra import OcraSuite [as 別名]
# 或者: from linotp.lib.ocra.OcraSuite import compute [as 別名]
#.........這裏部分代碼省略.........
def init_1(self, response):
""" take the response of the first init to setup the OcraOtp"""
jresp = json.loads(response.body)
app_import = str(jresp.get("detail").get("app_import"))
self.sharedsecret = str(jresp.get("detail").get("sharedsecret"))
self.serial = str(jresp.get("detail").get("serial"))
""" now parse the appurl for the ocrasuite """
uri = urlparse(app_import.replace("lseqr://", "http://"))
qs = uri.query
qdict = parse_qs(qs)
ocrasuite = qdict.get("os", None)
if ocrasuite != None and len(ocrasuite) > 0:
ocrasuite = ocrasuite[0]
self.ocrasuite = ocrasuite
return (self.ocrasuite, self.sharedsecret, self.serial)
def init_2(self, response, activationKey):
self.activationkey = activationKey
jresp = json.loads(response.body)
self.nonce = str(jresp.get("detail").get("nonce"))
self.transid = str(jresp.get("detail").get("transactionid"))
app_import = str(jresp.get("detail").get("app_import"))
""" now parse the appurl for the ocrasuite """
uri = urlparse(app_import.replace("lseqr://", "http://"))
qs = uri.query
qdict = parse_qs(qs)
nonce = qdict.get("no", None)
if nonce != None and len(nonce) > 0:
nonce = nonce[0]
challenge = qdict.get("ch", None)
if challenge != None and len(challenge) > 0:
challenge = challenge[0]
self.challenge = challenge
self.ocra = None
self.bkey = None
return (self.challenge, self.transid)
def _setup_(self):
if self.ocra != None and self.bkey != None:
return
key_len = 20
if self.ocrasuite.find("-SHA256"):
key_len = 32
elif self.ocrasuite.find("-SHA512"):
key_len = 64
self.bkey = kdf2(self.sharedsecret, self.nonce, self.activationkey, len=key_len)
self.ocra = OcraSuite(self.ocrasuite)
self.counter = 0
return
def callcOtp(self, challenge=None, ocrapin=None, counter=-1):
if self.ocra == None:
self._setup_()
if ocrapin == None:
ocrapin = self.ocrapin
if challenge == None:
challenge = self.challenge
if counter == -1:
counter = self.counter
param = {}
param["C"] = counter
param["Q"] = challenge
param["P"] = ocrapin
param["S"] = ""
if self.ocra.T != None:
""" Default value for G is 1M, i.e., time-step size is one minute and the
T represents the number of minutes since epoch time [UT].
"""
now = datetime.now()
stime = now.strftime("%s")
itime = int(stime)
param["T"] = itime
data = self.ocra.combineData(**param)
otp = self.ocra.compute(data, self.bkey)
if counter == -1:
self.counter += 1
return otp