mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 21:26:31 +00:00
fix auth, decryption, api interaction
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import base64
|
||||
import subprocess
|
||||
from hashlib import sha384
|
||||
from security cimport Security
|
||||
import psutil
|
||||
|
||||
cdef class HardwareInfo:
|
||||
def __init__(self, str cpu, str gpu, str memory, str mac_address, str hw_hash):
|
||||
@@ -10,6 +10,15 @@ cdef class HardwareInfo:
|
||||
self.mac_address = mac_address
|
||||
self.hash = hw_hash
|
||||
|
||||
cdef to_json_object(self):
|
||||
return {
|
||||
"CPU": self.cpu,
|
||||
"GPU": self.gpu,
|
||||
"MacAddress": self.mac_address,
|
||||
"Memory": self.memory,
|
||||
"Hash": self.hash,
|
||||
}
|
||||
|
||||
def __str__(self):
|
||||
return f'CPU: {self.cpu}. GPU: {self.gpu}. Memory: {self.memory}. MAC Address: {self.mac_address}'
|
||||
|
||||
@@ -27,6 +36,15 @@ cdef class HardwareService:
|
||||
print('Error during os type checking')
|
||||
self.is_windows = False
|
||||
|
||||
cdef get_mac_address(self, interface="Ethernet"):
|
||||
addresses = psutil.net_if_addrs()
|
||||
for interface_name, interface_info in addresses.items():
|
||||
if interface_name == interface:
|
||||
for addr in interface_info:
|
||||
if addr.family == psutil.AF_LINK:
|
||||
return addr.address.replace('-', '')
|
||||
return None
|
||||
|
||||
cdef HardwareInfo get_hardware_info(self):
|
||||
if self.is_windows:
|
||||
os_command = (
|
||||
@@ -49,20 +67,8 @@ cdef class HardwareService:
|
||||
cdef str cpu = lines[0].replace("Name=", "").replace(" ", " ")
|
||||
cdef str gpu = lines[1].replace("Name=", "").replace(" ", " ")
|
||||
cdef str memory = lines[2].replace("TotalVisibleMemorySize=", "").replace(" ", " ")
|
||||
|
||||
# Get MAC address
|
||||
if self.is_windows:
|
||||
mac_cmd = "getmac"
|
||||
else:
|
||||
mac_cmd = "cat /sys/class/net/*/address"
|
||||
cdef str mac_address = subprocess.check_output(mac_cmd, shell=True, text=True).splitlines()[0].strip()
|
||||
|
||||
cdef str mac_address = self.get_mac_address()
|
||||
cdef str full_hw_str = f'Azaion_{mac_address}_{cpu}_{gpu}'
|
||||
hw_hash = self.calc_hash(full_hw_str)
|
||||
return HardwareInfo(cpu, gpu, memory, mac_address, hw_hash)
|
||||
|
||||
cdef str calc_hash(self, str s):
|
||||
str_bytes = s.encode('utf-8')
|
||||
hash_bytes = sha384(str_bytes).digest()
|
||||
cdef str h = base64.b64encode(hash_bytes).decode('utf-8')
|
||||
return h
|
||||
hw_hash = Security.calc_hash(full_hw_str)
|
||||
return HardwareInfo(cpu, gpu, memory, mac_address, hw_hash)
|
||||
|
||||
Reference in New Issue
Block a user