def check_valid(self, certificates, poet_public_key):
        """Determines whether the wait certificate is valid.

        Args:
            certificates (list): A list of historical certs.
            poet_public_key (str): The PoET public key that corresponds to
                the private key used to sign the certificate.  This is
                obtained from the signup information for the validator
                that is the originator of the block for which the wait
                certificate is associated.

        Returns:
            True if the wait certificate is valid, False otherwise.
        """
        enclave_certificate = self.enclave_wait_certificate
        expected_mean = WaitTimer.compute_local_mean(certificates)

        if enclave_certificate.duration < WaitTimer.minimum_wait_time:
            raise \
                ValueError(
                    'Wait time less than minimum: {0} < {1}'.format(
                        enclave_certificate.duration,
                        WaitTimer.minimum_wait_time))

        if not _is_close(
                enclave_certificate.local_mean,
                expected_mean,
                abs_tol=0.001):
            raise \
                ValueError(
                    'Local mean does not match: {0} != {1}'.format(
                        enclave_certificate.local_mean,
                        expected_mean))

        if len(certificates) != 0 and \
            enclave_certificate.previous_certificate_id != \
                certificates[-1].identifier:
            raise \
                ValueError(
                    'Previous certificate ID does not match: {0} != '
                    '{1}'.foramt(
                        enclave_certificate.previous_certificate_id,
                        certificates[-1].identifier))

        try:
            self.poet_enclave.verify_wait_certificate(
                certificate=enclave_certificate,
                poet_public_key=poet_public_key)
        except Timeout:
            raise NotAvailableException
        except ConnectionError:
            raise NotAvailableException
    def check_valid(self, certificates, poet_public_key):
        """Determines whether the wait certificate is valid.

        Args:
            certificates (list): A list of historical certs.
            poet_public_key (str): The PoET public key that corresponds to
                the private key used to sign the certificate.  This is
                obtained from the signup information for the validator
                that is the originator of the block for which the wait
                certificate is associated.

        Returns:
            True if the wait certificate is valid, False otherwise.
        """
        enclave_certificate = self.enclave_wait_certificate
        expected_mean = WaitTimer.compute_local_mean(certificates)

        if enclave_certificate.duration < WaitTimer.minimum_wait_time:
            raise \
                ValueError(
                    'Wait time less than minimum: {0} < {1}'.format(
                        enclave_certificate.duration,
                        WaitTimer.minimum_wait_time))

        if not _is_close(
                enclave_certificate.local_mean, expected_mean, abs_tol=0.001):
            raise \
                ValueError(
                    'Local mean does not match: {0} != {1}'.format(
                        enclave_certificate.local_mean,
                        expected_mean))

        if len(certificates) != 0 and \
            enclave_certificate.previous_certificate_id != \
                certificates[-1].identifier:
            raise \
                ValueError(
                    'Previous certificate ID does not match: {0} != '
                    '{1}'.foramt(
                        enclave_certificate.previous_certificate_id,
                        certificates[-1].identifier))

        try:
            self.poet_enclave.verify_wait_certificate(
                certificate=enclave_certificate,
                poet_public_key=poet_public_key)
        except Timeout:
            raise NotAvailableException
        except ConnectionError:
            raise NotAvailableException
Beispiel #3
0
    def is_valid(self, certificates, poet_public_key):
        """Determines whether the wait certificate is valid.

        Args:
            certificates (list): A list of historical certs.
            poet_public_key (str): The PoET public key that corresponds to
                the private key used to sign the certificate.  This is
                obtained from the signup information for the validator
                that is the originator of the block for which the wait
                certificate is associated.

        Returns:
            True if the wait certificate is valid, False otherwise.
        """
        enclave_certificate = self.enclave_wait_certificate
        expected_mean = WaitTimer.compute_local_mean(certificates)

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

        if not _is_close(
                enclave_certificate.local_mean, expected_mean, abs_tol=0.001):
            LOGGER.warn('mismatch local mean: %s != %s',
                        enclave_certificate.local_mean, expected_mean)
            return False

        if enclave_certificate.previous_certificate_id == NullIdentifier:
            if len(certificates) == 0:
                return True

        if enclave_certificate.previous_certificate_id != \
                certificates[-1].identifier:
            LOGGER.warn('mismatch previous identifier: %s != %s',
                        enclave_certificate.previous_certificate_id,
                        certificates[-1].identifier)
            return False

        try:
            return \
                self.poet_enclave.verify_wait_certificate(
                    certificate=enclave_certificate,
                    poet_public_key=poet_public_key)
        except Timeout:
            raise NotAvailableException
        except ConnectionError:
            raise NotAvailableException