1
1
import time
2
2
import uuid
3
+ import base64
3
4
from base64 import b64encode
4
5
import random
5
6
import string
6
7
import re
7
8
from typing import Dict , List , Optional
8
9
9
10
from Crypto .Cipher import AES
11
+ from Crypto .Hash import SHA3_384
10
12
from Crypto .Random import get_random_bytes
13
+ from Crypto .Util .Padding import pad
11
14
12
15
13
16
def get_pwd_auth (username : str , password : str , token : str = None ) -> str :
@@ -29,6 +32,30 @@ def get_auth_token(user: str, key: str, domain: str = "") -> str:
29
32
return b64encode (iv + tag + msg , altchars = b"@$" ).decode ("utf-8" )
30
33
31
34
35
+ def get_login_token (self , key , user , action = 3 ):
36
+ try :
37
+ key = bytes .fromhex (key )
38
+ key1 = key [0 :48 ]
39
+ key2 = key [48 :]
40
+ msg = '{{"a":{}, "u":"{}","time":{}}}' .format (
41
+ action , user .lower (), int (time .time ())
42
+ )
43
+ iv = get_random_bytes (16 )
44
+
45
+ # sha
46
+ h = SHA3_384 .new ()
47
+ h .update (key1 )
48
+ hashed_msg = h .digest () + msg .encode ()
49
+
50
+ # aes
51
+ cipher = AES .new (key2 , AES .MODE_CBC , iv )
52
+ msg = cipher .encrypt (pad (hashed_msg , 16 ))
53
+
54
+ return base64 .b64encode (iv + msg , altchars = b"@$" ).decode ("utf-8" )
55
+ except Exception :
56
+ return "err"
57
+
58
+
32
59
def b64_to_hex (hex : str ) -> str :
33
60
return b64encode (bytes .fromhex (hex )).decode ().replace (r"/" , "$" ).replace (r"+" , "@" )
34
61
0 commit comments