{"id":1124,"date":"2021-08-20T09:50:34","date_gmt":"2021-08-20T01:50:34","guid":{"rendered":"http:\/\/www.dxQerp.com\/?p=1124"},"modified":"2024-04-28T12:19:48","modified_gmt":"2024-04-28T04:19:48","slug":"postfix-tls","status":"publish","type":"post","link":"http:\/\/www.dxQerp.com\/?p=1124","title":{"rendered":"Postfix &#8211; TLS"},"content":{"rendered":"\r\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\r\n<h2>\u70ba\u4e86\u4f7f\u7528 TLS\uff0cPostfix \u670d\u52d9\u5668\u901a\u5e38\u9700\u8981&#8217;<strong>\u8b49\u66f8&#8217;<\/strong>\u548c&#8217;<strong>\u79c1\u9470&#8217;<\/strong>\u3002<\/h2>\r\n<p>\u5169\u8005\u90fd\u5fc5\u9808\u662f \u201c<strong>PEM<\/strong>\u201d \u683c\u5f0f, <strong>\u79c1\u9470<\/strong>\u4e0d\u5f97\u52a0\u5bc6.<\/p>\r\n<p>CA\u8b49\u66f8, \u9700\u8981<strong>\u767c\u884c\u6a5f\u69cb<\/strong> (\u4ed8\u8cbb \u6216\u662f \u81ea\u5df1\u5c31\u662f\u767c\u884c\u6a5f\u69cb)<\/p>\r\n<p><strong>\u53d7\u4fe1\u4efb\u7684 CA<\/strong><\/p>\r\n<pre class=\"wp-block-code\"><code>dnf info ca-certificates<\/code><\/pre>\r\n<p><strong>\u7522\u751f SSL \u6191\u8b49<\/strong><\/p>\r\n<p>\u5229\u7528 dovecot \u7684 \u8173\u672c mkcert.sh \u751f\u6210<\/p>\r\n<pre class=\"wp-block-code\"><code>vi \/etc\/pki\/dovecot\/dovecot-openssl.cnf\u00a0 (dovecot-openssl.cnf \u6a23\u677f)<\/code><\/pre>\r\n<pre class=\"wp-block-code\"><code>\/usr\/libexec\/dovecot\/mkcert.sh\u00a0 \u00a0(\u9ed8\u8a8d\u60c5\u6cc1\u4e0b)<\/code><\/pre>\r\n<p>\u8b49\u66f8 \u5275\u5efa\u70ba \/etc\/pki\/tls\/certs\/mail.dxqerp.com.pem<br \/>\u79c1\u9470 \u5275\u5efa\u70ba \/etc\/pki\/tls\/private\/mail.dxqerp.com.pem<\/p>\r\n<p>\u6b64\u5916\uff0c\u9ed8\u8a8d\u60c5\u6cc1\u4e0b\uff0c\u8b49\u66f8\u5c07\u5728 365 \u5929\u540e\u904e\u671f\u3002<br \/>\u5982\u679c\u60a8\u60f3\u66f4\u6539\u5176\u4e2d\u4efb\u4f55\u4e00\u9805\uff0c\u8acb\u4fee\u6539 mkcert.sh \u8173\u672c<\/p>\r\n<pre class=\"wp-block-code\"><code>smtpd_tls_cert_file =\/etc\/pki\/tls\/certs\/mail.dxqerp.com.pem\r\nsmtpd_tls_key_file =\/etc\/pki\/tls\/private\/mail.dxqerp.com.pem<\/code><\/pre>\r\n<p><strong>\u8b49\u66f8 \u548c \u79c1\u9470<\/strong><\/p>\r\n<p>PEM \u683c\u5f0f\u662f\u8b49\u66f8\u9812\u767c\u6a5f\u69cb\u9812\u767c\u8b49\u66f8\u7684\u6700\u5e38\u898b\u683c\u5f0f\u3002<br \/>PEM \u8b49\u66f8\u901a\u5e38\u5177\u6709\u64f4\u5c55\u540d\uff0c\u4f8b\u5982 .pem\u3001.crt\u3001.cer \u548c .key\u3002<br \/>\u5b83\u5011\u662f Base64 \u7de8\u78bc\u7684 ASCII \u6587\u4ef6\uff0c<\/p>\r\n<p>\u5305\u542b\u201c&#8212;&#8211;BEGIN CERTIFICATE&#8212;&#8211;\u201d\u548c\u201c&#8212;&#8211;END CERTIFICATE&#8212;&#8211;\u201d\u8a9e\u53e5\u3002<br \/>\u670d\u52d9\u5668\u8b49\u66f8\u3001\u4e2d\u9593\u8b49\u66f8\u548c\u79c1\u9470\u90fd\u53ef\u4ee5\u653e\u5165 PEM \u683c\u5f0f\u3002<\/p>\r\n<p><strong>\u78ba\u8a8d<\/strong><\/p>\r\n<pre class=\"wp-block-code\"><code>openssl x509 -in mail.dxqerp.com.pem -noout -subject<\/code><\/pre>\r\n<pre class=\"wp-block-code\"><code>openssl x509 -<span class=\"hljs-keyword\">in<\/span> mail.dxqerp.com.pem -noout -text<\/code><\/pre>\r\n<p><strong>\u914d\u7f6e <\/strong><br \/><strong>Smtp Server<\/strong><\/p>\r\n<pre class=\"wp-block-code\"><code><span style=\"color: #800000;\">smtpd_tls_security_level = may<\/span>\u00a0 # \u9810\u8a2d \u7a7a\u5b57\u4e32\r\n# \u8f6c\u53d1\u90ae\u4ef6\u914d\u7f6e\u542f\u7528SSL\/TLS,\u82e5remote SMTP server\u652f\u6301 TLS\/SSL\uff0c\u5219\u4f7f\u7528TLS\/SSL\u4f20\u8f93\uff0c\u5426\u5219\u4f7f\u7528\u4f20\u7edf\u7684SMTP+TCP\u3002<\/code><\/pre>\r\n<pre class=\"wp-block-code\"><code><span style=\"color: #800000;\">smtpd_tls_loglevel = 1<\/span>\u00a0 \u00a0# \u9810\u8a2d 0\r\n# \u50c5\u8a18\u9304 TLS \u63e1\u624b\u5b8c\u6210\u6642\u7684\u6458\u8981\u6d88\u606f<\/code><\/pre>\r\n<pre class=\"wp-block-code\"><code><span style=\"color: #800000;\">smtpd_tls_received_header = yes<\/span>\u00a0 # \u9810\u8a2d \u7a7a\u5b57\u4e32\r\n# \u8acb\u6c42 Postfix SMTP \u670d\u52d9\u5668\u751f\u6210 Received: \u6d88\u606f\u6a19\u982d\uff0c\u5176\u4e2d\u5305\u542b\u6709\u95dc\u4f7f\u7528\u7684\u5354\u8b70\u548c\u5bc6\u78bc\u7684\u4fe1\u606f<\/code><\/pre>\r\n<pre class=\"wp-block-code\"><code><span style=\"color: #800000;\">smtpd_tls_auth_only = yes<\/span>\r\n#\u5f37\u8feb SASL \u9a57\u8b49\u63a1\u7528 TLS \u4e26\u7981\u6b62\u7d14\u6587\u5b57\u9a57\u8b49\u767c\u751f\uff0c\u9664\u975e\u5df2\u7d93\u5efa\u7acb\u4e86\u4e00\u500b TLS \u5de5\u4f5c\u968e\u6bb5\u3002\r\n\uff08\u5728\u6e2c\u8a66\u6642\u8a3b\u91cb\u6389 smtpd_tls_auth_only = yes \u4e5f\u8a31\u6703\u6709\u7528\uff0c\u597d\u8b93\u6211\u5011\u80fd\u6e2c\u8a66 SSL\uff0fTLS \u80fd\u5426\u904b\u4f5c\uff0c\u4f46\u7576 SSL\uff0fTLS \u5931\u6548\u6642\u4ecd\u6709\u7d14\u6587\u5b57 SASL \u9a57\u8b49\u4f5c\u70ba\u5f8c\u5099\uff09\u3002\r\n\u5982\u679c\u4e00\u5207\u5982\u671f\u904b\u4f5c\uff0c\u6211\u5011\u61c9\u8a72\u6703\u770b\u898b\u4f3a\u670d\u5668\u63d0\u4f9b STARTTLS\uff0c\u800c\u4e14\u56e0\u70ba\u6211\u5011\u6307\u5b9a 'smtpd_tls_auth_only = yes'\uff0c\u7d14\u6587\u5b57 SASL \u9a57\u8b49\uff08AUTH PLAIN LOGIN \u53ca AUTH=PLAIN LOGIN\uff09\u5df2\u4e0d\u518d\u88ab\u652f\u63f4\u3002<\/code><\/pre>\r\n<p><strong>Smtp Client<\/strong><\/p>\r\n<pre class=\"wp-block-code\"><code><span style=\"color: #800000;\">smtp_tls_security_level = encrypt<\/span>\u00a0 # \u9810\u8a2d may\r\n# Postfix SMTP \u5ba2\u6236\u7aef\u7684\u5b89\u5168\u7d1a\u5225 ( encrypt \u52a0\u5bc6)<\/code><\/pre>\r\n<pre class=\"wp-block-code\"><code><span style=\"color: #800000;\">smtp_tls_note_starttls_offer = yes<\/span>\r\n# \u7576\u5c1a\u672a\u70ba\u8a72\u670d\u52d9\u5668\u555f\u7528 TLS \u6642\uff0c\u8a18\u9304\u63d0\u4f9b STARTTLS \u7684\u9060\u7a0b SMTP \u670d\u52d9\u5668\u7684\u4e3b\u6a5f\u540d\u3002<\/code><\/pre>\r\n<pre class=\"wp-block-code\"><code>systemctl restart postfix<\/code><\/pre>\r\n<p><strong>\u6e2c\u8a66<\/strong><\/p>\r\n<pre class=\"wp-block-code\"><code>echo \"Body: This is a test mail. Hallo Charlie\" | mail -s \"Subject: A big test\" qq@mail.dxqerp.com<\/code><\/pre>\r\n<p><strong>Connection to the SMTP server<\/strong><\/p>\r\n<pre class=\"wp-block-code\"><code>openssl s_client -connect localhost:25 -starttls smtp<\/code><\/pre>\r\n<h4 id=\"starttls_command\" class=\"sectionedit18 heading-combo\">STARTTLS Command<\/h4>\r\n<p class=\"wp-block-code\"><code>nc localhost 25<\/code><\/p>\r\n<h2><strong>THE END<\/strong><\/h2>\r\n<h3>\u53c3\u8003<\/h3>\r\n<p><a href=\"https:\/\/datacadamia.com\/marketing\/email\/postfix\/tls#starttls_command\">https:\/\/datacadamia.com\/marketing\/email\/postfix\/tls#starttls_command<\/a><\/p>\r\n<p><a href=\"https:\/\/wiki.centos.org\/zh-tw\/HowTos\/postfix_sasl\">https:\/\/wiki.centos.org\/zh-tw\/HowTos\/postfix_sasl<\/a><\/p>\r\n<p><a href=\"https:\/\/doc.dovecot.org\/configuration_manual\/howto\/postfix_and_dovecot_sasl\/#howto-postfix-and-dovecot-sasl\">https:\/\/doc.dovecot.org\/configuration_manual\/howto\/postfix_and_dovecot_sasl\/#howto-postfix-and-dovecot-sasl<\/a><\/p>\r\n<p><a href=\"https:\/\/www.linuxtechi.com\/install-configure-postfix-mailserver-centos-8\/\">https:\/\/www.linuxtechi.com\/install-configure-postfix-mailserver-centos-8\/<\/a><\/p>\r\n<p>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n<\/p>\r\n<p><a href=\"https:\/\/www.cnblogs.com\/shenlinken\/p\/9968274.html\">https:\/\/www.cnblogs.com\/shenlinken\/p\/9968274.html<\/a><\/p>\r\n<\/div><\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>\u70ba\u4e86\u4f7f\u7528 TLS\uff0cPostfix \u670d\u52d9\u5668\u901a\u5e38\u9700\u8981&#8217;\u8b49\u66f8&#8217;\u548c&#8217;\u79c1\u9470&#038;#821 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1141,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[27],"tags":[],"class_list":["post-1124","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-postfix","post_format-post-format-image"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.dxQerp.com\/wp-content\/uploads\/2021\/09\/postfix-TLS-How-to.png?fit=470%2C138","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=\/wp\/v2\/posts\/1124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1124"}],"version-history":[{"count":5,"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=\/wp\/v2\/posts\/1124\/revisions"}],"predecessor-version":[{"id":1302,"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=\/wp\/v2\/posts\/1124\/revisions\/1302"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=\/wp\/v2\/media\/1141"}],"wp:attachment":[{"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1124"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.dxQerp.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}