def getContent(self): """ """ content = ["%s: %s" % (k, v) for k,v in self.options.iteritems()] if self.description: description=self.description.replace("\n","\n ") content.append('Description: ') content.append(' %s' % description) if self.changes: changes=self.changes.replace("\n","\n ") content.append('Changes: ') content.append(' %s' % changes) if self.ChangedBy: content.append("Changed-By: %s" % self.ChangedBy) content.append('Files:') for onefile in self.files: print onefile md5=md5hash.md5sum(onefile) size=os.stat(onefile).st_size.__str__() content.append(' ' + md5 + ' ' + size + ' ' + self.category +' '+self.repository+' '+os.path.basename(onefile)) return "\n".join(content) + "\n\n"
def _getContent(self): """ """ content = ["%s: %s" % (k, v) for k,v in self.options.iteritems()] #if self.description: # self.description=self.description.replace("\n","\n ") # content.append("Description: %s" % self.description) #if self.changes: # self.changes=self.changes.replace("\n","\n ") # content.append("Changes: %s" % self.changes) if self.BuildDepends: content.append("Build-Depends: %s" % self.BuildDepends) if self.StandardsVersion: content.append("Standards-Version: %s" % self.StandardsVersion) content.append('Files:') for onefile in self.files: print onefile md5=md5hash.md5sum(onefile) size=os.stat(onefile).st_size.__str__() content.append(' '+md5 + ' ' + size +' '+os.path.basename(onefile)) print "\n".join(content)+"\n" return "\n".join(content)+"\n\n"
def turn_file_to_hash(loc): wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) number_of_customers = sheet.nrows workbook = xlsxwriter.Workbook('hased_customers_data.xlsx') worksheet = workbook.add_worksheet() for i in range(0, number_of_customers): " cp1251 stands for standard utf-8 encoding in base64" message = md5sum(str.encode(sheet.cell_value(i, 0))) worksheet.write(i, 0, message) workbook.close() return workbook.filename
def _getContent(self): """ """ content = ["%s: %s" % (k, v) for k,v in self.options.iteritems()] if self.BuildDepends: content.append("Build-Depends: %s" % self.BuildDepends) if self.StandardsVersion: content.append("Standards-Version: %s" % self.StandardsVersion) content.append('Files:') for onefile in self.files: md5=md5hash.md5sum(onefile) size=os.stat(onefile).st_size.__str__() content.append(' '+md5 + ' ' + size +' '+os.path.basename(onefile)) return "\n".join(content)+"\n\n"
def get_user_data(cursor): """ we get info from user hash user password and save in db,also we use an instance of diffie-hellman algorithm to provide user with public_key and private_key for later encryption/decryption purpose then we save data in our sqlite3 table inside the server. :param cursor: cursor is for the sqlite3 database :return: None """ d1 = DiffieHellman() name_of_user = input("Please enter your name user :\n ") password_of_user = input("Please enter your password user :\n ") hashed_password = md5sum(str.encode(password_of_user)) private_key = d1.get_private_key() private_key = str(private_key) public_key = d1.gen_public_key() public_key = str(public_key).encode('ascii') login_amount = 0 insert_to_data_base(name_of_user, hashed_password, public_key, private_key, cursor, login_amount)
def getContent(self): """ """ content = ["%s: %s" % (k, v) for k, v in self.options.iteritems()] if self.description: description = self.description.replace("\n", "\n ") content.append("Description: ") content.append(" %s" % description) if self.changes: # create version header name = self.options["Source"] version = self.options["Version"] urgency = self.options["Urgency"] header = "%s (%s); urgency=%s" % (name, version, urgency) # normalize change line formatting changes = self.changes changes = changes.replace("\n ", "\n ") changes = " %s" % changes # append changes to header changes = "%s\n.\n%s" % (header, changes) # append to the rest content.append("Changes:") content.append("%s" % changes) if self.ChangedBy: content.append("Changed-By: %s" % self.ChangedBy) content.append("Files:") for onefile in self.files: print onefile md5 = md5hash.md5sum(onefile) size = os.stat(onefile).st_size.__str__() content.append( " " + md5 + " " + size + " " + self.category + " " + self.repository + " " + os.path.basename(onefile) ) return "\n".join(content) + "\n\n"
def enter_system(): """ this function is a login method,after succsesful login there is a public key exchange between another user that is also verified that he is inside the system(a user aswell) then we exchange public_keys from 2 users of the system and create the shared_key from diffie-hellman algorithm using the other user public_key and our own private_key to get shared_key whice we encrypt data using rc6 algorithm with(it is the secret key). how do we prevent man-in-the-middle attack? out network exchange is only between public_keys from each user we send user_a the public_key of user_b and the other way around ,there is no private_key transfer/exchange whatsoever,our private key is randomlly generated then it is digested to perform a digital signiture then after the shared_key is created we hash it and compare it with the shared_key of the other user if they are similar we send encrpyed_file and the user,uses his shared_key to decrypt the file. betfore the decryption is made first we use a digital signature to authenticate the file using hash comparison Diffie Hellman uses a private-public key pair to establish a shared secret, typically a symmetric key. DH is not a symmetric algorithm – it is an asymmetric algorithm used to establish a shared secret for a symmetric key algorithm. :return: """ name_of_user = input("Login ->Enter your user name :\n ") password_of_user = input("Please enter your password user :\n ") hashed_password = md5sum(str.encode(password_of_user)) try: connection = sqlite3.connect("User.db") cursor = connection.cursor() cursor.execute( "SELECT name,password FROM User WHERE name=? and password=?", (name_of_user, hashed_password)) result = cursor.fetchone() if result: print("System Access Granted\n") answer = get_yes_or_no_answer( "Would you like to view customers data?(yes/no)\n") if answer == "yes": cursor.execute( "SELECT public_key,private_key,login_amount FROM User WHERE name=? and password=?", (name_of_user, hashed_password)) result = cursor.fetchone() if int(result[2] ) >= 5: # change user keys if overused the same keys AUTDb.replaceKeys(name_of_user) AUTDb.update_user_login(name_of_user) name_of_second_user = input( "select name of second user(in db) for authentication\n") cursor.execute( "SELECT name,public_key,private_key,login_amount FROM User WHERE name=?", (name_of_second_user, )) result2 = cursor.fetchone() if result2: if int( result2[3] ) >= 5: # change user keys if overused the same keys AUTDb.replaceKeys(result2[0]) AUTDb.update_user_login(name_of_second_user) sharedkey_user_one = DiffieHellman().gen_shared_key( int(result2[1]), int(result[1])) encrypted_file, hashed_encrypted_file, signed_file_hex = encrypt_customers_data( sharedkey_user_one) sign = SAVM(signed_file_hex) sign.sign_message() sharedkey_user_two = DiffieHellman().gen_shared_key( int(result[0]), int(result2[2])) if sharedkey_user_one == sharedkey_user_two: decrypt_customers_data(sharedkey_user_two, encrypted_file, hashed_encrypted_file) else: print("User does not exist in db") else: print("Wrong information") except sqlite3.Error as error: print("Failed to insert data into sqlite table", error) finally: if (connection): connection.close()