Пример #1
0
    def __init__(
        self,
        host: str,
        checksum_address: str = None,
        private_key: Union[UmbralPrivateKey, UmbralPublicKey] = None,
        curve=None,
        certificate=None,
        certificate_filepath: str = None,
        generate_certificate=True,
    ) -> None:

        self.curve = curve or self._DEFAULT_CURVE

        if private_key and certificate_filepath:
            from nucypher.config.keyring import _read_tls_public_certificate
            certificate = _read_tls_public_certificate(
                filepath=certificate_filepath)
            super().__init__(private_key=private_key)

        elif certificate:
            super().__init__(public_key=certificate.public_key())

        elif certificate_filepath:
            from nucypher.config.keyring import _read_tls_public_certificate
            certificate = _read_tls_public_certificate(
                filepath=certificate_filepath)
            super().__init__(public_key=certificate.public_key())

        elif generate_certificate:
            if not host and checksum_address:
                message = "If you don't supply a TLS certificate, one will be generated for you." \
                          "But for that, you need to pass a host and checksum address."
                raise TypeError(message)

            certificate, private_key = generate_teacher_certificate(
                host=host,
                checksum_address=checksum_address,
                private_key=private_key,
                curve=self.curve)
            super().__init__(private_key=private_key)
        else:
            raise TypeError(
                "You didn't provide a cert, but also told us not to generate keys.  Not sure what to do."
            )

        if not certificate_filepath:
            certificate_filepath = constants.CERTIFICATE_NOT_SAVED

        self.certificate = certificate
        self.certificate_filepath = certificate_filepath
Пример #2
0
def _generate_tls_keys(
        host: str, checksum_address: str,
        curve: EllipticCurve) -> Tuple[_EllipticCurvePrivateKey, Certificate]:
    cert, private_key = generate_teacher_certificate(
        host=host, curve=curve, checksum_address=checksum_address)
    return private_key, cert