def test_compute_local_mean(self):
        with self.assertRaises(TypeError) as context:
            local_mean = WaitTimer.compute_local_mean(None)

        with self.assertRaises(TypeError) as context:
            local_mean = WaitTimer.compute_local_mean("")
        with self.assertRaises(TypeError) as context:
            local_mean = WaitTimer.compute_local_mean("XYZZY")
        with self.assertRaises(TypeError) as context:
            local_mean = WaitTimer.compute_local_mean(555)

        certs = []
        local_mean = WaitTimer.compute_local_mean(certs)
        self.assertEqual(local_mean, 30)
    def test_compute_local_mean(self):
        with self.assertRaises(TypeError) as context:
            local_mean = WaitTimer.compute_local_mean(None)

        with self.assertRaises(TypeError) as context:
            local_mean = WaitTimer.compute_local_mean("")
        with self.assertRaises(TypeError) as context:
            local_mean = WaitTimer.compute_local_mean("XYZZY")
        with self.assertRaises(TypeError) as context:
            local_mean = WaitTimer.compute_local_mean(555)

        certs = []
        local_mean = WaitTimer.compute_local_mean(certs)
        self.assertEqual(local_mean, 30)
    def is_valid_wait_certificate(self, certs):
        """Determines whether the wait certificate is valid.

        Args:
            certs (list): A list of historical certs.

        Returns:
            bool: Whether or not the wait certificate is valid.
        """
        cert = self.EnclaveWaitCertificate
        expectedmean = WaitTimer.compute_local_mean(certs)
        if not is_close(cert.LocalMean, expectedmean, abs_tol=0.001):
            logger.warn('mismatch local mean: %s != %s', cert.LocalMean,
                        expectedmean)
            # return False

        if cert.PreviousCertID == self.PoetEnclave.NullIdentifier:
            return True

        if cert.PreviousCertID != certs[-1].Identifier:
            logger.warn('mismatch previous identifier: %s != %s',
                        cert.PreviousCertID, certs[-1].Identifier)
            # return False

        return self.PoetEnclave.VerifyWaitCertificate(cert)
Exemplo n.º 4
0
    def is_valid_wait_certificate(self, certs):
        """Determines whether the wait certificate is valid.

        Args:
            certs (list): A list of historical certs.

        Returns:
            bool: Whether or not the wait certificate is valid.
        """
        cert = self.enclave_wait_certificate
        expected_mean = WaitTimer.compute_local_mean(certs)
        if not is_close(cert.local_mean, expected_mean, abs_tol=0.001):
            logger.warn('mismatch local mean: %s != %s', cert.local_mean,
                        expected_mean)
            # return False

        if cert.previous_certificate_id == self._poet_enclave.NULL_IDENTIFIER:
            return True

        if cert.previous_certificate_id != certs[-1].identifier:
            logger.warn('mismatch previous identifier: %s != %s',
                        cert.previous_certificate_id, certs[-1].identifier)
            # return False

        return self._poet_enclave.verify_wait_certificate(cert)
    def is_valid_wait_certificate(self, certs):
        """Determines whether the wait certificate is valid.

        Args:
            certs (list): A list of historical certs.

        Returns:
            bool: Whether or not the wait certificate is valid.
        """
        cert = self.EnclaveWaitCertificate
        expectedmean = WaitTimer.compute_local_mean(certs)
        if not is_close(cert.LocalMean, expectedmean, abs_tol=0.001):
            logger.warn('mismatch local mean: %s != %s', cert.LocalMean,
                        expectedmean)
            # return False

        if cert.PreviousCertID == self.PoetEnclave.NullIdentifier:
            return True

        if cert.PreviousCertID != certs[-1].Identifier:
            logger.warn('mismatch previous identifier: %s != %s',
                        cert.PreviousCertID, certs[-1].Identifier)
            # return False

        return self.PoetEnclave.VerifyWaitCertificate(cert)
Exemplo n.º 6
0
    def is_valid_wait_certificate(self, certs):
        """Determines whether the wait certificate is valid.

        Args:
            certs (list): A list of historical certs.

        Returns:
            bool: Whether or not the wait certificate is valid.
        """
        cert = self.enclave_wait_certificate

        if cert.duration < self._poet_enclave.MINIMUM_WAIT_TIME:
            logger.warn('Wait time less then minimum: %s != %s', cert.duration,
                        self._poet_enclave.MINIMUM_WAIT_TIME)
            return False

        expected_mean = WaitTimer.compute_local_mean(certs)
        if not is_close(cert.local_mean, expected_mean, abs_tol=0.001):
            logger.warn('mismatch local mean: %s != %s', cert.local_mean,
                        expected_mean)
            return False

        if cert.previous_certificate_id == self._poet_enclave.NULL_IDENTIFIER:
            if len(certs) == 0:
                return True

        if cert.previous_certificate_id != certs[-1].identifier:
            logger.warn('mismatch previous identifier: %s != %s',
                        cert.previous_certificate_id, certs[-1].identifier)
            return False

        return self._poet_enclave.verify_wait_certificate(cert)
Exemplo n.º 7
0
    def is_valid_wait_certificate(self, originator_id, certs, transactions):
        """Determines whether the wait certificate is valid.

        Args:
            certs (list): A list of historical certs.

        Returns:
            bool: Whether or not the wait certificate is valid.
        """
        if not isinstance(originator_id, basestring):
            raise TypeError

        if not isinstance(certs, list):
            raise TypeError

        if not isinstance(transactions, list):
            raise TypeError

        cert = self.enclave_wait_certificate
        if not cert:
            return False

        if cert.duration < self.poet_enclave.MINIMUM_WAIT_TIME:
            logger.warn('Wait time less then minimum: %s != %s',
                        cert.duration, self.poet_enclave.MINIMUM_WAIT_TIME)
            return False

        expected_mean = WaitTimer.compute_local_mean(certs)
        if not is_close(cert.local_mean, expected_mean, abs_tol=0.001):
            logger.warn('mismatch local mean: %s != %s', cert.local_mean,
                        expected_mean)
            return False

        if cert.previous_certificate_id == self.poet_enclave.NULL_IDENTIFIER:
            if len(certs) == 0:
                return True

        if cert.previous_certificate_id != certs[-1].identifier:
            logger.warn('mismatch previous identifier: %s != %s',
                        cert.previous_certificate_id, certs[-1].identifier)
            return False

        hasher = hashlib.sha256()
        for tid in transactions:
            hasher.update(tid)
        block_hash = hasher.hexdigest()

        if block_hash != self.block_hash:
            logger.warn('Transaction hash mismatch : %s != %s',
                        self.block_hash, block_hash)
            return False

        if self.validator_address != originator_id:
            logger.warn('Originator Id mismatch: %s != %s',
                        self.validator_address, originator_id)
            return False

        return self.poet_enclave.verify_wait_certificate(cert)
Exemplo n.º 8
0
    def is_valid_wait_certificate(self, certs):
        """Determines whether the wait certificate is valid.

        Args:
            certs (list): A list of historical certs.

        Returns:
            bool: Whether or not the wait certificate is valid.
        """
        if not isinstance(certs, list):
            raise TypeError

        cert = self.enclave_wait_certificate
        if not cert:
            return False

        if cert.duration < self.poet_enclave.MINIMUM_WAIT_TIME:
            logger.warn('Wait time less then minimum: %s != %s',
                        cert.duration, self.poet_enclave.MINIMUM_WAIT_TIME)
            return False

        expected_mean = WaitTimer.compute_local_mean(certs)
        if not is_close(cert.local_mean, expected_mean, abs_tol=0.001):
            logger.warn('mismatch local mean: %s != %s', cert.local_mean,
                        expected_mean)
            return False

        if cert.previous_certificate_id == self.poet_enclave.NULL_IDENTIFIER:
            if len(certs) == 0:
                return True

        if cert.previous_certificate_id != certs[-1].identifier:
            logger.warn('mismatch previous identifier: %s != %s',
                        cert.previous_certificate_id, certs[-1].identifier)
            return False

        return self.poet_enclave.verify_wait_certificate(cert)
    def is_valid_wait_certificate(self, originator_id, certs, transactions):
        """Determines whether the wait certificate is valid.

        Args:
            certs (list): A list of historical certs.

        Returns:
            bool: Whether or not the wait certificate is valid.
        """

        if not isinstance(originator_id, basestring):
            raise TypeError

        if not isinstance(certs, list):
            raise TypeError

        if not isinstance(transactions, list):
            raise TypeError

        cert = self.enclave_wait_certificate
        if not cert:
            return False

        if cert.duration < self.poet_enclave.MINIMUM_WAIT_TIME:
            logger.warn('Wait time less then minimum: %s != %s', cert.duration,
                        self.poet_enclave.MINIMUM_WAIT_TIME)
            return False

        expected_mean = WaitTimer.compute_local_mean(certs)
        if not is_close(cert.local_mean, expected_mean, abs_tol=0.001):
            logger.warn('mismatch local mean: %s != %s', cert.local_mean,
                        expected_mean)
            return False

        if cert.previous_certificate_id == self.poet_enclave.NULL_IDENTIFIER:
            if len(certs) == 0:
                return True

        if cert.previous_certificate_id != certs[-1].identifier:
            logger.warn('mismatch previous identifier: %s != %s',
                        cert.previous_certificate_id, certs[-1].identifier)
            return False

        hasher = hashlib.sha256()
        for tid in transactions:
            hasher.update(tid)
        block_hash = hasher.hexdigest()

        if block_hash != self.block_hash:
            logger.warn('Transaction hash mismatch : %s != %s',
                        self.block_hash, block_hash)
            return False

        if self.validator_address != originator_id:
            logger.warn('Originator Id mismatch: %s != %s',
                        self.validator_address, originator_id)
            return False

        try:
            return self.poet_enclave.verify_wait_certificate(cert)
        except Timeout:
            raise NotAvailableException
        except ConnectionError:
            raise NotAvailableException