Densaugeo / uploadserver

Python's http.server extended to include a file upload page
MIT License
233 stars 48 forks source link

SSLError when apply server-certificate using Let's Encrypt #46

Closed hwcho11 closed 1 week ago

hwcho11 commented 2 weeks ago

I'm using Python 3.8 on Ubuntu 20.04. just want to run with HTTPS using good certificate, create certificate from Let's Encrypt.

used command: $ python3 -m uploadserver --server-certificate /etc/letsencrypt/live/.../fullchain.pem

result: File upload available at /upload Traceback ... File ".../uploadserver/init.py", line 342, in ssl_wrap context.load_cert_chain(certfile=server_certificate) ssl.SSLError: [SSL] PEM lib (_ssl.c:4081)

using a self-signed server certificate as README works without error though. I double checked the .pem file is verified by openssl. no idea what is wrong.

Densaugeo commented 2 weeks ago

It looks like Let's Encrypt provides the certificate as separate certificate chain and private key files by default, while uploadserver expects the private key and certificate chain to be in a single .pem file. Are you able to get a certificate and key in a single .pem file and try that way?

I'm currently traveling but will try running uploadserver with a Let's Encrypt certificates on uploadserver when I get back. If it's just an issue of the private key being in a separate file it shouldn't be hard to add support for Let's Encrypt's default format.

hwcho11 commented 2 weeks ago

You were right—the single combined .pem file (cat privkey.pem fullchain.pem) works perfectly. It's likely just an issue of lack of knowledge about load_cert_chain(). I think it'd be helpful if you added some comments in readme that the server-certificate option needs a single .pem and that you should prepare it in some cases, e.g., Let's Encrypt. This issue thread can be closed. I appreciate it.

Densaugeo commented 2 weeks ago

Glad to hear you were able to get it working! It looks like it should be easy to add an argument for passing both files when there's two, I'll take a look when I get back home. If not I'll least update the docs before closing this.

Densaugeo commented 1 week ago

New version will give an informative error message when loading certificates fails. Thanks for the issue report!