【发布时间】:2014-04-28 07:34:54
【问题描述】:
在 C 语言中使用 OpenSSL 时,我们在上下文中设置选项以删除 SSLv2 和 SSLv3 等脆弱和受伤的协议。来自ssl.h,这里是一些有用选项的位掩码:
#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
但是,我无法在 Ruby 中设置它们:
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
结果:
$ ./TestCert.rb
./TestCert.rb:12:in `<main>': uninitialized constant OpenSSL::SSL::SSL_OP_SSL2 (NameError)
Ruby docs for 1.9.3(和 2.0.0)甚至懒得提它。
如何在 Ruby 中设置 TLS 上下文选项?
相关:setting SSLContext options in ruby。但是当http.use_ssl = true 时,无法将上下文附加到http。
【问题讨论】: