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 = \
            pybitcointools.ecdsa_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_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 = \
            pybitcointools.ecdsa_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())
Example #3
0
    def create_wait_timer(cls, previous_certificate_id, local_mean):
        # 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 = \
            pybitcointools.base64.b64decode(
                pybitcointools.ecdsa_sign(
                    previous_certificate_id,
                    cls._seal_private_key))

        tagd = float(struct.unpack('L', tag[-8:])[0]) / (2**64 - 1)

        # Now compute the duration
        duration = cls.__MINIMUM_DURATTION - local_mean * math.log(tagd)

        # Create and sign the wait timer
        wait_timer = \
            EnclaveWaitTimer(
                duration=duration,
                previous_certificate_id=previous_certificate_id,
                local_mean=local_mean)
        wait_timer.signature = \
            pybitcointools.ecdsa_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 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(
                duration=3.14159,
                previous_certificate_id='Bond.  James Bond.',
                local_mean=2.71828)

        self.assertIsNotNone(wait_timer.serialize())
    def create_wait_timer(cls, previous_certificate_id, local_mean):
        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 \
                    WaitTimerError(
                        '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 = \
                pybitcointools.base64.b64decode(
                    pybitcointools.ecdsa_sign(
                        previous_certificate_id,
                        cls._seal_private_key))

            tagd = float(struct.unpack('L', tag[-8:])[0]) / (2**64 - 1)

            # Now compute the duration
            duration = cls.__MINIMUM_DURATTION - local_mean * math.log(tagd)

            # Create and sign the wait timer
            wait_timer = \
                EnclaveWaitTimer(
                    duration=duration,
                    previous_certificate_id=previous_certificate_id,
                    local_mean=local_mean)
            wait_timer.signature = \
                pybitcointools.ecdsa_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 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 pybitcointools.ecdsa_verify(
                    serialized_timer,
                    signature,
                    cls._poet_public_key):
                return None

        return \
            EnclaveWaitTimer.wait_timer_from_serialized(
                serialized_timer=serialized_timer,
                signature=signature)
Example #9
0
    def test_create_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.assertEqual(wait_timer.request_time,
                         wait_certificate.request_time)
        self.assertEqual(wait_timer.duration, wait_certificate.duration)
        self.assertEqual(wait_timer.previous_certificate_id,
                         wait_certificate.previous_certificate_id)
        self.assertEqual(wait_timer.local_mean, wait_certificate.local_mean)
        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(
                request_time=wait_certificate.request_time,
                duration=wait_certificate.duration,
                previous_certificate_id=previous_certificate_id,
                local_mean=wait_certificate.local_mean,
                nonce='Eeny, meeny, miny, moe.',
                block_digest=wait_certificate.block_digest)

        self.assertEqual(wait_certificate.request_time,
                         other_wait_certificate.request_time)
        self.assertEqual(wait_certificate.duration,
                         other_wait_certificate.duration)
        self.assertEqual(wait_certificate.previous_certificate_id,
                         other_wait_certificate.previous_certificate_id)
        self.assertEqual(wait_certificate.local_mean,
                         other_wait_certificate.local_mean)
        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)
Example #10
0
    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())
Example #11
0
    def test_deserialized_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.')

        serialized = wait_certificate.serialize()
        signing_key = self._create_random_key()
        wait_certificate.signature = \
            pybitcointools.ecdsa_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.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())
Example #12
0
 def deserialize_wait_timer(cls, serialized_timer, signature):
     return \
         EnclaveWaitTimer.wait_timer_from_serialized(
             serialized_timer=serialized_timer,
             signature=signature)