Exemple #1
0
    async def _enable_encryption(self):
        # Encryption can be enabled whenever credentials are available but only
        # after DEVICE_INFORMATION has been sent
        if self.service.credentials:
            # Verify credentials and generate keys
            credentials = HapCredentials.parse(self.service.credentials)
            pair_verifier = MrpPairingVerifier(self, self.srp, credentials)

            try:
                await pair_verifier.verify_credentials()
                output_key, input_key = pair_verifier.encryption_keys()
                self.connection.enable_encryption(output_key, input_key)
            except Exception as ex:
                raise exceptions.AuthenticationError(str(ex)) from ex
Exemple #2
0
    async def _connect_and_encrypt(self):
        if not self.connection.connected:
            await self.start()

        # Encryption can be enabled whenever credentials are available but only
        # after DEVICE_INFORMATION has been sent
        if self.service.credentials and self._initial_message_sent:
            self._initial_message_sent = False

            # Verify credentials and generate keys
            credentials = Credentials.parse(self.service.credentials)
            pair_verifier = MrpPairingVerifier(self, self.srp, credentials)

            await pair_verifier.verify_credentials()
            output_key, input_key = pair_verifier.encryption_keys()
            self.connection.enable_encryption(output_key, input_key)
Exemple #3
0
    async def finish(self):
        """Stop pairing process."""
        if not self.pin_code:
            raise exceptions.PairingError("no pin given")

        credentials = str(await error_handler(
            self.pairing_procedure.finish_pairing,
            exceptions.PairingError,
            self.pin_code,
        ))

        _LOGGER.debug("Verifying credentials %s", credentials)

        verifier = MrpPairingVerifier(self.protocol, self.srp,
                                      Credentials.parse(credentials))
        await error_handler(verifier.verify_credentials,
                            exceptions.PairingError)

        self.service.credentials = credentials
        self._has_paired = True