Python socket ssl connetion
<p>Here is the senario:</p>

<p>Server listens to two ports 9999, 9998 via the host 10.10.10.1
Port 9999 for clients &amp; Port 9998 for the controller
I was able to connect client and the controller to the server and  control the client from the controller without ssl socket.
I wanted to use encrypted socket I added ssl certificate socket connection, The client does not connect to the server via SSL_SOCK as the controller too.
I appreciate your help or suggetion.</p>

<p>server :</p>

<pre><code>    s=socket(AF_INET, SOCK_STREAM)
    s.bind(("10.10.10.1",9999))
    s.listen(5)
    port = 9999
    password = "password"
    bridgeport = 9998

    allConnections = []
    allAddresses = []

    def getConnections():
        for item in allConnections:
            item.close()

        del allConnections[:]
        del allAddresses[:]

        while 1:
            try:
                q,addr=s.accept()
                connstream = ssl.wrap_socket(q, server_side=True, certfile="server.crt", keyfile="server.key", ssl_version=ssl.PROTOCOL_SSLv23) 
                connstream.setblocking(1)
                allConnections.append(connstream)
                allAddresses.append(addr)

            except:
                print "YOU ARE NOT CONNECTED!! TRY AGAIN LATER"
                time.sleep(10.0)
                break
def main():
    bridge=socket(AF_INET, SOCK_STREAM)
    bridge.bind(("10.10.10.1",9998))
    bridge.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    while 1:
        bridge.listen(1)
        q,addr=bridge.accept()
        bridgestream = ssl.wrap_socket(q, server_side=True, certfile="server.crt", keyfile="server.key", ssl_version=ssl.PROTOCOL_SSLv23)

        cpass = bridgestream.recv(4096)
        if (cpass == password):
            print "Controller is connected"
        else:
            print "Controller not conected"
try:        
    main()
except:
    try:

        del allConnections[:]
        del allAddresses[:]
    except:
        pass
</code></pre>

<p>Controller :</p>

<pre><code>host = '10.10.10.1'
port = 9998
password = "password"


def main():

    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ssl_sock = ssl.wrap_socket(s, ca_certs="server.crt", cert_reqs=ssl.CERT_REQUIRED)
        ssl_sock.connect((host, port))
    except:
        sys.exit("[ERROR] Can't connect to server")

    ssl_sock.sendall(password)
</code></pre>

<p>Client:</p>

<pre><code>host = "10.10.10.1"
port = 9999
def main(host, port):
    while 1:
        connected = False
        while 1:
            while (connected == False):
                try:

                    print host
                    print port
                    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    print s
                    ssl_sock = ssl.wrap_socket(s, ca_certs="server.crt", cert_reqs=ssl.CERT_REQUIRED)
                    print "ssl_sock"
                    ssl_sock.connect((host,port))
                    print "Connected"
                    connected = True
                except:
                    print "The client not Connected yet"
                    time.sleep(5)
while 1:
    try:
        main(host, port)
    except:
        time.sleep(5)
</code></pre>