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
def create_dh_commit(self, enc_gxmpi_data, hash_gxmpi_data): self.type = "dh_commit" self.protocol_version = list(OtrConstants["version_2_bytes"]) self.message_type = [OtrConstants["code_dh_commit"]] self.enc_gxmpi_data = enc_gxmpi_data self.hash_gxmpi_data = hash_gxmpi_data if ( not _OT.check_data(enc_gxmpi_data) or not _OT.check_data(hash_gxmpi_data) ): raise Exception('Invalid data format') message_data = self.protocol_version + self.message_type + \ self.enc_gxmpi_data + self.hash_gxmpi_data self.pack_message(message_data) self.parsed_ok = True return self
def create_reveal_sig(self, revealed_key_data, enc_sig_data, sig_mac): self.type = "reveal_sig" self.protocol_version = list(OtrConstants["version_2_bytes"]) self.message_type = [OtrConstants["code_reveal_sig"]] self.revealed_key_data = revealed_key_data self.enc_sig_data = enc_sig_data self.sig_mac = sig_mac if ( not _OT.check_data(revealed_key_data) or not _OT.check_data(enc_sig_data) ): raise Exception('Invalid data format') if ( not _OT.check_mac(sig_mac) ): raise Exception('Invalid MAC') message_data = self.protocol_version + self.message_type + \ revealed_key_data + enc_sig_data + sig_mac self.pack_message(message_data) self.parsed_ok = True return self