1

I am trying to learn python and for a class I need to create an assignment. This assignment states that I need to create a server with a self-signed certificate. I need to let this server listen on port "int(sys.argv[1])" abd send the result of the linux command "who" back to the client.

We can test our script like below:

run in 1 terminal the script on example port 1234

run in a other terminal the below command: (test: openssl s client -host localhost -port 1234)

At the moment once I execute the second command on a 2nd terminal, I receive all information on the certificate, but not the output of the command who send back to the client.

This is my code so far: http://pastebin.com/yFKLtyMW

Please help!

PS: I am running python 2.6

1 Answer 1

1
connstream = ssl.wrap_socket(newsocket, server_side=True, certfile="cert.pem", keyfile="test.key" )

After wraping the socket to a SSLSocket , you should only use connstream and not newsocket. So your code should look like:

   try:
    #data = connstream.read(1024)
    output = commands.getoutput("who")
    connstream.write(output)

Note that you don't need to read any data as the other end is only waiting on the output of the command. So keeping the read statement will make your SSL Server wait on data from the other end before sending the output of the who command

Sign up to request clarification or add additional context in comments.

1 Comment

Alright that I did see but forgot to edit when I pasted it to pastebin, aside from that I still cannot send information over the socket to the client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.