예제 #1
0
파일: client.py 프로젝트: zezo010/IoT-IDS
def on_message(data):
    keys = db.getKeys()
    data['status'] = func.decrypt(keys['privKey'], unhexlify(data['status']))
    data['time'] = func.decrypt(keys['privKey'], unhexlify(data['time']))
    #sio.emit('my response', {'response': 'my response'})
    db.addAuth(data['status'], float(time.time() - float(data['time'])))
    l.warning('message received with {0}'.format(data))
예제 #2
0
def auth(sid, data):
    # decrypting data
    keys = db.getKeys()
    data['status'] = func.decrypt(keys['privKey'], unhexlify(data['status']))
    data['time'] = func.decrypt(keys['privKey'], unhexlify(data['time']))

    # update status
    db.updateStatus(data['devId'], data['status'])

    # encrypting data
    deviceInfo = db.getDeviceInfo(str(data['devId']))
    data['status'] = hexlify(
        func.encrypt(str(deviceInfo['pubKey']), data['status']))
    data['time'] = hexlify(
        func.encrypt(str(deviceInfo['pubKey']), data['time']))

    sio.emit(str(data['devId']), data)
예제 #3
0
def main():
    # curr_path = os.path.abspath('main.py')[:-7]
    # login = getpass.getuser()
    # hostname = GetComputerName()
    # winpath = os.environ['WINDIR']
    # sysfilespath = os.environ['WINDIR'] + "\\System32\\"
    # width = GetSystemMetrics(0)
    # size, device = get_drive_details(curr_path)
    # keyboard_type = get_keyboard_details()
    # info = "Login {}, Hostname {}, Winpath {}, Sysfilespath {}, Monitorwidth {}, Drivesize {}, Drivedevices {}, Keyboardtype {}".format(login, hostname, winpath, sysfilespath, width, size, device, keyboard_type)
    # hash_info = SHA256.new(data=info.encode())
    # f = open('{}mykey.pem'.format(curr_path), 'rb')
    # pubkey = RSA.import_key(f.read())
    # signature = get_reg('Signature')
    # try:
    #     pkcs1_15.new(pubkey).verify(hash_info, signature)
    # except ValueError:
    #     print("Signature wasn't verified")
    #     exit()
    # print("Success")
    func.createPassFile()
    func.decrypt(r'D:\passfile')
    while True:
        print("1 - SignIn")
        print("2 - SignIn as ADMIN")
        print("3 - Info")
        print("4 - Exit")
        answ = 0
        answ = int(input())
        if answ == 1:
            flag = 1
            login = str(input("Type your login: "******"Your account is blocked")
                            flag = -1
                            break
                        else:
                            flag = 1
                            break
                if flag == 0:
                    print("No such username")
                    print("Enter 0 to exit")
                    login = input("Type your login: "******"0":
                        break
                else:
                    break
            if flag <= 0:
                break
            attempts = 1
            while True:
                if attempts > 3:
                    break
                elif 4 > attempts > 0:
                    password = input("Type your password: "******"Incorrect password")
                                print("You have {} more attempts".format(
                                    3 - attempts))
                                attempts += 1
                                continue
                elif attempts == 0:
                    break
            if attempts < 4:
                print("1 - Change password")
                print("2 - Exit")
                answ2 = 0
                answ2 = int(input())
                if answ2 == 1:
                    password = input("Type your current password: "******"Type new password: "******"0":
                                        break
                                    if u[4]:
                                        if func.verifyPassword(password):
                                            password2 = input(
                                                "Retype your new password: "******"Password has changed")
                                                break
                                            else:
                                                print(
                                                    "Password wasn't confirmed"
                                                )
                                                break
                                        else:
                                            print("Enter 0 to exit")
                                            continue
                                    else:
                                        password2 = input(
                                            "Retype your new password: "******"Password has changed")
                                            break
                                        else:
                                            print("Password wasn't confirmed")
                                            break
                            else:
                                print("Incorrect password")
                                break
                elif answ2 == 2:
                    break
                else:
                    print("You haven`t chosen any option")
                    break
            else:
                break
            break
        if answ == 2:
            flag = 1
            login = input("Type your login: "******"ADMIN":
                    print("Only for admin")
                    print("Enter 0 to exit")
                    login = input("Type your login: "******"0":
                        flag = 0
                        break
                else:
                    break
            if flag == 0:
                break
            attempts = 1
            while True:
                if 4 > attempts:
                    password = input("Type your password: "******"Incorrect password")
                        print("You have {} more attempts".format(3 - attempts))
                        attempts += 1
                        continue
                else:
                    flag = 0
                    break
            if flag == 0:
                break
            while True:
                print("1 - Change password")
                print("2 - List of users")
                print("3 - New user")
                print("4 - Block user")
                print("5 - Limit/unlimit user`s password")
                print("6 - Exit")
                answ3 = int(input())
                if answ3 == 1:
                    password = input("Type your current password: "******"Type your new password: "******"Retype your new password: "******"Password has changed")
                                    break
                                else:
                                    print("Password wasn't confirmed")
                                    break
                            else:
                                break
                        else:
                            password2 = input("Retype your new password: "******"Password has changed")
                                break
                            else:
                                print("Password wasn't confirmed")
                                break
                if answ3 == 1:
                    password = input("Type your current password: "******"Enter id: ")
                    username = input("Enter username: "******"Enter 1 if blocked, 0 if not: ")
                    islimited = input(
                        "Enter 1 if password is limited, 0 if not: ")
                    usr = [id, username, '', isblocked, islimited]
                    func.adminfunc.addUser(usr)
                    continue
                elif answ3 == 4:
                    username = input("Enter username: "******"If you want to set the limit, enter 1, enter 0 if not: "
                    )
                    username = input("Enter username: "******"Chose one option")
            break
        elif answ == 3:
            print("Zakhariash Kseniia")
            print("Upper and lowercase letters and numbers")
            continue
        elif answ == 4:
            break
        else:
            print("Chose one option")
        break
    func.encrypt(r'D:\passfile')
예제 #4
0
import socket
import func

HOST = ''              # Endereco IP do Servidor
PORT = 5000            # Porta que o Servidor esta
tcpServidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
orig = (HOST, PORT)
tcpServidor.bind(orig)
tcpServidor.listen(1)
encriptada = ''
while True:
    con, cliente = tcpServidor.accept()
    print 'Conectado por', cliente
    while True:	
		encriptada = con.recv(1024)
		if not encriptada: break
		print cliente, encriptada
		key = con.recv(1024)
		print cliente, key
		#original = func.decrypt(encriptada,int(key)) # para cifra de ceasar
		original = func.decrypt(encriptada,int(key)) # para cifra de transposicao
		print 'Original: ', original
		#con.send('Aguardando a chave...\n')
		#func.searchKey(original,encriptada)
		f = open("msgServidor.txt", "a") #Abre arquivo para gravar
		f.writelines(original) #Grava a mensagem original enviada pelo cliente no arquivo
		f.writelines("\n")
    print 'Finalizando conexao do cliente', cliente
    con.close()
예제 #5
0
from func import encrypt, decrypt

if __name__ == '__main__':
    message = str(input("Message:"))
    [code, cards] = encrypt(message)
    print("Coded message: ", code)
    decode = decrypt(code, cards)
    print("Your original message:", decode)