示例#1
0
	def create_data(self, flags, sender_keyid, recipient_keyid, next_dh,
					counter, enc_msg, authenticator, old_mac_keys):
		self.type = "data"
		#self.vars = (
		#	("protocol_version", "short"),
		#	("message_type", "byte"),
		#	("flags", "byte"),
		#	("sender_keyid", "int"),
		#	("recipient_keyid", "int"),
		#	("next_dh", "mpi"),
		#	("counter", "ctr"),
		#	("enc_msg", "data"),
		#	("authenticator", "mac"),
		#	("old_mac_keys", "data")
		#)
		
		if ( not len(flags) == 1 ):
			raise Exception('Invalid data format: flags')
		
		if ( not len(sender_keyid) == 4 ):
			raise Exception('Invalid data format: sender_keyid')
		
		if ( not len(recipient_keyid) == 4 ):
			raise Exception('Invalid data format: recipient_keyid')
		
		if ( not _OT.check_mpi(next_dh) ):
			raise Exception('Invalid data format: next_dh')
		
		if (not len(counter) == 8 ):
			raise Exception('Invalid data format: counter')
		
		if ( not _OT.check_data(enc_msg) ):
			raise Exception('Invalid data format: enc_msg')
		
		if ( not _OT.check_mac(authenticator) ):
			raise Exception('Invalid data format: authenticator')
		
		if ( not _OT.check_data(old_mac_keys) ):
			raise Exception('Invalid data format: old_mac_keys')
		
		self.protocol_version = list(OtrConstants["version_2_bytes"])
		self.message_type = [OtrConstants["code_data"]]
		
		self.flags = flags
		self.sender_keyid = sender_keyid
		self.recipient_keyid = recipient_keyid
		self.next_dh = next_dh
		self.counter = counter
		self.enc_msg = enc_msg
		self.authenticator = authenticator
		self.old_mac_keys = old_mac_keys
		
		message_data = self.protocol_version + self.message_type + \
						flags + sender_keyid + recipient_keyid + \
						next_dh + counter + enc_msg + authenticator + \
						old_mac_keys
		self.pack_message(message_data)
		self.parsed_ok = True
		return self
示例#2
0
	def create_dh_key(self, gympi):
		self.type = "dh_key"
		
		self.protocol_version = list(OtrConstants["version_2_bytes"])
		self.message_type = [OtrConstants["code_dh_key"]]
		self.gympi = gympi
		
		if ( not _OT.check_mpi(gympi) ):
			raise Exception('Invalid data format')
		
		message_data = self.protocol_version + self.message_type + \
						self.gympi
		self.pack_message(message_data)
		self.parsed_ok = True
		return self