Example #1
0
	def respond_to_data(self, msg):
		logging.debug("Responding to Data")
		if self.auth.message_state_is("MSGSTATE_ENCRYPTED"):
			# Verify the info in the message
			
			dec_msg = self.auth.dh_keys.receive_data_message(msg)
			logging.debug( dec_msg )
			if len(dec_msg) > 0:
				logging.debug( "DECRYPTED: "+_OT.bytes_to_string(dec_msg) )
				if self.echolalic:
					msg = self.message_factory().make_jabber_message(_OT.bytes_to_string(dec_msg))
					self.process_outgoing(msg)
			# If verification succeeds:
			
			# Decrypt the message and display the human-readable part (if non-empty) to the user.
			
			# Update the D-H encryption keys, if necessary.
			
			# If you have not sent a message to this correspondent in some (configurable) time, 
			# send a "heartbeat" message, consisting of a Data Message encoding an empty plaintext. 
			# The heartbeat message should have the IGNORE_UNREADABLE flag set.
			
			# If the received message contains a TLV type 1, forget all encryption keys 
			# for this correspondent, and transition msgstate to MSGSTATE_FINISHED.
			
		else:
			# Inform the user that an unreadable encrypted message was received, and reply with an Error Message.
			# TODO check for heartbeat messages
			
			logging.debug( "Not ready!" )
			pass
			
		return None
Example #2
0
 def sign(self, data):
     if self.replay.can_replay("k"):
         k = self.replay.data["k"]
     else:
         k = random.SystemRandom().randint(2, self.my_private_key.q - 1)
     r, s = self.my_private_key.sign(_OT.bytes_to_string(data), k)
     ra = _OT.zero_pad(_OT.int_to_bytes(r), self.my_q_len)
     sa = _OT.zero_pad(_OT.int_to_bytes(s), self.my_q_len)
     return ra + sa
Example #3
0
 def verify(key, data, r, s):
     return key.verify(_OT.bytes_to_string(data), (r, s))
Example #4
0
	def get_sha1_bytes(data):
		return _OT.string_to_bytes(SHA.new(_OT.bytes_to_string(data)).digest())
Example #5
0
	def get_sha1_hmac(key, data):
		return _OT.string_to_bytes(HMAC.new(_OT.bytes_to_string(key), _OT.bytes_to_string(data), SHA).digest())
Example #6
0
		def __call__(self):
			c = _OT.int_to_bytes(self.count)
			self.count += 1
			return _OT.bytes_to_string(_OT.zero_pad(c, 16))