<?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>Kabisa Blog &#187; openssl</title>
	<atom:link href="http://blog.kabisa.nl/tag/openssl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.kabisa.nl</link>
	<description>The Ruby on Rails Experts</description>
	<lastBuildDate>Thu, 17 Jun 2010 11:13:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ruby and SSL Certificate Validation</title>
		<link>http://blog.kabisa.nl/2009/12/04/ruby-and-ssl-certificate-validation/</link>
		<comments>http://blog.kabisa.nl/2009/12/04/ruby-and-ssl-certificate-validation/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 14:35:38 +0000</pubDate>
		<dc:creator>Ariejan de Vroom</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=31</guid>
		<description><![CDATA[If your ruby app is doing SSL, you have probably seen one of the following errors:
doc = Hpricot(open("https://www.cert.org/blogs/vuls/rss.xml")) # => /usr/lib/ruby/1.8/net/http.rb:590:in `connect': certificate verify failed (OpenSSL::SSL::SSLError)
or
warning: peer certificate won't be verified in this SSL session
The solution is to make sure ruby has access to the right set of root certificates.

The easiest way to get hold [...]]]></description>
			<content:encoded><![CDATA[<p>If your ruby app is doing SSL, you have probably seen one of the following errors:</p>
<p><code>doc = Hpricot(open("https://www.cert.org/blogs/vuls/rss.xml")) # => /usr/lib/ruby/1.8/net/http.rb:590:in `connect': certificate verify failed (OpenSSL::SSL::SSLError)</code></p>
<p>or</p>
<p><code>warning: peer certificate won't be verified in this SSL session</code></p>
<p>The solution is to make sure ruby has access to the right set of root certificates.<br />
<span id="more-31"></span><br />
The easiest way to get hold of those root certificates is by downloading this file <a href="http://curl.haxx.se/ca/cacert.pem">cacert.pem</a> (<a href="http://curl.haxx.se/docs/caextract.html">details</a>) (updated weekly by the developers of CURL, based on the Mozilla browser). Download this file and store it somewhere in your app. </p>
<p>If you&#8217;re really keen on security, don&#8217;t trust the guys from CURL and download the different root certificates from their providers manually. However, in most cases, the file from CURL will suffice.</p>
<p>Then, in your ruby code, setup the connection like this and you&#8217;ll have a validated SSL connection:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#! /usr/bin/env ruby</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'net/https'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'uri'</span>
&nbsp;
uri = <span style="color:#CC00FF; font-weight:bold;">URI</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">'https://localhost/'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
http = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>uri.<span style="color:#9900CC;">host</span>, uri.<span style="color:#9900CC;">port</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">if</span> uri.<span style="color:#9900CC;">scheme</span> == <span style="color:#996600;">&quot;https&quot;</span>  <span style="color:#008000; font-style:italic;"># enable SSL/TLS</span>
  http.<span style="color:#9900CC;">use_ssl</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#008000; font-style:italic;"># Only needed for ruby 1.8.6</span>
  <span style="color:#008000; font-style:italic;"># http.enable_post_connection_check = true</span>
  http.<span style="color:#9900CC;">verify_mode</span> = <span style="color:#6666ff; font-weight:bold;">OpenSSL::SSL::VERIFY_PEER</span>
  http.<span style="color:#9900CC;">ca_file</span> = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;cacert.pem&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
http.<span style="color:#9900CC;">start</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
  http.<span style="color:#9900CC;">request_get</span><span style="color:#006600; font-weight:bold;">&#40;</span>uri.<span style="color:#9900CC;">path</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>res<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC0066; font-weight:bold;">print</span> res.<span style="color:#9900CC;">body</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2009/12/04/ruby-and-ssl-certificate-validation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
