示例#1
0
    def get_web_session_cookies(self):
        """Get web authentication cookies via WebAPI's ``AuthenticateUser``

        .. note::
            A session is only valid during the current steam session.

        :return: dict with authentication cookies
        :rtype: :class:`dict`, :class:`None`
        """
        if not self.logged_on: return None

        resp = self.send_job_and_wait(MsgProto(EMsg.ClientRequestWebAPIAuthenticateUserNonce), timeout=5)

        if resp is None: return None

        skey, ekey = generate_session_key()

        data = {
            'steamid': self.steam_id,
            'sessionkey': ekey,
            'encrypted_loginkey': symmetric_encrypt(resp.webapi_authenticate_user_nonce.encode('ascii'), skey),
        }

        try:
            resp = webapi.post('ISteamUserAuth', 'AuthenticateUser', 1, params=data)
        except Exception as exp:
            self._logger.debug("get_web_session_cookies error: %s" % str(exp))
            return None

        return {
            'steamLogin': resp['authenticateuser']['token'],
            'steamLoginSecure': resp['authenticateuser']['tokensecure'],
        }
示例#2
0
文件: web.py 项目: jaredballou/steam
    def get_web_session_cookies(self):
        """Get web authentication cookies via WebAPI's ``AuthenticateUser``

        .. note::
            A session is only valid during the current steam session.

        :return: dict with authentication cookies
        :rtype: :class:`dict`, :class:`None`
        """
        if not self.logged_on:
            return None

        skey, ekey = generate_session_key()

        data = {
            'steamid': self.steam_id,
            'sessionkey': ekey,
            'encrypted_loginkey': symmetric_encrypt(self.webapi_authenticate_user_nonce, skey),
        }

        try:
            resp = webapi.post('ISteamUserAuth', 'AuthenticateUser', 1, params=data)
        except Exception as exp:
            self._logger.debug("get_web_session_cookies error: %s" % str(exp))
            return None

        return {
            'sessionid': hexlify(sha1_hash(random_bytes(32))),
            'steamLogin': resp['authenticateuser']['token'],
            'steamLoginSecure': resp['authenticateuser']['tokensecure'],
        }
示例#3
0
    def test_keygen_with_challenge(self):
        expected_key = b'1' * 32
        expected_ekey = (b'd710c55122f9bf772ec9c0f21d75c05055764d5445902577340029b4707e1725'
                         b'd61bec77f41b17faed6577d08c812cef76dca8b0b0b2329e1f33ea4cfa31f1e6'
                         b'0babc859c55b6ac94497b5dc9b0bc89629290dc038274af4377771e088e92887'
                         b'30d3906f6b698fd113ba36e3d28a5e1ce0283b27a1adda538df5dc5b179cf84f'
                         )

        key, ekey = crypto.generate_session_key(b'5'*16)
        ekey = hexlify(ekey)

        self.assertEqual(key, expected_key)
        self.assertEqual(ekey, expected_ekey)
示例#4
0
    def test_keygen(self):
        expected_key = b'1' * 32
        expected_ekey = (b'82a5d4d6de38e443ed3e6f0a1701a2c47bc98e0860e7883638ea5263a1744d02'
                         b'f733f09bc6b0f9b2a371bbb79b639208521f88658aab38c23e181d39a58ae39e'
                         b'c4e207fba822d523028d3c04e812abdc2247aa8d8e6e4a89c7a65671c5bcb329'
                         b'51c6d721ccf57cc2920d6ff3b69bfb2c611b1275badcd3e37fe024c9a25bf4b0'
                         )

        key, ekey = crypto.generate_session_key()
        ekey = hexlify(ekey)

        self.assertEqual(key, expected_key)
        self.assertEqual(ekey, expected_ekey)
示例#5
0
文件: cm.py 项目: jackma92/steam
    def __handle_encrypt_request(self, req):
        self._LOG.debug("Securing channel")

        try:
            if req.body.protocolVersion != 1:
                raise RuntimeError("Unsupported protocol version")
            if req.body.universe != EUniverse.Public:
                raise RuntimeError("Unsupported universe")
        except RuntimeError as e:
            self._LOG.exception(e)
            gevent.spawn(self.disconnect)
            return

        resp = Msg(EMsg.ChannelEncryptResponse)

        challenge = req.body.challenge
        key, resp.body.key = crypto.generate_session_key(challenge)
        resp.body.crc = binascii.crc32(resp.body.key) & 0xffffffff

        self.send(resp)

        result = self.wait_event(EMsg.ChannelEncryptResult, timeout=5)

        if result is None:
            self.cm_servers.mark_bad(self.current_server_addr)
            gevent.spawn(self.disconnect)
            return

        eresult = result[0].body.eresult

        if eresult != EResult.OK:
            self._LOG.error("Failed to secure channel: %s" % eresult)
            gevent.spawn(self.disconnect)
            return

        self.channel_key = key

        if challenge:
            self._LOG.debug("Channel secured")
            self.channel_hmac = key[:16]
        else:
            self._LOG.debug("Channel secured (legacy mode)")

        self.channel_secured = True
        self.emit(self.EVENT_CHANNEL_SECURED)
示例#6
0
文件: cm.py 项目: jaredballou/steam
    def __handle_encrypt_request(self, req):
        self._LOG.debug("Securing channel")

        try:
            if req.body.protocolVersion != 1:
                raise RuntimeError("Unsupported protocol version")
            if req.body.universe != EUniverse.Public:
                raise RuntimeError("Unsupported universe")
        except RuntimeError as e:
            self._LOG.exception(e)
            gevent.spawn(self.disconnect)
            return

        resp = Msg(EMsg.ChannelEncryptResponse)

        challenge = req.body.challenge
        key, resp.body.key = crypto.generate_session_key(challenge)
        resp.body.crc = binascii.crc32(resp.body.key) & 0xffffffff

        self.send(resp)

        result = self.wait_event(EMsg.ChannelEncryptResult, timeout=5)

        if result is None:
            self.cm_servers.mark_bad(self.current_server_addr)
            gevent.spawn(self.disconnect)
            return

        eresult = result[0].body.eresult

        if eresult != EResult.OK:
            self._LOG.error("Failed to secure channel: %s" % eresult)
            gevent.spawn(self.disconnect)
            return

        self.channel_key = key

        if challenge:
            self._LOG.debug("Channel secured")
            self.channel_hmac = key[:16]
        else:
            self._LOG.debug("Channel secured (legacy mode)")

        self.channel_secured = True
        self.emit('channel_secured')
示例#7
0
文件: web.py 项目: jaredballou/steam
    def get_web_session_cookies(self):
        """Get web authentication cookies via WebAPI's ``AuthenticateUser``

        .. note::
            A session is only valid during the current steam session.

        :return: dict with authentication cookies
        :rtype: :class:`dict`, :class:`None`
        """
        if not self.logged_on:
            return None

        skey, ekey = generate_session_key()

        data = {
            'steamid':
            self.steam_id,
            'sessionkey':
            ekey,
            'encrypted_loginkey':
            symmetric_encrypt(self.webapi_authenticate_user_nonce, skey),
        }

        try:
            resp = webapi.post('ISteamUserAuth',
                               'AuthenticateUser',
                               1,
                               params=data)
        except Exception as exp:
            self._logger.debug("get_web_session_cookies error: %s" % str(exp))
            return None

        return {
            'sessionid': hexlify(sha1_hash(random_bytes(32))),
            'steamLogin': resp['authenticateuser']['token'],
            'steamLoginSecure': resp['authenticateuser']['tokensecure'],
        }