コード例 #1
0
ファイル: protocol.py プロジェクト: iffy/txOpenID
	def __init__(self, requestData, assoc_type='HMAC-SHA1', handle=None):
		"""
		Create a new association with the provided requestData.
		"""
		if(handle):
			self.handle = handle
		else:
			self.handle = base64.b64encode(util.handle())
		
		self.assoc_type = assoc_type
		self.secret = util.secret(self.handle, assoc_type)
		self.created = time.time()
		self.expires_in = '86400'
		
		if(DH_SHA1_ENABLED and requestData.get('openid.session_type') == 'DH-SHA1'):
			self.dh_modulus = util.mklong(base64.b64decode(requestData['openid.dh_modulus']))
			self.dh_gen = util.mklong(base64.b64decode(requestData['openid.dh_gen']))
			self.dh_consumer_public = util.mklong(base64.b64decode(requestData['openid.dh_consumer_public']))
			self.dh_server_private = util.mkkey()
			self.dh_server_public = base64.b64encode(util.btwoc(pow(self.dh_gen, self.dh_server_private) % self.dh_modulus))
			self.dh_shared_secret = pow(self.dh_consumer_public, self.dh_server_private) % self.dh_modulus
			self.enc_mac_key = util.secret(util.btwoc(self.dh_shared_secret), 'HMAC-SHA1') ^ self.secret
		else:
			self.mac_key = base64.b64encode(self.secret)
コード例 #2
0
ファイル: test_util.py プロジェクト: iffy/txOpenID
	def test_btwoc(self):
		value = 1212602127
		expected = 'HF\xd7\x0f'
		got = util.btwoc(value)
		self.failUnlessEqual(got, expected, "Got %r when expecting %r" % (got, expected))