From 63f0e68253e8ce5db5173d16c6d89cde84922bc2 Mon Sep 17 00:00:00 2001 From: Scratchcat1 Date: Sat, 18 Nov 2017 11:34:41 +0000 Subject: [PATCH] Add files via upload -Bug fixes --- AATC_Client.py | 2 +- AATC_Config.py | 2 +- AATC_Crypto.py | 29 ++++++++++++++++++++++------- AATC_DB.py | 2 +- AATC_Drone.py | 8 +++++++- AATC_Drone_Logic.py | 4 ++++ AATC_GPIO.py | 20 +++++++++++++++++++- AATC_Monitor.py | 8 +++++++- AATC_Server_002.py | 2 +- 9 files changed, 63 insertions(+), 14 deletions(-) diff --git a/AATC_Client.py b/AATC_Client.py index 6657dc8..fb113c4 100644 --- a/AATC_Client.py +++ b/AATC_Client.py @@ -248,7 +248,7 @@ def Recv(self): #Returns tuple of Sucess,Message,Data of which data may just # Sucess, Message , Data return data[0],data[1],data[2] except Exception as e: - print("Socket data recive error") + print("Socket data receive error") print(str(e)) return (False,"Conversion/Transfer Error"+str(e),[]) diff --git a/AATC_Config.py b/AATC_Config.py index 31738fa..6366372 100644 --- a/AATC_Config.py +++ b/AATC_Config.py @@ -7,7 +7,7 @@ SERVER_PRIVATE_KEY = b"0\x82\x02]\x02\x01\x00\x02\x81\x81\x00\xb4N\xe2,D\x10\t.\x07UkD\x0b\x05u\x95n\r4\xcd\xa0A\x07\x8e\x93\xc3$ZP\x1e\x82\xce\x908a\x88A[\x84L\xcbk\xf9\xf1\xd5\xb6\x18\xcf\x11\x0eo\x9e\x9b\x83\xff\x87z\xd0\xa5\xf5gDR\xd7\xb9\x13\xc7\xb3\xedAV\x96\x15\x0e\xe9i\xf7\n\x93\n\xf2-\xd4\xe9\x90\x8f\xaa\xa4y\x9b\x91\x1f\x0c\x93\xc6\xf3\xc0\x1e\xfd\xccl\xa32\xde`\xa9\x9bH$Q\x94.\xf0s\x12\x87\x8bS\x1cs\r\xa1O\xb8\xca\xa46y\x02\x03\x01\x00\x01\x02\x81\x80N,}F\xef\xe3{\xf7f\xda\x93\xfd\x16B1\xae\xad\xde/\xec\x8e\xf4b\xd0`$\x15\x18\xca\xef\xcf\x8a\xbb`\x96x\xba\xcdp\xd8\xd2\xc1g\xc6\x7f\xff\xc9U\xcdqR\xd7\x93YqjM\xc74\x8c\xe7N\xea\x13>14\xfb\xce \xab'\xcdg\x9c\\C(d\x8b\xc9\x7f\xc2\xc9\xd6\x18t\x1cS\xa1\xa6\x82\x94\x80\xce3\xba\x81\x0fU\x043\xf2\xa6\x96}\x98,q\xce\xaeH\x97\xe1\xdd3e~\xa5\xd7\x06Q\xf8\xc0\x92\xb1q\x19\x02A\x00\xc1\xbd\xaa\xa20\xe1W~#\x10r\xeeG\x19\x83@\x94\xe1\x8c\xe1D\xe84f\x00\xee\xc9k/\xec\xa3\x01N\x1e\xd7\x00\xc50\xc3l\xcd\xb5\xbe\xa9\x91&\x05W[(<\t\x9bALL\xf3%\x03<\xd3\x17&\x0f\x02A\x00\xee@'\xcc\xb6C\x1e5f\xda\xb6\xf5\x11\xcci\xc2Xo\xd4\xb1\xd0!\x1b\xb5F]\x83\x10\xa6\xf1d<,\x82\xd8\xce\xaf~1\xb9\x07:\xb9\xc5\x10r\xb7\x1f,\x1c\x11k\xf2\xc1\t\xe2\xb5\xbb\x11{\xf47\xa2\xf7\x02A\x00\x95\xe2\xb4v\x126\xe3\xc7t=/\x8ddx:p\xe6=\xb1\x0e>\x8f\x1e\xaa\xa3\xa2\x195\xd1\xb7\xd3L\x192\x06\xc8S\xc6,\n\xab\x03&dm$\xeb\x10\xf07*k\x8c/rf=\xdd\xae\xa9\x89\xed\xe8\xc5\x02A\x00\xc73\x16\xd3\xbfT0\xce\xbfw\x80\xdf8\x89k\xa7\x95\x9f\xb2\xfb\x14\xa4\x89\xf1/\xab\x01\xe9\x8b[j\xce0\xfd\x19\xde\xfd\xb6\nF\xc4\xb7\xa2\x19\x15\x1e\x84\xe3hR\xf3r\t\x1e\xc3p-8\x02o\\\n\xa4\x93\x02@=\x1cp*k\xbb\x8fL\xc7\xc0\xf4/xY6NJ\x1e/\x04\xb6y\x8e\x13`pL\x8e\xfbl\xads2\x00\x1a\xfb\\n\xda\xe2 \xe3\x9a\x18', 'NotBefore': 1, 'Name': '0', 'PublicKey': b'0\x81\x9f0\r\x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x03\x81\x8d\x000\x81\x89\x02\x81\x81\x00\xc2\x0cmp\xbaN\x86\xb9\x05!*\x8d\xd2\xa1\x95\x16}\xa9gALok\x9d\xa7\xf6\xa9\r\x80\xae\x82\x90*N\x071}\x0f\xd5\xe7F0\xe4\x03\xaal\xb6b\xdc\xbc\xea\x087\xd3\xce\x92Pl~\x01\x8d\xc2\xb9\tY\x9c\xdf\xa9\xbe\xa7F!\xfdG_Wj\x7f\xf2P\xad\xa9\x87?\xc5\xdd.\x0c\xa0+!\xf4\xdcv\x8d\xe05S\xa3\x15TL\xa7\x10\x888h\x9a\x0f\xebU\n\x8c\xec\xc7\xa3E\x98\xe6h\xc6yM\xe1PGRm\x02\x03\x01\x00\x01', 'Issuer': 'IssuerA'}, {'NotAfter': 10000000000, 'Signature': b"\xba\xe2Q\xf4A\xe1\xdc\xad\xbb\xaf\xcdtvAD\xae\xad\xad\x86\x12\xf5e\xe4\x8d\rT\xce\xf7\xe0R\x0eF\xd58\xa6w\x8c\xd0JL\xde\xa7n\xf1j\xa7H\x96\xba\xa5\x1a\x17H\xe7\x02\x80_6x\x0b\xec]\x80\xde'\xcc\x15\xf6\tF\xab1\xb56ga\xd3\x17*\x0c8\xc9k?\x12\x00%\x1b\x14D~\x89\xf2\xcb\x0cP\xf6\x1dy\xbf\x9e\xbd\x96\n\x8a\xfc\x974z\x1a\xaaV\x0c\x06\x86\xbeNv\xeeYHl\x00\xf6\xc3\xffy\x98", 'NotBefore': 1, 'Name': '1', 'PublicKey': b'0\x81\x9f0\r\x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x03\x81\x8d\x000\x81\x89\x02\x81\x81\x00\xb2}\t\xe1\xd3\x95J\x0ba\xc6~K\xbeT\xdcu\xba\x8d\x94\xd1s\xf0\x8bn\xfe*\x9e(B\x9f<3\xdd\xd1\nvz]P\x95\xb9\xf6Oa\xc0\x9e\xfcn\xa8\xa8I\x81Y\xc6k\xbe\xe1\x03L\xae\xec\xe7\xb0e\x90\x9b\xef\xc9-\x92\xce\xce\x06:t\xbc \xa4\x9eEgw\x0c>\x84\xf2i]\x0e\xb2\xb8\x7f\x10\xc8\xed\xcf4\xaa\x0fvD\xd4\x026\xf3\x86Dd\xa5\x11\x897\x9c\x9e/\xe6J\xb1.\x10\xdb\xa9o5R{\xb1\xcb\x02\x03\x01\x00\x01', 'Issuer': '0'}, {'NotAfter': 10000000000, 'Signature': b"+\x8e\xf0\xad\xfe&\x9avY\xaaP\xcdE\x86a\x84\xf8\xd2\x97\xba\xa5}N;\xa0\x14-\x8e\xad\xe2Y\xcf@\xab\x17\xfdO\xca\xe8H:\xfc}I\xfd\xc4\xe1\x95\xd4\x07\xe2\x8c\xb0Z\x10\xa2\xa2\x1b\xb4?\x0c8\xb2\xbd\x92X)\xa2\xdf\x9b\xa8F\x1b\x88|\\\xe6\xa6'7$\xa9\x8b[\xe3\xc3\xbc\xe2j2\x82\x8c:\xf0;\xd8l\xcd*\xd1\x08C\xfe\x1b\xa5\x00\xebW\x9f\xdf\xc4a\xd8\xe3\x01v\xb6a\x14\xd3\n*\xf4)W}7\x0c", 'NotBefore': 1, 'Name': 'localhostsssss', 'PublicKey': b'0\x81\x9f0\r\x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x03\x81\x8d\x000\x81\x89\x02\x81\x81\x00\xb4N\xe2,D\x10\t.\x07UkD\x0b\x05u\x95n\r4\xcd\xa0A\x07\x8e\x93\xc3$ZP\x1e\x82\xce\x908a\x88A[\x84L\xcbk\xf9\xf1\xd5\xb6\x18\xcf\x11\x0eo\x9e\x9b\x83\xff\x87z\xd0\xa5\xf5gDR\xd7\xb9\x13\xc7\xb3\xedAV\x96\x15\x0e\xe9i\xf7\n\x93\n\xf2-\xd4\xe9\x90\x8f\xaa\xa4y\x9b\x91\x1f\x0c\x93\xc6\xf3\xc0\x1e\xfd\xccl\xa32\xde`\xa9\x9bH$Q\x94.\xf0s\x12\x87\x8bS\x1cs\r\xa1O\xb8\xca\xa46y\x02\x03\x01\x00\x01', 'Issuer': '1'}] -#Minor setting to use given AES and IV. Will be removed as it is a security issue. +#Minor setting to use given AES and IV. Will not removed even if it is a security issue, preshared keys is the simple counter against shor's algorithm (cannot have a fibre optic cable to a drone for quantum cryptography). SET_ENCRYPTION_KEYS_ENABLE = False SET_AES_KEY = b"00000000000000000000000000000000" SET_IV_KEY = b"00000000000000000000000000000000" diff --git a/AATC_Crypto.py b/AATC_Crypto.py index 700c193..d4ff52a 100644 --- a/AATC_Crypto.py +++ b/AATC_Crypto.py @@ -66,6 +66,9 @@ def ClientPreSharedKeys(self,RSA_KeySize,AES_KeySize): if not Sucess: raise Exception("Server did not respond to command") + if AES_KeySize not in AATC_Config.ALLOWED_AES_KEYSIZES: + raise Exception("AES key size not in ALLOWED_AES_KEYSIZES. Change keysize to an allowed value") + AESKey,IV = GenerateKeys(AES_KeySize) PublicKey = AATC_CryptoBeta.VerifyCertificates(CertificateChain,AATC_Config.ROOT_CERTIFICATES,self.con) @@ -76,7 +79,9 @@ def ClientPreSharedKeys(self,RSA_KeySize,AES_KeySize): EncryptedIV = PKO.encrypt(IV) self.SetEncryptionKeys(AESKey,IV) self.Send(("SetKey",(EncryptedAESKey,EncryptedIV))) - data = self.Recv() + Sucess,Message,Data = self.SplitData(self.Recv()) + if not Sucess: + raise Exception("Server rejected setting AES_Keys"+Message) else: @@ -112,9 +117,11 @@ def ClientExchangeKeys(self,RSA_KeySize,AES_KeySize): ################################################################ def ServerGenerateKey(self): + if AATC_Config.SET_ENCRYPTION_KEYS_ENABLE: + self.SetEncryptionKeys(AATC_Config.SET_AES_KEY, AATC_Config.SET_IV_KEY) - Exit = False - while not Exit: + self.Exit = False + while not self.Exit: data = self.Recv() Command, Arguments = data[0],data[1] @@ -130,13 +137,16 @@ def ServerGenerateKey(self): elif Command == "Exit": Sucess,Message,Data = True,"Exiting",[] - Exit = True + self.Exit = True else: Sucess,Message,Data = False,"Command does not exist",[] self.Send((Sucess,Message,Data)) + if not hasattr(self,"AESKey"): #Only set if sucessfully setup. + raise Exception("Failure during crypter setup") + @@ -163,8 +173,13 @@ def ServerSetKey(self,Arguments): PKO = PKCS1_OAEP.new(RSA.import_key(AATC_Config.SERVER_PRIVATE_KEY)) AESKey,IV = Arguments[0],Arguments[1] AESKey,IV = PKO.decrypt(AESKey),PKO.decrypt(IV) - self.SetEncryptionKeys(AESKey,IV) - return True,"Keys set",[] + + if len(AESKey) in AATC_Config.ALLOWED_AES_KEYSIZES: + self.SetEncryptionKeys(AESKey,IV) + return True,"Keys set",[] + else: + #self.Exit = True + return False,"AES key size not in ALLOWED_AES_KEYSIZES:"+str(AATC_Config.ALLOWED_AES_KEYSIZES),[] @@ -178,7 +193,7 @@ def SetEncryptionKeys(self,AESKey,IV): self.IV = IV self.EncryptAES = AES.new(self.AESKey,AES.MODE_GCM,self.IV) #Two seperate instances to encrypt and decrypt as non ECB AES is a stream cipher self.DecryptAES = AES.new(self.AESKey,AES.MODE_GCM,self.IV) #Errors will occur if encrypt and decrypt are not equal in count. - + diff --git a/AATC_DB.py b/AATC_DB.py index 15d8283..a5fc642 100644 --- a/AATC_DB.py +++ b/AATC_DB.py @@ -302,7 +302,7 @@ def MonitorCheckCredentials(self,MonitorName,MonitorPassword): if MonitorIDFetch != (): return True,"Correct Credentials",MonitorIDFetch[0][0] else: - return False,"Incorrect Credntials",-1 + return False,"Incorrect Credentials",-1 def MonitorChangePassword(self,MonitorID,OldPassword,NewPassword): self.cur.execute("SELECT 1 FROM Monitor WHERE MonitorID = %s AND MonitorPassword = %s",(MonitorID,Hash(OldPassword))) diff --git a/AATC_Drone.py b/AATC_Drone.py index b24e198..bc7b026 100644 --- a/AATC_Drone.py +++ b/AATC_Drone.py @@ -38,7 +38,7 @@ def Recv(self): #Returns tuple of Sucess,Message,Data of which data may just # Sucess, Message , Data return data[0],data[1],data[2] except Exception as e: - print("Socket data recive error",e) + print("Socket data receive error",e) return (False,"Conversion/Transfer Error"+str(e),[]) @@ -87,6 +87,12 @@ def MarkFlightComplete(self,FlightID,Code): Sucess,Message,_ = self.Recv() return Sucess,Message + def Exit(self): + self.Send("Exit",()) + Sucess,Message,_ = self.Recv() + self.con.close() + return Sucess,Message + class Flight: diff --git a/AATC_Drone_Logic.py b/AATC_Drone_Logic.py index d4ef498..9177d39 100644 --- a/AATC_Drone_Logic.py +++ b/AATC_Drone_Logic.py @@ -20,15 +20,19 @@ def Main(self): if LoginSucess: if not InFlight: + AATC_GPIO.GPIO_Wait_Switch(26,Indicator_Pin = 13) print("Entering Flight Check Mode") self.GPIO_Queue.put(("GREEN","Function",(AATC_GPIO.Pattern,( [(21,1,5),(21,0,1)],)))) #Let the Thread for the GREEN LED blink on pin 21 at 0.5 Hz for 1 cycle repeatedly until stopped self.CheckForFlight() + self.D.Exit() InFlight = True else: print("Entering Run Flight Mode") self.GPIO_Queue.put(("GREEN","Function",(AATC_GPIO.Blink,(21,0.5,1,True)))) #Let the Thread for the GREEN LED blink on pin 21 at 0.5 Hz for 1 cycle repeatedly until stopped self.RunFlight() InFlight = False #Once RunFlight has completed sucessfully go back to checking for flights. Will only complete once finished, if crashes will not pass here. + self.D.Exit() + self.GPIO_Queue.put(("GREEN","Function",(AATC_GPIO.BlankFunction,()))) # Resets the green LED to be off. else: self.GPIO_Queue.put(("RED","Function",(AATC_GPIO.Blink,(11,1,10,False)))) #Let the Thread for RED LED blink on pin 11 at 1Hz 10 times and not repeat. diff --git a/AATC_GPIO.py b/AATC_GPIO.py index 55fedba..ab0431f 100644 --- a/AATC_GPIO.py +++ b/AATC_GPIO.py @@ -1,4 +1,4 @@ -import threading,multiprocessing,queue,time,random +import threading,multiprocessing,queue,time,random, sys try: import RPi.GPIO as GPIO except: @@ -11,6 +11,24 @@ ##GPIO.setup(21, GPIO.OUT) #green ##GPIO.setup(26, GPIO.IN) #button +def GPIO_Wait_Switch(pin,wait_time = 1, SWITCH_MODE= GPIO.HIGH, Indicator_Pin = False): # Will wait for pin to switch to the SWITCH_MODE setting. If not will sleep for wait_time seconds. + if "GPIO" not in sys.modules: # If does not have GPIO will automatically pass through. + GPIO.setmode(GPIO.BOARD) + GPIO.setup(pin,GPIO.IN) + + if Indicator_Pin: + GPIO_Queue = Create_Controller() + GPIO_Queue.put(("Controller","Create_Thread",("INDICATOR",))) + + while GPIO.input(pin) != SWITCH_MODE: + if Indicator_Pin: + GPIO_Queue.put(("INDICATOR","Function",(Blink,(Indicator_Pin,1/wait_time,1,False)))) # will automatically blink at a rate of 1 blink per wait_time + time.sleep(wait_time) + + else: + pass + + def GPIO_Thread(Thread_Name,GPIO_Queue): Exit = False Function = BlankFunction diff --git a/AATC_Monitor.py b/AATC_Monitor.py index cf47381..3f7f32d 100644 --- a/AATC_Monitor.py +++ b/AATC_Monitor.py @@ -28,7 +28,7 @@ def Recv(self): #Returns tuple of Sucess,Message,Data of which data may just # Sucess, Message , Data return data[0],data[1],data[2] except Exception as e: - print("Socket data recive error") + print("Socket data receive error") print(str(e)) return (False,"Conversion/Transfer Error"+str(e),[]) @@ -117,6 +117,12 @@ def GetFlightWaypointsAll(self): Sucess,Message,WaypointsAll = self.Recv() return Sucess,Message,WaypointsAll + def Exit(self): + self.Send("Exit",()) + Sucess,Message,_ = self.Recv() + self.con.close() + return Sucess,Message + diff --git a/AATC_Server_002.py b/AATC_Server_002.py index 6d7b47f..81052fe 100644 --- a/AATC_Server_002.py +++ b/AATC_Server_002.py @@ -615,7 +615,7 @@ def GetDronesAll(self,Arguments = None): ####### User ################# def GetUserID(self,Arguments): - Username = Arguements[0] + Username = Arguments[0] Sucess,Message,Data = self.DB.GetUserID(Username) return Sucess,Message,Data