コード例 #1
0
ファイル: client.py プロジェクト: FrankRays/NetManagement
import socket
import symmetric
import Asymmetric
s = socket.socket()
host = socket.gethostname()
port = 15823
s.connect((host, port))
print s.recv(1024)
servers_rsa_public_key_exported = s.recv(2048)
servers_rsa_public_key = Asymmetric.import_key(servers_rsa_public_key_exported)
servers_rsa = Asymmetric.RSAkey1(servers_rsa_public_key)
clients_rsa = Asymmetric.RSAkey0()
clients_private_rsa_exported = clients_rsa.export_private()
clients_private_rsa_exported_encrypted = servers_rsa.encrypt_data(clients_private_rsa_exported)
print type(clients_private_rsa_exported_encrypted)
s.send(clients_private_rsa_exported_encrypted)
symmetric_key = "mychiper"
client_symmetric = symmetric.AESCipher(symmetric_key)
clients_symmetric_key_encryptedd = clients_rsa.encrypt_data(symmetric_key)
clients_symmetric_key_encrypted = servers_rsa.encrypt_data(clients_symmetric_key_encryptedd)
s.send(clients_symmetric_key_encrypted)
encryptd_confirmation_message = s.recv(1024)
confirmation_message = client_symmetric.decrypt(encryptd_confirmation_message)
if confirmation_message == "hand shake completed":
    print "connection to manager succssed"


s.close
コード例 #2
0
ファイル: server.py プロジェクト: hadarrabin/NetManagement
import socket
import symmetric
import Asymmetric

listenersock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listenersock.bind(("0.0.0.0", 15823))
listenersock.listen(-1)
while True:
    c, addr = listenersock.accept()  # Establish connection with client.
    c.send("Hello")
    servers_rsa = Asymmetric.RSAkey0()
    c.send(servers_rsa.export_public())
    clients_private_rsa_exported_encryped = c.recv(2048)
    clients_private_rsa_exported = servers_rsa.decrypt_data(clients_private_rsa_exported_encryped)
    clients_private_rsa = Asymmetric.import_key(clients_private_rsa_exported)
    clients_public_rsa = Asymmetric.generate_public(clients_private_rsa)
    clients_rsa = Asymmetric.RSAkey2(clients_private_rsa, clients_public_rsa)
    clients_symmetric_key_encryptedd = c.recv(2048)
    clients_symmetric_key_encrypted = servers_rsa.decrypt_data(clients_symmetric_key_encrypted)
    clients_symmetric_key = clients_rsa.decrypt_data(clients_symmetric_key_encrypted)
    clients_symmetric_cipher = symmetric.AESCipher(clients_symmetric_key)
    c.send(clients_symmetric_cipher.encrypt("hand shake completed"))
    c.close()
コード例 #3
0
ファイル: server.py プロジェクト: FrankRays/NetManagement
import socket
import symmetric
import Asymmetric

listenersock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listenersock.bind(("0.0.0.0", 15823))
listenersock.listen(-1)
while True:
    c, addr = listenersock.accept()  # Establish connection with client.
    c.send('Hello')
    servers_rsa = Asymmetric.RSAkey0()
    c.send(servers_rsa.export_public())
    clients_private_rsa_exported_encryped = c.recv(2048)
    clients_private_rsa_exported = servers_rsa.decrypt_data(
        clients_private_rsa_exported_encryped)
    clients_private_rsa = Asymmetric.import_key(clients_private_rsa_exported)
    clients_public_rsa = Asymmetric.generate_public(clients_private_rsa)
    clients_rsa = Asymmetric.RSAkey2(clients_private_rsa, clients_public_rsa)
    clients_symmetric_key_encryptedd = c.recv(2048)
    clients_symmetric_key_encrypted = servers_rsa.decrypt_data(
        clients_symmetric_key_encrypted)
    clients_symmetric_key = clients_rsa.decrypt_data(
        clients_symmetric_key_encrypted)
    clients_symmetric_cipher = symmetric.AESCipher(clients_symmetric_key)
    c.send(clients_symmetric_cipher.encrypt("hand shake completed"))
    c.close()