-
Notifications
You must be signed in to change notification settings - Fork 4
/
ysfd_protocol.py
41 lines (30 loc) · 1.26 KB
/
ysfd_protocol.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
import logging
from hashlib import sha256
from utils import pad
def send_login_message(call: str, bm_sock):
message = "YSFL".encode() + pad(call.encode(), 10)
logging.debug("sending: %s" % message)
bm_sock.send(message)
def send_challenge_message(call: str, salt: bytes, password: str, bm_sock):
secret = salt + password.encode()
secret_hash = sha256(secret).digest()
message = "YSFK".encode() + pad(call.encode(), 10) + secret_hash
logging.debug("sending: %s" % message)
bm_sock.send(message)
def send_tg_message(call: str, tg: int, bm_sock):
message = "YSFO".encode() + pad(call.encode(), 10) + f"group={tg}".encode()
logging.debug("sending: %s" % message)
bm_sock.send(message)
def login_and_set_tg(callsign, bm_password, tg, bm_sock, is_salt_received, maybe_salt: list):
send_login_message(callsign, bm_sock)
is_salt_received.wait(10.0)
is_salt_received.clear()
salt = maybe_salt[0]
maybe_salt.clear()
send_challenge_message(callsign, salt, bm_password, bm_sock)
send_tg_message(callsign, tg, bm_sock)
def send_logout_message(call: str, bm_sock):
message = "YSFU".encode() + pad(call.encode(), 10)
for i in range(1,3):
logging.debug("sending: %s" % message)
bm_sock.send(message)