コード例 #1
0
ファイル: keypairs.py プロジェクト: tko-heyjude/nucypher
    def __init__(
        self,
        host: str,
        checksum_public_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_public_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_self_signed_certificate(
                host=host,
                checksum_address=checksum_public_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.bool_value(
                False)

        self.certificate = certificate
        self.certificate_filepath = certificate_filepath
コード例 #2
0
ファイル: keypairs.py プロジェクト: federico9256/nucypher
    def __init__(
        self,
        host: str,
        checksum_address: str = None,
        private_key: Union[UmbralPrivateKey, UmbralPublicKey] = None,
        certificate=None,
        certificate_filepath: str = None,
        generate_certificate=False,
    ) -> None:

        if private_key:
            if not certificate_filepath:
                raise ValueError(
                    'public certificate required to load a hosting keypair.')
            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)
            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