Use certifi root certificates when available
This commit is contained in:
parent
fc08a442fa
commit
15bd1d5681
2 changed files with 30 additions and 9 deletions
|
@ -82,13 +82,16 @@ The old READMEs are also preserved in the [docs](docs) folder:
|
||||||
## RUNNING FROM SOURCE <img src="smilies/tab.gif">
|
## RUNNING FROM SOURCE <img src="smilies/tab.gif">
|
||||||
Pesterchum is a Python script. This means that as long as you have Python installed you can run it without requiring a build/executable, this is useful if there's no compatible build for your system.
|
Pesterchum is a Python script. This means that as long as you have Python installed you can run it without requiring a build/executable, this is useful if there's no compatible build for your system.
|
||||||
|
|
||||||
### REQUIREMENTS
|
### DEPENDENCIES
|
||||||
- [Python 3]
|
- [Python 3]
|
||||||
- Ideally 3.8 or later, though older versions may still work, I don't test them.
|
- Ideally 3.8 or later, though older versions may still work, I don't test them.
|
||||||
- [PyQt6] (prefered) or [PyQt5] (legacy)
|
- [PyQt6] (prefered) or [PyQt5] (legacy)
|
||||||
- Qt6 only supports maintained 64 bit operating systems, like Windows 10 or later for Windows. ([Qt 6.3 Supported Platforms](https://doc.qt.io/qt-6/supported-platforms.html))
|
- Qt6 only supports maintained 64 bit operating systems, like Windows 10 or later for Windows. ([Qt 6.3 Supported Platforms](https://doc.qt.io/qt-6/supported-platforms.html))
|
||||||
- Qt5 supports Windows 7 or later, but is past its EOL for non-commercial use. ([Qt 5.15 Supported Platforms](https://doc.qt.io/qt-6/supported-platforms.html))
|
- Qt5 supports Windows 7 or later, but is past its EOL for non-commercial use. ([Qt 5.15 Supported Platforms](https://doc.qt.io/qt-6/supported-platforms.html))
|
||||||
- (Linux-specific) [pygame] or [GStreamer] for audio.
|
- (Optional) [pygame] can provide an alternative audio backend for certain systems.
|
||||||
|
- Useful for Linux systems that don't meet the Qt6 requirements, as Qt5 Multimedia has a GStreamer dependency.
|
||||||
|
- (Optional) [certifi] can provide alternative root certificates for TLS certificate validation.
|
||||||
|
- Useful for MacOS, as Python doesn't use the system-provided certificates because of MacOS' outdated SSL library. Also miscellaneous systems without usable root certificates.
|
||||||
|
|
||||||
### WALKTHROUGH
|
### WALKTHROUGH
|
||||||
|
|
||||||
|
@ -114,6 +117,7 @@ Pesterchum is a Python script. This means that as long as you have Python instal
|
||||||
[PyQt5]: https://pypi.org/project/PyQt5/
|
[PyQt5]: https://pypi.org/project/PyQt5/
|
||||||
[PyQt6]: https://pypi.org/project/PyQt6/
|
[PyQt6]: https://pypi.org/project/PyQt6/
|
||||||
[pygame]: https://pypi.org/project/pygame/
|
[pygame]: https://pypi.org/project/pygame/
|
||||||
|
[certifi]: https://pypi.org/project/certifi/
|
||||||
[GStreamer]: https://gstreamer.freedesktop.org/
|
[GStreamer]: https://gstreamer.freedesktop.org/
|
||||||
|
|
||||||
## FREEZE / BUILD <img src="themes/win95chum/admin.png">
|
## FREEZE / BUILD <img src="themes/win95chum/admin.png">
|
||||||
|
|
|
@ -15,21 +15,31 @@
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
import logging
|
import sys
|
||||||
|
|
||||||
PchumLog = logging.getLogger("pchumLogger")
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import socket
|
|
||||||
import time
|
import time
|
||||||
import traceback
|
|
||||||
import ssl
|
import ssl
|
||||||
|
import socket
|
||||||
import select
|
import select
|
||||||
|
import logging
|
||||||
|
import traceback
|
||||||
|
|
||||||
from oyoyo.parse import parse_raw_irc_command
|
from oyoyo.parse import parse_raw_irc_command
|
||||||
from oyoyo import helpers
|
from oyoyo import helpers
|
||||||
from oyoyo.cmdhandler import CommandError
|
from oyoyo.cmdhandler import CommandError
|
||||||
|
|
||||||
|
PchumLog = logging.getLogger("pchumLogger")
|
||||||
|
|
||||||
|
try:
|
||||||
|
import certifi
|
||||||
|
except ImportError:
|
||||||
|
if sys.platform == "darwin":
|
||||||
|
# Certifi is required to validate certificates on MacOS with pyinstaller builds.
|
||||||
|
PchumLog.warning(
|
||||||
|
"Failed to import certifi, which is recommended on MacOS. "
|
||||||
|
"Pesterchum might not be able to validate certificates unless "
|
||||||
|
"Python's root certs are installed."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class IRCClientError(Exception):
|
class IRCClientError(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -199,6 +209,13 @@ class IRCClient:
|
||||||
if verify_hostname == False:
|
if verify_hostname == False:
|
||||||
context.check_hostname = False
|
context.check_hostname = False
|
||||||
context.verify_mode = ssl.CERT_NONE
|
context.verify_mode = ssl.CERT_NONE
|
||||||
|
else:
|
||||||
|
# Also load certifi provided root certs if present. (Mainly useful for MacOS)
|
||||||
|
if "certifi" in sys.modules:
|
||||||
|
try:
|
||||||
|
context.load_verify_locations(cafile=certifi.where())
|
||||||
|
except:
|
||||||
|
PchumLog.exception("")
|
||||||
|
|
||||||
bare_sock = socket.create_connection((self.host, self.port))
|
bare_sock = socket.create_connection((self.host, self.port))
|
||||||
self.socket = context.wrap_socket(
|
self.socket = context.wrap_socket(
|
||||||
|
|
Loading…
Reference in a new issue