Python3 CGI HTTPS server fails on Unix

前端 未结 2 594
一向
一向 2021-01-16 05:25

This Python3 CGI HTTPS server used to work a few weeks (or months) ago, but now no longer works under Linux (Ubuntu). I tried on Ubuntu 10.04 and Ubuntu 14.04 and the behavi

2条回答
  •  独厮守ぢ
    2021-01-16 06:16

    Although the OP found the solution already, here are a few more details why it behaves that way:

    • Plain sockets are kernel only, but sslwraped sockets put an additional user-space layer on top.
    • http.server does a fork (on platforms supporting fork, that is not on windows) and a remapping of the file descriptors to stdin/stdout before finally executing the cgi program. This way the executed program works on the plain (kernel only, no ssl) file descriptors
    • All writes of the program thus go directly to the kernel socket, that is plain unencrypted data.
    • The peer will croak on this plain data because it expects SSL frames. The kind of error it produces depends on the data it gets, e.g. ssl_error_rx_record_too_long or "wrong version number" or something like this.

提交回复
热议问题