Closed mpeter50 closed 1 year ago
I wanted to figure out how is the failing check implemented. So far I have found by setting breakpoints and doing a regular requests.get()
to this domain that the exception is coming from inside ssl.SSLSocket.do_handshake
, from the call to self._sslobj.do_handshake()
.
Unfortunately, the definition of that function cannot be found by my IDE, and trying to step into it results in ending up in the next finally block, which probably means that this is native code, which I cannot inspect.
The problem was that my self-signed certificate was incorrect.
And not specifically with twine, but generally python's requests
pacakge did not like it.
The reason is that for ~23 years now, the Common Name of a certificate cannot be used for the domain name (you can put it there for your convenience, but software wont look there for it). Details here: 1, 2. Instead, the domain name has to be specified in the Subject Alt Names list.
If someone reading this also wants to upload their package to a selfhosted package index, but has also received this error message, you should make sure that your certificate is correct regarding that. This solution helped a lot in figuring out how to make a correct TLS certificate, but for self signed certs you will have to use -x509
instead of -new
and -out cert.crt
instead of -out cert.csr
in the command arguments, and also x509_extensions = req_ext
instead of req_extensions = req_ext
in the config file. In the config file you may also want to use basicConstraints=CA:TRUE, pathlen: 0
in the req_ext
INI section.
OS version
Windows 10
Python version
3.10.11
Pip version
23.1.2
Guide link
https://packaging.python.org/tutorials/packaging-projects
Problem description
I wanted to upload the test package with twine to my package registry, that runs on the local network. It is a Gitea server, for which I use a wildcard self-signed certificate.
When I pass the certificate's PEM file (obtained from my web browser, which communicates with the server without issue, after accepting the cert once) to the twine command, it repeats this error while retrying a few times: "SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'REDACTED'"
When the error happens, I use this command:
Error message