Я сгенерировал закрытый ключ и самозаверяющий сертификат, используя:
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
Создано context
, как показано ниже:
from OpenSSL import SSL
context = SSL.Context(SSL.TLSv1_2_METHOD)
context.use_certificate('localhost.crt')
context.use_privatekey('localhost.key')
И запустило приложение фляги двумя способами (ни один из них)сработало):
if __name__ == '__main__':
app.run(ssl_context=('localhost.crt', 'localhost.key'), debug=True)
ИЛИ
if __name__ == '__main__':
app.run(host='127.0.0.1', ssl_context=context, debug=True)
Наконец,
python app.py
Тем не менее, он не работает на https. Как я могу запустить как: https://localhost:5000?