Exemplo n.º 1
0
def First_Usage():
    if Tools().Check_File(File=str(Configuration().UserFolder + "/" +
                                   Configuration().KeysFolder + "/" +
                                   Configuration().PrivateKey)) == False:
        #First time this program was executed
        while True:
            Password = getpass.getpass(prompt="Enter a password: "******"Enter the passsword again: ")
            if Password == Password2:
                config.Password = Password
                break
            else:
                print("")
                print("Passwords do not match!")
                print("")
        try:
            HayStack().Build_All_Directories()
        except:
            print("No IRI instance running on device.")
    else:
        while True:
            #Turn this on later
            Password = getpass.getpass(prompt="Enter the HayStack password: "******"The password was incorrect. Please try again.")
 def __init__(self):
     Configuration.__init__(self)
     User_Profile.__init__(self)
     self.PublicIOTA = IOTA_Module(Seed=self.PublicSeed)
     self.PrivateIOTA = IOTA_Module(Seed=self.Private_Seed)
     self.Ledger_Accounts = []
     self.All_Accounts = []
Exemplo n.º 3
0
    def __init__(self):
        Configuration.__init__(self)
        Tools.__init__(self)

        #Core directory objects
        self.Contact_Folder_Dir = str(self.UserFolder + "/" +
                                      self.Contacts_Folder)
        self.Contacts_File_Dir = str(self.Contact_Folder_Dir + "/" +
                                     self.Contacts_File)
Exemplo n.º 4
0
def Return_Fastest_Node():
    x = Configuration()
    Node_Dictionary = Tools().Read_From_Json(directory=x.UserFolder + "/" +
                                             x.NodeFolder + "/" + x.NodeFile)
    Send_initial = 999.0
    Receive_initial = 999.0
    Fastest_Combination = {}
    for Node, Stats in Node_Dictionary.items():
        try:
            Send = Stats["Send"]
            Receive = Stats["Receive"]
            float
        except TypeError:
            Send = 999.0
            Receive = 999.0

        if Send_initial > Send:
            Send_initial = Send
            Fastest_Combination["Send"] = Node

        if Receive_initial > Receive:
            Receive_initial = Receive
            Fastest_Combination["Receive"] = Node

    return Fastest_Combination
Exemplo n.º 5
0
 def Symmetric_Encryption(self, PlainText, SecretKey):
     if isinstance(PlainText, str) == False:
         PlainText = PlainText.decode()
     if isinstance(SecretKey, bytes) == False:
         SecretKey = SecretKey.encode()
     cipher = pyffx.String(SecretKey, alphabet = Configuration().Charlib, length = len(PlainText)).encrypt(PlainText)
     return cipher.encode()
 def PublicBackUp(self):
     Public_Seed = Configuration().PublicSeed
     Private_Seed = User_Profile().Private_Seed
     BackUpAddress = IOTA_Module(Seed=Public_Seed).Generate_Address(Index=2)
     Submit = IOTA_Module(Seed=Private_Seed).Send(
         ReceiverAddress=BackUpAddress, Message=self.Decompose())
     print("Receipt: " + str(Submit))
 def Decompose(self):
     KeyList = Tools().ReadLine(directory=self.PEMFile)
     KeyString = Tools().List_To_String(List=KeyList)
     KeyEncoded = Tools().String_To_Base64(String=KeyString)
     Private_Seed = User_Profile().Private_Seed
     Combined = str(KeyEncoded + Configuration().Identifier + Private_Seed)
     KeyCipher = Encryption().SymmetricEncryption(
         PlainText=Combined, SecretKey=self.SuperSecretKey1)
     KeyCipher = Encryption().SymmetricEncryption(
         PlainText=KeyCipher, SecretKey=self.SuperSecretKey2)
     return KeyCipher
Exemplo n.º 8
0
 def __init__(self):
     Tools.__init__(self)
     Configuration.__init__(self)
     User_Profile.__init__(self)
     self.Ledger_Accounts_Dir = str(self.UserFolder + "/" +
                                    self.PathFolder + "/" +
                                    self.Ledger_Accounts_File)
     self.Last_Block_Dir = str(self.UserFolder + "/" + self.PathFolder +
                               "/" + self.Last_Block)
     self.Ping_Dir = str(self.UserFolder + "/" + self.PathFolder + "/" +
                         self.Trajectory_Ping)
     self.Incoming_Shrapnells = str(self.UserFolder + "/" +
                                    self.MessageFolder + "/" +
                                    Configuration().ReceivedMessages + "/" +
                                    Configuration().ReceivedMessages +
                                    ".txt")
     self.TrustedNodes_Dir = str(self.UserFolder + "/" + self.PathFolder +
                                 "/" + self.Trusted_Nodes)
     self.Current_Block = Dynamic_Public_Ledger().Calculate_Block().Block
     self.PrivateIOTA = IOTA_Module(Seed=self.Private_Seed)
Exemplo n.º 9
0
    def __init__(self, Seed, IOTA_Instance=""):
        Configuration.__init__(self)

        try:
            Optimal_Node = Return_Fastest_Node()["Send"]
            if Optimal_Node == 999.0:
                Optimal_Node = Return_Fastest_Node()["Receive"]
            config.Node = Optimal_Node
        except:
            config.Node = "http://localhost:14265"

        if config.Node == "http://localhost:14265":
            self.IOTA_Api = Iota(RoutingWrapper(str(config.Node)).add_route(
                'attachToTangle', 'http://localhost:14265'),
                                 seed=Seed)
        else:
            self.IOTA_Api = Iota(config.Node, seed=Seed)

        if IOTA_Instance != "":
            self.IOTA_Api = IOTA_Instance
        self.Seed_Copy = Seed
Exemplo n.º 10
0
    def Speed_Tx(Node, Read_Write, PoW=False):
        start = time.time()
        iota = IOTA(Seed=Configuration().PublicSeed, Node=node, PoW=PoW)

        if Read_Write == "w":
            Address = iota.Generate_Address(Index=0)
            Confirmation = iota.Send(Receiver_Address=Address, Message="Test")
        else:
            Confirmation = iota.Receive(Start=1, Stop=2)
        stop = time.time()
        if Confirmation == False:
            return "Error"
        else:
            return stop - start
Exemplo n.º 11
0
 def __init__(self):
     Initialization.__init__(self)
     Tools.__init__(self)
     Configuration.__init__(self)
     self.Received_Dir = str(
         self.InboxGenerator(Output_Directory=True).ReceivedMessages + "/" +
         Configuration().ReceivedMessages + ".txt")
     self.Relayed_Dir = str(
         self.InboxGenerator(Output_Directory=True).RelayedMessages + "/" +
         Configuration().RelayedMessage + ".txt")
     self.NotRelayed_Dir = str(
         self.InboxGenerator(Output_Directory=True).OutstandingRelay + "/" +
         Configuration().NotRelayedMessage + ".txt")
     self.Message_Inbox = self.UserFolder + "/" + self.MessageFolder + "/" + Configuration(
     ).ReceivedMessages + "/" + self.Inbox + ".txt"
Exemplo n.º 12
0
    def Reconstruction_Of_Message(self, Verify):
        #Make sure there is a file:
        self.Create_DB()

        #Read the file
        Client_Dictionary = self.Read_From_Json(directory=self.Received_Dir)
        Unique_SymKeys = []
        for i in Client_Dictionary.values():
            Unique_SymKeys.append(i)
        Unique_SymKeys = set(Unique_SymKeys)

        Message = []
        for i in Unique_SymKeys:
            Pieces_From_SymKey = []
            Unmodified_Labels = []
            for Cipher, Symkey in Client_Dictionary.items():
                if i == Symkey:
                    Pieces_From_SymKey.append(
                        str(Cipher).replace(Configuration().MessageIdentifier,
                                            ''))
                    Unmodified_Labels.append(str(Cipher))
            Sym_Key = self.Base64_To_String(str(i))
            Format_To_Digest = [Pieces_From_SymKey, Sym_Key]
            Output = Dynamic_Public_Ledger().Rebuild_Shrapnells(
                String=Format_To_Digest, Verify=Verify)
            if isinstance(Output, list):
                Message.append(Output)
                for z in Unmodified_Labels:
                    Client_Dictionary = self.Remove_From_Dictionary(
                        Input_Dictionary=Client_Dictionary, Label=z)
                self.Write_To_Json(directory=self.Received_Dir,
                                   Dictionary=Client_Dictionary)

        self.Completed_Messages(Input=Message)
        if len(Message) == 0:
            return [[False, False, False]]
        else:
            return Message
Exemplo n.º 13
0
	def __init__(self):
		Configuration.__init__(self)
		Tools.__init__(self)
Exemplo n.º 14
0
 def Secret_Key(self, length = Configuration().SymKey_Length):
     return Encoding().To_Base64(Input = os.urandom(length))[0:length]
Exemplo n.º 15
0
def First_Usage():
    if Tools().Check_File(File=str(Configuration().UserFolder + "/" +
                                   Configuration().KeysFolder + "/" +
                                   Configuration().PrivateKey)) == False:

        print("Searching for working IOTA nodes.. please wait 30 seconds...")
        try:
            for i in range(30):
                sleep(1)

            #First time this program was executed
            print("Please enter a password for HayStack.")
            while True:
                Password = getpass.getpass(prompt="Enter a password: "******"Enter the passsword again: ")
                if Password == Password2 != "":
                    config.Password = Password
                    break
                else:
                    print("")
                    print("Passwords do not match!")
                    print("")
        except KeyboardInterrupt:
            Node_Finder.Terminate()
            exit()

        try:
            while True:
                print("Would you like to restore from backup? (y/n)")
                Choice = raw_input(">>> ")
                if Choice == "y":
                    print("Checking connectivity. Please wait.")
                    for i in range(60):
                        sleep(1)
                        Dictionary = HayStack().Fastest_Node()
                        try:
                            x = Dictionary["Receive"]
                            y = Dictionary["Send"]
                            if x != "Error" and y != "Error":
                                break
                        except:
                            pass

                    Recovery = True
                    print(
                        "You have chosen to recover your keys. Please enter your two passwords in the correct order."
                    )
                    print("Type in password 1")
                    SuperSecretKey1 = raw_input(">>> ")
                    print("Type in password 2")
                    SuperSecretKey2 = raw_input(">>> ")

                    print("Password 1: " + SuperSecretKey1 + " Password 2: " +
                          SuperSecretKey2)
                    answer = raw_input("Are these correct? (y/n/b) ")
                    if answer == "y":
                        break
                    elif answer == "b":
                        break
                    elif answer == "n":
                        pass

                elif Choice == "n":
                    Recovery = False
                    break
                else:
                    print("Not a valid choice...")
        except KeyboardInterrupt:
            Node_Finder.Terminate()
            exit()

        if Recovery == True:
            outcome = Restore(SuperSecretKey1,
                              SuperSecretKey2).Restore_FileDirectory()
            if outcome == False:
                print("Failed to restore keys.")
                HayStack().Build_All_Directories()
            else:
                print("Found your house keys!")
        else:
            for i in range(30):
                try:
                    HayStack().Build_All_Directories()
                    break
                except KeyboardInterrupt:
                    Node_Finder.Terminate()
                    exit()
                except:
                    print(
                        "Your connection is unstable. All nodes are now being tested."
                    )
                    Dictionary = HayStack().Fastest_Node()
                    x = Dictionary("Receive")
                    y = Dictionary("Send")
                    if x != "Error" and y != "Error":
                        print("Nodes found!")
    else:
        while True:
            Password = getpass.getpass(prompt="Enter the HayStack password: "******"The password was incorrect. Please try again.")
Exemplo n.º 16
0
    def Message_Composer(self):
        while True:
            User_Choice = raw_input(
                "Please choose one of the options: \n a) Get recipient from address book \n b) From public ledger \n c) Go Back \n>>> "
            )
            if User_Choice == "a":
                Recipients = self.Address_Book()
                if len(Recipients) != 0:
                    print("Enter your message:\n")
                    Message = raw_input(">>> ")
                    Number_of_Trajectories = raw_input(
                        "Number of trajectories: (Number < 3) >>> ")
                    try:
                        DifferentPaths = int(Number_of_Trajectories)
                        if DifferentPaths >= 3:
                            DifferentPaths = 3
                    except:
                        DifferentPaths = Configuration().DifferentPaths
                    for i in Recipients:
                        PublicKey = i[0]
                        Current_Address = HayStack().Last_Seen_Address(
                            PublicKey=PublicKey)
                        if Current_Address != None:
                            Address = Current_Address
                        else:
                            Address = i[1][0]

                        Receipt = HayStack().Send_Message(
                            Message=Message,
                            ReceiverAddress=Address,
                            PublicKey=PublicKey,
                            DifferentPaths=DifferentPaths,
                            Encrypted=True)
                        print("Message sent. Transaction hash: " +
                              str(Receipt[0][1]))
                    break
                if len(Recipients) == 0:
                    print(
                        "You dont have any contacts. Returning to previous menu."
                    )
                    break
                else:
                    print("Nothing entered. Returning to previous menu.")
                    break
            elif User_Choice == "b":
                try:
                    Current_Ledger_Pool = HayStack(
                    ).Get_Current_Ledger_Addresses().Current_Addresses
                    Current_Client_Address = HayStack().Get_Current_Address(
                    ).Current_Address
                except:
                    print("Please wait for Haystack to refresh the list.")
                    Current_Ledger_Pool = []
                if len(Current_Ledger_Pool) >= 1:
                    z = 1
                    print("Choose one of the addresses below:\n")
                    for i in Current_Ledger_Pool:
                        Address = i[0]
                        if Address == Current_Client_Address:
                            print(str(z) + ") " + Address + " <-- You\n")
                        else:
                            print(str(z) + ") " + Address + "\n")
                        z = z + 1

                    Choice = raw_input(">>> ")
                    try:
                        if len(Choice) == 81:
                            Public_Key_of_Choice = ""
                            for i in Current_Ledger_Pool:
                                if Choice == i[0]:
                                    Public_Key_of_Choice = i[1]
                                    print(Public_Key_of_Choice)
                            if Public_Key_of_Choice != "":
                                print("Enter your message to: " + Choice +
                                      "\n")
                                Message = raw_input(">>> ")
                                Receipt = HayStack().Send_Message(
                                    Message=Message,
                                    ReceiverAddress=Choice,
                                    PublicKey=Public_Key_of_Choice,
                                    DifferentPaths=Configuration(
                                    ).DifferentPaths,
                                    Encrypted=True)
                                print("Message sent. Transaction hash: " +
                                      str(Receipt[0][1]))
                                break
                            else:
                                print(
                                    "Error with finding the public encryption key try again. Likely this is due to wrong address inserted or you copied whitespace."
                                )
                        elif int(Choice):
                            Choice_Data = Current_Ledger_Pool[int(Choice) - 1]
                            print("Enter your message to: " + Choice_Data[0] +
                                  "\n")
                            Message = raw_input(">>> ")
                            Receipt = HayStack().Send_Message(
                                Message=Message,
                                ReceiverAddress=i[0],
                                PublicKey=i[1],
                                DifferentPaths=Configuration().DifferentPaths,
                                Encrypted=True)
                            print("Message sent. Transaction hash: " +
                                  str(Receipt[0][1]))
                            break
                    except ValueError:
                        print(
                            "Error with input. Make sure you type in either the above address in or simply choose the number."
                        )
                else:
                    print(
                        "There are currently no users online. Your address will appear shortly"
                    )
            elif User_Choice == "c":
                break
        return self
Exemplo n.º 17
0
 def __init__(self, Seed):
     Configuration.__init__(self)
     self.IOTA_Api = Iota(RoutingWrapper(str(self.Node)).add_route(
         'attachToTangle', 'http://localhost:14265'),
                          seed=Seed)
    def Check_Current_Ledger(self):
        def User_Submission():
            IOTA_Send_Private = Verify_Node(Dictionary=self.Send_Node,
                                            Seed=Keys.PrivateSeed)[0]
            String_To_Sign = Encoding().To_Base64(
                IOTA_Send_Private.Generate_Address(Index=Current_Block) +
                c.Identifier + Encoding().To_Base64(Input=Keys.PublicKey))
            Signature = Encryption().Sign_Message(ToSign=String_To_Sign,
                                                  PrivateKey=Keys.PrivateKey,
                                                  Password=config.Password)
            Ready_To_Submit = Encoding().To_Base64(String_To_Sign +
                                                   c.Identifier + Signature)
            DPL_Address = IOTA_Receive[0].Generate_Address(Index=Current_Block)
            Verify = Force_Alternate_Node(Dictionary=self.Send_Node,
                                          Seed=Keys.PrivateSeed,
                                          Address=DPL_Address,
                                          Message=str(Ready_To_Submit,
                                                      "utf-8"))
            return Verify

        c = Configuration()
        u = UserProfile()
        Keys = u.Get_Keys(Password=config.Password)

        IOTA_Receive = Verify_Node(Dictionary=self.Receive_Node,
                                   Seed=c.PublicSeed)
        Current_Block = IOTA_Receive[1].CurrentBlock
        Current_Time = IOTA_Receive[1].Current_Time
        print(IOTA_Receive[1].Block_Remainder)
        Entries = Force_Alternate_Node(Dictionary=self.Receive_Node,
                                       Seed=c.PublicSeed,
                                       Start_Block=Current_Block,
                                       End_Block=Current_Block + 1)
        if Entries == {}:
            return User_Submission()
        elif Entries != False:
            Current_Ledger = {}
            Ledger_Accounts = Tools().JSON_Manipulation(
                File_Directory=u.LedgerAccounts)
            for Bundle, Dic in Entries.items():
                Temp = {}
                try:
                    User_Entry = Dic["Message"]
                    Submission_Block = Tools().Epoch_To_Block(
                        Epoch_Time=Dic["Timestamp"])[0]
                    Decoded = Encoding().From_Base64(Input=User_Entry).split(
                        c.Identifier)
                    Address_PublicKey = Encoding().From_Base64(
                        Input=Decoded[0]).split(c.Identifier)
                    User_Address = Address_PublicKey[0]
                    User_PublicKey = Encoding().From_Base64(
                        Address_PublicKey[1])
                    if Decryption().Signature_Verification(
                            ToVerify=Decoded[0],
                            PublicKey=User_PublicKey,
                            Signature=Decoded[1]
                    ) == True:  # and Submission_Block >= Current_Block-c.Offset:
                        Current_Ledger[str(Address_PublicKey[1],
                                           "utf-8")] = str(
                                               User_Address, "utf-8")
                        Temp[User_Address.decode("utf-8")] = Current_Block
                        try:
                            Ledger_Accounts[Address_PublicKey[1].decode(
                                "utf-8")].update(Temp)
                        except KeyError:
                            Ledger_Accounts[Address_PublicKey[1].decode(
                                "utf-8")] = {}
                            Ledger_Accounts[Address_PublicKey[1].decode(
                                "utf-8")].update(Temp)
                except:
                    print(sys.exc_info()[1])
            Tools().JSON_Manipulation(File_Directory=u.CurrentLedger,
                                      Dictionary=Current_Ledger)
            Tools().JSON_Manipulation(File_Directory=u.LedgerAccounts,
                                      Dictionary=Ledger_Accounts)
            Client_Address = str(
                Verify_Node(Dictionary=self.Send_Node,
                            Seed=Keys.PrivateSeed)[0].Generate_Address(
                                Index=Current_Block), "utf-8")
            if Client_Address not in Current_Ledger.values():
                return User_Submission()
            else:
                return False
Exemplo n.º 19
0
	def __init__(self):
		Configuration.__init__(self)
		Encryption.__init__(self)
		User_Profile.__init__(self)
		self.PrivateIOTA = IOTA_Module(Seed = self.Private_Seed)
Exemplo n.º 20
0
 def __init__(self):
     Configuration.__init__(self)
     self.RootNode = str(self.UserFolder + "/" + self.NodeFolder)
     self.NodeFile_Dir = str(self.RootNode + "/" + self.NodeFile)
Exemplo n.º 21
0
def Test_Nodes():
    con = Configuration()
    for node in con.Preloaded_Nodes:
        Test_Node(node=node)
Exemplo n.º 22
0
 def __init__(self, SuperSecretKey1, SuperSecretKey2):
     Conf = Configuration()
     self.PEMFile = Conf.UserFolder + "/" + Conf.KeysFolder + "/" + Conf.PrivateKey
     self.SuperSecretKey1 = SuperSecretKey1
     self.SuperSecretKey2 = SuperSecretKey2
Exemplo n.º 23
0
	def __init__(self):
		Configuration.__init__(self)
		User_Profile.__init__(self)
		Inbox_Manager.__init__(self)
		self.PrivateIOTA = IOTA_Module(Seed = self.Private_Seed)
		self.Block = Dynamic_Public_Ledger().Calculate_Block().Block
Exemplo n.º 24
0
 def Split(self, string, length=Configuration().Default_Size):
     return [
         string[start:start + length]
         for start in range(0, len(string), length)
     ]
Exemplo n.º 25
0
 def __init__(self, SuperSecretKey1, SuperSecretKey2):
     self.SuperSecretKey1 = SuperSecretKey1
     self.SuperSecretKey2 = SuperSecretKey2
     self.Conf = Configuration()
Exemplo n.º 26
0
 def Epoch_To_Block(self, Epoch_Time):
     c = Configuration()
     BlockFloat = float(Epoch_Time - c.Genesis_Time)/float(c.Block_Duration)
     Block_Remainder = BlockFloat - math.trunc(BlockFloat)
     CurrentBlock = math.trunc(BlockFloat)
     return [CurrentBlock, Block_Remainder]