{"id":10005966,"date":"2022-07-22T11:37:34","date_gmt":"2022-07-22T03:37:34","guid":{"rendered":"https:\/\/ityet.com\/?p=10005966"},"modified":"2022-07-22T11:37:34","modified_gmt":"2022-07-22T03:37:34","slug":"%e7%aa%81%e7%a0%b4%e7%a5%9e%e5%a5%87%e7%9a%84cloudflare%e9%98%b2%e7%81%ab%e5%a2%99","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10005966","title":{"rendered":"\u7a81\u7834\u795e\u5947\u7684Cloudflare\u9632\u706b\u5899"},"content":{"rendered":"<h2>\u80cc\u666f<\/h2>\n<p>\u6700\u8fd1\u78b0\u5230\u4e00\u4e2a\u795e\u5947\u7684\u7f51\u7ad9\uff0c\u5728\u6d4f\u89c8\u5668\u53ef\u4ee5\u6253\u5f00\uff0c\u4f46\u662f\u901a\u8fc7 curl \u6216\u8005 \u4ee3\u7801\u8bbf\u95ee\u5c31\u76f4\u63a5 403\uff0c\u6211\u4f30\u6478\u7740\u8fd9\u80af\u5b9a\u662f\u505a\u4e86<code>UA\u6821\u9a8c<\/code>\uff0c\u4e8e\u662f\u8bf7\u6c42\u7684\u65f6\u5019\u628a\u6d4f\u89c8\u5668\u7684 UA \u7ed9\u5e26\u4e0a\uff0c\u7136\u540e\u8bbf\u95ee\u53d1\u73b0\u8fd8\u662f 403\uff0c\u4e0d\u8fc7\u8fd9\u4e5f\u96be\u4e0d\u5012\u6211\uff0c\u80af\u5b9a\u662f\u8fd8\u6709\u6821\u9a8c\u5176\u5b83\u7684\u8bf7\u6c42\u5934\uff0c\u76f4\u63a5\u6d4f\u89c8\u5668\u6253\u5f00 network\uff0c\u628a\u6240\u6709\u7684\u8bf7\u6c42\u5934\u590d\u5236\u8fc7\u6765\u5e76\u4e14\u5e26\u4e0a\uff0c\u786e\u4fdd\u6211\u548c\u6d4f\u89c8\u5668\u5728 http \u534f\u8bae\u5c42\u9762\u7684\u8bf7\u6c42\u5b8c\u5168\u4e00\u6837\uff0c\u8fd9\u6837\u4e0d\u53ef\u80fd\u4f1a\u5931\u8d25\u4e86\u5427\uff0c\u7136\u800c\u8fd0\u884c\u5b8c\u53d1\u73b0\u8fd8\u662f 403\u3002<\/p>\n<blockquote><p>\u653e\u4e2a\u5730\u5740: <a href=\"https:\/\/link.segmentfault.com\/?enc=jEy3Liu0WVoLXl2TjgUK8A%3D%3D.QoQFcswqP1iiSFbsOPZiTh2aGqaX3Re6sqcyjLxzopg%3D\" rel=\"nofollow\">https:\/\/pixabay.com<\/a><\/p><\/blockquote>\n<h2>\u601d\u8003<\/h2>\n<p>\u670d\u52a1\u7aef\u6821\u9a8c\u5ba2\u6237\u7aef\u6ca1\u6709\u4ec0\u4e48\u9ed1\u9b54\u6cd5\uff0c\u56e0\u4e3a\u90fd\u662f\u901a\u8fc7 TCP \u534f\u8bae\u901a\u8baf\uff0c\u4e0d\u53ef\u80fd\u5b58\u5728\u6d4f\u89c8\u5668\u53d1\u9001\u4e00\u4e2a HTTP \u62a5\u6587\u548c\u6211\u53d1\u9001\u4e00\u4e2a\u540c\u6837\u7684 HTTP \u62a5\u6587\u670d\u52a1\u5668\u80fd\u8bc6\u522b\u51fa\u6765\uff0c\u65e2\u7136\u4e0d\u662f\u6821\u9a8c\u7684 HTTP \u5c42\uff0c\u90a3\u53ea\u53ef\u80fd\u662f\u5728 TLS \u5c42\u6821\u9a8c\u7684\uff0c\u4e8e\u662f\u796d\u51fa<code>wireshark<\/code>\u6293\u5305\uff0c\u770b\u770b\u80fd\u4e0d\u80fd\u627e\u5230 TLS \u63e1\u624b\u4e2d\u5dee\u5f02\u5316\u7684\u4e1c\u897f\uff0c\u4f17\u6240\u5468\u77e5\u5728 TLS \u63e1\u624b\u65f6\u6709\u4e00\u4e2a\u5ba2\u6237\u7aef\u53d1\u9001\u7ed9\u670d\u52a1\u7aef\u7684<code>Client Hello<\/code>\u62a5\u6587\uff0c\u5f88\u6709\u53ef\u80fd\u5c31\u662f\u6839\u636e\u5b83\u6765\u8fa8\u522b\u6d4f\u89c8\u5668\u548c\u975e\u6d4f\u89c8\u5668\u8bf7\u6c42\u7684\uff0c\u56e0\u4e3a\u5728\u8fd9\u4e2a\u62a5\u6587\u4e2d\uff0c\u5ba2\u6237\u7aef\u8981\u544a\u8bc9\u670d\u52a1\u7aef\u652f\u6301\u7684\u52a0\u5bc6\u5957\u4ef6\uff0cTLS \u7248\u672c\u7b49\u7b49\u4fe1\u606f\uff0c\u800c\u8fd9\u4e9b\u4fe1\u606f\u6839\u636e\u5ba2\u6237\u7aef\u7684\u5b9e\u73b0\u90fd\u4f1a\u6709\u6240\u5dee\u5f02\uff0c\u5148\u6293\u4e2a\u6b63\u5e38\u6d4f\u89c8\u5668\u8bf7\u6c42\u7684\u62a5\u6587\u770b\u770b\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042207806\" alt=\"\" title=\"\" loading=\"lazy\" ><\/p>\n<p>\u7136\u540e\u518d\u901a\u8fc7 curl \u8bbf\u95ee\u6293\u5305\uff0c\u5982\u4e0b\u56fe\uff1b<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc1gk4\" alt=\"\" title=\"\" loading=\"lazy\" ><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u4e24\u8fb9\u7684\u62a5\u6587\u786e\u5b9e\u5b58\u5728\u5f88\u5927\u7684\u5dee\u5f02\uff0c\u9010\u4e00\u5bf9\u6bd4\u6392\u67e5\u4e4b\u540e\u53d1\u73b0\u5f88\u6709\u53ef\u80fd\u662f\u56e0\u4e3a curl \u7684\u8bf7\u6c42\u62a5\u6587\u91cc\u7f3a\u5c11<code>supported_versions<\/code>\u6269\u5c55\u4fe1\u606f\u5bfc\u81f4\u7684 403\uff0c\u6d4f\u89c8\u5668\u90a3\u8fb9\u5728\u6b64\u6269\u5c55\u4fe1\u606f\u5185\u5bb9\u5982\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc1gk9\" alt=\"\" title=\"\" loading=\"lazy\" ><\/p>\n<p>\u8868\u793a\u652f\u6301<code>TLSv1.2<\/code>\u548c<code>TLSv1.3<\/code>\uff0c\u800c\u4e14\u6700\u7ec8\u63e1\u624b\u4e4b\u540e\u7684\u534f\u8bae\u4e5f\u662f\u5207\u6362\u5230\u4e86<code>TLSv1.3<\/code>\uff0c\u5728\u4e0a\u9762\u4e24\u4e2a\u5bf9\u6bd4\u56fe\u53ef\u4ee5\u770b\u5230\uff0c\u6d4f\u89c8\u5668\u8d70\u7684\u662f<code>TLSv1.3<\/code>\uff0c\u800c curl \u8d70\u7684\u662f<code>TLSv1.2<\/code>\uff0c\u53ef\u80fd\u662f\u4e00\u5b9a\u8981\u4f7f\u7528<code>TLSv1.3<\/code>\u624d\u80fd\u8bbf\u95ee\u6210\u529f\u3002<\/p>\n<h2>\u9a8c\u8bc1<\/h2>\n<p>\u9a6c\u4e0a google \u4e86\u4e0b\u5982\u4f55\u6307\u5b9a curl \u7684 TLS \u7248\u672c\uff0c\u53d1\u73b0\u53ea\u9700\u8981\u52a0\u4e0a<code>--tlsv1.3<\/code>\u53c2\u6570\u5c31\u53ef\u4ee5\u4e86\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"bash\">$ curl -I --tlsv1.3 'https:\/\/pixabay.com\/'  \/\n&gt; -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' \/\n&gt; -H 'user-agent: Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/103.0.5060.114 Safari\/537.36 Edg\/103.0.1264.49'\nHTTP\/2 200\ndate: Fri, 22 Jul 2022 02:40:35 GMT\ncontent-type: text\/html; charset=utf-8\ncf-ray: 72e8cffc18c73d5a-HKG\ncache-control: s-maxage=86400\ncontent-language: en\nvary: Accept-Encoding, Cookie, Accept-Language\ncf-cache-status: MISS\ncontent-security-policy: frame-ancestors none\nexpect-ct: max-age=604800, report-uri=&quot;https:\/\/report-uri.cloudflare.com\/cdn-cgi\/beacon\/expect-ct&quot;\nreferrer-policy: strict-origin-when-cross-origin\nx-frame-options: DENY\nset-cookie: __cf_bm=Cy4a751rDND6kHhu.RzEr5DpqnaxRdpUxaMfNfkya0A-1658457635-0-AS1DaewDqNjWHZ\/m74A88bNyEG0EFsZAwmsm\/ON5QQEuh8B6XOS7PkSnhGgXPLV+LtEvzOKTy\/WWHmwY63uGlD0=; path=\/; expires=Fri, 22-Jul-22 03:10:35 GMT; domain=.pixabay.com; HttpOnly; Secure; SameSite=None\nserver: cloudflare\nalt-svc: h3=&quot;:443&quot;; ma=86400, h3-29=&quot;:443&quot;; ma=86400<\/code><\/pre>\n<p>\u7ecf\u8fc7\u53cd\u590d\u9a8c\u8bc1\uff0c\u53d1\u73b0\u9664\u4e86\u8981\u6307\u5b9a<code>tlsv1.3<\/code>\u4e4b\u5916\uff0c\u8fd8\u9700\u8981\u52a0\u4e0a<code>accept-language<\/code>\u548c<code>user-agent<\/code>\u5934\uff0c\u5e76\u4e14\u4e00\u5b9a\u5f97\u662f http2 \u534f\u8bae\uff0c\u4e09\u4e2a\u6761\u4ef6\u7f3a\u4e00\u4e0d\u53ef\u3002<\/p>\n<h2>nodejs \u8bbf\u95ee<\/h2>\n<p>\u4e0a\u9762\u8bf4\u5230\u4e86\u4e00\u5b9a\u8981\u8d70 http2 \u534f\u8bae\uff0c\u800c\u73b0\u5728\u5e02\u9762\u4e0a\u6d41\u884c\u7684 http client \u57fa\u672c\u90fd\u662f\u53ea\u652f\u6301 http1.1\uff0c\u6240\u4ee5\u53ea\u80fd\u76f4\u63a5\u4ece\u57fa\u7840\u5e93\u5165\u624b\u4e86\uff0c\u5b98\u65b9\u6709\u4e00\u4e2a<code>http2<\/code>\u7684\u5e93\uff0c\u4e00\u756a\u8c03\u6559\u4e4b\u540e\u4e5f\u662f\u6210\u529f\u8bf7\u6c42\u4e86\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"js\">const http2 = require(&quot;http2&quot;);\n\nfunction get(host, path) {\n  return new Promise((resolve, reject) =&gt; {\n    const session = http2.connect(`https:\/\/${host}`, {\n      minVersion: &quot;TLSv1.3&quot;,\n      maxVersion: &quot;TLSv1.3&quot;,\n    });\n\n    session.on(&quot;error&quot;, (err) =&gt; {\n      reject(err);\n    });\n\n    const req = session.request({\n      [http2.constants.HTTP2_HEADER_AUTHORITY]: host,\n      [http2.constants.HTTP2_HEADER_METHOD]: http2.constants.HTTP2_METHOD_GET,\n      [http2.constants.HTTP2_HEADER_PATH]: path,\n      &quot;user-agent&quot;:\n        &quot;Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/100.0.4896.127 Safari\/537.36 Edg\/100.0.1185.50&quot;,\n    });\n\n    req.setEncoding(&quot;utf8&quot;);\n    let data = &quot;&quot;;\n    req.on(&quot;data&quot;, (chunk) =&gt; {\n      data += chunk;\n    });\n    req.on(&quot;end&quot;, () =&gt; {\n      session.close();\n      if (data) {\n        try {\n          resolve(data);\n        } catch (e) {\n          reject(e);\n        }\n      }\n    });\n    req.on(&quot;error&quot;, (err) =&gt; {\n      reject(err);\n    });\n    req.end();\n  });\n}\n\n(async function () {\n  const data = await get(&quot;pixabay.com&quot;, &quot;\/&quot;);\n  console.log(data);\n})();<\/code><\/pre>\n<h2>\u6df1\u5165<\/h2>\n<p>\u867d\u7136\u5df2\u7ecf\u6210\u529f\u8bf7\u6c42\u4e86\uff0c\u4f46\u662f\u672c\u7740\u63a2\u7d22\u7684\u7cbe\u795e\u7ee7\u7eed\u6df1\u5165\u53d1\u73b0 cloudflare \u5b98\u65b9\u6709\u4e00\u7bc7\u535a\u5ba2\u5c31\u662f\u4e13\u95e8\u4ecb\u7ecd\u8fd9\u4e2a TLS \u62e6\u622a\u6280\u672f\u7684\uff0c\u94fe\u63a5\u5982\u4e0b\uff1a<br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=gl7Yp9q3%2Fs34TUAA6LD3Ng%3D%3D.HWuWlON7V234P0IW3%2BPWdicO3G6Lvs6vluQDrJFqkun%2FPtZfJDexD3UXQmr6UjnYqY73Qm0FWuXIEZ5igG0hqw%3D%3D\" rel=\"nofollow\">https:\/\/blog.cloudflare.com\/monsters-in-the-middleboxes\/<\/a><\/p>\n<p>\u5176\u4e2d\u6709\u4e00\u6bb5\u5185\u5bb9\u4e5f\u8bc1\u660e\u4e86\u6211\u7684\u731c\u60f3\uff0c\u7ffb\u8bd1\u540e\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc1gla\" alt=\"\" title=\"\" loading=\"lazy\" ><\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4 cloudflare \u4f1a\u7ef4\u62a4\u4e00\u7ec4\u6d4f\u89c8\u5668\u7684 TLS \u6307\u7eb9\uff0c\u5f53\u6536\u5230\u4e00\u4e2a Client Hello \u8bf7\u6c42\u65f6\uff0c\u4f1a\u68c0\u67e5\u8fd9\u7ec4\u6307\u7eb9\uff0c\u5982\u679c\u5339\u914d\u4e0d\u4e0a\uff0c\u5c31\u4f1a\u62e6\u622a\u8fd9\u4e2a\u8bf7\u6c42\uff0c\u8fd9\u6837\u53ef\u4ee5\u62e6\u622a\u6389\u5927\u90e8\u5206\u4e0d\u662f\u6765\u81ea\u6d4f\u89c8\u5668\u7684\u8bf7\u6c42\u4e86\u3002<\/p>\n<blockquote><p>\u6211\u662f<strong>MonkeyWie<\/strong>\uff0c\u6b22\u8fce\u626b\u7801\ud83d\udc47\ud83d\udc47\u5173\u6ce8\uff01\u4e0d\u5b9a\u671f\u5728\u516c\u4f17\u53f7\u4e2d\u5206\u4eab<code>JAVA<\/code>\u3001<code>Golang<\/code>\u3001<code>\u524d\u7aef<\/code>\u3001<code>docker<\/code>\u3001<code>k8s<\/code>\u7b49\u5e72\u8d27\u77e5\u8bc6\u3002<\/p><\/blockquote>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000025158099\" alt=\"wechat\" title=\"wechat\" loading=\"lazy\" ><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042207804\">https:\/\/segmentfault.com\/a\/1190000042207804<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u6700\u8fd1\u78b0\u5230\u4e00\u4e2a\u795e\u5947\u7684\u7f51\u7ad9\uff0c\u5728\u6d4f\u89c8\u5668\u53ef\u4ee5\u6253\u5f00\uff0c\u4f46\u662f\u901a\u8fc7 curl \u6216\u8005 \u4ee3\u7801\u8bbf\u95ee\u5c31\u76f4\u63a5 403\uff0c\u6211\u4f30\u6478\u7740\u8fd9\u80af [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10005966","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10005966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10005966"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10005966\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10005966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10005966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10005966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}