File: //usr/lib64/python3.7/site-packages/license_manager/validity.py
#
# Copyright (c) 2017 BigCloud Enterprise Linux, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# BigCloud Enterprise Linux trademarks are not licensed under GPLv2.
# No permission is granted to use or replicate trademarks that are
# incorporated in this software or its documentation.
#
import base64
import subprocess
import sys
import pwd
import os
sys.path.append("/usr/share/bclinux/")
from license_manager.rsa import rsa_decrypt
# get system-uuid by "/etc/bclinux/dmidecode"
def get_system_id():
id = []
p = subprocess.Popen(['/etc/bclinux/dmidecode -s system-uuid'],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
p.wait()
# Returns output and error
output = p.communicate()
# Replace the tuple type with a List
output = list(output)
id.append(p.returncode)
if p.returncode != 0:
id.append(output[1])
else:
# '/etc/bclinux/dmidecode -s system-uuid' output error
output[0] = output[0].decode()
if output[0] == "Not Present\n":
p2 = subprocess.Popen(['/etc/bclinux/dmidecode -s system-serial-number'],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
output2 = p2.communicate()
# Replace the tuple type with a List
output2 = list(output2)
output2[0] = output2[0].decode()
spac_num = output2[0].find(' ')
if spac_num >= 0:
serial_id = output2[0].replace(' ','-')
id.append(serial_id.replace('\n',''))
else:
id.append(output2[0].replace('\n',''))
else:
# change bytes into str
output[0] = output[0].replace('\n','')
id.append(output[0])
return id
def generate_activation_code(system_id, service_id, product_id, service_time):
uuid = system_id + ',' + service_id + ',' + product_id + ',' + service_time
return rsa_encrypt(uuid)
def verify_activation_code(pub_key,activation_code):
try:
uuid = rsa_decrypt(pub_key,activation_code)
uuid = uuid.decode()
id_list = uuid.split(',')
return_id = get_system_id()
if return_id[0] != 0:
print (return_id[1])
return False
else:
if return_id[1] == id_list[3]:
return True
else:
return False
except:
return False