Пример #1
0
    def parse(cls, detail_string):
        """Parse a string represention of Credentials."""
        split = detail_string.split(':')
        if len(split) != 4:
            raise exceptions.InvalidCredentialsError('invalid credentials')

        ltpk = binascii.unhexlify(split[0])
        ltsk = binascii.unhexlify(split[1])
        atv_id = binascii.unhexlify(split[2])
        client_id = binascii.unhexlify(split[3])
        return Credentials(ltpk, ltsk, atv_id, client_id)
Пример #2
0
    def _get_auth_type(self) -> AuthenticationType:
        if (self.ltpk == b"" and self.ltsk == b"" and self.atv_id == b""
                and self.client_id == b""):
            return AuthenticationType.Null
        if self.ltpk == b"transient":
            return AuthenticationType.Transient
        if (self.ltpk == b"" and self.ltsk != b"" and self.atv_id == b""
                and self.client_id != b""):
            return AuthenticationType.Legacy
        if self.ltpk and self.ltsk and self.atv_id and self.client_id:
            return AuthenticationType.HAP

        raise exceptions.InvalidCredentialsError("invalid credentials type")
Пример #3
0
    def _get_credentials(self):
        if not self.service or self.service.credentials is None:
            _LOGGER.debug("No AirPlay credentials loaded")
            return None

        if not re.match(r"[0-9A-Fa-f]{16}:[0-9A-Fa-f]{64}", self.service.credentials):
            raise exceptions.InvalidCredentialsError(
                f"invalid credentials: {self.service.credentials}"
            )

        split = self.service.credentials.split(":")
        _LOGGER.debug("Loaded AirPlay credentials: %s", self.service.credentials)

        return split[1]
Пример #4
0
 def _mkurl(self, cmd, *args, session=True, login_id=False):
     url = "{}".format(cmd.format(*args))
     parameters = []
     if login_id:
         if re.match(r"0x[0-9A-Fa-f]{16}", self._login_id):
             parameters.append("pairing-guid={}".format(self._login_id))
         elif re.match(
                 r"[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}",
                 self._login_id):
             parameters.append("hsgid={}".format(self._login_id))
         else:
             raise exceptions.InvalidCredentialsError(
                 "invalid credentials: " + self._login_id)
     if session:
         parameters.insert(0, "session-id={}".format(self._session_id))
     return url.replace("[AUTH]", "&".join(parameters))
Пример #5
0
def parse_credentials(detail_string: Optional[str]) -> HapCredentials:
    """Parse a string represention of HapCredentials."""
    if detail_string is None:
        return NO_CREDENTIALS

    split = detail_string.split(":")

    # Compatibility with "legacy credentials" used by AirPlay where seed is stored
    # as LTSK and identifier as client_id (others are empty).
    if len(split) == 2:
        client_id = binascii.unhexlify(split[0])
        ltsk = binascii.unhexlify(split[1])
        return HapCredentials(b"", ltsk, b"", client_id)
    if len(split) == 4:
        ltpk = binascii.unhexlify(split[0])
        ltsk = binascii.unhexlify(split[1])
        atv_id = binascii.unhexlify(split[2])
        client_id = binascii.unhexlify(split[3])
        return HapCredentials(ltpk, ltsk, atv_id, client_id)

    raise exceptions.InvalidCredentialsError("invalid credentials: " +
                                             detail_string)