PyPtt 2.0.8__tar.gz → 2.0.9__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.
Files changed (80) hide show
  1. {pyptt-2.0.8 → pyptt-2.0.9}/PKG-INFO +1 -1
  2. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/PTT.py +5 -0
  3. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/__init__.py +1 -1
  4. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/config.py +3 -0
  5. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/connect_core.py +19 -14
  6. pyptt-2.0.9/PyPtt/ssl_config.py +24 -0
  7. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt.egg-info/PKG-INFO +1 -1
  8. pyptt-2.0.8/PyPtt/ssl_config.py +0 -24
  9. {pyptt-2.0.8 → pyptt-2.0.9}/LICENSE +0 -0
  10. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_bucket.py +0 -0
  11. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_call_status.py +0 -0
  12. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_change_pw.py +0 -0
  13. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_comment.py +0 -0
  14. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_del_post.py +0 -0
  15. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_board_info.py +0 -0
  16. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_board_list.py +0 -0
  17. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_bottom_post_list.py +0 -0
  18. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_favourite_board.py +0 -0
  19. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_newest_index.py +0 -0
  20. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_post.py +0 -0
  21. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_post_index.py +0 -0
  22. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_post_list.py +0 -0
  23. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_time.py +0 -0
  24. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_user.py +0 -0
  25. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_get_waterball.py +0 -0
  26. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_give_money.py +0 -0
  27. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_has_new_mail.py +0 -0
  28. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_loginout.py +0 -0
  29. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_mail.py +0 -0
  30. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_mark_post.py +0 -0
  31. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_post.py +0 -0
  32. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_reply_post.py +0 -0
  33. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_search_user.py +0 -0
  34. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_set_board_title.py +0 -0
  35. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/_api_util.py +0 -0
  36. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/api_server.py +0 -0
  37. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/check_value.py +0 -0
  38. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/command.py +0 -0
  39. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/data_type.py +0 -0
  40. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/exceptions.py +0 -0
  41. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/i18n.py +0 -0
  42. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/lang_en_US.py +0 -0
  43. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/lang_zh_TW.py +0 -0
  44. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/lib_util.py +0 -0
  45. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/log.py +0 -0
  46. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/screens.py +0 -0
  47. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt/service.py +0 -0
  48. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt.egg-info/SOURCES.txt +0 -0
  49. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt.egg-info/dependency_links.txt +0 -0
  50. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt.egg-info/requires.txt +0 -0
  51. {pyptt-2.0.8 → pyptt-2.0.9}/PyPtt.egg-info/top_level.txt +0 -0
  52. {pyptt-2.0.8 → pyptt-2.0.9}/README.md +0 -0
  53. {pyptt-2.0.8 → pyptt-2.0.9}/pyproject.toml +0 -0
  54. {pyptt-2.0.8 → pyptt-2.0.9}/setup.cfg +0 -0
  55. {pyptt-2.0.8 → pyptt-2.0.9}/setup.py +0 -0
  56. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_change_pw.py +0 -0
  57. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_comment.py +0 -0
  58. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_del_post.py +0 -0
  59. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_exceptions.py +0 -0
  60. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_board_info.py +0 -0
  61. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_board_list.py +0 -0
  62. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_bottom_post_list.py +0 -0
  63. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_favourite_boards.py +0 -0
  64. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_mail.py +0 -0
  65. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_newest_index.py +0 -0
  66. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_post.py +0 -0
  67. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_post_list.py +0 -0
  68. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_post_parser.py +0 -0
  69. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_time.py +0 -0
  70. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_user.py +0 -0
  71. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_get_waterball.py +0 -0
  72. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_give_money.py +0 -0
  73. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_i18n.py +0 -0
  74. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_init.py +0 -0
  75. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_logger.py +0 -0
  76. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_parse_query_post.py +0 -0
  77. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_post.py +0 -0
  78. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_reply_post.py +0 -0
  79. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_search_user.py +0 -0
  80. {pyptt-2.0.8 → pyptt-2.0.9}/tests/test_service.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyPtt
3
- Version: 2.0.8
3
+ Version: 2.0.9
4
4
  Summary: PyPtt github: https://github.com/PyPtt/PyPtt
5
5
  Author-email: CodingMan <pttcodingman@gmail.com>
6
6
  License: GNU Lesser General Public License v3 (LGPLv3)
@@ -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()
@@ -1,4 +1,4 @@
1
- __version__ = '2.0.8'
1
+ __version__ = '2.0.9'
2
2
  __author__ = 'CodingMan'
3
3
  __email__ = 'pttcodingman@gmail.com'
4
4
 
@@ -36,6 +36,9 @@ class Config:
36
36
  # 預設使用 23
37
37
  port = 23
38
38
 
39
+ # 預設驗證 server 端 TLS 憑證;設為 False 可在 SSL 攔截 proxy 環境下使用
40
+ verify_ssl = True
41
+
39
42
  logger_callback = None
40
43
 
41
44
 
@@ -32,12 +32,15 @@ except AttributeError:
32
32
  websockets.http11.USER_AGENT += f' PyPtt/{PyPtt.__version__}'
33
33
  use_http11 = True
34
34
 
35
- ssl_context = None
36
-
37
-
38
- def ssl_init():
39
- global ssl_context
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
- ssl_context = ssl.create_default_context()
51
- ssl_context.check_hostname = False
52
- ssl_context.load_cert_chain(certfile=cert_file.name, keyfile=key_file.name)
53
- ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2
54
- ssl_context.verify_mode = ssl.CERT_NONE
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=ssl_context))
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
+ MHcCAQEEIJ4+93aR3f/McywQGoGTaA4Yp0UkTsG/wnpTMHoRM6GyoAoGCCqGSM49
6
+ AwEHoUQDQgAEIBR8dqNw+UPQDb4TauXJAOiBKt6NtroEnTnugQOWNIoK68pZZFxJ
7
+ IlC1pAUKU5aPpihf5ciQx0vtMsKvwL9Q2Q==
8
+ -----END EC PRIVATE KEY-----
9
+ """
10
+
11
+ cert = """-----BEGIN CERTIFICATE-----
12
+ MIIB5zCCAY8CFH565JyYP4U6zJXXDS3k4g54XJ/iMAoGCCqGSM49BAMCMHcxCzAJ
13
+ BgNVBAYTAlRXMQ4wDAYDVQQIDAVTdGF0ZTENMAsGA1UEBwwEQ2l0eTEVMBMGA1UE
14
+ CgwMT3JnYW5pemF0aW9uMRwwGgYDVQQLDBNPcmdhbml6YXRpb25hbCBVbml0MRQw
15
+ EgYDVQQDDAtDb21tb24gTmFtZTAeFw0yNjA1MDkxNDIzMjVaFw0zNjA1MDYxNDIz
16
+ MjVaMHcxCzAJBgNVBAYTAlRXMQ4wDAYDVQQIDAVTdGF0ZTENMAsGA1UEBwwEQ2l0
17
+ eTEVMBMGA1UECgwMT3JnYW5pemF0aW9uMRwwGgYDVQQLDBNPcmdhbml6YXRpb25h
18
+ bCBVbml0MRQwEgYDVQQDDAtDb21tb24gTmFtZTBZMBMGByqGSM49AgEGCCqGSM49
19
+ AwEHA0IABCAUfHajcPlD0A2+E2rlyQDogSrejba6BJ057oEDljSKCuvKWWRcSSJQ
20
+ taQFClOWj6YoX+XIkMdL7TLCr8C/UNkwCgYIKoZIzj0EAwIDRgAwQwIfbizXt/No
21
+ 1GN3IfYB6qRwEZMJ8/AV31mWZve37j1g2AIgPQuPxE3QfgaxMsAmy6s0Xvs1dCRk
22
+ 65bTnGMhK3zjpJE=
23
+ -----END CERTIFICATE-----
24
+ """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyPtt
3
- Version: 2.0.8
3
+ Version: 2.0.9
4
4
  Summary: PyPtt github: https://github.com/PyPtt/PyPtt
5
5
  Author-email: CodingMan <pttcodingman@gmail.com>
6
6
  License: GNU Lesser General Public License v3 (LGPLv3)
@@ -1,24 +0,0 @@
1
- key = """-----BEGIN EC PARAMETERS-----
2
- BggqhkjOPQMBBw==
3
- -----END EC PARAMETERS-----
4
- -----BEGIN EC PRIVATE KEY-----
5
- MHcCAQEEIERB+UA+r+F9qEtBJ52f9p3sWAQkNIl0UZJv6O3vj3qtoAoGCCqGSM49
6
- AwEHoUQDQgAEgTo7bZCEZpOdQa2o6P6KnSyVhfsFpvnEK0FGiU/V6xz6XWUMIVSy
7
- +7dG5zGx7/OHa3iK6txCh11mPb+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