Exemple #1
0
	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"
Exemple #2
0
# Create Key Pair
random_generator = Random.new().read
key = RSA.generate(1024, random_generator)
fromField = "+447872124086"

# Create stores
store = SMSSecServerDataStore("+442033229681", key.exportKey(), key.publickey().exportKey())
clientstore = SMSSecClientStore("+447872124086", "abcd1234", "442033229681", key.publickey().exportKey())

# Create detail in server store
store.addDetail("+447872124086", "abcd1234")

# Create client initiator
initiator = SMSSecInitiatorMessage(clientstore.server_telephone, clientstore.booth_telephone)
initDetails = initiator.createMessage(clientstore.server_public_key, clientstore.booth_password, 1)
clientstore.startNewSession(
    initDetails["session_id"], initDetails["iv"], initDetails["key_params"], initDetails["random_challenge"]
)

# Send message to server

# Decrypt client initiator
# Create responder
# 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(