def test_deserialized_wait_timer(self): wait_timer = \ EnclaveWaitTimer( duration=3.14159, previous_certificate_id='Bond. James Bond.', local_mean=2.71828) serialized = wait_timer.serialize() signing_key = self._create_random_key() wait_timer.signature = \ signing.sign(serialized, signing_key) copy_wait_timer = \ EnclaveWaitTimer.wait_timer_from_serialized( serialized, wait_timer.signature) self.assertAlmostEquals( wait_timer.request_time, copy_wait_timer.request_time) self.assertAlmostEquals( wait_timer.duration, copy_wait_timer.duration) self.assertEqual( wait_timer.previous_certificate_id, copy_wait_timer.previous_certificate_id) self.assertAlmostEquals( wait_timer.local_mean, copy_wait_timer.local_mean) self.assertEqual( wait_timer.signature, copy_wait_timer.signature) self.assertEqual(serialized, copy_wait_timer.serialize())
def test_serialize_wait_timer(self): wait_timer = \ EnclaveWaitTimer( duration=3.14159, previous_certificate_id='Bond. James Bond.', local_mean=2.71828) self.assertIsNotNone(wait_timer.serialize())
def test_serialize_wait_timer(self): wait_timer = \ EnclaveWaitTimer( validator_address='1600 Pennsylvania Avenue NW', duration=3.14159, previous_certificate_id='Bond. James Bond.', local_mean=2.71828) self.assertIsNotNone(wait_timer.serialize())
def test_create_wait_certificate(self): wait_timer = \ EnclaveWaitTimer( validator_address='1600 Pennsylvania Avenue NW', duration=3.14159, previous_certificate_id='Smart, Maxwell Smart', local_mean=2.71828) wait_certificate = \ EnclaveWaitCertificate.wait_certificate_with_wait_timer( wait_timer=wait_timer, nonce='Eeny, meeny, miny, moe.', block_digest='Indigestion. Pepto Bismol.') self.assertAlmostEquals(wait_timer.request_time, wait_certificate.request_time) self.assertAlmostEquals(wait_timer.duration, wait_certificate.duration) self.assertEqual(wait_timer.previous_certificate_id, wait_certificate.previous_certificate_id) self.assertAlmostEquals(wait_timer.local_mean, wait_certificate.local_mean) self.assertEqual(wait_timer.validator_address, wait_certificate.validator_address) self.assertEqual(wait_certificate.nonce, 'Eeny, meeny, miny, moe.') self.assertEqual(wait_certificate.block_digest, 'Indigestion. Pepto Bismol.') self.assertIsNone(wait_certificate.signature) # You probably wonder why I bother assigning # wait_certificate.previous_certificate_id to a local variable - # this is to simply get around PEP8. # If I don't, it complains about the line being too long. # If I do a line continuation, it complains about a space around the =. previous_certificate_id = wait_certificate.previous_certificate_id other_wait_certificate = \ EnclaveWaitCertificate( duration=wait_certificate.duration, previous_certificate_id=previous_certificate_id, local_mean=wait_certificate.local_mean, request_time=wait_certificate.request_time, validator_address='1600 Pennsylvania Avenue NW', nonce='Eeny, meeny, miny, moe.', block_digest=wait_certificate.block_digest) self.assertAlmostEquals(wait_certificate.duration, other_wait_certificate.duration) self.assertEqual(wait_certificate.previous_certificate_id, other_wait_certificate.previous_certificate_id) self.assertAlmostEquals(wait_certificate.local_mean, other_wait_certificate.local_mean) self.assertAlmostEquals(wait_certificate.request_time, other_wait_certificate.request_time) self.assertEqual(wait_certificate.validator_address, other_wait_certificate.validator_address) self.assertEqual(wait_certificate.nonce, other_wait_certificate.nonce) self.assertEqual(wait_certificate.block_digest, other_wait_certificate.block_digest) self.assertIsNone(other_wait_certificate.signature)
def create_wait_timer(cls, validator_address, previous_certificate_id, local_mean, minimum_wait_time): with cls._lock: # If we don't have a PoET private key, then the enclave has not # been properly initialized (either by calling create_signup_info # or unseal_signup_data) if cls._poet_private_key is None: raise \ ValueError( 'Enclave must be initialized before attempting to ' 'create a wait timer') # Create some value from the cert ID. We are just going to use # the seal key to sign the cert ID. We will then use the # low-order 64 bits to change that to a number [0, 1] tag = \ base64.b64decode( signing.sign( previous_certificate_id, cls._seal_private_key)) tagd = float(struct.unpack('Q', tag[-8:])[0]) / (2**64 - 1) # Now compute the duration with a minimum wait time guaranteed duration = minimum_wait_time - local_mean * math.log(tagd) # Create and sign the wait timer wait_timer = \ EnclaveWaitTimer( validator_address=validator_address, duration=duration, previous_certificate_id=previous_certificate_id, local_mean=local_mean) wait_timer.signature = \ signing.sign( wait_timer.serialize(), cls._poet_private_key) # Keep track of the active wait timer cls._active_wait_timer = wait_timer return wait_timer
def deserialize_wait_timer(cls, serialized_timer, signature): with cls._lock: # Verify the signature before trying to deserialize if not signing.verify(serialized_timer, signature, cls._poet_public_key): return None return \ EnclaveWaitTimer.wait_timer_from_serialized( serialized_timer=serialized_timer, signature=signature)
def test_create_wait_timer(self): wait_timer = \ EnclaveWaitTimer( duration=3.14159, previous_certificate_id='Bond. James Bond.', local_mean=2.71828) self.assertAlmostEquals(wait_timer.duration, 3.14159, 3) self.assertLessEqual(wait_timer.request_time, time.time()) self.assertEqual( wait_timer.previous_certificate_id, 'Bond. James Bond.') self.assertAlmostEquals(wait_timer.local_mean, 2.71828, 3) self.assertIsNone(wait_timer.signature)
def deserialize_wait_timer(cls, serialized_timer, signature): with cls._lock: # Verify the signature before trying to deserialize if not signing.verify( serialized_timer, signature, cls._poet_public_key): return None return \ EnclaveWaitTimer.wait_timer_from_serialized( serialized_timer=serialized_timer, signature=signature)
def test_deserialized_wait_timer(self): wait_timer = \ EnclaveWaitTimer( validator_address='1600 Pennsylvania Avenue NW', duration=3.14159, previous_certificate_id='Bond. James Bond.', local_mean=2.71828) serialized = wait_timer.serialize() signing_key = self._create_random_key() wait_timer.signature = \ signing.sign(serialized, signing_key) copy_wait_timer = \ EnclaveWaitTimer.wait_timer_from_serialized( serialized, wait_timer.signature) self.assertEqual( wait_timer.validator_address, copy_wait_timer.validator_address) self.assertAlmostEqual( wait_timer.request_time, copy_wait_timer.request_time) self.assertAlmostEqual( wait_timer.duration, copy_wait_timer.duration) self.assertEqual( wait_timer.previous_certificate_id, copy_wait_timer.previous_certificate_id) self.assertAlmostEqual( wait_timer.local_mean, copy_wait_timer.local_mean) self.assertEqual( wait_timer.signature, copy_wait_timer.signature) self.assertEqual(serialized, copy_wait_timer.serialize())
def test_serialize_wait_certificate(self): wait_timer = \ EnclaveWaitTimer( duration=3.14159, previous_certificate_id='Smart, Maxwell Smart', local_mean=2.71828) wait_certificate = \ EnclaveWaitCertificate.wait_certificate_with_wait_timer( wait_timer=wait_timer, nonce='Eeny, meeny, miny, moe.', block_digest='Indigestion. Pepto Bismol.') self.assertIsNotNone(wait_certificate.serialize())
def test_create_wait_timer(self): wait_timer = \ EnclaveWaitTimer( validator_address='1600 Pennsylvania Avenue NW', duration=3.14159, previous_certificate_id='Bond. James Bond.', local_mean=2.71828) self.assertEqual(wait_timer.validator_address, '1600 Pennsylvania Avenue NW') self.assertAlmostEqual(wait_timer.duration, 3.14159, 3) self.assertLessEqual(wait_timer.request_time, time.time()) self.assertEqual(wait_timer.previous_certificate_id, 'Bond. James Bond.') self.assertAlmostEqual(wait_timer.local_mean, 2.71828, 3) self.assertIsNone(wait_timer.signature)
def test_deserialized_wait_certificate(self): wait_timer = \ EnclaveWaitTimer( validator_address='1600 Pennsylvania Avenue NW', duration=3.14159, previous_certificate_id='Smart, Maxwell Smart', local_mean=2.71828) wait_certificate = \ EnclaveWaitCertificate.wait_certificate_with_wait_timer( wait_timer=wait_timer, nonce='Eeny, meeny, miny, moe.', block_digest='Indigestion. Pepto Bismol.') serialized = wait_certificate.serialize() signing_key = self._create_random_key() wait_certificate.signature = \ signing.sign(serialized, signing_key) copy_wait_certificate = \ EnclaveWaitCertificate.wait_certificate_from_serialized( serialized, wait_certificate.signature) self.assertAlmostEquals(wait_certificate.request_time, copy_wait_certificate.request_time) self.assertAlmostEquals(wait_certificate.duration, copy_wait_certificate.duration) self.assertEqual(wait_certificate.previous_certificate_id, copy_wait_certificate.previous_certificate_id) self.assertAlmostEquals(wait_certificate.local_mean, copy_wait_certificate.local_mean) self.assertEqual(wait_certificate.validator_address, copy_wait_certificate.validator_address) self.assertEqual(wait_certificate.nonce, copy_wait_certificate.nonce) self.assertEqual(wait_certificate.block_digest, copy_wait_certificate.block_digest) self.assertEqual(wait_certificate.signature, copy_wait_certificate.signature) self.assertEqual(serialized, copy_wait_certificate.serialize())