"Certificate verify failed" while using http://rubygems.org instead of https - ruby-on-rails

I used to get a certificate verification error when I used the https:/rubygems.org.
A workaround was suggested: remove the "s" (so I end up using http instead of https). It worked for some time but today after starting a new rails application rails new 'filename' I got the same certificate validation error:
Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read
server certificate B: certificate verify failed
(https://rubygems.org/gems/mime-types-data-3.2016.0521.gem)
An error occurred while installing mime-types-data (3.2016.0521), and Bundler
cannot continue.
Make sure that gem install mime-types-data -v '3.2016.0521' succeeds before
bundling.
I typed gem sources only to find that https://rubygems.org doesn't even exist.
$ gem sources
*** CURRENT SOURCES ***
http://rubygems.org
I go to the gemfile and I find
source 'https://rubygems.org'
What could be the problem?

Be sure to update the certificate, http://guides.rubygems.org/ssl-certificate-update/
Then look for default cert file
ruby -ropenssl -e 'p OpenSSL::X509::DEFAULT_CERT_FILE' that outputs "/usr/local/etc/openssl/cert.pem"
And then renamed, that will use the new certificate you downloaded
mv /usr/local/etc/openssl/cert.pem /usr/local/etc/openssl/cert.pem.old

If anyone is still seeing this issue on Ubuntu 20.04 with ARMV7, ensure:
ca-certificates is installed
run update-ca-certificates at least once after updating OS packages
You may additionally need to install the GlobalSign certificate prior to running update-ca-certificates:
curl -sL -o /usr/local/share/ca-certificates/GlobalSignRootCA_R3.crt https://raw.githubusercontent.com/rubygems/rubygems/master/lib/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA_R3.pem
This appeared to fix the issue for me.

Related

Ruby on rails windows installed using railsInstaller fails to install gems / bundles

I have an existing project which is stored on bitbucket, and just cloned that onto my windows box.
I enter the main project directory and run
rails server
I get the message:
Could not find rake-10.4.1 in any of the sources
Run `bundle install` to install missing gems.
so I run bundle install - which responds:
DL is deprecated, please use Fiddle
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies...
Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read
server certificate B: certificate verify failed (https://rubygems.org/gems/rake-
10.4.1.gem)
An error occurred while installing rake (10.4.1), and Bundler cannot continue.
Make sure that `gem install rake -v '10.4.1'` succeeds before bundling.
So I run command
gem install rake -v '10.4.1'
Which responds:
ERROR: Could not find a valid gem 'rake' (= 10.4.1), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect retur
ned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (
https://api.rubygems.org/specs.4.8.gz)
I read some other posts and people were asked to run this command:
ruby -ropenssl -e 'p OpenSSL::OPENSSL_VERSION'
Which responds:
"OpenSSL 1.0.0o 15 Oct 2014"
Please can somebody guide me as to what is wrong here!
This seems to be some longstanding issue with Ruby on windows.
I solved it by following these windows fix instructions:
https://gist.github.com/fnichol/867550

Update bash error for ruby on rails

When I try to start a new project - my command I'm using is:
rails new testproject
But when it tries to install the bundle I end up with the error message:
Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed <https://rubygems.org/gems/rake-10.4.2.gem>
An error occured while installing rake <10.4.2>, and Bundler cannot continue. Make sure that 'gem install rake -v '10.4.2' ' succeeds before bundling.
So then I try to install that rake version, using
gem install rake -v 10.4.2
and I get the same SSL read server certificate error.
Now I've tried to figure out how to fix this. From what I can tell, I need to update my Bash version, but that's impossible for me - it just tells me what bash version I have when I give it the command
\curl -sSL https://get.rvm.io | bash -s stable --ruby
found on https://rvm.io/rvm/install.
How do I fix this issue and how do I get an actual working version of RoR on my computer without having to do everything manually? Almost all the other places I've been to eventually point back to railsinstaller.org, and that does me no good.
Thank you very much for your help!
There seems to be something wrong with the certificates. You could try to fetch the packages from hhtp instead using something like:
sudo gem sources -r https://rubygems.org
sudo gem sources -a http://rubygems.org
Ref this

Could not find valid gem: certificate verify failed

I'm trying to establish an ssh tunnel to a remote server as described here: SSH from Heroku into remote server with Mysql Db
But I'm hung up just simply trying to download the gems. I added:
# file: Gemfile
...
gem 'net-ssh-gateway', '~> 1.2.0'
but when I do bundle install (or even just gem install net-ssh on the command line), I get:
ERROR: Could not find a valid gem 'net-ssh' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://api.rubygems.org/latest_specs.4.8.gz)
As per the README for net-ssh (https://github.com/net-ssh/net-ssh), I checked my OpenSSL bindings for Ruby -- they look okay:
$ ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
OpenSSL 1.0.1j 15 Oct 2014
I'm not sure if this is related, but when I tried to download the .pem file for a high security download of the gemfile:
$ curl -O https://raw.github.com/net-ssh/net-ssh/master/gem-public_cert.pem
... it didn't download a .pem file, and visiting the URL directly result in 'not found'.
Other info:
$ rake about
About your application's environment
Ruby version 2.1.4-p265 (x86_64-darwin14.0)
RubyGems version 2.2.2
Rack version 1.5
Rails version 4.1.7
So for right now, I'm stuck. Does anyone recognize this problem?
This helped in my case, when I had a problem with certificate:
gem sources -r https://rubygems.org
gem sources -a http://rubygems.org
gem update --system
gem sources -r http://rubygems.org
gem sources -a https://rubygems.org
Despite #the Tin Man's helpful answer, my problem was that I didn't have certificates set up in a place that OpenSSL could find them.
Following suggestions(s) in SSL Error When installing rubygems, Unable to pull data from 'https://rubygems.org/:
An inferior workaround
One can work around this by changing the first line of Gemfile from
source 'https://rubygems.org'
to the non-https form:
source 'http://rubygems.org'
and then do the usual bundle install. Afterwards, you should restore the first line of your Gemfile to use the https form. This is generally considered a security risk.
What's more, you haven't really addressed the real problem that you lack valid certificates and you will run into trouble if your application calls uses OpenSSL (e.g. net-ssh).
A better fix
See SSL Error When installing rubygems, Unable to pull data from 'https://rubygems.org/. For OS X users, we ask Ruby to tell us where it's looking for the certificates file, and then use security find-certificate to populate the certificates file:
$ cert_file=$(ruby -ropenssl -e 'puts OpenSSL::X509::DEFAULT_CERT_FILE')
$ echo $cert_file
$ security find-certificate -a -p /Library/Keychains/System.keychain > "$cert_file"
$ security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain >> "$cert_file"
After I did this, I was able to call bundle install without an error.
hey everyone follow this link so you wont have to manual install everytime.
This says that the problem is from rubygems' change of ssl certasdaasdlashjd blah blah. NVM the link explains it best :p

Why do I get OpenSSL::SSL::SSLError when installing Rails?

When I run 'sudo gem install rails', this error occurs:
ERROR: While executing gem ... (OpenSSL::SSL::SSLError)
SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server session ticket A
BTW, I'm running Ruby version 1.9.3p0, Gem version 2.0.3, and OpenSSL version OpenSSL 1.0.1.
Any advice?
Please try the following commands
Root causes
1) outdate open SSL
$ rvm -v
$ rvm get head
2) outdate bundle
$ gem install bundle
hope it will solve
try this :
$ gem update --system
While I was about installing rails, I also get the exact same error. As Aye Mon Chit mention earlier, this error is possibly caused by an outdated open SSL. Here's my solution: update your openssl
In my Wheezy, I simply run:
apt-get install openssl
And that's all. Hope this help somebody out there.

bundle install fails with SSL certificate verification error

When I run bundle install for my Rails 3 project on Centos 5.5 it fails with an error:
Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3
read server certificate B: certificate verify failed
(https://bb-m.rubygems.org/gems/multi_json-1.3.2.gem)
An error occured while installing multi_json (1.3.2), and Bundler cannot continue.
Make sure that `gem install multi_json -v '1.3.2'` succeeds before bundling.
When I try to install the gem manually (by gem install multi_json -v '1.3.2') it works. The same problem occurs with several other gems. I use RVM (1.12.3), ruby 1.9.2, bundler 1.1.3.
How to fix it?
Update
Now that I've karma wh..err mined enough from this answer everyone should know that this should have been fixed.
re: via Ownatik again bundle install fails with SSL certificate verification error
gem update --system
My answer is still correct and left below for reference if that ends up not working for you.
Honestly the best temporary solution is to
[...] use the non-ssl version of rubygems in your gemfile as a temporary workaround.
via user Ownatik
what they mean is at the top of the Gemfile in your rails application directory change
source 'https://rubygems.org'
to
source 'http://rubygems.org'
note that the second version is http instead of https
Replace the ssl gem source with non-ssl as a temp solution:
gem sources -r https://rubygems.org/
gem sources -a http://rubygems.org/
The reason is old rubygems. You need to update system part using non ssl source first:
gem update --system --source http://rubygems.org/ (temporarily updating system part using non-ssl connection).
Now you're ready to use gem update.
If you're on a mac and use a recent version of RVM (~1.20), the following command worked for me.
rvm osx-ssl-certs update
This issue should now be fixed. Update rubygems (gem update --system), make sure openssl is at the latest version on your OS, or try these tips of it's still not working: http://railsapps.github.com/openssl-certificate-verify-failed.html
Temporary solution (as alluded to by Ownatik):
Create or modify a file called .gemrc in your home path, including the line :ssl_verify_mode: 0
This will prevent bundler from checking the SSL certificates of gems when it attempts to install them.
For *nix devices, 'home path' means ~/.gemrc. You can also create /etc/gemrc if you prefer. For Windows XP, 'home path' means c:\Documents and Settings\All Users\Application Data\gemrc. For Windows 7, C:\ProgramData\gemrc
On windows7 you can download the cacert.pem file from here and set the environementvariable SSL_CERT_FILE to the path where you store the certificate eg
SET SSL_CERT_FILE="C:\users\<username>\cacert.pem"
or you can set the variable in your script like this ENV['SSL_CERT_FILE']="C:/users/<username>/cacert.pem"
Replace <username> with you own username.
The real solution to this problem, if you are using RVM:
Update rubygems: gem update --system
Use RVM to refresh SSL certs: rvm osx-ssl-certs update all
Hat tip to this tip on the RailsApps project!
You can download a list of CA certificates from curl's website at http://curl.haxx.se/ca/cacert.pem
Then set the SSL_CERT_FILE environment variable to tell Ruby to use it. For example, in Linux:
$ SSL_CERT_FILE=~/cacert.pem bundle install
(Reference: https://gist.github.com/fnichol/867550)
For those of you that have ruby installed through RVM and want a quick fix (preferring not to read per Bruno's request) just try this:
rvm remove 1.9.x (or whatever version of ruby you are using)
rvm pkg install openssl
rvm install 1.9.2 --with-openssl-dir=$rvm_path/usr
For a more details, here is the link where I found the solution.
http://railsapps.github.com/openssl-certificate-verify-failed.html
BTW, I didn't have to touch my certificates on Ubuntu.
Best of all, this isn't a workaround. It will download gems through
SSL and fail if there if there is a problem like a man in the middle
attack which is much better than just turning off security.
This has been fixed
http://guides.rubygems.org/ssl-certificate-update/
Now that RubyGems 2.6.x has been released, you can manually update to this version.
Download https://rubygems.org/downloads/rubygems-update-2.6.7.gem
Please download the file in a directory that you can later point to (eg. the root of your harddrive C:)
Now, using your Command Prompt:
C:\>gem install --local C:\rubygems-update-2.6.7.gem
C:\>update_rubygems --no-ri --no-rdoc
After this, gem --version should report the new update version.
You can now safely uninstall rubygems-update gem:
C:\>gem uninstall rubygems-update -x
Simple copy paste instruction given here about .pem file
https://gist.github.com/luislavena/f064211759ee0f806c88
For certificate verification failed
If you've read the previous sections, you will know what this means (and shame > on you if you have not).
We need to download AddTrustExternalCARoot-2048.pem.
Open a Command Prompt and type in:
C:>gem which rubygems
C:/Ruby21/lib/ruby/2.1.0/rubygems.rb
Now, let's locate that directory. From within the same window, enter the path part up to the file extension, but using backslashes instead:
C:>start C:\Ruby21\lib\ruby\2.1.0\rubygems
This will open a Explorer window inside the directory we indicated.
Step 3: Copy new trust certificate
Now, locate ssl_certs directory and copy the .pem file we obtained from previous step inside.
It will be listed with other files like GeoTrustGlobalCA.pem.
same problem but with different gem here:
Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3
read server certificate B: certificate verify failed
(https://bb-m.rubygems.org/gems/builder-3.0.0.gem)
An error occured while installing builder (3.0.0), and Bundler cannot continue.
Make sure that `gem install builder -v '3.0.0'` succeeds before bundling.
temporarily solution: gem install builder -v '3.0.0' makes it possible to continue bundle install
The simplest solution:
rvm pkg install openssl
rvm reinstall all --force
Voila!
This is How you fix this problem on Windows:
download .perm file then set the SSL_CERT_FILE in command prompt
https://gist.github.com/fnichol/867550
My permanent fix for Windows:
Download the CACert , save as C:\ruby\ssl_certs\GlobalSignRootCA.pem from http://guides.rubygems.org/ssl-certificate-update/
Create system variable named "SSL_CERT_FILE", set to C:\ruby\ssl_certs\GlobalSignRootCA.pem.
Try again: gem install bundler:
C:\gem sources
*** CURRENT SOURCES ***
https://rubygems.org/
C:\gem install bundler
Fetching: bundler-1.13.5.gem (100%)
Successfully installed bundler-1.13.5
1 gem installed
I get a slightly different error, though perhaps related, on Ubuntu 12.04:
Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=unknown state: sslv3 alert handshake failure (https://d2chzxaqi4y7f8.cloudfront.net/gems/activesupport-3.2.3.gem)
An error occured while installing activesupport (3.2.3), and Bundler cannot continue.
Make sure that `gem install activesupport -v '3.2.3'` succeeds before bundling.
It happens when I run bundle install with source 'https://rubygems.org' in a Gemfile.
This is an issue with OpenSSL on Ubuntu 12.04. See Rubygems issue #319.
To fix this, run apt-get update && apt-get upgrade on Ubuntu 12.04 to upgrade your OpenSSL.
I was able to track this down to the fact that the binaries that rvm downloads do not play nice with OS X's OpenSSL, which is old and is no longer used by the OS.
The solution for me was to force compilation when installing Ruby via rvm:
rvm reinstall --disable-binary 2.2
Thx to #Alexander.Iljushkin for:
gem update --system --source http://rubygems.org/
After that bundler still failed and the solution to that was:
gem install bundler
I was getting a similar error. Here is how I solved this: In your path directory, check for Gemfile. Edit the source in the gemfile to http instead of https and save it. This might install the bundler without the SSL certificate issue.l
For Windows machine, check your gem version with
gem --version
Then update your gem as follow:
Running 1.8.x: download 1.8.30
Running 2.0.x: download 2.0.15
Running 2.2.x: download 2.2.3
Please download the file in a directory that you can later point to (eg. the root of your hard drive C:)
Now, using your Command Prompt:
C:\>gem install --local C:\rubygems-update-1.8.30.gem
C:\>update_rubygems --no-ri --no-rdoc
Now, bundle install will success without SSL certificate verification error.
More detailed instruction is here
This worked for me:
download latest gem at https://rubygems.org/pages/download
install the gem with gem install --local [path to downloaded gem file]
update the gems with update_rubygems
check that you're on the latest gem version with gem --version
I had to reinstall openssl:
brew uninstall --force openssl
brew install openssl
I was just recently faced with this issue and followed the steps outlined here. There might be a chance that you are not pointing to the right OpenSSL certificate. After running:
rvm osx-ssl-certs status all
rvm osx-ssl-certs update all
and
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
the bundle complete ran!
Download rubygems-update-2.6.7.gem .
Now, using your Command Prompt:
C:\>gem install --local C:\rubygems-update-2.6.7.gem
C:\>update_rubygems --no-ri --no-rdoc
After this, gem --version should report the new update version.
You can now safely uninstall rubygems-update gem:
C:\>gem uninstall rubygems-update -x
Removing update_rubygems
Successfully uninstalled rubygems-update-2.6.7
To note, if you're grabbing gems from a source which SSL cert is trusted by an internal certificate authority (or you are connecting to an external source through a company web proxy with SSL inspection), point your SSL_CERT_FILE env variable to your certificate chain. This most likely just requires exporting your root certificate from your certificate store (System Keychain on macOS) to an accessible location from your shell i.e.:
export SSL_CERT_FILE=~/RootCert.pem
If you're using rails-assets
If you were using https://rails-assets.org/ to manage your assets, no answers will help you. Even converting to http won't help.
The simplest fix is using this source instead, http://insecure.rails-assets.org. This has been mentioned in their homepage.
The only thing that worked for me on legacy windows system and ruby 1.9 version is downloading cacert file from
http://guides.rubygems.org/ssl-certificate-update/
And then running below command before running bundle install
bundle config --global ssl_ca_cert /path/to/file.pem

Resources