Exemplo n.º 1
0
    def authenticate(self, username, auth_data, auth_type):
        auth_request = authentication.ClientResponseEncrypted(
            **{
                'login_credentials':
                authentication.LoginCredentials(**{
                    'username': username,
                    'typ': auth_type,
                    'auth_data': auth_data
                }),
                'system_info':
                authentication.SystemInfo(
                    **{
                        'cpu_family': authentication.CPU_UNKNOWN,
                        'os': authentication.OS_UNKNOWN,
                        'system_information_string': INFORMATION_STRING,
                        'device_id': DEVICE_ID
                    }),
                'version_string':
                VERSION_STRING
            })
        packet = self._connection.send_packet(LOGIN_REQUEST_COMMAND,
                                              auth_request.SerializeToString())
        # Get response
        command, size, body = self._connection.recv_packet()
        if command == AUTH_SUCCESSFUL_COMMAND:
            auth_welcome = authentication.APWelcome()
            auth_welcome.ParseFromString(body)
            print(auth_welcome)
            return auth_welcome.reusable_auth_credentials_type, auth_welcome.reusable_auth_credentials
        elif command == AUTH_DECLINED_COMMAND:
            raise Exception('AUTH DECLINED. Code: %02X' % command)

        raise Exception('UNKNOWN AUTH CODE %02X' % command)
Exemplo n.º 2
0
    def decryptBlob(self, base64Blob, username, deviceId):
        encryptedBlob = base64.b64decode(base64Blob)

        # base_key = PBKDF2(SHA1(deviceID), username, 0x100, 1)
        secret = hashlib.sha1(deviceId.encode()).digest()
        basekey = hashlib.pbkdf2_hmac('sha1', secret, username, 256, dklen=20)

        # key = SHA1(base_key) || htonl(len(base_key))
        base_key_hashed = hashlib.sha1(basekey).digest()
        key = base_key_hashed + (20).to_bytes(4, byteorder='big')

        # login_data = AES192-DECRYPT(key, data)
        cipher = AES.new(key, AES.MODE_ECB)
        decryptedBlob = cipher.decrypt(encryptedBlob)

        login_data = bytearray(decryptedBlob)

        l = len(decryptedBlob)
        for i in range(0, l - 16):
            login_data[l - i - 1] ^= login_data[l - i - 17]

        '''
        with open('blob.dat', 'wb') as f:
            f.write(login_data)
            f.close()
        '''

        pointer = 1
        lenght, count = self.readBlobInt(login_data[pointer:(pointer + 1)])
        pointer = pointer + count + lenght + 1

        typeInt, count = self.readBlobInt(login_data[pointer:(pointer + 1)])
        pointer = pointer + count + 1

        lenght, count = self.readBlobInt(login_data[pointer:(pointer + 1)])
        pointer = pointer + count

        authData = login_data[pointer:(pointer + lenght)]

        self.username = username
        self.typ = Authentication.AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS
        self.auth_data = authData

        login = Authentication.LoginCredentials()
        login.username = bytes(username)
        login.typ = Authentication.AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS
        login.auth_data = bytes(authData)

        return login
Exemplo n.º 3
0
 def createLogin(self):
     login = Authentication.LoginCredentials()
     Authentication.AuthenticationType.Name(1)
Exemplo n.º 4
0
 def create_login(self):
     login = Authentication.LoginCredentials()
     login.username = bytes(self.username)
     login.typ = Authentication.AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS
     login.auth_data = bytes(self.auth_data)
     return login
Exemplo n.º 5
0
import json
from google.protobuf import text_format
import protocol.impl.authentication_pb2 as Authentication
from authtoken import AuthToken
from connection import Connection
from mercury import MercuryManager
from session import Session
from pyfy import Spotify
from blob import Blob

message = None
with open('credentials/YiP.dat', 'r') as f:
    message = f.read()
    f.close()

login = Authentication.LoginCredentials()
text_format.Merge(message, login)

blob = Blob('credentials/YiP.blob', login.username, login.typ,
            login.auth_data.decode())

connection = Connection()
session = Session().connect(connection)
session.authenticate(login)
manager = MercuryManager(connection)
authToken = AuthToken(manager)
print("AuthToken: ", authToken)
manager.terminate()

token = None
with open('auth_data.dat', 'r') as f: