예제 #1
0
파일: TGS.py 프로젝트: xiyiyia/vv-yc-zn
def TGS():
    Key_tgs = 'cdefghi'
    # 从Client接收message3
    # 从Client接收lenofticket(str型)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    localhost = socket.gethostname()
    port = 10001
    s.bind(("localhost", port))
    s.listen(5)

    cs, address = s.accept()
    print("got connection : ", address)

    message3 = cs.recv(1024)
    message3 = message3.decode()
    print("messge3 = ", message3)
    print("1")
    lenofticket = cs.recv(1024)
    print("2")
    lenofticket = lenofticket.decode()
    print("len = ", lenofticket)

    #message3 = '192.168.43.204*928F4FE9A2F3D3CED3D397336CC8B2EEEC307CAEB9A0471F8127A8CFD08E295189D108A74C4DD9D61666640358B672B03E3CE0B836AE132C175F44F4F1488D50072D6EE80E2A596368ED77CEC893F50B********6662F19DEF926DBD87A95C21E5C4C0D3D3D397336CC8B2EEFF08097D8012F6E2A02087B20DB77FE24536257798F303C3E9AB683C1432B9B0'
    lenofmessage = len(message3)
    # lenofticket = '168'
    ip_Server = message3[0:15]
    ip_Server = tostr.takeout(ip_Server)

    ticket_TGS = message3[15:int(lenofticket) + 15]
    ticket_TGS = tostr.takeout(ticket_TGS)
    ticket_TGS = des_de.test(ticket_TGS, Key_tgs)
    print("ticket_TGS = ", ticket_TGS)

    Key_ctgs_fromclient = ticket_TGS[0:7]
    ip_Client_fromclient = ticket_TGS[7:22]
    ip_Client_fromclient = tostr.takeout(ip_Client_fromclient)
    print("ip_Client_fromclient = ", ip_Client_fromclient)

    AD_Client_fromclient = ticket_TGS[22:37]
    AD_Client_fromclient = tostr.takeout(AD_Client_fromclient)
    print("AD_Client_fromclient = ", AD_Client_fromclient)

    ip_TGS_fromclient = ticket_TGS[37:52]
    ip_TGS_fromclient = tostr.takeout(ip_TGS_fromclient)
    print("ip_TGS_fromclient = ", ip_TGS_fromclient)

    ts2_fromclient = ticket_TGS[52:70]
    ts2_fromclient = tostr.takeout(ts2_fromclient)
    print("ts2_fromclient = ", ts2_fromclient)

    lifetime2_fromclient = ticket_TGS[70:78]
    lifetime2_fromclient = tostr.takeout_0(lifetime2_fromclient)
    print("lifetime2 = ", lifetime2_fromclient)

    Authencator_client = message3[int(lenofticket) + 15:lenofmessage]
    Authencator_client = tostr.takeout(Authencator_client)
    Authencator_client = des_de.test(Authencator_client, Key_ctgs_fromclient)
    print("Authencator_c = ", Authencator_client)

    ip_Client_fromclient2 = Authencator_client[0:15]
    ip_Client_fromclient2 = tostr.takeout(ip_Client_fromclient2)
    print("ip_Client_fromclient2 = ", ip_Client_fromclient2)

    AD_Client_fromclient2 = Authencator_client[15:30]
    AD_Client_fromclient2 = tostr.takeout(AD_Client_fromclient2)
    print("AD_Client_fromclient2 = ", AD_Client_fromclient2)

    ts3_fromclient = Authencator_client[30:48]
    ts3_fromclient = tostr.takeout(ts3_fromclient)
    print("ts3 = ", ts3_fromclient)

    message4 = TGS_to_Client(ip_Client_fromclient, ip_Server,
                             Key_ctgs_fromclient)
    print("message4 = ", message4)

    cs.send(message4.encode())

    cs.close()
예제 #2
0
파일: Server.py 프로젝트: xiyiyia/vv-yc-zn
def SERVER():
    Key_server = 'bcdefgh'
    #message5 = '928F4FE9A2F3D3CED3D397336CC8B2EEEC307CAEB9A0471F8127A8CFD08E295189D108A74C4DD9D61666640358B672B00FBB826366B28F2BBC712109B4856D6EA4910B74D4E183C668ED77CEC893F50B9B2431C2F876C9CA2DDB21338EE8003F4421A988FA40BBB991D4E08E7FA7594CF47D82B5A28666B16460CABC8840EF21E9AB683C1432B9B0'
    #lenofticket_server = '160'
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    localhost = socket.gethostname()
    port = 10002
    s.bind(("localhost", port))
    s.listen(5)

    cs, address = s.accept()
    print("got connection : ", address)

    message5 = cs.recv(1024)
    message5 = message5.decode()
    print("messge5 = ", message5)
    lenofticket = cs.recv(1024)
    lenofticket_server = lenofticket.decode()
    print("len = ", lenofticket)

    ticket_server = message5[0:int(lenofticket_server)]
    ticket_server = des_de.test(ticket_server, Key_server)
    ticket_server = tostr.takeout(ticket_server)
    print("ticket_server = ", ticket_server)

    Key_cv = ticket_server[0:7]
    print("Key_cv = ", Key_cv)
    ip_Client = ticket_server[7:22]
    ip_Client = tostr.takeout(ip_Client)
    print("ip_Client = ", ip_Client)

    AD_client = ticket_server[22:37]
    AD_client = tostr.takeout(AD_client)
    print("AD_client = ", AD_client)

    ip_Server = ticket_server[37:52]
    ip_Server = tostr.takeout(ip_Server)
    print("ip_Server = ", ip_Server)

    ts4 = ticket_server[52:70]
    ts4 = tostr.takeout(ts4)
    print("ts4 = ", ts4)

    lifetime4 = ticket_server[70:78]
    lifetime4 = tostr.takeout_0(lifetime4)
    print("lifetime4 = ", lifetime4)

    Authencator_c = message5[int(lenofticket_server):len(message5)]
    Authencator_c = des_de.test(Authencator_c, Key_cv)
    print("Authencator_c = ", Authencator_c)

    ip_Client_fromAu = Authencator_c[0:15]
    ip_Client_fromAu = tostr.takeout(ip_Client_fromAu)
    print("ip_Client_fromAu = ", ip_Client_fromAu)

    AD_client_fromAu = Authencator_c[15:30]
    AD_client_fromAu = tostr.takeout(AD_client_fromAu)
    print("AD_client_fromAu = ", AD_client_fromAu)

    ts5 = Authencator_c[30:]
    ts5 = tostr.takeout(ts5)
    ts5 = float(ts5)
    print("ts5 = ", ts5)

    message6 = Server_to_Client(ts5, Key_cv)
    print("message6 = ", message6)

    cs.send(message6.encode())
    cs.close()
예제 #3
0
파일: Client.py 프로젝트: xiyiyia/vv-yc-zn
def CLIENT():
    Key_c = 'abcdefg'  # Key_Client
    message1 = Client_to_AS()
    localhost = socket.gethostname()
    port_AS = 10000
    port_TGS = 10001
    port_Server = 10002
    print("mesage1 = ", message1)
    """s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect((localhost,port_AS))
    s.send(message1.encode('utf-8'))
    message2 = s.recv(1024)
    message2 = message2.decode()
    print("message2 = ",message2)
    s.close()"""

    message2 = 'D3A41D74DCE667CAD3D397336CC8B2EE06A83080661277324F876410EE84ABECC6B0D269AD00758D98B3A781D438F4A6D937FF4846783646DCB15C599E2C137B2D05A915E1BC78D60714C9C1477EC21E3548C7C732258EABAFE786C2F56DEEB6F81F416ADB8E3CFBFDFEBAC756938898C4C22A9EAEAE084BD6A7A513DDF0B8D0F4E418C00D3AE157D17B2A230E64D2A84AA3FCDF931C1BC5D1250522F2248F8D4816C86CB5DAEB1FEF5C3DB8F84256B4E26239A103B0D406D28D90703D277F2DAD0E6439F7333D2E47AAA1EB7B5E0CDCE9AB683C1432B9B0'
    message2 = des_de.test(message2, Key_c)
    print("message2 = ", message2)
    Key_ctgs = message2[0:7]
    print("Key_ctgs = ", Key_ctgs)

    ip_TGS_fromAS = message2[7:22]
    ip_TGS_fromAS = tostr.takeout(ip_TGS_fromAS)
    print("ip_TGS = ", ip_TGS_fromAS)

    ts2 = message2[22:40]
    ts2 = tostr.takeout(ts2)
    ts2 = float(ts2)
    print("ts2 = ", ts2)

    lifetime2 = message2[40:48]
    lifetime2 = tostr.takeout_0(lifetime2)
    print("lifetime2 = ", lifetime2)

    ticket_TGS = message2[48:]
    print("ticket_TGS = ", ticket_TGS)
    # 给TGS发送报文

    message3, lenofticket_tgs = Client_to_TGS(ticket_TGS, Key_ctgs)
    print("message3 = ", message3)
    print("lenofticket = ", lenofticket_tgs)
    # 发送报文到TGS,再把lenofticket也发送过去
    """tgs = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    print("1")
    tgs.connect(("localhost", port_TGS))
    print("2")
    tgs.send(message3.encode('utf-8'))
    print("3")
    time.sleep(1)
    tgs.send(lenofticket_tgs.encode('utf-8'))
    message4 = tgs.recv(1024)
    message4 = message4.decode()
    print("message4 = ", message4)
    tgs.close()"""
    # 从TGS接收到message4
    message4 = '49A728EEEC2411B0D76FA69341FB845BEA16784472B24B6150E3E1170BF397C17C358F1F52DA4E7A33575AC1B0E26CD9BDF61603A6079C03648F48FD5D77180D5A7A15C1AA4D2F37BBE8E0DA85F4272C8C9AA4474D1512E35BE1F8CAF1CF1F068C29AD49EB7340CDA749078B3FFF743630CF7A311678C55F65197A570A5E4DA5F7242F37BD68F4A85DCED3BFB43AA654A51CD2E64D6242A6596922B1756A635313E24EB0456C244FADEDD8DA50377DF567994303910A8CA6CC130C743E83F60867D77BE9F9CC2B0E7358F0ED7796932F'
    message4 = des_de.test(message4, Key_ctgs)
    message4 = tostr.takeout(message4)
    print("message4 = ", message4)
    lenofmessage4 = len(message4)
    Key_cv = message4[0:7]
    print("Key_cv = ", Key_cv)

    ip_Server = message4[7:22]
    ip_Server = tostr.takeout(ip_Server)
    print("ip_Server = ", ip_Server)

    ts4 = message4[22:40]
    ts4 = tostr.takeout(ts4)
    print("ts4 = ", ts4)

    ticket_Server = message4[40:lenofmessage4]

    print("ticket_Server = ", ticket_Server)

    message5, lenofticket_server, ts5 = Client_to_Server(ticket_Server, Key_cv)
    lenofticket_server = str(lenofticket_server)
    ts5 = tostr.takeout(ts5)
    ts5 = float(ts5)
    print("message5 = ", message5)
    print("lenofticket_server = ", lenofticket_server)
    print("ts5 = ", ts5)

    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.connect(("localhost", port_Server))
    server.send(message5.encode('utf-8'))
    time.sleep(1)
    server.send(lenofticket_server.encode('utf-8'))
    message6 = server.recv(1024)
    message6 = message6.decode()
    print("message6 = ", message6)
    server.close()
    message6 = des_de.test(message6, Key_cv)
    ts6 = tostr.takeout(message6)
    ts6 = float(ts6)
    print("ts6 = ", ts6)

    if 1 == ts6 - ts5:
        print("Get server authentication!!!")
    else:
        print("The authentication of server is wrong!!!")