コード例 #1
0
ファイル: server.py プロジェクト: Kellonius/swdv-660-week-7
print('Socket is listening')

while 1:
    conn, addr = s.accept()

    with conn:
        print('Connected by', addr)
        while True:
            data = conn.recv(1024)
            if not data:
                break
            stringData = data.decode('utf-8')
            print('Server Received: ', stringData)

            if validated == False:
                print('Server Translated: ', getKey(stringData, False))
                response = validateAuthenticity(stringData)
                if response == "client.py":
                    print('Authenticated: ', response)
                    print('Server Sending: ssl certificate')
                    conn.send(getKey("I am a cert", True).encode('utf-8'))
                    validated = True
                else:
                    print('Error: Unknown server certificate received!')
                    print('Sending Goodbye and closing connection')
                    conn.send("Goodbye".encode('utf-8'))
            elif keySent == False:
                key = getKey(stringData, False, getPublicKey())
                print('Server Received: Private session key, ', key)
                print('Server Sending: Key acknowledgement')
                conn.sendall(
コード例 #2
0
print("Client sent Hello")
s.send(publicKey)
print("Client Received ")
status = s.recv(1024)
print(status)
hash_object = hashlib.sha1(publicKey)
hex_digest = hash_object.hexdigest()
if status == b'YES':
    s.send(str.encode(hex_digest))

    #Connection session key
    data_key = s.recv(1024)
    print("Received {0}".format(data_key))
    encrypted_key = eval(data_key.decode("utf-8"))
    decrypt = certificateAuthority.getKey().decrypt(encrypted_key)
    # hashing sha1
    en_object = hashlib.sha1(decrypt)
    en_digest = en_object.hexdigest()
    print("\n-----ENCRYPTED PUBLIC KEY AND SESSION KEY FROM SERVER-----")
    print(data_key)
    print("\n-----DECRYPTED SESSION KEY-----")
    print(en_digest)
    print("\n-----HANDSHAKE COMPLETE-----\n")
    alais = "\nServer Client Https Secured Connection check -> "

    while True:
        thread_send = threading.Thread(target=send,
                                       args=("------Sending Message------",
                                             alais, en_digest))
        thread_recv = threading.Thread(target=recv,
コード例 #3
0
ファイル: client.py プロジェクト: jaredwheet/660-Week7
from certificateAuthority import getKey, validateAuthenticity, getPublicKey

  
# Create a socket object 
s = socket.socket()          
  
# Define the port on which you want to connect 
port = 9500 
key = random.randint(0,9)              
  
# connect to the server on local computer 
# s.connect(('127.0.0.1', port)) 
  
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect(('127.0.0.1', port))
    s.sendall(getKey('Hello World', True).encode('utf-8'))
    data = s.recv(1024)
    stringData = data.decode('utf-8')
    print('Client Received Certificate: ', stringData)

    response = validateAuthenticity(stringData)
    if response == 'server.py':
        print('Authenticated: ', response)
    else:
        print('Error: Unknown server certificate received!')
    
    s.sendall(getKey(str(key), True, getPublicKey()).encode('utf-8'))
    print('Sending: Private Session Key')
    data = s.recv(1024)
    print('Received: ', getKey(data.decode('utf-8'), False, key))