Ejemplo n.º 1
0
def main():
    # Setup serial connection
    ports = getPorts()
    if len(ports) == 0:
        print(
            "No serial ports found. Please check your USB connection and try again."
        )
        sys.exit(1)
    port = ports[0]
    print(f"No port specified, defaulting to {port}")
    ser = serial.Serial(port, 9600)

    # Restart arduino
    ser.setDTR(False)
    print("Resetting Arduino...")
    sleep(1)
    ser.setDTR(True)

    # Read 'Arduino is ready' message
    response_length = int.from_bytes(ser.read(2), byteorder='big')
    print(ser.read(response_length).decode("utf8"))
    # Acknowledge welcome message
    ser.write(b's')
    ser.flush()

    while True:
        message_data = read_message(ser)
        print(f"XORed memory in: {message_data['elapsed_time']}ms")
        print(f"Calculated value is {message_data['xor']}\n")
Ejemplo n.º 2
0
def main():
    # Check if hexfile exists
    hexfile = "microvisor.hex"
    if not os.path.isfile(hexfile):
        print("ERROR: File not found:", hexfile)
        sys.exit(2)
    ih = IntelHex(hexfile)

    # Setup serial connection
    ports = getPorts()
    if len(ports) == 0:
        print(
            "No serial ports found. Please check your USB connection and try again."
        )
        sys.exit(1)
    port = ports[0]
    print(f"No port specified, defaulting to {port}")
    ser = serial.Serial(port, 9600)

    # Restart arduino
    ser.setDTR(False)
    print("Resetting Arduino...")
    sleep(1)
    ser.setDTR(True)

    # Read 'Arduino is ready' message
    response_length = int.from_bytes(ser.read(2), byteorder='big')
    print(ser.read(response_length).decode("utf8"))
    # Acknowledge welcome message
    ser.write(b's')
    ser.flush()

    while True:
        # Wait for message
        msg = read_message(ser)
        elapsed_time = msg['timer']
        mac_nonce = msg['mac_nonce']
        remote_mac = msg['mac']
        data = msg['data']

        # Calc digest
        hmac_gen = hmac.new(MAC_KEY, None, hashlib.sha1)
        hmac_gen.update(ih.tobinstr(0, 30 * 1024 - 1))
        hmac_gen.update(msg['mac_nonce'])
        local_mac = hmac_gen.digest()

        if (remote_mac == local_mac):
            print(
                colored(f"✓ Received message has valid proof ",
                        'green',
                        attrs=["bold"]) + f"({remote_mac.hex()})")
        else:
            print(
                colored(f"✗ Received message with invalid proof!",
                        "red",
                        attrs=["bold"]))
        print(f"Measurement: {data}")
        print(f"Time to create message: {elapsed_time}ms")
Ejemplo n.º 3
0
    def __init__(self, port=None):
        self.do_decrypt_messages = False
        self.keys = dict()
        self.symm_key = None
        if port is None:
            ports = getPorts()
            if len(ports) == 0:
                print(
                    "No serial ports found. Please check your USB connection and try again."
                )
                sys.exit(1)
            port = ports[0]
            print(f"No port specified, defaulting to {port}")
        baudrate = 9600
        self.ser = serial.Serial(port, baudrate)

        # Restart arduino
        self.ser.setDTR(False)
        # print("Resetting Arduino...")
        time.sleep(1)
        self.ser.flushInput()
        self.ser.setDTR(True)
Ejemplo n.º 4
0
import sys
import os
from time import sleep

import serial

from listPorts import getPorts
from aes import AESCipher, unpad

NONCE_LENGTH = 16
AES_KEY = bytes([0x39, 0x79, 0x24, 0x42, 0x26, 0x45, 0x29, 0x48, 0x40, 0x4D, 0x63, 0x51, 0x66, 0x54, 0x6A, 0x57])

ports = getPorts()
if len(ports) == 0:
    print("No serial ports found. Please check your USB connection and try again.")
    sys.exit(1)
port = ports[0]
print(f"No port specified, defaulting to {port}")
baudrate = 9600
ser = serial.Serial(port, baudrate)

# Restart arduino
ser.setDTR(False)
print("Resetting Arduino...")
sleep(1)
ser.setDTR(True)

# Read 'Arduino is ready' message
response_length = int.from_bytes(ser.read(2), byteorder='big')
ser.read(response_length)