Closed kvillar93 closed 1 month ago
I find that SSL labs has pretty useful tests and explanation of what goes wrong with a certificate: https://www.ssllabs.com/ssltest/analyze.html?d=www.dgii.gov.do
It appears that the intermediate certificate (DigiCert EV RSA CA G2) is not sent by the server which is a mis-configuration on the server side. That the site works in most browsers is that browsers can download the certificate via AIA chasing or cache seen intermediate certificates. This is not supported in Python, see https://github.com/python/cpython/issues/62817
The work-around is to download the intermediate certificate and add it to the trust store you're using. I'll see if I can add the intermediate certificate to python-stdnum but it is quite tricky because it goes via a number of abstraction layers and possibly fragile if the certificate changes.
Unless I'm mistaken there is no easy way to specify that requests can trust the system or built-in certificate store as well as a certain extra certificate.
Thank you for your thougthful response. I assumed there wasn't an easy way, everything related to the DGII is always problematic.
In the pull request #453, jeffryjdelarosa suggested disabling the SSL verification to bypass this problem. Does it work or it is recommendend?
Also, in the same /cpython/issues/62817 there is a linked workaround to do AIA chasing in python at the end: danilobellini/aia.
Do you think this library can work with this issue?
In my experience, DGII often faces challenges with certificates, as they typically acquire them through third parties via the government's 'Purchasing and Contracting' department. As a result, they are sometimes unaware when a certificate has expired or has technical issues. This is why I chose to disable SSL verification. It's unfortunate that in our country, we constantly have to deal with these types of problems, and every four years, the person in charge of each government department changes, affecting continuity and efficiency.
@jeffryjdelarosa you are so damn right.
It seems the problem with the missing intermediate certificate has been fixed by the operators of www.dgii.gov.do
.
In 3fcebb2 I've added a verify
argument to all functions that deal with network services to allow working around this from caller applications without having to update python-stdnum itself.
For example until the requests library supports AIA chasing this can probably be accomplished by (untested because the proper intermediate certificate is present now):
from aia import AIASession
from stdnum.do import rnc
from tempfile import NamedTemporaryFile
aia_session = AIASession()
cadata = aia_session.cadata_from_url(rnc.dgii_wsdl)
with NamedTemporaryFile("w") as pem_file:
pem_file.write(cadata)
pem_file.flush()
result = rnc.search_dgii('132262875', end_at=20, start_at=1, timeout=4, verify=pem_file.name)
When executing the method same as always, the service returns SSLError. Please see next example:
Any idea why this happens?