def sendMessage(self, to_field, message_body): #try: # If sending an initiator if self.data_store.getSessionDetails(to_field) is None: # get session id session_id = self.data_store.getNewSessionID() # create init init = SMSSecInitiatorMessage(to_field, self.data_store.this_telephone) details = init.createMessage(self.data_store.getPublicKey(to_field), self.data_store.this_password, session_id) # create session self.data_store.startNewSendingSession(to_field, details["session_id"], details["iv"], details["key_params"], details["random_challenge"]) # put message on backburner self.data_store.storeMessage(to_field, message_body) # increment send count self.data_store.incrementSendSequence(to_field) # return message. return {"status": 0, "message":init} # If sending a responder elif self.data_store.getSessionDetails(to_field)["send_sequence"] == 0 and self.data_store.getSessionDetails(to_field)["receive_sequence"] == 1: # Create responder responder = SMSSecResponderMessage(to_field, self.data_store.this_telephone) details = self.data_store.getSessionDetails(to_field) responder.createMessage(details['random_challenge'], details['send_iv'], details['key']) return {"status":1, "message":responder, "random_challenge":details['random_challenge'], "iv":details['send_iv'], "key":details['key']} # If sending a message elif self.data_store.getSessionDetails(to_field)["send_sequence"] >= 1: if message_body is None and self.data_store.getSessionDetails(to_field)['stored_message'] is not None: message_body = self.data_store.getSessionDetails(to_field)['stored_message'] if message_body is not None: # Divide message divided_messages = self.divideMessage(message_body) messages = [] for message in divided_messages: # increment send count details = self.data_store.getSessionDetails(to_field) smsMessage = SMSSecSequenceMessage(to_field, self.data_store.this_telephone) smsMessage.createMessage(message, details["send_sequence"], details["send_iv"], details["key"]) messages.append({"message":smsMessage, "sequence":details["send_sequence"],"iv":details["send_iv"],"key":details["key"]}) self.data_store.incrementSendSequence(to_field) return {"status":2, "messages":messages} # return message else: print "Message is empty"
# Create session on server # Send responder to client servInitiator = SMSSecInitiatorMessage(store.server_telephone, fromField) servInitDetails = servInitiator.decrypt(initiator.message, store.getBoothPassword(fromField), store.private_key) responder = SMSSecResponderMessage(store.server_telephone, fromField) store.startNewSession( fromField, servInitDetails["session_id"], servInitDetails["iv"], servInitDetails["key_params"], servInitDetails["random_challenge"], ) details = store.getSessionDetails(fromField) responder.createMessage(details["random_challenge"], details["send_iv"], details["key"]) store.incrementSendSequence(fromField) # Decrypt responder clientResp = SMSSecResponderMessage(clientstore.server_telephone, clientstore.booth_telephone) curSesh = clientstore.getCurrentSessionDetails() message = SMSSecSequenceMessage(clientstore.server_telephone, clientstore.booth_telephone) if clientResp.decrypt(responder.message, curSesh["random_challenge"], curSesh["receive_iv"], curSesh["key"]): clientstore.incrementRecieveSequence() message = SMSSecSequenceMessage(clientstore.server_telephone, clientstore.booth_telephone) details = clientstore.getCurrentSessionDetails() # Encrypt first message message.createMessage( "candidates:{candidate: {name1:'ben' name2:'kingsley' party:'Pirate Party'},candidate: {name1:'ben' name2:'kingsley' party:'Pirate Party'}}", details["send_sequence"], details["send_iv"],