Esempio n. 1
0
def run():
    productKey = "K3I5ZkgyZjkydGli"
    productSecret = "VUFyVE92YVJmSUNQ"
    rand = "q9f5UdAlh687grFl0JVuyY6095302ehd"
    imei = modem.getDevImei()
    VER = '1'

    h1 = uhashlib.md5()
    h1.update(imei + "," + productSecret + "," + rand)
    SIGN = ubinascii.hexlify(h1.digest()).decode()
    print("MD5:   %s" % SIGN)  # 8ab41bc1e5e74fbf9cec16a6e0990d89

    DATA = imei + ";" + rand + ";" + SIGN
    print("DATA:  %s  " %DATA)
    h1 = uhashlib.sha1(productSecret)
    res = ubinascii.hexlify(h1.digest()).decode()
    print(res)
    res = uhashlib.hash_sha1(res, 20)
    print("SHA1(PS) :  %s" % res)
    aes_key = res[0:16].upper()
    print("aes_key : %s" % aes_key)
    res = uhashlib.aes_ecb(aes_key, DATA)
    print(res)
    raw = uhashlib.hash_base64(res)
    print(raw)
    data = productKey + ";" + raw + ";" + VER
    url = "220.180.239.212:8415"
    # url = "192.168.25.64:30884"
    response = request.post(url, data=data)
    print(response.json())   # 获取到密钥
    # {'RESPCODE': 10200, 'RESPMSG': 'SUCCESS', 'SERVERURI': 'mqtt://220.180.239.212:8420', 'DS': 'd5f01bddfc994c037be90ede69399ac0'}
    return response.json()
Esempio n. 2
0
def md5_concat(arg1, arg2, arg3):
    h = uhashlib.md5(arg1)
    h.update(b":")
    h.update(arg2)
    if arg3 is not None:
        h.update(b":")
        h.update(arg3)
    return ubinascii.hexlify(h.digest()).decode()
Esempio n. 3
0
def hash_file(fname):
    with open(fname, "rb") as f:
        buf = bytearray(64 * 1024)
        hsh = uhashlib.md5()
        while True:
            sz = f.readinto(buf)
            if not sz:
                break
            hsh.update(memoryview(buf)[:sz])
    return ubinascii.hexlify(hsh.digest()).decode()
Esempio n. 4
0
    def init_key(self):
        """ key regeneration """

        if len(self.key) > self.blocksize:
            self.key = bytearray(_hashlib.md5(key).digest())
        elif len(self.key) < self.blocksize:
            i = len(self.key)
            while i < self.blocksize:
                self.key += b"\x00"
                i += 1
    def calculate():
        files = os.listdir()

        allFilesHash = ""
        hasher = uhashlib.md5(".")
        files.sort()
        for file in files:
            if file.endswith('.py'):
                f = open(file, 'r')
                contents = f.read()
                hasher.update(contents)
                f.close()

        return ubinascii.hexlify(hasher.digest()).decode()[1:8]
Esempio n. 6
0
    def download(self, link):
        try:
            resp = requests.get(url=link)
        except Exception as e:
            print('RESPONSE: failed to perform request: {}'.format(e))
            raise

        shutil.rmtree(self._tmp_dir)
        os.mkdir(self._tmp_dir)
        tmp_path = self._tmp_dir + os.sep + self._tmp_name

        f = open(tmp_path, 'wb')
        shutil.copyfileobj(resp.raw, f)
        f.close()

        # check md5 sum
        filename = link.split('/')[-1]
        md5sum = filename.split('.')[-2]
        print('firmware downloaded to {}, received md5sum: {}, checking...'.
              format(tmp_path, md5sum))

        f = open(tmp_path, 'rb')
        m = md5()
        while True:
            buf = f.read(512)
            if not buf:
                break
            m.update(buf)
        f.close()
        os.sync()

        calculated_md5 = hexlify(m.digest()).decode('ascii')
        if md5sum != calculated_md5:
            print('md5 sum check failed: {} != {}'.format(
                md5sum, calculated_md5))
            raise Exception()
        print('successfully checked md5 sum')
        return tmp_path
Esempio n. 7
0
except:
    exists = False

if not exists:
    while True:
        value = uart.read()
        if value != None:
            if str(value, 'utf-8') == "dev":
                print(dev_eui)
                f = open("preset", "x")
                f.close()
                break

# this uses the UART_1 default pins for TXD and RXD (``P3`` and ``P4``)

app_key = uhashlib.md5(dev_eui)
app_key = app_key.digest()
app_key = binascii.hexlify(app_key)
app_key = app_key.decode("utf-8")
print(
    "================================================Pycom Lopy 4 - CSTC  ==============================================="
)
print("")
print("")
print("                      DevEui : " + dev_eui)
print("                      AppKey : " + app_key)
print("")
print("")
print(
    "====================================================================================================================="
)
Esempio n. 8
0
import hashlib
import uhashlib


md5 = hashlib.md5(b"foo")
umd5 = uhashlib.md5(b"foo")
md5.update(b"bar")
umd5.update(b"bar")
assert md5.digest() == umd5.digest()
Esempio n. 9
0
try:
    import uhashlib as hashlib
except ImportError:
    try:
        import hashlib
    except ImportError:
        # This is neither uPy, nor cPy, so must be uPy with
        # uhashlib module disabled.
        print("SKIP")
        raise SystemExit

try:
    hashlib.md5
except AttributeError:
    # MD5 is only available on some ports
    print("SKIP")
    raise SystemExit

md5 = hashlib.md5(b'hello')
md5.update(b'world')
print(md5.digest())
Esempio n. 10
0
try:
    import uhashlib as hashlib
except ImportError:
    try:
        import hashlib
    except ImportError:
        # This is neither uPy, nor cPy, so must be uPy with
        # uhashlib module disabled.
        print("SKIP")
        raise SystemExit

try:
    hashlib.md5
except AttributeError:
    # MD5 is only available on some ports
    print("SKIP")
    raise SystemExit

md5 = hashlib.md5(b"hello")
md5.update(b"world")
print(md5.digest())
Esempio n. 11
0
def calculate_checksum(data):
    return uhashlib.md5(data).digest()
Esempio n. 12
0
import hashlib
import uhashlib

md5 = hashlib.md5(b"foo")
umd5 = uhashlib.md5(b"foo")
md5.update(b"bar")
umd5.update(b"bar")
assert md5.digest() == umd5.digest()