访问Litmus API会导致SSL错误。有什么方法可以解决吗?

时间:2014-07-11 18:02:06

标签: ruby ssl openssl httparty

摘要:当我通过gem连接到Litmus时,出现以下错误:

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: tlsv1 unrecognized name

使用相同的凭据通过curl访问api可以正常工作。

我找到了类似错误的解决方案:SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A - Faraday::Error::ConnectionFailed

建议更改oauth中的SSL选项:

ssl_options[:version] = :TLSv1

有没有办法为Litmus设置ssl选项?还有其他可能的解决方法吗?

以下是完整的跟踪:

2.0.0-p247 :002 > Litmus::Base.new("xxx.litmus.com", "yyy@yyy.com", "zzz", true)
 => #<Litmus::Base:0x007fad4a66dc68> 
2.0.0-p247 :003 > Litmus::EmailTest.list
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: tlsv1 unrecognized name
  from /Users/andrei/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:918:in `connect'
  from /Users/andrei/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:918:in `block in connect'
  from /Users/andrei/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
  from /Users/andrei/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:918:in `connect'
  from /Users/andrei/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
  from /Users/andrei/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:851:in `start'
  from /Users/andrei/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:1367:in `request'
  from /Users/andrei/.rvm/gems/ruby-2.0.0-p247/gems/httparty-0.13.1/lib/httparty/request.rb:93:in `perform'
  from /Users/andrei/.rvm/gems/ruby-2.0.0-p247/gems/httparty-0.13.1/lib/httparty.rb:521:in `perform_request'
  from /Users/andrei/.rvm/gems/ruby-2.0.0-p247/gems/httparty-0.13.1/lib/httparty.rb:457:in `get'
  from /Users/andrei/.rvm/gems/ruby-2.0.0-p247/gems/litmus-0.3.0/lib/litmus/test.rb:4:in `list'
  from /Users/andrei/.rvm/gems/ruby-2.0.0-p247/gems/litmus-0.3.0/lib/litmus/email_test.rb:4:in `list'
  from (irb):3
  from /Users/andrei/.rvm/rubies/ruby-2.0.0-p247/bin/irb:16:in `<main>'

1 个答案:

答案 0 :(得分:1)

我认为您需要修补base.rb's初始化方法以接受ssl版本参数,然后将类似的内容添加到方法中:

def initialize(company, username, password, ssl = false, ssl_version)
  protocol = ssl ? 'https' : 'http'
  self.class.base_uri "#{protocol}://#{company}.litmus.com"
  self.class.basic_auth(username, password)
  self.class.ssl_version = ssl_version # <=
end

然后称之为:

Litmus::Base.new("xxx.litmus.com", "yyy@yyy.com", "zzz", true, :TLSv1)

希望有所帮助,我注意到你在他们的Github回购中发布了同一主题的问题。也许你可以岔路口创建拉取请求。