import ssl
import socket


def get_ssl_serversocket(file_certchain, file_privatekey, bindoptions, password_privkey=None):
    """
    Create a SSL based server socket. Useage:
    conn, addr = ssock.accept()
    data = conn.recv()
    conn.send(data)

    Certificate/private key can be create via:
    openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365

    return -- SSL wrapped TCP server socket
    """
    context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
    context.load_cert_chain(file_certchain, file_privatekey, password=password_privkey)

    socket_simple = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
    socket_simple.bind(bindoptions)
    socket_simple.listen(5)

    return context.wrap_socket(socket_simple, server_side=True)