title: How to set TLS context options in Ruby (like OpenSSL::SSL::SSL_OP_NO_SSLv2)
body: <p>When using OpenSSL in C, we set options on the context to remove weak and wounded protocols like SSLv2 and SSLv3. From <code>ssl.h</code>, here is a bitmask of some of the options that are useful:</p>
  
  <pre class="lang-c prettyprint-override"><code>#define SSL_OP_NO_SSLv2     0x01000000L
  #define SSL_OP_NO_SSLv3     0x02000000L
  #define SSL_OP_NO_TLSv1     0x04000000L
  #define SSL_OP_NO_TLSv1_2   0x08000000L
  #define SSL_OP_NO_TLSv1_1   0x10000000L
  </code></pre>
  
  <p>However, I'm having trouble setting them in Ruby:</p>
  
  <pre class="lang-ruby prettyprint-override"><code>if uri.scheme == "https"
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    http.options = OpenSSL::SSL::SSL_OP_NO_SSLv2 | OpenSSL::SSL::OP_NO_SSLv3 |
                   OpenSSL::SSL::SSL_OP_NO_COMPRESSION
  end
  </code></pre>
  
  <p>Results in:</p>
  
  <pre class="lang-bash prettyprint-override"><code>$ ./TestCert.rb
  ./TestCert.rb:12:in `&lt;main&gt;': uninitialized constant OpenSSL::SSL::SSL_OP_SSL2 (NameError)
  </code></pre>
  
  <p>The <a href="http://www.ruby-doc.org/stdlib-1.9.3/libdoc/openssl/rdoc/OpenSSL.html" rel="nofollow noreferrer">Ruby docs for 1.9.3</a> (and 2.0.0) don't even bother to mention it.</p>
  
  <p>How does one set the TLS context options in Ruby?</p>
  
  <hr>
  
  <p>Related: <a href="https://stackoverflow.com/q/3818232/608639">setting SSLContext options in ruby</a>. But there's no way to attach the context to an <code>http</code> when <code>http.use_ssl = true</code>.</p>