PyPtt 2.0.8__tar.gz → 2.0.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyptt-2.0.8 → pyptt-2.0.10}/PKG-INFO +1 -1
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/PTT.py +5 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/__init__.py +1 -1
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/config.py +3 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/connect_core.py +19 -14
- pyptt-2.0.10/PyPtt/ssl_config.py +24 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt.egg-info/PKG-INFO +1 -1
- pyptt-2.0.8/PyPtt/ssl_config.py +0 -24
- {pyptt-2.0.8 → pyptt-2.0.10}/LICENSE +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_bucket.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_call_status.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_change_pw.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_comment.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_del_post.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_board_info.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_board_list.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_bottom_post_list.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_favourite_board.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_newest_index.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_post.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_post_index.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_post_list.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_time.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_user.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_get_waterball.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_give_money.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_has_new_mail.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_loginout.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_mail.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_mark_post.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_post.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_reply_post.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_search_user.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_set_board_title.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/_api_util.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/api_server.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/check_value.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/command.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/data_type.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/exceptions.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/i18n.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/lang_en_US.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/lang_zh_TW.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/lib_util.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/log.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/screens.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt/service.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt.egg-info/SOURCES.txt +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt.egg-info/dependency_links.txt +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt.egg-info/requires.txt +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/PyPtt.egg-info/top_level.txt +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/README.md +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/pyproject.toml +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/setup.cfg +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/setup.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_change_pw.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_comment.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_del_post.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_exceptions.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_board_info.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_board_list.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_bottom_post_list.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_favourite_boards.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_mail.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_newest_index.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_post.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_post_list.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_post_parser.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_time.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_user.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_get_waterball.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_give_money.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_i18n.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_init.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_logger.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_parse_query_post.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_post.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_reply_post.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_search_user.py +0 -0
- {pyptt-2.0.8 → pyptt-2.0.10}/tests/test_service.py +0 -0
|
@@ -53,6 +53,7 @@ class API:
|
|
|
53
53
|
logger_callback (Callable): PyPtt 顯示訊息的 callback。預設為 None。
|
|
54
54
|
port (int): PyPtt 連線的 port。預設為 **23**。
|
|
55
55
|
host (:ref:`host`): PyPtt 連線的 PTT 伺服器。預設為 **PTT1**。
|
|
56
|
+
verify_ssl (bool): 是否驗證 PTT server 端的 TLS 憑證。預設為 **True**。若你的網路環境透過 SSL 攔截 proxy(如企業防火牆),可設為 **False** 以停用驗證。
|
|
56
57
|
check_update (bool): 是否檢查 PyPtt 的更新。預設為 **False**。
|
|
57
58
|
|
|
58
59
|
Returns:
|
|
@@ -145,6 +146,10 @@ class API:
|
|
|
145
146
|
raise exceptions.ParameterError('[PyPtt] TELNET is not available on PTT1 and PTT2')
|
|
146
147
|
self.config.connect_mode = connect_mode
|
|
147
148
|
|
|
149
|
+
verify_ssl = kwargs.get('verify_ssl', True)
|
|
150
|
+
check_value.check_type(verify_ssl, bool, 'verify_ssl')
|
|
151
|
+
self.config.verify_ssl = verify_ssl
|
|
152
|
+
|
|
148
153
|
self.connect_core = connect_core.API(self)
|
|
149
154
|
self._exist_board_list = set()
|
|
150
155
|
self._exist_user_list = set()
|
|
@@ -32,12 +32,15 @@ except AttributeError:
|
|
|
32
32
|
websockets.http11.USER_AGENT += f' PyPtt/{PyPtt.__version__}'
|
|
33
33
|
use_http11 = True
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
def ssl_init(verify_ssl: bool = True) -> ssl.SSLContext:
|
|
36
|
+
# Verify the PTT server certificate against the system CA bundle.
|
|
37
|
+
# The client cert loaded below is *not* for identity (PTT does not
|
|
38
|
+
# validate it); it exists purely to make the TLS handshake succeed in
|
|
39
|
+
# environments where omitting a Certificate message breaks negotiation.
|
|
40
|
+
# See PyPtt/ssl_config.py for details.
|
|
41
|
+
#
|
|
42
|
+
# Pass verify_ssl=False only when connecting through an SSL-inspecting
|
|
43
|
+
# proxy whose CA cert is not in the system trust store.
|
|
41
44
|
cert_file = tempfile.NamedTemporaryFile(delete=False, suffix='.pem')
|
|
42
45
|
cert_file.write(ssl_config.cert.encode('utf-8'))
|
|
43
46
|
|
|
@@ -47,17 +50,18 @@ def ssl_init():
|
|
|
47
50
|
cert_file.close()
|
|
48
51
|
key_file.close()
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
ctx = ssl.create_default_context()
|
|
54
|
+
ctx.load_cert_chain(certfile=cert_file.name, keyfile=key_file.name)
|
|
55
|
+
ctx.minimum_version = ssl.TLSVersion.TLSv1_2
|
|
56
|
+
|
|
57
|
+
if not verify_ssl:
|
|
58
|
+
ctx.check_hostname = False
|
|
59
|
+
ctx.verify_mode = ssl.CERT_NONE
|
|
55
60
|
|
|
56
61
|
os.unlink(cert_file.name)
|
|
57
62
|
os.unlink(key_file.name)
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
ssl_init()
|
|
64
|
+
return ctx
|
|
61
65
|
|
|
62
66
|
|
|
63
67
|
class TargetUnit:
|
|
@@ -153,6 +157,7 @@ class API(object):
|
|
|
153
157
|
self._UseTooManyResources = TargetUnit(screens.Target.use_too_many_resources,
|
|
154
158
|
exceptions_=exceptions.UseTooManyResources())
|
|
155
159
|
self._loop = None
|
|
160
|
+
self._ssl_context = ssl_init(self.config.verify_ssl)
|
|
156
161
|
|
|
157
162
|
def _get_event_loop(self):
|
|
158
163
|
if self._loop and not self._loop.is_closed():
|
|
@@ -208,7 +213,7 @@ class API(object):
|
|
|
208
213
|
websockets.connect(
|
|
209
214
|
websocket_host,
|
|
210
215
|
origin=websocket_origin,
|
|
211
|
-
ssl=
|
|
216
|
+
ssl=self._ssl_context))
|
|
212
217
|
connect_success = True
|
|
213
218
|
break
|
|
214
219
|
except Exception as e:
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
key = """-----BEGIN EC PARAMETERS-----
|
|
2
|
+
BggqhkjOPQMBBw==
|
|
3
|
+
-----END EC PARAMETERS-----
|
|
4
|
+
-----BEGIN EC PRIVATE KEY-----
|
|
5
|
+
MHcCAQEEIMm/frEbk7WCyFvGd+CJveLnElsKhBDuk6ktPOYSI+/OoAoGCCqGSM49
|
|
6
|
+
AwEHoUQDQgAE7KtBn7Lmzl9czBvQE/7jgt0DdQkPLQjUREYpUsGjRB7Xlk+CsL2c
|
|
7
|
+
xr1FQ8AcCxSu9SO0wTqAA4b9gNNeLngcbw==
|
|
8
|
+
-----END EC PRIVATE KEY-----
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
cert = """-----BEGIN CERTIFICATE-----
|
|
12
|
+
MIIB6TCCAY8CFGmCwd8Y9oagOeoSh2eZ9db35aYiMAoGCCqGSM49BAMCMHcxCzAJ
|
|
13
|
+
BgNVBAYTAlRXMQ4wDAYDVQQIDAVTdG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6txCh11mPb+w/DYe8w==
|
|
8
|
-
-----END EC PRIVATE KEY-----
|
|
9
|
-
"""
|
|
10
|
-
|
|
11
|
-
cert = """-----BEGIN CERTIFICATE-----
|
|
12
|
-
MIIB6TCCAY8CFCwmWlM+i2IbtHKF0gLrHa2/PqvPMAoGCCqGSM49BAMCMHcxCzAJ
|
|
13
|
-
BgNVBAYTAlRXMQ4wDAYDVQQIDAVTdGF0ZTENMAsGA1UEBwwEQ2l0eTEVMBMGA1UE
|
|
14
|
-
CgwMT3JnYW5pemF0aW9uMRwwGgYDVQQLDBNPcmdhbml6YXRpb25hbCBVbml0MRQw
|
|
15
|
-
EgYDVQQDDAtDb21tb24gTmFtZTAeFw0yNjA0MDUxNTIyNTZaFw0zNjA0MDIxNTIy
|
|
16
|
-
NTZaMHcxCzAJBgNVBAYTAlRXMQ4wDAYDVQQIDAVTdGF0ZTENMAsGA1UEBwwEQ2l0
|
|
17
|
-
eTEVMBMGA1UECgwMT3JnYW5pemF0aW9uMRwwGgYDVQQLDBNPcmdhbml6YXRpb25h
|
|
18
|
-
bCBVbml0MRQwEgYDVQQDDAtDb21tb24gTmFtZTBZMBMGByqGSM49AgEGCCqGSM49
|
|
19
|
-
AwEHA0IABIE6O22QhGaTnUGtqOj+ip0slYX7Bab5xCtBRolP1esc+l1lDCFUsvu3
|
|
20
|
-
Rucxse/zh2t4iurcQoddZj2/sPw2HvMwCgYIKoZIzj0EAwIDSAAwRQIgc2K0N6II
|
|
21
|
-
gvywv1b/rDjIhQdXK6/TF62MWyk5GtrX7N0CIQCMyhwOeA+HYyh4yBbrbP5pA70b
|
|
22
|
-
n6j6snhIR6x2l0HWSw==
|
|
23
|
-
-----END CERTIFICATE-----
|
|
24
|
-
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|