예제 #1
0
    def __init__(self):
        self.db = Database()
        self.command = commands.Commands()
        self.encrypt = Encrypt()
        self.auth = Authentication()

        self.commands = {
            "help": self.command.help,
            "new": self.command.new,
            "show": self.command.show,
            "save": self.command.save,
            "search": self.command.search,
            "delete": self.command.delete,
            "update": self.command.update_master_password,
            "security": self.command.security
        }
예제 #2
0
def get_session_id(jwt_token):
    if jwt_token:
        jwt_string = jwt_token[2:len(jwt_token) - 1]
        decoded_data = Encrypt.decrypt(jwt_string)
        if decoded_data:
            return decoded_data
    return None
예제 #3
0
def Generate(name: str, length: int) -> str:
    Password = ''
    for c in range(length):
        Password += random.choice(chars)
    password = shelve.open("password")
    password[name] = Encrypt(Password)
    password.close()
    return Password
예제 #4
0
def init():
     SK = input("Neutron > SK (h for help): ")
     if SK == "h":
          println("SK 0 is used to access the email client.")
          println("SK 1 is used to access the password manager.")
          println("OK 0 for SK 1 is used to append passwords to your personal password database.")
          println("OK 1 for SK 1 is used to retreive passwords from your personal password database.")
          println("OK 2 for SK 1 is used to generate passwords and append them to you personal password database.")
          println("OK 3 for SK 1 is used to retreive all your passwords from your personal password database.")
          println("SK 2 is used to access the encryption machine.")
          println("OK 0 for SK 2 is used to encrypt messages.")
          println("OK 1 for SK 2 is used to decrypt messages previously encrypted by Neutron.")
          init()
     elif SK == "0":
          println(SK)
     elif SK == "1":
          println(SK)
          OK = input("Neutron > OK (h for help): ")
          if OK == "0":
               Site = input("Neutron > Site: ")
               Password = input("Neutron > Password: "******"1":
               Site = input("Neutron > Site: ")
               println(Retreive(Site))
          elif OK == "2":
               Name = input("Neutron > Name: ")
               Length = int(input("Neutron > Length: "))
               println(Generate(Name, Length))
          elif OK == "3":
               println(All())
          else:
               println("Error: Invalid Neturon OK. Type h for help.")
               init()
     elif SK == "2":
          println(SK)
          OK = input("Neutron > OK (h for help): ")
          if OK == "h":
               println("OK 0 is used to encrypt messages.")
               println("OK 1 is used to decrypt messages previously encrypted by Neutron.")
          elif OK == "0":
               String = input("Neutron > String: ")
               println(Encrypt(String))
          elif OK == "1":
               String = input("Neutron > String: ")
               println(Decrypt(String))
          else:
               println("Error: Invalid Neutron OK. Type h for help.")
               init()
     else:
          println("Error: Invalid Neutron SK. Type h for help.")
          init()
예제 #5
0
def Append(Site: str, Password: str):
    password = shelve.open("password")
    Password = Encrypt(Password)
    password[Site] = Password
    password.close()
    return "Password added."
예제 #6
0
class PasswordManager:
    def __init__(self):
        self.db = Database()
        self.command = commands.Commands()
        self.encrypt = Encrypt()
        self.auth = Authentication()

        self.commands = {
            "help": self.command.help,
            "new": self.command.new,
            "show": self.command.show,
            "save": self.command.save,
            "search": self.command.search,
            "delete": self.command.delete,
            "update": self.command.update_master_password,
            "security": self.command.security
        }

    def check_config(self):
        if os.path.isfile("config.json"):
            print(green("> Config found!"))
        else:
            print(blue("> Config not found! Creating one.."))
            self.create_config()
            print(green("> Config created!"))

    def check_key(self):
        if os.path.isfile("key.txt"):
            with open("key.txt", "r+") as f:
                key = f.read()
            if not key:
                print(red("> Key not found!"))
                self.encrypt.new_key()
                print(green("> Key created and stored in key.txt"))
        else:
            with open("key.txt", "w+") as f:
                newKey = self.encrypt.new_key()
                print(green("> Key created and stored in key.txt"))

    def create_config(self):
        config = [{
            "included": {
                "lower": True,
                "upper": True,
                "numbers": True,
                "symbols": True
            },
            "export": {
                "file": True,
                "database": True
            }
        }]

        print(red(" > Config missing. Creating one..."))

        with open("config.json", "w+") as f:
            json.dump(config, f, indent=4)

        print(blue("> Config created."))

    def login(self):
        login = stdiomask.getpass("> Enter master password: "******"> Enter 2fa code: "))
            if self.auth.verify(code):
                print(green("> Logged in!"))
                self.run()
            else:
                print(red("> Incorrect 2fa code"))
                self.login()
        else:
            print(red("> Master password incorrect!"))
            self.login()

    def get_cmd(self):
        cmd = input("Enter command: ")
        if cmd not in self.commands.keys():
            print(
                red("> Command not recognised. Try using the command 'help' to get the list of available commands"
                    ))
        else:
            self.commands[cmd]()

    def run(self):
        while True:
            self.get_cmd()
    def test_Encrypt(self):

        self.encrypted = Encrypt(self.data, key=self.key, iv=self.iv)
        self.assertEqual(self.encrypted, self.tradeinfo)