def keys_and_save(user_list): keyGen = kg.RSAEncryption() publickey, privatekey = keyGen.generate_keys() db = connect_to_DB() userid, username = save_user_pass(user_list,db) save_pub_priv(userid,publickey,privatekey,db) save_pub_key(userid,username,publickey,db) db.commit()
def verify_signature(raw_parameters, signature, username): key = fetch_specific_attribs_record([ 'public_key', ], 'users', "where username = '******'".format(username)) data = ''.join([str(x) for x in raw_parameters]) keyGen = kg.RSAEncryption() result = keyGen.verifying_signature(data, signature, key['public_key']) return result
def create_signature(raw_parameters, username): key = fetch_specific_attribs_record([ 'private_key', ], 'users', "where username = '******'".format(username)) data = ''.join([str(x) for x in raw_parameters]) keyGen = kg.RSAEncryption() signature = keyGen.generate_signature(data, key['private_key']) return signature
def send_message (message, realUser, claimingUser): if claimingUser == None: whoPosted = realUser else: whoPosted = claimingUser keyGen = kg.RSAEncryption() privatekey = get_privatekey(realUser) signature = keyGen.generate_signature(message,privatekey) save_secure_message(message,signature,whoPosted)
def edit_message(messageid,message,username): keyGen = kg.RSAEncryption() privatekey = get_privatekey(username) signature = keyGen.generate_signature(message, privatekey) db = connect_to_DB() sql = "UPDATE messages SET message = (%s), user = (%s), signature = (%s) WHERE mid = (%s)" parameters =(message,username,signature,messageid) db.insert(sql,parameters) db.commit()
def check_signature(messageList): resultList = [] keyGen = kg.RSAEncryption() publickeyDict = fetch_users_public()[0] for elements in messageList: sender = elements[1] publickey = publickeyDict[sender] message = elements [0] signature = elements[2] messageid = elements[3] authenticity = keyGen.verifying_signature(message,signature,publickey) resultList.append((message,sender,authenticity,messageid)) return resultList
def define_user(username, latitude, longitude, role): isadmin = 1 if role == 'admin' else 0 user_attribs = [x for x in table_attribs('users')] user_id = get_nextval_counter('user_id') sql = "INSERT INTO users VALUES (%s)" % ",".join( "%s" for i in range(len(user_attribs))) keyGen = kg.RSAEncryption() pub_key, priv_key = keyGen.generate_keys() parameters = [ user_id, username, priv_key, pub_key, latitude, longitude, isadmin ] db.insert(sql, parameters) db.commit() print 'The user {0} with {1} role added to the database'.format( username, role)