Beispiel #1
0
def load_key(persist=False):
    old_time = time.time()

    Console.print('Retrieving keys...\n', Colors.BLACK_BOLD)

    keys = KeyScraper.get_key(bcc_main.user)
    current_keys = set(list_keys())

    Console.print('Loading keys...', Colors.BLUE_BOLD)
    Console.print('%i key(s) loaded.\n' % len(keys), Colors.CYAN_BOLD)

    for key in keys:
        if key not in current_keys:
            Console.print(
                '[+] ' + sha256frompubkey.sha256_fingerprint_from_pub_key(key),
                Colors.GREEN_BOLD)
            add_key(key)

    # So revokes are verbose
    if not persist:
        for r in current_keys - keys:
            Console.print(
                '[-] ' + sha256frompubkey.sha256_fingerprint_from_pub_key(r),
                Colors.RED)
            revoke_key(r)

    Console.print(
        'Keys updated!\n\nCompleted update in %5.5f seconds\n' %
        (time.time() - old_time), Colors.BOLD)
def get_key(user):
    global keynames

    new_keys = set()

    response = urllib.request.urlopen('https://keybase.pub/'+user+'/gatekeeper')
    if response.getcode() == 200:
        data = [x for x in str(response.read()).split("\\n") if "<td class=\"name-col\"><a href=\"https://keybase.pub/%s/" % user in x]
        files = []
        for file in data:
            if "class=\"file\"" in file:
                for word in file.split("\""):
                    if ".pub" in word:
                        files.append(word)
                        break
        for key in files:
            print("Checking file:", "https://"+user + ".keybase.pub/gatekeeper/"+key.split("/")[-1]+"?dl=1")
            data = urllib.request.urlopen("https://"+user + ".keybase.pub/gatekeeper/"+key.split("/")[-1]+"?dl=1")
            if response.getcode() == 200:
                k = str(data.read().decode('utf-8')).strip()
                new_keys.add(k)

                keynames[sha256frompubkey.sha256_fingerprint_from_pub_key(k)] = key.split("/")[-1]

    return new_keys
Beispiel #3
0
def get_name_from_key(key):
    keys = glob.glob("/keybase/public/" + bcc_main.user + "/gatekeeper/*")

    for f in keys:
        k = open(f).read().strip()

        if key.strip() == sha256frompubkey.sha256_fingerprint_from_pub_key(k):
            return f.split('/')[-1]
Beispiel #4
0
def add_key(key):
    if not key_exists(key):
        dataparsing.log(sha256frompubkey.sha256_fingerprint_from_pub_key(key),
                        'ADD-KEY')
        os.system(
            'echo \'command="python3.7 BlockChainChain/bcc_main.py $SSH_ORIGINAL_COMMAND",no-port-forwarding,no-x11-forwarding,no-agent-forwarding %s\' >> %s/.ssh/authorized_keys'
            % (key, home))
        return True
    else:
        return False
Beispiel #5
0
def key_exists(k):
    keys = list_keys()

    for i in range(len(keys)):
        key = keys[i]

        try:
            reference_key = sha256frompubkey.sha256_fingerprint_from_pub_key(
                key)

            if 'ssh-rsa' in k:
                k = sha256frompubkey.sha256_fingerprint_from_pub_key(k)

            if k == reference_key:
                return [keys, i]
        except:
            traceback.print_exc()
    else:
        return False
Beispiel #6
0
def revoke_key(key):
    k = key_exists(key)

    if k:
        del k[0][k[1]]

        dataparsing.log(sha256frompubkey.sha256_fingerprint_from_pub_key(key),
                        'REVOKE-KEY')
        with open(home + '/.ssh/authorized_keys', 'w') as file:
            file.write('\n'.join(k[0]))

        return True
    else:
        return False
Beispiel #7
0
def main():

    global locked

    andrew = serialgao.Andrewino('/dev/ttyACM0')

    #locked = andrew.status()

    Console.clear()

    MenuFormatter.splash()

    key = authorized()

    if key:
        while True:
            Console.print(
                '\nSystem State: %s' % ('LOCKED' if locked else 'UNLOCKED'),
                Colors.WHITE)

            choice = MenuFormatter.option_list([
                'Lock' if not locked else 'Unlock', 'View Log', 'Clear Log',
                'Train', 'Exit'
            ])

            if choice == 1 and authorized():

                state = Prompts.yn_prompt(
                    'Are you sure you want to %s the chain?' %
                    ('LOCK' if not locked else 'UNLOCK'), 'n')

                if state == 'y':
                    if andrew.status():
                        andrew.unlock(
                            sha256frompubkey.sha256_fingerprint_from_pub_key(
                                key[0][0]))
                    else:
                        andrew.lock(
                            sha256frompubkey.sha256_fingerprint_from_pub_key(
                                key[0][0]))

                    Console.print(
                        'Chain has been %s' %
                        'LOCKED' if not locked else 'UNLOCKED',
                        Colors.PURPLE_BOLD_BRIGHT)
                    Prompts.cn_prompt()

                locked = andrew.status()

            elif choice == 2 and authorized():
                dataparsing.print_log()
                Prompts.cn_prompt()

            elif choice == 3 and authorized():
                state = Prompts.yn_prompt(
                    'Are you sure you want to clear system logs?', 'n')

                if state == 'y':
                    dataparsing.clear_log()

                    Console.clear()
                    Console.print('Logs cleared!', Colors.GREEN_BOLD_BRIGHT)
                    Prompts.cn_prompt()
            elif choice == 4:
                os.system('sl')
            elif choice == 5:
                Console.print('Goodbye.', Colors.BLUE_BOLD)
                break
            else:
                break