示例#1
0
    async def _refresh_snitun_token(self) -> None:
        """Handle snitun token."""
        if self._token and self._token.valid > utils.utcnow():
            _LOGGER.debug("Don't need refresh snitun token")
            return

        if self.cloud.subscription_expired:
            raise SubscriptionExpired()

        # Generate session token
        aes_key, aes_iv = generate_aes_keyset()
        try:
            async with async_timeout.timeout(30):
                resp = await cloud_api.async_remote_token(self.cloud, aes_key, aes_iv)
                if resp.status == 409:
                    raise RemoteInsecureVersion()
                if resp.status != 200:
                    raise RemoteBackendError()
        except (asyncio.TimeoutError, aiohttp.ClientError):
            raise RemoteBackendError() from None

        data = await resp.json()
        self._token = SniTunToken(
            data["token"].encode(),
            aes_key,
            aes_iv,
            utils.utc_from_timestamp(data["valid"]),
            data["throttling"],
        )
示例#2
0
    async def _refresh_snitun_token(self) -> None:
        """Handle snitun token."""
        if self._token and self._token.valid > utils.utcnow():
            _LOGGER.debug("Don't need refresh snitun token")
            return

        # Generate session token
        aes_key, aes_iv = generate_aes_keyset()
        try:
            async with async_timeout.timeout(15):
                resp = await cloud_api.async_remote_token(self.cloud, aes_key, aes_iv)
            assert resp.status == 200
        except (asyncio.TimeoutError, AssertionError):
            raise RemoteBackendError() from None

        data = await resp.json()
        self._token = SniTunToken(
            data["token"].encode(),
            aes_key,
            aes_iv,
            utils.utc_from_timestamp(data["valid"]),
            data["throttling"],
        )
示例#3
0
def test_aes_function():
    """Test crypto with generated keys."""
    key, iv = aes.generate_aes_keyset()
    assert CryptoTransport(key, iv)
示例#4
0
def test_unique_aes():
    """Test unique aes function."""
    keyset_1 = aes.generate_aes_keyset()
    keyset_2 = aes.generate_aes_keyset()
    assert keyset_1 != keyset_2