rtm_connect to slackbot gives SSL certificate validation error - ssl

I have a slackbot in my workspace. I am using this python script to connect to the slackbot and process the chat messages it gets. The below line gives SSL error:
slack_client.rtm_connect(with_team_state=False)
Error:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/slackclient/client.py", line 52, in rtm_connect
self.server.rtm_connect(use_rtm_start=with_team_state, **kwargs)
File "/usr/lib/python2.7/site-packages/slackclient/server.py", line 147, in rtm_connect
self.connect_slack_websocket(self.ws_url)
File "/usr/lib/python2.7/site-packages/slackclient/server.py", line 186, in connect_slack_websocket
raise SlackConnectionError(message=str(e))
SlackConnectionError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)
Connection failed. Exception traceback printed above.
I tried updating REQUESTS_CA_BUNDLE in the python code, but didn't work.
How can I install and make it verify the certificate? Also, how can I skip certificate verification?
Any detailed link on usage of SSL certificates is appreciated.

The reason this fails comes from the websocket package and the CA bundle it uses (which is not up-to-date). I couldn't figure out which CA bundle is actually used (I've tried to update the package supplied as well as system-installed OpenSSL bundle), but it can be overwritten on command line.
So first I've downloaded the DigiCert certs:
wget https://www.tbs-certificats.com/issuerdata/DigiCertGlobalRootCA.crt
(NOTE: I couldn't find an official download link on the DigiCert page, dunno why they're not offering it)
Then set the environment variable:
export WEBSOCKET_CLIENT_CA_BUNDLE=DigiCertGlobalRootCA.crt
And that worked for me:
$ python bot.py
Starter Bot connected and running!

Related

Using pygbag to package PyGame for web results in SSL error

Instead of packaging my PyGame game into an .exe using PyInstaller, I am attempting to use the new Python library pygbag to package the game using web assembly to share on a site like itch.io.
I followed a tutorial to try to get a local test in my browser on port 8000... 1) inserted the asyncio code into my game code 2) ran pygbag from the terminal on the specified directory.
Pygbag does some of the build, but then it hits this SSL error. Any thoughts? Thanks.
WARNING: web.get(https://pygame-web.github.io/archives/0.5/default.tmpl) : <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
retrying in 5 seconds
On MacOS 11.6.7; Python 3.10.8; pygbag 0.5.0; pygame 2.1.2
ctrl-c quitting, I see another SSL error:
WARNING: web.get(https://pygame-web.github.io/archives/0.5/favicon.png) : <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
retrying in 5 seconds
crtl-c quitting again gets it to stop completely.
There was an "Install Certificates.command" file in Applications/Python 3.10/. I double clicked to run it and that solved my problem.
certificate verify failed: unable to get local issuer certificate

Matomo 4.7.1 core:archive ssl certificate problem

I have Matomo 4.7.1 installed on RHEL8 and am getting an error message when running the core archive.
/opt/matomo/matomo-4.7.1/plugins/GeoIp2/GeoIP2AutoUpdater.php(175): GeoIP2AutoUpdater: failed to download 'https://download.db-ip.com/free/dbip-city-lite-2022-03.mmdb.gz' to '/opt/matomo/matomo-4.7.1/tmp/latest/DBIP-City.mmdb.gz.download': curl_exec: SSL certificate problem: unable to get local issuer certificate. Hostname requested was: download.db-ip.com [Query: , CLI mode: 1]
Our company uses a self signed cert and it is installed on this server and Apache and PHP both work as expected. I can use command line curl to download the file given in the error message with no problems, but running the core archive always shows the error. I also added the option to accept invalid ssl certificates and that didn't help.
php /opt/matomo/matomo/console core:archive --url=https://myserver.com/matomo/ --accept-invalid-ssl-certificate
I also updated the php.ini file with the path to the pem file and that didn't work.
curl.cainfo = "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"
Is there anything else I am missing or can check?
Turns out there is config item for Matomo where you can set it to use your custom pem file instead of the one included with Matomo.
https://forum.matomo.org/t/certificate-issues-during-update/30238/8https://matomo.org/faq/troubleshooting/faq_34226/
To solve this issue, you are able to provide your own cacert file that trusts your proxies certificate. To use your own file, follow these steps:
1. Upload your cacert.pem file in a folder on your server such as /path/to/your/cacert.pem
2. Add custom_cacert_pem = "/path/to/your/cacert.pem" to the [General] section of your config file config/config.ini.php.
3. Make sure the certification is readable by your webserver.

How to disable SSL certificate verification in Twine?

When I tried to push a new package to my company's artifactory :
python -m twine upload --repository-url https:///artifactory/api/pypi/gdp_pypi dist/*
I got an error on SSL.
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841)
Any way to disable the SSL verification?
I just tried the solution by another post:
Disable Python requests SSL validation for an imported module
Simply setting environment variable CURL_CA_BUNDLE to an empty string did the job!
$ export CURL_CA_BUNDLE=""

Installing certificate for a specific CA, or understanding why the existing one doesn't work

I have the following code in Python3.7:
import urllib.request
import urllib.error
import ssl
import certifi
# Create the SSL context
# Was using cafile=certifi.where() before, but copied it inline. Read below
context = ssl.create_default_context(cafile='cacert.pem')
# Prepare the request
request = urllib.request.Request(some_url)
try:
connection = urllib.request.urlopen(request, context=context)
except urllib.error.URLError as e:
print(e)
I've tried several different some_url and I'm getting a problem for a specific one, https://hypelabs.io. Other URLs are working; I tested, for example, https://facebook.com, https://stackoverflow.com, and so on, all working properly. For hypelabs.io I get this instead:
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)>
First thoughts were that the CA was not recognized by the system, and that I needed to install the CA certificate first. I checked the chain in the browser and this is what I found:
However, the COMODO RSA Certification Authority is in all bundle files that I tried (as expected) and in the Keychain as well (I'm using MacOS High Sierra). Notice that the serial numbers match.
The second certificate in the chain is not in the system. I know that the root is enough, but just in case I tried downloading it and adding it to the bundle file, after converting the CRT file to PEM:
Same result. Why is this particular certificate failing? What should I be looking at?
The site is misconfigured and fails to provide a necessary intermediate certificate. The SSLLabs report therefore says:
This server's certificate chain is incomplete. Grade capped to B.
The second certificate in the chain is not in the system. I know that the root is enough, but just in case I tried downloading it and adding it to the bundle file, after converting the CRT file to PEM.
My guess is that you did something wrong here. Given that your description is correct I assume that it does not fully match what you actually did.
I've took the missing certificate with the same fingerprint as can be found here and added it to the list of root CA (taken on Ubuntu from /etc/ssl/certs/ca-certificates.crt. After that access to the site worked without any problems.

Does buildout/easy_install/setup_tools verify SSL certificates?

I'm trying to diagnose this error:
Getting distribution for 'zc.buildout<2dev'.
Got zc.buildout 1.7.1.
Generated script '/opt/mytardis/releases/a549cd05272afe8f16c2fe5efe8158490acbde82/bin/buildout'.
Download error on http://pypi.python.org/simple/buildout-versions/: [Errno 104] Connection reset by peer -- Some packages may not be found!
Couldn't find index page for 'buildout-versions' (maybe misspelled?)
Download error on http://pypi.python.org/simple/: [Errno 104] Connection reset by peer -- Some packages may not be found!
Getting distribution for 'buildout-versions'.
STDERR: /usr/lib64/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: 'src_root'
warnings.warn(msg)
While:
Installing.
Loading extensions.
Getting distribution for 'buildout-versions'.
Error: Couldn't find a distribution for 'buildout-versions'.
It happens deep inside a Chef + buildout installation stack. One thing I have discovered is that if I attempt to access the buildout-versions package directly:
$ wget https://pypi.python.org/packages/source/b/buildout-versions/buildout-versions-1.7.tar.gz#md5=731ecc0c9029f45826fa9f31d44e311d
--2013-07-09 12:50:18-- https://pypi.python.org/packages/source/b/buildout-versions/buildout-versions-1.7.tar.gz
Resolving proxy.redacted.com... 123.45.67.8
Connecting to proxy.redacted.com|123.45.67.8|:8080... connected.
ERROR: certificate common name “*.a.ssl.fastly.net” doesn’t match requested host name “pypi.python.org”.
To connect to pypi.python.org insecurely, use ‘--no-check-certificate’.
I can access the file fine from my desktop. So I suspect the proxy (provided by a university, and this server has to use it to reach the web). It's set with https_proxy=....
Is this the likely cause of buildout failing? Any way around it?
Your version of wget is too old.
wget started to support SNI (Server Name Indication) only since version 1.14 and that TLS extension is needed to be presented the correct certificate on pypi.python.org.
Yes, zc.buildout and easy_install both use urllib2 to retrieve HTTPS resources, which does not verify SSL certificates:
Warning: HTTPS requests do not do any verification of the server’s certificate.
Your wget tool does verify certificates, but your local certificate authorities certificates are incomplete, it seems; see SSL certificate rejected trying to access GitHub over HTTPS behind firewall for instructions on how to update those.
As for your original error, it appears your firewall proxy is doing the peer resets.
As per PEP 476, Python 2.7.9 remedies this situation. From that version onwards, urllib2 will verify SSL certificates by default.
Since Python 2.7.9 (released) / 3.4.3 (released soon), certificates are validated by default:
HTTPS certificate validation using the system's certificate store is
now enabled by default. See PEP 476 for details.
https://www.python.org/downloads/release/python-279/
you can try it:
wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea --no-check-certificate