简体   繁体   中英

How to restrict access by using a self-signed certificate?

I have a python script that wants to communicate via HTTPS to a flask application using a self-signed certificate.

I've created an SSL certificate with openssl . I want flask to only accept connections that use that certificate and refuse those that do not.

Can anyone give some thoughts of how can I do that?

I don't think flask is capable of that. Flask only takes care of the content building stuff. It in fact uses Werkzeug as backend while in development mode.

During development, werkzeug's builtin server supports SSL for testing purposes:

run_simple('localhost', 4000, application,
       ssl_context=('/path/to/the/key.crt',
                    '/path/to/the/key.key'))

Details can be found here .

When it comes to production, a flask project has to be depolyed with a WSGI backend that is more productive. There are many backends out there like gunicorn and uWSGI (with nginx ). If you choose to use one of them, You may want to check out their documentation to find about how to add HTTPS support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM