-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSteamMobileAuth.py
58 lines (53 loc) · 2.1 KB
/
SteamMobileAuth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import time, hmac, hashlib, requests, re, pdb
from bitstring import BitArray
from base64 import b64decode,b64encode
from binascii import hexlify
def getTimeOffset():
url = "http://api.steampowered.com/ITwoFactorService/QueryTime/v1/"
headers = {'Content-Length':0}
response = requests.post(url,headers=headers)
offset = int(response.json()['response']['server_time']) - int(time.time())
latency = response.elapsed.seconds
return offset + latency
def timeOffset(offset=0):
return(int(time.time()) + offset)
def generateAuthCode(secret,offset=0):
secret = b64decode(secret)
secret = BitArray(bytes=secret,length=len(secret)*8)
buff = BitArray(8*8)
timestamp = timeOffset(offset)
buff[4*8:] = int(timestamp/30)
auth_hmac = hmac.new(secret.tobytes(),buff.tobytes(),hashlib.sha1)
hashed = auth_hmac.digest()
hashed = BitArray(bytes=hashed,length=len(hashed)*8)
start = hashed[(19*8):(19*8)+8] & BitArray('0x0f')
hash_slice = hashed[start.int*8:(start.int*8)+(4*8)]
fullcode = hash_slice & BitArray("0x7fffffff")
fullcode = fullcode.int
chars = '23456789BCDFGHJKMNPQRTVWXY'
code = ""
for x in range(5):
code += chars[int(fullcode % len(chars))]
fullcode = fullcode/len(chars)
return code
def generateConfirmationKey(identitySecret,time,tag=""):
identitysecret = b64decode(identitySecret)
secret = BitArray(bytes=identitysecret,length=len(identitysecret)*8)
if tag != "":
tagBuff = BitArray(bytes=tag,length=len(tag)*8)
buff = BitArray(4*8)
time = int(time)
buff.append(BitArray(int=time,length=32))
if tag != "":
buff.append(tagBuff)
conf_hmac = hmac.new(secret.tobytes(),buff.tobytes(),hashlib.sha1)
return b64encode(conf_hmac.digest())
def getDeviceID(steamID):
hashed_hmac = hmac.new("",str(steamID),hashlib.sha1)
hashed_hmac = hexlify(hashed_hmac.digest())
match = re.match(r'^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12}).*$',hashed_hmac)
devid = "android:"
for x in match.groups():
devid += x
devid +="-"
return devid[:-1]