Python Forum
Handshake ( Server Hello )
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handshake ( Server Hello )
#1
Do I need to send a ( Server Hello ) as a response to the handshake ( Client Hello ) received, but I couldn’t find out why it doesn’t work? If I can help, below is an example:

import socket
import ssl

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to port 443
sock.bind(("", 443))

# Listen for connections
sock.listen(1)

# Accept a connection
conn, addr = sock.accept()

# Create a SSL/TLS context
ctx = ssl.SSLContext()

# Load the server's certificate
ctx.load_cert_chain("server.crt")

# Create a SSL/TLS wrapper around the socket
ssl_sock = ctx.wrap_socket(conn)

# Receive the "ClientHello" message
client_hello = ssl_sock.recv(16384)

# Select the highest version of SSL/TLS common between the client and the server
ssl_version = client_hello[0:2]

# Select a set of encryption algorithms and security parameters supported by both the client and the server
ciphers = ssl.get_ciphers()

# Send the "ServerHello" message to the client
ssl_sock.sendall(b"Server Hello\n" + ssl_version + b"\n" + ciphers + b"\n")

# Receive the "ClientKeyExchange" message from the client
client_key_exchange = ssl_sock.recv(16384)

# Generate a shared secret
shared_secret = ssl.generate_shared_secret(client_key_exchange)

# Encrypt the data stream
ssl_sock.write(shared_secret)

# Receive data from the client
data = ssl_sock.read()

# Decrypt the data
decrypted_data = ssl.decrypt_data(data, shared_secret)

# Print the decrypted data
print(decrypted_data)

# Close the socket
ssl_sock.close()
Reply


Messages In This Thread
Handshake ( Server Hello ) - by JohnnyCoffee - May-25-2023, 10:39 AM
RE: Handshake ( Server Hello ) - by DigiGod - May-26-2023, 12:03 AM
RE: Handshake ( Server Hello ) - by JohnnyCoffee - May-27-2023, 03:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Paramiko Server -- Exception (server): Error reading SSH protocol banner ujlain 3 4,865 Jul-24-2023, 06:52 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020