Esempio n. 1
0
    def sendPayload(self, payload):
        try:
            print("App 1 connecting on port 8080 using TLS")
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            ssl_sock = ssl.wrap_socket(s,
                                       ca_certs="team1Server.crt",
                                       cert_reqs=ssl.CERT_REQUIRED)
            ssl_sock.connect(('localhost', 8080))
            ssl_sock.sendall(payload)
            print("JSON payload sent to _______ using TLS")
            ssl_sock.close()
            print(ssl_sock.cipher())
            # Logging
            MongoDB.mongoInstance("Test", "Sent to app2")
            return True

        except Exception as e:
            client = MongoClient('localhost', 27017)
            db = client.Team1
            collection = db.logs

            print(e)

            #Logging
            MongoDB.mongoInstance("Test", "Failed to send to app2")
            return False
Esempio n. 2
0
    def readAndDecodeJSON(self):
        try:
            with urllib.request.urlopen(self.url + self.param) as payload:
                jsonPayload = json.loads(payload.read().decode('utf-8'))
                # Log to App5 Success

                MongoDB.mongoInstance("Test", "Got Payload")
                return jsonPayload

        except Exception as e:
            print("error: %s" % e)
            # Log to App5 Failure
            MongoDB.mongoInstance("Test", "Failed to get Payload")
Esempio n. 3
0
    def savePayload(self,payload):
        try:
            with open('jsonPayload.txt', 'w') as outFile:
                outFile.write(json.dumps(payload))
                #Logging
                MongoDB.mongoInstance("test","Saved Payload")
                return True

        except Exception as e:
            print("Error: %s" % e)

            #Logging
            MongoDB.mongoInstance("test","Failed to Save Payload")


            return False
Esempio n. 4
0
    def tls_connection(self):
        try:
            # Receive the secure payload using TLS
            print("App 2 connecting on port 8080 using SSL (TLS)")
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s2.connect(('localhost', 9999))
            s2.send(b'App 2 got connection from app 1')
            s2.close()
            ssl_socket = ssl.wrap_socket(s,
                                         server_side=True,
                                         certfile="team1tls.crt",
                                         keyfile="team1tls.key")

            # Listen on port 8080
            ssl_socket.bind(('localhost', 8080))
            ssl_socket.listen(5)
            mongoDB = MongoDB()
            condition = True
            while condition:
                print("Accept connections from outside")
                (clientSocket, address) = ssl_socket.accept()
                #print(clientSocket.recv(1024))
                dataRecieved = clientSocket.recv(1024)
                print(dataRecieved)
                mongoDB.mongoInstance("Test", "Got Connection")
                #if(clientSocket.recv(1024) is None):
                if (dataRecieved is None):
                    print("data is none")
                    #condition = False
                    #print(dataRecieved)
                    #hash_payload_hmac(dataRecieved)
                else:
                    condition = False
                    return dataRecieved
        except Exception as e:
            print(e)
Esempio n. 5
0
 def testInsertOne(self):
     MongoDB.mongoInstance("Unit test", "testing unit")
     self.assertEqual(("Unit test", "testing unit"),
                      collection.find({"Type": "Unit test"}))