{"id":467,"date":"2022-07-30T21:14:34","date_gmt":"2022-07-30T13:14:34","guid":{"rendered":"https:\/\/himpqblog.cn\/?p=467"},"modified":"2022-07-30T21:14:34","modified_gmt":"2022-07-30T13:14:34","slug":"%e7%ac%94%e8%ae%b0-python-ssl-alpn-%e8%ae%be%e7%bd%ae%e5%8d%8f%e8%ae%ae","status":"publish","type":"post","link":"https:\/\/himpqblog.cn\/index.php\/archives\/467","title":{"rendered":"[\u7b14\u8bb0] Python SSL ALPN \u8bbe\u7f6e\u534f\u8bae"},"content":{"rendered":"\n<p> \u6700\u8fd1\u5728\u7814\u7a76HTTP2\u534f\u8bae\uff0c\u60f3\u7528Python\u5b9e\u73b0\u4e00\u4e0b\u670d\u52a1\u7aef\u3002\u4f46\u662f\u7f51\u7edc\u4e0a\u6240\u76f8\u4f20\u7684\u901a\u8fc7\u5b57\u6bb5 <strong><em>Upgrade: h2c <\/em><\/strong>\u6240\u8bf7\u6c42\u5347\u7ea7\u5230http2\u6839\u672c\u6ca1\u7528\u3002<\/p>\n\n\n\n<p>\u56e0\u4e3a\u6d4f\u89c8\u5668\u53ea\u652f\u6301\u52a0\u5bc6\u7684http2\uff0c\u800ch2c\u662fhttp2 cleartext\uff08\u660e\u6587http2\uff09\uff0c\u6240\u4ee5\u6ca1\u6709\u7528\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><a href=\"https:\/\/docs.python.org\/zh-cn\/3\/library\/ssl.html#ssl.SSLContext.set_alpn_protocols\">Python docs &#8211; ssl.SSLContext.set_alpn_protocols<\/a><\/p>\n\n\n\n<p>\u8be5\u6587\u6863\u8bb2\u8ff0\u4e86\u52a0\u5bc6\u7684http2\u5982\u4f55\u4f7f\u5f97\u670d\u52a1\u5668\u5728 ALPN \u53d1\u9001\u62a5\u6587\u65f6\u544a\u8bc9\u5ba2\u6237\u7aef\u670d\u52a1\u5668\u6240\u652f\u6301\u7684\u534f\u8bae<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"144\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2022\/07\/image-1024x144.png\" alt=\"\" class=\"wp-image-468\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2022\/07\/image-1024x144.png 1024w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2022\/07\/image-300x42.png 300w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2022\/07\/image-768x108.png 768w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2022\/07\/image.png 1160w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\uff08\u5373\u5f53\u4f60\u521b\u5efa\u4e86\u4e00\u4e2a SSLContext \u5bf9\u8c61\u4e4b\u540e\u53ef\u4ee5\u6307\u5b9a\u5176\u5bf9\u5ba2\u6237\u7aef\u8fd4\u56de\u7684\u652f\u6301\u534f\u8bae<\/p>\n\n\n\n<p>&#8212;\u4e0b\u9762\u662fPython\u6587\u6863\u539f\u6587<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><a href=\"https:\/\/docs.python.org\/zh-cn\/3\/library\/ssl.html#module-ssl\"><code>ssl<\/code><\/a>\u00a0&#8212; \u5957\u63a5\u5b57\u5bf9\u8c61\u7684 TLS\/SSL \u5305\u88c5\u5668<\/p><cite><code>SSLContext.set_alpn_protocols<\/code>(<em>protocols<\/em>)<a href=\"https:\/\/docs.python.org\/zh-cn\/3\/library\/ssl.html#ssl.SSLContext.set_alpn_protocols\"><\/a><br>\u6307\u5b9a\u5728 SSL\/TLS \u63e1\u624b\u671f\u95f4\u5957\u63a5\u5b57\u5e94\u5f53\u901a\u544a\u7684\u534f\u8bae\u3002 \u5b83\u5e94\u4e3a\u7531 ASCII \u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u5217\u8868\uff0c\u4f8b\u5982\u00a0<code>['http\/1.1',\u00a0'spdy\/2']<\/code>\uff0c\u6309\u9996\u9009\u987a\u5e8f\u6392\u5217\u3002 \u534f\u8bae\u7684\u9009\u62e9\u5c06\u5728\u63e1\u624b\u671f\u95f4\u53d1\u751f\uff0c\u5e76\u4f9d\u636e\u00a0<a href=\"https:\/\/tools.ietf.org\/html\/rfc7301.html\"><strong>RFC 7301<\/strong><\/a>\u00a0\u6765\u6267\u884c\u3002 \u5728\u63e1\u624b\u6210\u529f\u540e\uff0c<a href=\"https:\/\/docs.python.org\/zh-cn\/3\/library\/ssl.html#ssl.SSLSocket.selected_alpn_protocol\"><code>SSLSocket.selected_alpn_protocol()<\/code><\/a>\u00a0\u65b9\u6cd5\u5c06\u8fd4\u56de\u5df2\u8fbe\u6210\u4e00\u81f4\u7684\u534f\u8bae\u3002<br>\u5982\u679c\u00a0<a href=\"https:\/\/docs.python.org\/zh-cn\/3\/library\/ssl.html#ssl.HAS_ALPN\"><code>HAS_ALPN<\/code><\/a>\u00a0\u4e3a\u00a0<code>False<\/code>\u00a0\u5219\u6b64\u65b9\u6cd5\u5c06\u5f15\u53d1\u00a0<a href=\"https:\/\/docs.python.org\/zh-cn\/3\/library\/exceptions.html#NotImplementedError\"><code>NotImplementedError<\/code><\/a>\u3002<br><em>3.5 \u65b0\u7248\u529f\u80fd.<\/em><\/cite><\/blockquote>\n\n\n\n<p><\/p>\n\n\n\n<p>\u8fd8\u6709\u4e00\u4e2a\u5f88\u6709\u610f\u601d\u7684\u51fd\u6570\uff0c<em>SSLSocket.<code>selected_alpn_protocol<\/code><\/em>\uff0c\u5b83\u5728Socket\u8fde\u63a5\u5efa\u7acb\u4e4b\u540e\u8c03\u7528\u4f1a\u8fd4\u56de\u5ba2\u6237\u7aef\u6240\u9009\u7528\u7684\u534f\u8bae\u3002<\/p>\n\n\n\n<p>&#8212;\u4e0b\u9762\u662fPython\u6587\u6863\u539f\u6587<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><a href=\"https:\/\/docs.python.org\/zh-cn\/3\/library\/ssl.html#module-ssl\"><code>ssl<\/code><\/a>\u00a0&#8212; \u5957\u63a5\u5b57\u5bf9\u8c61\u7684 TLS\/SSL \u5305\u88c5\u5668<\/p><cite><code>SSLSocket.selected_alpn_protocol<\/code>()<a href=\"https:\/\/docs.python.org\/zh-cn\/3\/library\/ssl.html#ssl.SSLSocket.selected_alpn_protocol\"><\/a><br>\u8fd4\u56de\u5728 TLS \u63e1\u624b\u671f\u95f4\u6240\u9009\u62e9\u7684\u534f\u8bae\u3002 \u5982\u679c\u00a0<a href=\"https:\/\/docs.python.org\/zh-cn\/3\/library\/ssl.html#ssl.SSLContext.set_alpn_protocols\"><code>SSLContext.set_alpn_protocols()<\/code><\/a>\u00a0\u672a\u88ab\u8c03\u7528\uff0c\u5982\u679c\u53e6\u4e00\u65b9\u4e0d\u652f\u6301 ALPN\uff0c\u5982\u679c\u6b64\u5957\u63a5\u5b57\u4e0d\u652f\u6301\u4efb\u4f55\u5ba2\u6237\u7aef\u6240\u7528\u7684\u534f\u8bae\uff0c\u6216\u8005\u5982\u679c\u63e1\u624b\u5c1a\u672a\u53d1\u751f\uff0c\u5219\u5c06\u8fd4\u56de\u00a0<code>None<\/code>\u3002<br><em>3.5 \u65b0\u7248\u529f\u80fd.<\/em><\/cite><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5728\u7814\u7a76HTTP2\u534f\u8bae\uff0c\u60f3\u7528Python\u5b9e\u73b0\u4e00\u4e0b\u670d\u52a1\u7aef\u3002\u4f46\u662f\u7f51\u7edc\u4e0a\u6240\u76f8\u4f20\u7684\u901a\u8fc7\u5b57\u6bb5 Upgrade: h2c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-467","post","type-post","status-publish","format-standard","hentry","category-10"],"_links":{"self":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=467"}],"version-history":[{"count":1,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":469,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/467\/revisions\/469"}],"wp:attachment":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}