title: Python ssl socket server SSLV3_ALERT_CERTIFICATE_UNKNOWN issue
body: <p>I am writing a python socket server with ssl and I am encountering certificate unknown error during ssl handshake.</p>
  <p>I have created private key and certificate with <code>openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes</code> command on my own.<br />
  This server is intended to run in intranet(under wifi) in my PC, and users will contact my PC IPaddress with their browser. Hence I have not registered this certificate with any CA. and I don't think its mandatory in my case.<br />
  Below more details..</p>
  <p><strong>echoserver.py</strong></p>
  <pre class="lang-py prettyprint-override"><code>import socket
  import ssl
  import threading
  class echoserver:
      def __init__(self,i,p):
          self.ip=i
          self.port=p
      def handler(self,c,a):
          msg=c.recv(1024)
          c.send(msg)
      def serve(self):
          echoserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          echoserver = ssl.wrap_socket(echoserver, keyfile='keys/key.pem', certfile='keys/cert.pem', server_side=True)
          echoserver.bind((self.ip, self.port))
          echoserver.listen()
          while True:
              (c,a)=echoserver.accept()
              threading.Thread(target=self.handler, args=(c,a)).start()
  
  es=echoserver('192.168.43.124',443) #My PC's ip assigned under wifi network
  es.serve()
  
  #Connecting from mobile phone within same network as https://192.163.43.124
  </code></pre>
  <p><strong>Error in server during ssl handshake</strong></p>
  <pre><code>        self._sslobj.do_handshake()      
      ssl.SSLError: [SSL: SSLV3_ALERT_CERTIFICATE_UNKNOWN] sslv3 alert certificate unknown (_ssl.c:1108)
  </code></pre>
  <p><strong>What I tried</strong></p>
  <ul>
  <li>Adding cert_reqs=ssl.CERT_NONE and ca_certs=&quot;/location/to/keys&quot; parameters in wrap_socket function.<br />
  Doesn't seems to work. I assume these options are for client side.</li>
  <li>Adding do_handshake_on_connect=False in wrap_socket function<br />
  In Chrome, When connected server throws same error and thread/connection closed with exception. and <strong>chrome seems to send same connection request immediately again</strong>, and the second request works flawlessly !!.<br />
  In firefox, First connection closed with same error and there is no second request.</li>
  <li>Assigning common name in certificate same as IP address<br />
  Not working.</li>
  <li>Checked certificate_unknown error in ietf specification <a href="https://www.rfc-editor.org/rfc/rfc8446" rel="nofollow noreferrer">here</a>. It gives no clue except this explanation    <code>certificate_unknown:  Some other (unspecified) issue arose in processing the certificate, rendering it unacceptable. </code></li>
  </ul>
  <p><strong>One other thing I noted is</strong>, if I use built-in <code>ThreadedHTTPServer</code> in the same way as below, It works beautifully, without any issues I mentioned above.</p>
  <pre class="lang-py prettyprint-override"><code>httpd = self.ThreadedHTTPServer((self.ip, self.port), self.handler)
  httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='keys/key.pem', certfile='keys/cert.pem', server_side=True)
  </code></pre>
  <p>I am not sure why this happens and how should I proceed with this. and not sure how built-in server modules works fine.</p>
  <p>Appreciate any leads. Thanks.</p>
  <p><strong>Below Python builtin HTTPServer works fine with ssl, not showing any error. Not sure how?</strong></p>
  <pre class="lang-py prettyprint-override"><code>import ssl
  from http.server import HTTPServer, BaseHTTPRequestHandler
  
  class requesthandler(BaseHTTPRequestHandler):
      def do_GET(self):
          self.send_response(200)
          self.send_header(&quot;Content-type&quot;,&quot;text/html&quot;)
          self.end_headers()
          self.wfile.write(&quot;&lt;html&gt;&lt;body&gt;It works&lt;/body&gt;&lt;/html&gt;&quot;.encode('utf8'))
  
  httpd = HTTPServer(('192.168.43.124', 443), requesthandler)
  httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='keys/key.pem', certfile='keys/cert.pem', server_side=True)
  httpd.serve_forever()
  </code></pre>