Twilio app; twilio-ruby (3.4.2), SSL error - ruby

I have followed the sample code on the Twilio github page and it doesn't work. In my Rails console, it looks like this:
irb(main):039:0> require 'twilio-ruby'
=> nil
irb(main):040:0* account_sid='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
=> "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
irb(main):041:0> auth_token='yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
=> "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
irb(main):042:0> client=Twilio::REST::Client.new account_sid, auth_token
=> <Twilio::REST::Client #account_sid=AC1322312300a752f6e84a8254535ecce5>
irb(main):043:0> client.account.sms.messages.create :from=>'16135551234', :to=>'16135551212', :body=>"Ada is fat"
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:678:in `connect'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:678:in `block in connect'
from C:/Ruby192/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
from C:/Ruby192/lib/ruby/1.9.1/timeout.rb:87:in `timeout'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:678:in `connect'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:626:in `start'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1168:in `request'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/net_http_ext.rb:51:in `request'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/twilio-ruby-3.4.2/lib/twilio-ruby/rest/client.rb:214:in `connect_and_send'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/twilio-ruby-3.4.2/lib/twilio-ruby/rest/client.rb:138:in `block (2 levels) in <class:Client>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/twilio-ruby-3.4.2/lib/twilio-ruby/rest/list_resource.rb:73:in `create'
from (irb):43
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.11/lib/rails/commands/console.rb:44:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.11/lib/rails/commands/console.rb:8:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.11/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):044:0>
What else do I need to do to get twilio-ruby to successfully send a text message? I have used these numbers and credentials for incoming calls, so they are good.
** EDIT Dec 24, 2011 ***
Instead of running this code on my PC, I deployed it to heroku.com. Then I had no SSL errors and I was able to place outgoing calls. I'm very puzzled.

This shouldn't be a problem in twilio-ruby versions starting with 3.5.0. It "just works" out of the box now.
With twilio-ruby versions before 3.5.0 there wasn't an SSL CA cert bundle packaged with the gem. So the only way to "fix" this was to either point your client at a cert bundle at initialization time:
client = Twilio::REST::Client.new sid, token, :ssl_ca_file => '/path/to/file'
or to disable SSL verification altogether (not recommended in production):
client = Twilio::REST::Client.new sid, token, :ssl_verify_peer => false

You may be missing root certificate files. This typically shouldn't be necessary but you can try disabling certificate verification by adding these lines before making the call:
require 'open-uri'
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

Related

Why do I get an OpenSSL error when trying to connect to Apple Push Notification Service?

Maybe there are other questions answered around this, but I cannot seem to be able to solve my problem.
I am trying to use the Apple Push Notification Service as a Provider, using ruby 2.2.3.
I have tried a series of gems that I found and they all have the same problem. The gems that I have tried are:
grocer
apns
houston
They all raise the same exception:
OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server session ticket A
These gems are using OpenSSL to create an SSL connection to APNS end point. But they fail to do that.
Please, note that I am working on a Mac OS X Yosemite machine.
Any help?
EDIT More info on how I use grocer:
pusher = Grocer.pusher(
certificate: "/Users/panayotismatsinopoulos/Documents/ProgrammingSwift/certificate.pem",
passphrase: "the passphrase for loading certificate",
gateway: "gateway.sandbox.push.apple.com",
port: 2195,
retries: 3
)
notification = Grocer::Notification.new(
device_token: "....the device token here...",
alert: "Hello There!",
badge: 42)
pusher.push(notification)
And the exception I get is:
OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server session ticket A
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/grocer-0.6.1/lib/grocer/ssl_connection.rb:43:in `connect'
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/grocer-0.6.1/lib/grocer/ssl_connection.rb:43:in `connect'
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/grocer-0.6.1/lib/grocer/connection.rb:29:in `connect'
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/grocer-0.6.1/lib/grocer/connection.rb:55:in `with_connection'
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/grocer-0.6.1/lib/grocer/connection.rb:23:in `write'
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/grocer-0.6.1/lib/grocer/pusher.rb:8:in `push'
from (irb):29
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start'
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start'
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/panayotismatsinopoulos/.rvm/gems/ruby-2.2.3#my_project/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Finally, I realised that I was using wrong .pem file. It was not the one specific for the Mobile app that I was trying to push notifications to.
It was the .pem file corresponding to signing certificate to sign my code.
As soon as I used the correct .pem file, everything went smoothly.

tor-privoxy error: connection refused

I'm trying to use tor-privoxy to switch my IP address.
I copied the code from the README, for the most part:
require 'tor-privoxy'
agent ||= TorPrivoxy::Agent.new '127.0.0.1', '', {8123 => 9051} do |agent|
sleep 5
p agent
p "New IP is #{agent.ip}"
end
But when I run it, I got this error:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:641:in `rescue in connection_for': connection refused: 127.0.0.1:8123 (Net::HTTP::Persistent::Error)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:589:in `connection_for'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:994:in `request'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.7.3/lib/mechanize/http/agent.rb:259:in `fetch'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.7.3/lib/mechanize.rb:440:in `get'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:38:in `ip'
from C:/Users/Lap/Dropbox/Programming_Stuff/Ruby_Stuff/Code/tor and socksify stuff/torPrivoxyTest.rb:6:in `block in <main>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:11:in `call'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:11:in `initialize'
from C:/Users/Lap/Dropbox/Programming_Stuff/Ruby_Stuff/Code/tor and socksify stuff/torPrivoxyTest.rb:3:in `new'
from C:/Users/Lap/Dropbox/Programming_Stuff/Ruby_Stuff/Code/tor and socksify stuff/torPrivoxyTest.rb:3:in `<main>'
[Finished in 8.5s with exit code 1]
What am I doing wrong?
It seems you are using the wrong port. Privoxy uses port 8118 (8123 is polipo). Tor on the other side uses either 9050 (plain Tor) or 9150 (Tor browser bundle). So if you change your settings the communication should work.

Jumpstart Labs MicroBlogger unable to connect

I'm following the Jumpstart Labs MicroBlogger tutorial and I'm running into an issue where I'm unable to connect to twitter. I am getting the following errors:
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:799:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (Twitter::Error::ClientError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:799:in `block in connect'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:799:in `connect'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:744:in `start'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:1284:in `request'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/adapter/net_http.rb:75:in `perform_request'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/adapter/net_http.rb:38:in `call'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/response.rb:8:in `call'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/response.rb:8:in `call'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/response.rb:8:in `call'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/request/url_encoded.rb:14:in `call'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/request/multipart.rb:13:in `call'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-4.8.1/lib/twitter/request/multipart_with_file.rb:14:in `call'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/connection.rb:253:in `run_request'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/connection.rb:118:in `post'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-4.8.1/lib/twitter/client.rb:108:in `request'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-4.8.1/lib/twitter/client.rb:72:in `post'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-4.8.1/lib/twitter/api/utils.rb:82:in `object_from_response'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-4.8.1/lib/twitter/api/tweets.rb:129:in `update'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/jumpstart_auth-0.3.0/lib/jumpstart_auth.rb:32:in `update'
from C:/Users/Steve/RubymineProjects/MicroBlogger/micro_blogger.rb:12:in `tweet'
from C:/Users/Steve/RubymineProjects/MicroBlogger/micro_blogger.rb:18:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
This is my code so far:
require 'jumpstart_auth'
class MicroBlogger
attr_reader :client
def initialize
puts "Initializing"
#client = JumpstartAuth.twitter
end
def tweet(message)
#client.update(message)
end
end
blogger = MicroBlogger.new
blogger.tweet("hey")
As indicated in the error message, the SSL library couldn't verify the SSL certificate returned from the Twitter server. In this case, it is most likely because no certificate authorities were installed for you.
The details and solution are available here:
https://gist.github.com/fnichol/867550#file-readme-md
I suggest using the "boring" method, since it does not involve running code copied off the internet (instructions in case the link disappears, but better to read info at link):
Download http://curl.haxx.se/ca/cacert.pem
Save it to somewhere like C:\RailsInstaller\cacert.pem
Run set SSL_CERT_FILE=C:\RailsInstaller\cacert.pem to set the location for the current shell
Run your script in the same shell
If you have installed ruby directly to windows you can copy the cacert.pem file to the Ruby200dir(eg. c:\ruby200) and run the set SSL_CERT_FILE=[path to the cert file] command from the command prompt.
Keep in mind that this will require you to add the SSL cert for every boot of your computer

SSL Error Twitter Request using HTTPS

consumer and token hash is defined in my code
access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
url = URI.encode("https://api.twitter.com/1.1/statuses/update.json?status=awesome!")
response = access_token.request(:post, url)
it gives us
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
from /usr/lib/ruby/1.8/net/http.rb:586:in `connect'
from /usr/lib/ruby/1.8/net/http.rb:586:in `connect'
from /usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
from /usr/lib/ruby/1.8/net/http.rb:542:in `start'
from /usr/lib/ruby/1.8/net/http.rb:1035:in `__request__'
from /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/net_http_ext.rb:51:in `request'
from /usr/lib/ruby/gems/1.8/gems/oauth-0.4.7/lib/oauth/consumer.rb:161:in `request'
from /usr/lib/ruby/gems/1.8/gems/oauth-0.4.7/lib/oauth/tokens/consumer_token.rb:25:in `request'
from /usr/lib/ruby/gems/1.8/gems/oauth-0.4.7/lib/oauth/tokens/access_token.rb:12:in `request'
Please help me
Use Latest RVM (Ruby Version Manager) to fix third party app integration by using Ruby on Rail framework.
For more info use Step by Step guide here - OpenSSL Errors and Rails Certificate Verify Failed
Hope it helps!
I had the same error. I still havn't been able able to resolve the underlying issues but try pasting this into your .rb files.
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
It basically turns off the verification step.

Ruby Gem Twitter - certificate verify failed (Twitter::Error::ClientError)

I am trying to use the ruby gem 'twitter' but for unknown reasons I cant get it to work.
Here is the .rb code:
require 'twitter'
puts "Greetings, World!"
puts "Checkpoint 1"
Twitter.configure do |config|
config.consumer_key = "xxxxxxx" #removed for posting
config.consumer_secret = "xxxxxxx" #removed for posting
config.oauth_token = "xxxxxxx" #removed for posting
config.oauth_token_secret = "xxxxxxx" #removed for posting
end
Twitter.verify_credentials
puts "Checkpoint 2"
and I get the following error:
Greetings, World!
Checkpoint 1
C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:918:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (Twitter::Error::ClientError)
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:918:in `block in connect'
from C:/Ruby200-x64/lib/ruby/2.0.0/timeout.rb:66:in `timeout'
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:918:in `connect'
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:851:in `start'
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1367:in `request'
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1126:in `get'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/adapter/net_http.rb:73:in `perform_request'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/adapter/net_http.rb:38:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/response.rb:8:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/response.rb:8:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/response.rb:8:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/request/url_encoded.rb:14:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/request/multipart.rb:13:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter/request/multipart_with_file.rb:14:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/connection.rb:247:in `run_request'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/connection.rb:100:in `get'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter/client.rb:108:in `request'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter/client.rb:66:in `get'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter/api/utils.rb:82:in `object_from_response'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter/api/users.rb:50:in `verify_credentials'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter.rb:60:in `method_missing'
from C:/Ruby200-x64/AppCode/twitter_connect.rb:13:in `<main>'
I am a ruby newbie and I cant make sense of the client error... perhaps I am missing something. I have also confirmed my Oauth credentials are working in python.
Thanks in advance and I look forward to your help.
I was able to solve my own question. For those having the same issue try using the following:
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
It disables the SSL security but it allows you to process with troubleshooting. The underlying issue is an outdated SSL.
I'm very new to ruby as well but are you using a Mac? It may be because of outdated SSL certificate files. Here's a link to instructions that solved the problem for me.
http://railsapps.github.io/openssl-certificate-verify-failed.html

Resources