{"id":176,"date":"2010-03-08T19:45:37","date_gmt":"2010-03-08T11:45:37","guid":{"rendered":"http:\/\/blog.nuface.tw\/?p=176"},"modified":"2010-03-16T12:44:38","modified_gmt":"2010-03-16T04:44:38","slug":"%e5%a6%82%e4%bd%95%e8%a3%bd%e4%bd%9c-ssl-x-509%e6%86%91%e8%ad%89","status":"publish","type":"post","link":"https:\/\/blog.nuface.tw\/?p=176","title":{"rendered":"\u5982\u4f55\u88fd\u4f5c SSL X.509\u6191\u8b49"},"content":{"rendered":"<p><strong><em>\u88fd\u4f5c\u76ee\u7684<\/em><\/strong><br \/>\n\u81ea\u5f9e\u4e0a\u6b21\u767c\u751f\u88ab\u99ed\u4e8b\u4ef6\u5f8c\uff0c\u89ba\u5f97\u7db2\u8def\u5b89\u5168\u9632\u8b77\u771f\u7684\u662f\u5f88\u91cd\u8981\uff0c\u6240\u4ee5\u91dd\u5c0d\u76ee\u524d\uff0c\u516c\u53f8\u6709\u4f7f\u7528\u7684\u7db2\u8def\u670d\u52d9\uff0c\u9032\u884c\u901a\u8a0a\u52a0\u5bc6\u4f5c\u696d\u3002<\/p>\n<p>\u8981\u9032\u884c\u52a0\u5bc6\u4f5c\u696d\uff0c\u5fc5\u9808\u5148\u505a\u597dSSL\u6191\u8b49\uff0c\u5728\u901a\u8a0a\u7684\u5169\u7aef\u628a\u8cc7\u6599\u7528\u516c\u9470\u505a\u52a0\u5bc6\uff0c\u518d\u7531\u63a5\u53d7\u7aef\uff0c\u7528\u79c1\u9470\u505a\u89e3\u5bc6\u7684\u4f5c\u696d\u3002<\/p>\n<p>\u57fa\u672c\u4e0a HTTP \/ SMTP \/ POP3 \/ FTP \/ IMAP \u76ee\u524d\u90fd\u53ef\u4ee5\u652f\u63f4SSL \u7684\u52a0\u5bc6\u4f5c\u696d\uff0c\u6240\u4ee5\u5c31\u91dd\u5c0d\u76ee\u524d\u516c\u53f8\u5728\u7528\u7684\u670d\u52d9\uff0c\u76f4\u63a5\u505a\u4e00\u500bSSL\u6191\u8b49\u7d66\u9019\u4e9b\u670d\u52d9\u7528\u5373\u53ef\u3002<br \/>\n<!--more--><br \/>\n<strong><em>\u74b0\u5883\u8aaa\u660e<\/em><\/strong><br \/>\n\u4f7f\u7528\u865b\u64ec\u6a5f\u4f86\u5efa\u7acbSSL \u6191\u8b49<br \/>\nCentOS 5.4 X86-64 \/ 20G hdd \/ RAM 4G \/ CPU 4<br \/>\nopenssl 0.98e.12.el5_4.1<br \/>\n\u4f7f\u7528root \u5e33\u865f<\/p>\n<p>\u8a2d\u5b9aOpenSSL \u8a2d\u5b9a\u6a94\u7684\u4f4d\u7f6e<\/p>\n<blockquote><p>\n<code>#mkdir \/etc\/ssl<br \/>\n#cp \/etc\/pki\/tls\/openssl.cnf \/etc\/ssl\/.<br \/>\n#cd \/etc\/ssl<br \/>\n#mkdir private<br \/>\n#mkdir certs<br \/>\n#mkdir crl<br \/>\n#mkdir newcerts<br \/>\n#touch index.txt<br \/>\n#export OPENSSL_CONF=\"\/etc\/ssl\/openssl.cnf\"<\/code>\n<\/p><\/blockquote>\n<p>\u7136\u5f8c\u4fee\u6539 \/etc\/ssl\/openssl.cnf \uff0c\u628a\u9019\u4e00\u884c<br \/>\ndir\t\t= ..\/..\/CA\t\t# Where everything is kept<br \/>\n\u6539\u6210\u9019\u6a23<br \/>\ndir\t\t= \/etc\/ssl\t\t# Where everything is kept<br \/>\ncountryName_default = GB \u6539\u70ba TW<\/p>\n<p>\u628a OpenSSL \u8a2d\u5b9a\u6a94\u7684\u4f4d\u7f6e\u52a0\u9032 .bashrc \u4e2d<\/p>\n<blockquote><p><code>#echo \"export OPENSSL_CONF=\\\"\/etc\/ssl\/openssl.cnf\\\"\" >> ~\/.bashrc<\/code><\/p><\/blockquote>\n<p>\u7522\u751f\u4e82\u6578\u7684\u6a94\u6848<\/p>\n<blockquote><p><code>#openssl rand 1024 > \/etc\/ssl\/private\/.rand<br \/>\n#chmod og-rwx \/etc\/ssl\/private\/.rand<\/code><\/p><\/blockquote>\n<p>\u4ee5\u4e0a\u6e96\u5099\u597d\u5f8c\uff0c\u53ef\u4ee5\u958b\u59cb\u88fd\u4f5cRoot CA \u4e86\u3002<\/p>\n<p><strong><em>\u88fd\u4f5cRoot CA<\/em><\/strong><br \/>\n#\u9000\u51fa shell \u91cd\u65b0\u767b\u5165root<br \/>\n\u6211\u5011\u8981\u505a\u7684Root CA \u70banuface.ca \uff0c\u5982\u679c\u4e4b\u524d\u6709\u505a\u904e\u7684\u8a71\uff0c\u73fe\u5728\u518d\u505a\u4e00\u6b21\uff0c\u4e4b\u524d\u7c3d\u7684\u6191\u8b49\u90fd\u6703\u5931\u6548\u3002<\/p>\n<p>\u6b64\u6642\u5fc5\u9808\u70ba\u6700\u9ad8\u5c64\u8a8d\u8b49\u4e2d\u5fc3\u7684 Private Key \u8a2d\u5b9a\u4e00\u500b\u9069\u7576\u7684\u5bc6\u78bc\uff0c\u4ee5\u5f8c\u5728\u7528\u9019\u628aPrivate Key\u7c3d\u767c\u5176\u5b83\u6191\u8b49\u6642\uff0c\u90fd\u9700\u8981\u7528\u5230\u9019\u500b\u5bc6\u78bc\u3002<\/p>\n<blockquote><p><code>#openssl genrsa -des3 -out \/etc\/ssl\/private\/nuface.ca.key.pem  2048<br \/>\n#chmod og-rwx \/etc\/ssl\/private\/nuface.ca.key.pem<\/code><\/p><\/blockquote>\n<p>\u63a5\u8457\u586b\u5beb\u6191\u8b49\u7533\u8acb<br \/>\n\u8ddf\u8ab0\u7533\u8acb\uff1f\u56e0\u70ba\u662fRoot CA \uff0c\u6c92\u6709\u4e0a\u7d1a\u4e86\uff0c\u6240\u4ee5\u5c31\u662f\u8ddf\u81ea\u5df1\u7533\u8acb\u3002<\/p>\n<blockquote><p><code>#openssl req -new -key \/etc\/ssl\/private\/nuface.ca.key.pem -out \/tmp\/nuface.ca.req.pem<\/code><\/p><\/blockquote>\n<p>\u586b\u5165\u8cc7\u6599<\/p>\n<blockquote><p><code>Country Name (2 letter code) [TW]:<br \/>\nState or Province Name (full name) [Taiwan]:<br \/>\nLocality Name (eg, city) [Newbury]:Taipei<br \/>\nOrganization Name (eg, company) [My Company Ltd]:nuface<br \/>\nOrganizational Unit Name (eg, section) []:CA<br \/>\nCommon Name (eg, your name or your server's hostname) []:ca.nuface.tw<br \/>\nEmail Address []:admin@nuface.tw<br \/>\n<\/code><\/p><\/blockquote>\n<p>\u81ea\u5df1\u7d66\u81ea\u5df1\u7c3d\u540d<\/p>\n<blockquote><p><code>#openssl x509 -req -days 7305 -sha1 \\<br \/>\n -extfile \/etc\/ssl\/openssl.cnf -extensions v3_ca \\<br \/>\n -signkey \/etc\/ssl\/private\/nuface.ca.key.pem \\<br \/>\n -in \/tmp\/nuface.ca.req.pem -out \/etc\/ssl\/certs\/nuface.ca.crt.pem<br \/>\n<\/code><\/p><\/blockquote>\n<p>\u522a\u9664\u6191\u8b49\u7533\u8acb\u66f8<\/p>\n<blockquote><p><code>#rm -f \/tmp\/nuface.ca.req.pem<\/code><\/p><\/blockquote>\n<p>\u4fdd\u8b77 nuface.ca.key.pem<\/p>\n<blockquote><p><code>#chmod 0400 \/etc\/ssl\/private\/nuface.ca.key.pem<\/code><\/p><\/blockquote>\n<p>Root CA\u641e\u5b9a\u5f8c\uff0c\u5373\u53ef\u4f7f\u7528\u9019\u500bRoot CA \u7c3d\u767c\u5176\u5b83\u7684\u6191\u8b49\u3002<\/p>\n<p><strong><em>\u88fd\u4f5c\u4f3a\u670d\u5668\u6191\u8b49<\/em><\/strong><br \/>\n\u63a5\u8457\u6211\u5011\u4f86\u88fd\u4f5cblog.nuface.tw \u7684SSL\u6191\u8b49\u3002<\/p>\n<blockquote><p><code>#openssl genrsa -out \/etc\/ssl\/private\/blog.nuface.key.pem 2048<br \/>\n#chmod og-rwx \/etc\/ssl\/private\/blog.nuface.key.pem<br \/>\n<\/code><\/p><\/blockquote>\n<p>\u586b\u5beb\u6191\u8b49\u7533\u8acb\u66f8\uff0c\u5411nuface Root CA \u505a\u7533\u8acb\u3002<\/p>\n<blockquote><p><code>#openssl req -new -key \/etc\/ssl\/private\/blog.nuface.key.pem -out \/tmp\/blog.nuface.req.pem<br \/>\n<\/code><\/p><\/blockquote>\n<p>\u586b\u5165\u8cc7\u6599<\/p>\n<blockquote><p><code>Country Name (2 letter code) [TW]:<br \/>\nState or Province Name (full name) [Taiwan]:<br \/>\nLocality Name (eg, city) [Newbury]:Taipei<br \/>\nOrganization Name (eg, company) [My Company Ltd]:nuface<br \/>\nOrganizational Unit Name (eg, section) []:blog<br \/>\nCommon Name (eg, your name or your server's hostname) []:blog.nuface.tw<br \/>\nEmail Address []:admin@blog.nuface.tw<\/code><\/p><\/blockquote>\n<p>\u7528\u6700\u9ad8\u5c64\u8a8d\u8b49\u4e2d\u5fc3(Root CA)\u7c3d\u767c\u6191\u8b49<\/p>\n<blockquote><p><code>#openssl x509 -req -days 3650 -sha1 \\<br \/>\n -extfile \/etc\/ssl\/openssl.cnf -extensions v3_req \\<br \/>\n -CA \/etc\/ssl\/certs\/nuface.ca.crt.pem -CAkey \/etc\/ssl\/private\/nuface.ca.key.pem \\<br \/>\n -CAserial \/etc\/ssl\/nuface.ca.srl -CAcreateserial \\<br \/>\n -in \/tmp\/blog.nuface.req.pem -out \/etc\/ssl\/certs\/blog.nuface.crt.pem<\/code><\/p><\/blockquote>\n<p>\u522a\u9664\u6191\u8b49\u7533\u8acb\u66f8<\/p>\n<blockquote><p><code>\uff03rm -f \/tmp\/blog.nuface.req.pem<\/code><\/p><\/blockquote>\n<p>\u4fdd\u8b77 blog.nuface.key.pem<\/p>\n<blockquote><p><code>\uff03chmod 0400 \/etc\/ssl\/private\/blog.nuface.key.pem<\/code><\/p><\/blockquote>\n<p>\u4ee5\u4e0a\u70baSSL X.509\u6191\u8b49 \u7684\u88fd\u4f5c \u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u88fd\u4f5c\u76ee\u7684 \u81ea\u5f9e\u4e0a\u6b21\u767c\u751f\u88ab\u99ed\u4e8b\u4ef6\u5f8c\uff0c\u89ba\u5f97\u7db2\u8def\u5b89\u5168\u9632\u8b77\u771f\u7684\u662f\u5f88\u91cd\u8981\uff0c\u6240\u4ee5\u91dd\u5c0d\u76ee\u524d\uff0c\u516c\u53f8\u6709\u4f7f\u7528\u7684\u7db2\u8def\u670d\u52d9\uff0c\u9032\u884c\u901a\u8a0a\u52a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,24],"tags":[29,28,35],"class_list":["post-176","post","type-post","status-publish","format-standard","hentry","category-mistech","category-mistech-net","tag-root-ca","tag-28","tag-35"],"_links":{"self":[{"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/posts\/176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=176"}],"version-history":[{"count":91,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions"}],"predecessor-version":[{"id":411,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions\/411"}],"wp:attachment":[{"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}