<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Behind the Code &#187; 安全</title>
	<atom:link href="http://yinwm.com/category/%e5%ae%89%e5%85%a8/feed/" rel="self" type="application/rss+xml" />
	<link>http://yinwm.com</link>
	<description>Thinking in Techique</description>
	<lastBuildDate>Fri, 06 Aug 2010 02:38:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>网络安全通讯（5）&#8212;-支持客户端验证的python web server</title>
		<link>http://yinwm.com/2008/04/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%885%ef%bc%89-%e6%94%af%e6%8c%81%e5%ae%a2%e6%88%b7%e7%ab%af%e9%aa%8c%e8%af%81%e7%9a%84python-web-server/</link>
		<comments>http://yinwm.com/2008/04/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%885%ef%bc%89-%e6%94%af%e6%8c%81%e5%ae%a2%e6%88%b7%e7%ab%af%e9%aa%8c%e8%af%81%e7%9a%84python-web-server/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 12:49:39 +0000</pubDate>
		<dc:creator>yinwm</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[安全]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[twisted]]></category>

		<guid isPermaLink="false">http://yinwm.cn/wordpress/?p=45</guid>
		<description><![CDATA[前面我们说道很多的场景是需要客户端验证（Client Certificate）的，而python的web server如何支持呢？大多数的python web server都是符合WSGI标准的，也就是他们提供WSGI标准支持的功能，也就是他们几乎都不支持WSGI不支持的功能。很遗憾，客户端验证不在此列。换句话说，Cherrypy，webpy等常用的python web server都无法支持客户端验证。 我终于找到了Twisted（他怎么一下从2.5就蹦到了8.0.1）的web模块可以作为一个单独的web server。而这个web模块是包装的很底层的，使用pyopenssl，并且不是WSGI的一个实现。也就是说，他很可能是支持客户端验证的。经过一番google，发现了支持的办法。如下：首先我们看一下如何让Twisted支持HTTPS，他需要执行reactor.listenSSL方法， class Hello(Resource) :&#160;&#160;&#160; isLeaf = True&#160;&#160;&#160; def render(self, request) :&#160;&#160;&#160;&#160;&#160;&#160;&#160; return &#8216;Hello, SSL&#8217;root = server.Site(Hello())ctxFactory = ssl.DefaultOpenSSLContextFactory(&#160;&#160;&#160; &#8216;/path/to/server.key&#8217;,&#160;&#160;&#160; &#8216;/path/to/server.crt&#8217;&#160;&#160;&#160; )reactor.listenSSL(443, root, contextFactory = ctxFactory)reactor.run() 这是最基本的支持HTTPS的方法，我们看，他需要一个contextFactory，深入到Twisted里面发现这个contextFactory是SSL进行设置。我们想要他支持客户端验证，就要从这里下手了。DefaultOpenSSLContextFactory的cacheContext方法是对context进行的操作。我们重写这个方法。 class SSLClientCertificateFactory(ssl.DefaultOpenSSLContextFactory) : &#160;&#160;&#160; def __init__(self, privateKeyFileName, certificateFileName, sslmethod=SSL.SSLv23_METHOD) :&#160;&#160;&#160;&#160;&#160;&#160;&#160; ssl.DefaultOpenSSLContextFactory.__init__(self, privateKeyFileName, certificateFileName, sslmethod) &#160;&#160;&#160; def _verify(self, connection, x509, errnum, errdepth, [...]]]></description>
			<content:encoded><![CDATA[<p>前面我们说道很多的场景是需要客户端验证（Client Certificate）的，而python的web server如何支持呢？<br />大多数的python web server都是符合WSGI标准的，也就是他们提供WSGI标准支持的功能，也就是他们几乎都不支持WSGI不支持的功能。很遗憾，客户端验证不在此列。换句话说，Cherrypy，webpy等常用的python web server都无法支持客户端验证。</p>
<p>我终于找到了<a href="http://twistedmatrix.com/" target="blank">Twisted</a>（他怎么一下从2.5就蹦到了8.0.1）的web模块可以作为一个单独的web server。而这个web模块是包装的很底层的，使用pyopenssl，并且不是WSGI的一个实现。也就是说，他很可能是支持客户端验证的。<br />经过一番google，发现了支持的办法。如下：<br />首先我们看一下如何让Twisted支持HTTPS，他需要执行reactor.listenSSL方法，</p>
<p>class Hello(Resource) :<br />&nbsp;&nbsp;&nbsp; isLeaf = True<br />&nbsp;&nbsp;&nbsp; def render(self, request) :<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &#8216;Hello, SSL&#8217;<br />root = server.Site(Hello())<br />ctxFactory = ssl.DefaultOpenSSLContextFactory(<br />&nbsp;&nbsp;&nbsp; &#8216;/path/to/server.key&#8217;,<br />&nbsp;&nbsp;&nbsp; &#8216;/path/to/server.crt&#8217;<br />&nbsp;&nbsp;&nbsp; )<br />reactor.listenSSL(443, root, contextFactory = ctxFactory)<br />reactor.run()</p>
<p>这是最基本的支持HTTPS的方法，我们看，他需要一个contextFactory，深入到Twisted里面发现这个contextFactory是SSL进行设置。我们想要他支持客户端验证，就要从这里下手了。<br />DefaultOpenSSLContextFactory的cacheContext方法是对context进行的操作。我们重写这个方法。</p>
<p>class SSLClientCertificateFactory(ssl.DefaultOpenSSLContextFactory) :</p>
<p>&nbsp;&nbsp;&nbsp; def __init__(self, privateKeyFileName, certificateFileName, sslmethod=SSL.SSLv23_METHOD) :<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ssl.DefaultOpenSSLContextFactory.__init__(self, privateKeyFileName, certificateFileName, sslmethod)</p>
<p>&nbsp;&nbsp;&nbsp; def _verify(self, connection, x509, errnum, errdepth, ok):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;&#8221;"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#8216;_verify (ok=%d):&#8217; % ok<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#8216;&nbsp; subject:&#8217;, x509.get_subject()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#8216;&nbsp; issuer:&#8217;, x509.get_issuer()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#8216;&nbsp; errnum %s, errdepth %d&#8217; % (errnum, errdepth)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;&#8221;"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ok<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; def cacheContext(self) :<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ssl.DefaultOpenSSLContextFactory.cacheContext(self)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx = self._context<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ctx.load_verify_locations(&#8216;/path/to/ca.crt&#8217;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.set_verify(SSL.VERIFY_PEER|SSL.VERIFY_FAIL_IF_NO_PEER_CERT, self._verify)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._context = ctx</p>
<p>我们在通过默认的contextFactory生成context之后，执行ctx.set_verify(SSL.VERIFY_PEER|SSL.VERIFY_FAIL_IF_NO_PEER_CERT, self._verify)，这样就加入和客户端验证，并且在self._verify函数里面我们还可以具体的验证证书的情况。<br />改写最上面的程序，<br />class Hello(Resource) :<br />
&nbsp;&nbsp;&nbsp; isLeaf = True<br />
&nbsp;&nbsp;&nbsp; def render(self, request) :<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &#8216;Hello, SSL&#8217;<br />
root = server.Site(Hello())<br />
ctxFactory = SSLClientCertificateFactory(<br />
&nbsp;&nbsp;&nbsp; &#8216;/path/to/server.key&#8217;,<br />
&nbsp;&nbsp;&nbsp; &#8216;/path/to/server.crt&#8217;<br />
&nbsp;&nbsp;&nbsp; )<br />
reactor.listenSSL(443, root, contextFactory = ctxFactory)<br />reactor.run()</p>
<p>好了，此时我们的python web server已经支持客户端验证了</p>
<p>后记：这里我有一个思考，就是为什么WSGI（暂时）不支持客户端验证？我想应该不是设计者忽视了这个问题。一般的，需要客户端验证这样的应用场景，很难只是假设一个python的web server，前面应该都有一个Apache等纯粹的服务器，那么这些验证之类的工作完全交付给Apache就足够好了，python没必要自己来处理。也许这就是原因吧。<br />那么，从这里我们也能看出，作为一个纯粹的网络应用组件，Twisted至少从功能上还是非常强大的。</p>
]]></content:encoded>
			<wfw:commentRss>http://yinwm.com/2008/04/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%885%ef%bc%89-%e6%94%af%e6%8c%81%e5%ae%a2%e6%88%b7%e7%ab%af%e9%aa%8c%e8%af%81%e7%9a%84python-web-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>网络安全通讯（4）&#8212;-为Python Webserver添加HTTPS支持</title>
		<link>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%884%ef%bc%89-%e4%b8%bapython-webserver%e6%b7%bb%e5%8a%a0https%e6%94%af%e6%8c%81/</link>
		<comments>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%884%ef%bc%89-%e4%b8%bapython-webserver%e6%b7%bb%e5%8a%a0https%e6%94%af%e6%8c%81/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 10:22:00 +0000</pubDate>
		<dc:creator>yinwm</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[安全]]></category>
		<category><![CDATA[cherrypy]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://yinwm.cn/wordpress/?p=44</guid>
		<description><![CDATA[前面我们说的都是为Apache服务器添加HTTPS的支持，今天我们讨论一下为Python的Webserver添加HTTPS的支持。 Python的Webserver基本上都是遵循Python的WSGI标准，包括我使用的CherryPy和webpy。在这两个Webserver的源代码中都有一个package叫做wsgiserver，里面只有__init__.py。这两个Webserver的wsgiserver内容几乎一样，而且明显有CherryPy的痕迹，看来CherryPy可能是WSGI标准的一个（半）官方实现，就好像Tomcat至于Servlet。 WSGI标准写的很是笼统，他只是说可以支持SSL，无他。只好阅读源代码，代码里面写的倒不是很差。需要同时给出ssl需要的服务器端的私钥和证书，分别使用如下两个变量存放。ssl_certificate: the filename of the server SSL certificate.&#160;&#160;&#160;&#160;&#160; 服务器端的SSL证书ssl_privatekey: the filename of the server&#8217;s private key file.&#160;&#160;&#160; 服务器端的私钥我们只要遵循每个服务器的文档设置上就可以了。我们以CherryPy为例。（好吧，我说实话，我只会这个。） 在CherryPy的配置文件里面，可以设置这两个变量，分别指向文件系统的文件。[global]server.socket_port : 8081server.socket_host : &#8220;0.0.0.0&#8243;server.ssl_certificate : &#8220;conf/cert/server.crt&#8221;server.ssl_private_key : &#8220;conf/cert/server.key&#8221;这样，当我们重新启动的时候，我们的webserver就已经开始支持HTTPS了。如果这两个变量有一个没有设置的话，HTTPS就不会起作用。 这里我不得不说一下，CherryPy的文档已经算是不错的了，但是还是不行，只有在ServerAPI里面稍微提及了一下这两个变量而已。想要完整的搞明白，就只能祭出hack源代码大发，还得有连蒙带唬的功能。 至于webpy，就最好看看他的文档了。]]></description>
			<content:encoded><![CDATA[<p>前面我们说的都是为Apache服务器添加HTTPS的支持，今天我们讨论一下为Python的Webserver添加HTTPS的支持。</p>
<p>Python的Webserver基本上都是遵循Python的<a href="http://www.python.org/dev/peps/pep-0333/" target="_blank">WSGI标准</a>，包括我使用的CherryPy和webpy。在这两个Webserver的源代码中都有一个package叫做wsgiserver，里面只有__init__.py。这两个Webserver的wsgiserver内容几乎一样，而且明显有CherryPy的痕迹，看来CherryPy可能是WSGI标准的一个（半）官方实现，就好像Tomcat至于Servlet。</p>
<p>WSGI标准写的很是笼统，他只是说可以支持SSL，无他。只好阅读源代码，代码里面写的倒不是很差。需要同时给出ssl需要的服务器端的私钥和证书，分别使用如下两个变量存放。<br />ssl_certificate: the filename of the server SSL certificate.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 服务器端的SSL证书<br />ssl_privatekey: the filename of the server&#8217;s private key file.&nbsp;&nbsp;&nbsp; 服务器端的私钥<br />我们只要遵循每个服务器的文档设置上就可以了。我们以CherryPy为例。（好吧，我说实话，我只会这个。）</p>
<p>在CherryPy的配置文件里面，可以设置这两个变量，分别指向文件系统的文件。<br />[global]<br />server.socket_port : 8081<br />server.socket_host : &#8220;0.0.0.0&#8243;<br />server.ssl_certificate : &#8220;conf/cert/server.crt&#8221;<br />server.ssl_private_key : &#8220;conf/cert/server.key&#8221;<br />这样，当我们重新启动的时候，我们的webserver就已经开始支持HTTPS了。如果这两个变量有一个没有设置的话，HTTPS就不会起作用。</p>
<p>这里我不得不说一下，CherryPy的文档已经算是不错的了，但是还是不行，只有在ServerAPI里面稍微提及了一下这两个变量而已。想要完整的搞明白，就只能祭出hack源代码大发，还得有连蒙带唬的功能。</p>
<p>至于webpy，就最好看看他的文档了。</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%884%ef%bc%89-%e4%b8%bapython-webserver%e6%b7%bb%e5%8a%a0https%e6%94%af%e6%8c%81/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>网络安全通讯（3）&#8212;-相信你的客户</title>
		<link>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%883%ef%bc%89-%e7%9b%b8%e4%bf%a1%e4%bd%a0%e7%9a%84%e5%ae%a2%e6%88%b7/</link>
		<comments>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%883%ef%bc%89-%e7%9b%b8%e4%bf%a1%e4%bd%a0%e7%9a%84%e5%ae%a2%e6%88%b7/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 00:54:04 +0000</pubDate>
		<dc:creator>yinwm</dc:creator>
				<category><![CDATA[安全]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ca]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://yinwm.cn/wordpress/?p=40</guid>
		<description><![CDATA[在前两篇文章中网络安全通讯（1）&#8212;-给你的Webserver启用SSL网络安全通讯（2）&#8212;-让别人相信你的服务器我们探讨了如何让你的客户相信你的服务器，这篇文章我们探讨一下你如何去相信你的客户。 在很多场景下，我们是需要关心客户的身份的，一个很安全的做法就是给你的客户发放一个签名的证书，让你的客户拿着证书来，这时候你验证了证书，你也就相信了你的客户。我们可以使用Apache提供的客户端验证（Client Certificate）功能。 生成客户端的私钥和CSR文件openssl genrsa -out client.key 1024openssl req -new -key client.key -out client.csr 用前面我们自己的CA签发客户的证书openssl x509 -req -days 360 -in client.csr -CA ca.crt -CAkey ca.key -CAserial ca.srl -out client.crt 此时客户端的证书已经制作完毕（和制作Server的一样），但是我们的浏览器需要pkcs12格式的文件，所以我们需要签一个pkcs12格式的文件openssl pkcs12 -export -clcerts -in client.crt -inkey client.key&#160;-out client.p12 -name your_certificate_client_name这里需要你的client的CSR文件设置的密码，还有your_certificate_client_name替换成你client的名字 打开Apache需要客户验证的设置SSLVerifyClient requireSSLVerifyDepth&#160; 1SSLCACertificateFile &#8220;/path_to/ca.crt&#8221; 重新启动apache，尝试一下访问，此时访问并不成功Firefox会包一个-12227的错误，IE干脆显示不出来，说明客户端验证没有通过 把生成的客户端pkcs12文件导入到浏览器，Firefox Tools-&#62;Options-&#62;Advanced-&#62;Encryption-&#62;View Certificates-&#62;Your Certificates-&#62;ImportIE Tools-&#62;Internet Options-&#62;Content-&#62;Certificates-&#62;Personal-&#62;Import 再次访问服务器，It works. 此时你的客户端（也就是浏览器）可以通过服务器的验证了。你也可以相信你的客户了。]]></description>
			<content:encoded><![CDATA[<p>在前两篇文章中<br /><a href="http://yinwm.cn/blog/2008/03/webserver-with-ssl.html" target="_blank">网络安全通讯（1）&#8212;-给你的Webserver启用SSL<br /></a><a href="http://yinwm.cn/blog/2008/03/let-others-trust-your-server.html" target="_blank">网络安全通讯（2）&#8212;-让别人相信你的服务器</a><br />我们探讨了如何让你的客户相信你的服务器，这篇文章我们探讨一下你如何去相信你的客户。</p>
<p>在很多场景下，我们是需要关心客户的身份的，一个很安全的做法就是给你的客户发放一个签名的证书，让你的客户拿着证书来，这时候你验证了证书，你也就相信了你的客户。我们可以使用Apache提供的客户端验证（<a href="http://en.wikipedia.org/wiki/Public_key_certificate" target="_blank">Client Certificate</a>）功能。</p>
<ol>
<li>生成客户端的私钥和CSR文件<br />openssl genrsa -out client.key 1024<br />openssl req -new -key client.key -out client.csr</li>
<li>用前面我们自己的CA签发客户的证书<br />openssl x509 -req -days 360 -in client.csr -CA ca.crt -CAkey ca.key -CAserial ca.srl -out client.crt</li>
<li>此时客户端的证书已经制作完毕（和制作Server的一样），但是我们的浏览器需要pkcs12格式的文件，所以我们需要签一个pkcs12格式的文件<br />openssl pkcs12 -export -clcerts -in client.crt -inkey client.key&nbsp;-out client.p12 -name your_certificate_client_name<br />这里需要你的client的CSR文件设置的密码，还有your_certificate_client_name替换成你client的名字</li>
<li>打开Apache需要客户验证的设置<br />SSLVerifyClient require<br />SSLVerifyDepth&nbsp; 1<br />SSLCACertificateFile &#8220;/path_to/ca.crt&#8221;</li>
<li>重新启动apache，尝试一下访问，此时访问并不成功Firefox会包一个-12227的错误，IE干脆显示不出来，说明客户端验证没有通过</li>
<li>把生成的客户端pkcs12文件导入到浏览器，<br />Firefox Tools-&gt;Options-&gt;Advanced-&gt;Encryption-&gt;View Certificates-&gt;Your Certificates-&gt;Import<br />IE Tools-&gt;Internet Options-&gt;Content-&gt;Certificates-&gt;Personal-&gt;Import</li>
<li>再次访问服务器，It works.</li>
</ol>
<p>此时你的客户端（也就是浏览器）可以通过服务器的验证了。你也可以相信你的客户了。</p>
]]></content:encoded>
			<wfw:commentRss>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%883%ef%bc%89-%e7%9b%b8%e4%bf%a1%e4%bd%a0%e7%9a%84%e5%ae%a2%e6%88%b7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>网络安全通讯（2）&#8212;-让别人相信你的服务器</title>
		<link>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%882%ef%bc%89-%e8%ae%a9%e5%88%ab%e4%ba%ba%e7%9b%b8%e4%bf%a1%e4%bd%a0%e7%9a%84%e6%9c%8d%e5%8a%a1%e5%99%a8/</link>
		<comments>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%882%ef%bc%89-%e8%ae%a9%e5%88%ab%e4%ba%ba%e7%9b%b8%e4%bf%a1%e4%bd%a0%e7%9a%84%e6%9c%8d%e5%8a%a1%e5%99%a8/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 08:00:59 +0000</pubDate>
		<dc:creator>yinwm</dc:creator>
				<category><![CDATA[安全]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ca]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[服务器验证]]></category>

		<guid isPermaLink="false">http://yinwm.cn/wordpress/?p=39</guid>
		<description><![CDATA[上文（网络安全通讯（1）&#8212;-给你的Webserver启用SSL）我们讲解了我们如何能够保证我们的服务器和客户端之间的安全通讯。 但是有些时候，用户凭什么相信你呢，你总得想办法证明你的身份吧。该CA（Certificate Authority）出场了，CA是一个大家都相信的第三方，因为你的客户相信CA，而CA又说你（你的服务器）是可以被信任的，那么你的客户就会相信你。所以刚才那个自签名的证书可是不行，你需要ca用他的key给你签个名字，这样别人才相信不是。Q：我们不认识CA怎么办？A：去公认的CA申请啊！Q：难道就我们自己用也要申请？A：好吧，我们可以自己假装自己就是CA，只要大家相信你就好。 我们开始假装CA，创建自己的CA。 &#160;&#160; 1. 建立CA私钥&#160;&#160;&#160;&#160;&#160; openssl genrsa -out ca.key 1024&#160;&#160; 2. 建立自己的CRT文件&#160;&#160;&#160;&#160;&#160; openssl req -new -x509 -key ca.key -out ca.crt -days 3600&#160;&#160; 3. 用自己的CA文件签署刚刚的服务器CSR，生成服务器证书&#160;&#160;&#160;&#160;&#160; openssl x509 -req -days 360 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt&#160;&#160;&#160;&#160;&#160; 注意，这里的参数-CAcreateserial会建立一个serial文件ca.srl，用来记录ca的serial number，如果你已经有了这个文件，那么请使用-CAserial serial_file替换-CAcreateserial参数。&#160;&#160; 4. 使用新的server.key和server.crt文件，重启apache，再次访问。看一下你的浏览器说什么，是不是此时的Issuer已经是你自己的CA了？ 如果你是使用第三方的CA，你就需要把你的server.csr发给他们，然后他们会签一个证书发挥给你的。 此时我们的客户已经相信了你的服务器了。好了本本没电了，明天我们再讨论如何相信你的客户吧。]]></description>
			<content:encoded><![CDATA[<p>上文（<a href="http://yinwm.cn/blog/2008/03/webserver-with-ssl.html" target="_blank">网络安全通讯（1）&#8212;-给你的Webserver启用SSL</a>）我们讲解了我们如何能够保证我们的服务器和客户端之间的安全通讯。</p>
<p>但是有些时候，用户凭什么相信你呢，你总得想办法证明你的身份吧。该CA（<a href="http://en.wikipedia.org/wiki/Certificate_authority" target="_blank">Certificate Authority</a>）出场了，CA是一个大家都相信的第三方，因为你的客户相信CA，而CA又说你（你的服务器）是可以被信任的，那么你的客户就会相信你。所以刚才那个自签名的证书可是不行，你需要ca用他的key给你签个名字，这样别人才相信不是。<br />Q：我们不认识CA怎么办？<br />A：去公认的CA申请啊！<br />Q：难道就我们自己用也要申请？<br />A：好吧，我们可以自己假装自己就是CA，只要大家相信你就好。</p>
<p>我们开始假装CA，创建自己的CA。</p>
<p>&nbsp;&nbsp; 1. 建立CA私钥<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; openssl genrsa -out ca.key 1024<br />&nbsp;&nbsp; 2. 建立自己的CRT文件<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; openssl req -new -x509 -key ca.key -out ca.crt -days 3600<br />&nbsp;&nbsp; 3. 用自己的CA文件签署刚刚的服务器CSR，生成服务器证书<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; openssl x509 -req -days 360 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 注意，这里的参数-CAcreateserial会建立一个serial文件ca.srl，用来记录ca的serial number，如果你已经有了这个文件，那么请使用-CAserial serial_file替换-CAcreateserial参数。<br />&nbsp;&nbsp; 4. 使用新的server.key和server.crt文件，重启apache，再次访问。看一下你的浏览器说什么，是不是此时的Issuer已经是你自己的CA了？</p>
<p>如果你是使用第三方的CA，你就需要把你的server.csr发给他们，然后他们会签一个证书发挥给你的。</p>
<p>此时我们的客户已经相信了你的服务器了。<br />好了本本没电了，明天我们再讨论如何相信你的客户吧。</p>
]]></content:encoded>
			<wfw:commentRss>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%882%ef%bc%89-%e8%ae%a9%e5%88%ab%e4%ba%ba%e7%9b%b8%e4%bf%a1%e4%bd%a0%e7%9a%84%e6%9c%8d%e5%8a%a1%e5%99%a8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>网络安全通讯（1）&#8212;-给你的Webserver启用SSL</title>
		<link>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%881%ef%bc%89-%e7%bb%99%e4%bd%a0%e7%9a%84webserver%e5%90%af%e7%94%a8ssl/</link>
		<comments>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%881%ef%bc%89-%e7%bb%99%e4%bd%a0%e7%9a%84webserver%e5%90%af%e7%94%a8ssl/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 06:07:05 +0000</pubDate>
		<dc:creator>yinwm</dc:creator>
				<category><![CDATA[安全]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://yinwm.cn/wordpress/?p=38</guid>
		<description><![CDATA[互联网很危险，你还是回火星吧。好吧，我们还有SSL，你可以等一下了。 先说一下这里面用到的库OpenSSL 0.9.8gApache Httpd 2.2 SSL是一个可以保证你的通讯安全的机制，采用公钥私钥的非对加密机制，具体机制我就不说了，网上一抓一大把。你可以使用openssl建立自己的密钥，并使用在Apache Webserver上，让你的服务器支持https。 建立你自己的服务器私钥，一个1024位的就够了openssl genrsa -des3 -out server.key 1024 生成CSR文件，Certificate Signing Requestopenssl req -new -key server.key -out server.csr 生成证书CRT文件，X509协议openssl x509 -req -in server.csr -signkey server.key -out server.crt注意，这是一个自签名的证书 修改你apache的ssl配置，SSLCertificateFile &#8220;/path-to/server.crt&#8221;SSLCertificateKeyFile &#8220;/path-to/server.key&#8221; 启动你的apache，使用https访问试试看，是不是要你确认是否允许证书通过 这时候，你的服务器已经支持SSL了，刚才浏览器问你是否通过你服务器提供的证书是表示客户端（浏览器）信任了你的服务器，这里也就是服务器认证。你们之间的通讯已经是加密的了。]]></description>
			<content:encoded><![CDATA[<p>互联网很危险，你还是回火星吧。<br />好吧，我们还有SSL，你可以等一下了。</p>
<p>先说一下这里面用到的库<br />OpenSSL 0.9.8g<br />Apache Httpd 2.2</p>
<p><a target="_blank" href="http://en.wikipedia.org/wiki/Secure_Sockets_Layer">SSL</a>是一个可以保证你的通讯安全的机制，采用公钥私钥的非对加密机制，具体机制我就不说了，网上一抓一大把。<br />你可以使用openssl建立自己的密钥，并使用在Apache Webserver上，让你的服务器支持https。
<ol>
<li>建立你自己的服务器私钥，一个1024位的就够了<br />openssl genrsa -des3 -out server.key 1024</li>
<li><span class="Body-0020Text-002cBody-0020Text-0020Char--Char" style="font-weight: bold;"></span><span class="Body-0020Text-002cBody-0020Text-0020Char--Char" style="font-weight: bold;"></span>生成CSR文件，<a target="_blank" href="http://en.wikipedia.org/wiki/Certificate_signing_request">Certificate Signing Request</a><br />openssl req -new -key server.key -out server.csr</li>
<li>生成证书CRT文件，X509协议<br />openssl x509 -req -in server.csr -signkey server.key -out server.crt<br />注意，这是一个自签名的证书</li>
<li>修改你apache的ssl配置，<br />SSLCertificateFile &#8220;/path-to/server.crt&#8221;<br />SSLCertificateKeyFile &#8220;/path-to/server.key&#8221;</li>
<li>启动你的apache，使用https访问试试看，是不是要你确认是否允许证书通过</li>
</ol>
<p>这时候，你的服务器已经支持SSL了，刚才浏览器问你是否通过你服务器提供的证书是表示客户端（浏览器）信任了你的服务器，这里也就是服务器认证。你们之间的通讯已经是加密的了。</p>
]]></content:encoded>
			<wfw:commentRss>http://yinwm.com/2008/03/%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e9%80%9a%e8%ae%af%ef%bc%881%ef%bc%89-%e7%bb%99%e4%bd%a0%e7%9a%84webserver%e5%90%af%e7%94%a8ssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
