Beispiel #1
0
def server():

    host = socket.gethostname()
    port = 7000

    server_socket = socket.socket()
    server_socket.bind((host, port))  # bind host address and port together
    server_socket.listen(3)
    print("...............server is listening...............")
    while True:
        conn, address = server_socket.accept()
        print("server connected to: "+ str(address))
        data=conn.recv(2048).decode()
        data = data.split("$$")
        ticket = data[0]
        autheticator = data[1]
        ticket = decryption(server_key,base64.b64decode(ticket))
        ticket = ticket.split("$$")
        key_c_v = ticket[0]

        time = decryption(key_c_v , base64.b64decode(autheticator)).split("$$")
        print(time)
        message = encryption(key_c_v,time[-1])
        conn.send(message)
        conn.close()
def connect_to_tgs(key_c_tgs, ticket):
    host = socket.gethostname()
    port = 6000  #server port
    client_socket = socket.socket()
    client_socket.connect((host, port))
    print("...............connection established................")

    id_client = "1"
    id_server = "4"
    ts3 = datetime.datetime.now()

    #create authenticator
    auth = encryption(key_c_tgs, id_client + "$$" + str(ts3))
    message = id_server + "$$" + ticket + "$$" + str(auth)
    message = message.encode()
    client_socket.send(message)
    data = client_socket.recv(2024)

    data = decryption(key_c_tgs, data)
    data = data.split("$$")
    key_c_v = data[0]
    print(key_c_v)
    ticket_v = data[-1]
    print(ticket_v)
    return key_c_v, ticket_v
Beispiel #3
0
def decryptionECB(key, ciphertext):
	cipher = tl.h2b(ciphertext[0])
	result = ""
	for x in xrange(0, (len(cipher)/64)):
		result += aes.decryption(key, cipher[(x*64):(x*64+64)])

	result = tl.unPadding(result, ciphertext[1])
	return result
Beispiel #4
0
def decryptionCBC(key,ciphertext,iv):
	hexCipher = tl.h2b(ciphertext[0])

	count = len(tl.h2b(ciphertext[0]))/64

	plain = ''
	for i in xrange(0,count,1):
		c = tl.h2b(aes.decryption(key,hexCipher[i*64:(i*64)+64]))

		p = tl.b2h(tl.xor(c,iv))
		iv = hexCipher[i*64:(i*64)+64]

		plain += p
	plain = tl.unPadding(plain, ciphertext[1])
	return plain
def connect_to_v(key_c_v, ticket):

    host = socket.gethostname()
    port = 7000  #server port
    client_socket = socket.socket()
    client_socket.connect((host, port))
    print("...............connection established................")

    authenticator, time1 = make_authenticator(key_c_v)
    authenticator = str(base64.b64encode(authenticator), "utf-8")
    message = ticket + "$$" + authenticator
    client_socket.send(message.encode())
    data = client_socket.recv(2024)
    time2 = decryption(key_c_v, data)
    print("hey:", time1)
    print(time2)
    if time1 == time2:
        print("connected to right server")
def connect_to_as():

    host = socket.gethostname()
    port = 5000  #server port
    client_socket = socket.socket()
    client_socket.connect((host, port))
    print("...............connection established................")

    id_client = "1"
    id_tgt = "3"
    time = datetime.datetime.now()
    message = id_client + "$$" + id_tgt + "$$" + str(time)
    message = message.encode()
    client_socket.send(message)
    data = client_socket.recv(2024)
    data = decryption(client_key, data)
    data = data.split("$$")
    key_c_tgs = data[0]
    print(key_c_tgs)
    ticket = data[-1]
    print(ticket)
    return key_c_tgs, ticket