Ruby crashes on login to imap.gmail.com (ssl)

Bug #1809500 reported by Geir Isene
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
ruby-defaults (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

I do this:

ruby -r net/imap -e 'p Net::IMAP.new("imap.gmail.com", 993, ssl: true)'

...and get this:

Traceback (most recent call last):
 5: from -e:1:in `<main>'
 4: from -e:1:in `new'
 3: from /usr/lib/ruby/2.5.0/net/imap.rb:1092:in `initialize'
 2: from /usr/lib/ruby/2.5.0/net/imap.rb:1531:in `start_tls_session'
 1: from /usr/lib/ruby/2.5.0/net/protocol.rb:44:in `ssl_socket_connect'
/usr/lib/ruby/2.5.0/net/protocol.rb:44:in `connect_nonblock': SSL_connect returned=1 errno=0 state=error: certificate verify failed (self signed certificate) (OpenSSL::SSL::SSLError)

But this is not a certificate error, because when I do this:

openssl s_client -showcerts -connect imap.gmail.com -port 993

... certs verifies as fine

And when I do this in Python:

import imaplib
imap = imaplib.IMAP4_SSL('imap.gmail.com')
imap.login("myusername", "mypassword")

...it works just fine (reports success on login).

With Ruby I don't even get to login as the connection to imap.gmail.com fails.

I have been using a script to fetch my gmail to local imap server, and this script (https://github.com/isene/mailfetch/blob/master/mail_fetch.rb) has been running every minute since 10 years ago (more than 5 million times) across many Ubuntu releases without a hitch. It stopped working when I upgraded from 18.04 to 18.10 yesterday.

apt-cache policy ruby

ruby:
  Installed: 1:2.5.1
  Candidate: 1:2.5.1
  Version table:
 *** 1:2.5.1 500
        500 http://no.archive.ubuntu.com/ubuntu cosmic/main amd64 Packages
        100 /var/lib/dpkg/status

I first thought this was a certificate issue and tried updating ca-certificates, symlinking certs manually, etc. I have had help in debugging this over at irc/freenode/#ruby and one person running Suse could not reproduce it. But another running Ubuntu 18.10 was able to reproduce this.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in ruby-defaults (Ubuntu):
status: New → Confirmed
Revision history for this message
Seth Arnold (seth-arnold) wrote :
Download full text (5.3 KiB)

GMail crashes:

 ruby -r net/imap -e 'p Net::IMAP.new("imap.gmail.com", 993, ssl: true)'
Traceback (most recent call last):
 5: from -e:1:in `<main>'
 4: from -e:1:in `new'
 3: from /usr/lib/ruby/2.5.0/net/imap.rb:1092:in `initialize'
 2: from /usr/lib/ruby/2.5.0/net/imap.rb:1531:in `start_tls_session'
 1: from /usr/lib/ruby/2.5.0/net/protocol.rb:44:in `ssl_socket_connect'
/usr/lib/ruby/2.5.0/net/protocol.rb:44:in `connect_nonblock': SSL_connect returned=1 errno=0 state=error: certificate verify failed (self signed certificate) (OpenSSL::SSL::SSLError)

Canonical's imap server seems to work okay:
# ruby -r net/imap -e 'p Net::IMAP.new("mail.canonical.com", 993, ssl: true)'
#<Net::IMAP:0x000055fc83a42600 @mon_owner=nil, @mon_count=0, [...]

openssl itself to gmail seems fine:

# openssl s_client -verify 3 -CApath /etc/ssl/certs -connect imap.gmail.com:993
verify depth is 3
CONNECTED(00000006)
depth=2 OU = GlobalSign Root CA - R2, O = GlobalSign, CN = GlobalSign
verify return:1
depth=1 C = US, O = Google Trust Services, CN = Google Internet Authority G3
verify return:1
depth=0 C = US, ST = California, L = Mountain View, O = Google LLC, CN = imap.gmail.com
verify return:1
---
Certificate chain
 0 s:C = US, ST = California, L = Mountain View, O = Google LLC, CN = imap.gmail.com
   i:C = US, O = Google Trust Services, CN = Google Internet Authority G3
 1 s:C = US, O = Google Trust Services, CN = Google Internet Authority G3
   i:OU = GlobalSign Root CA - R2, O = GlobalSign, CN = GlobalSign
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIEgjCCA2qgAwIBAgIIZBW8UvGAR7IwDQYJKoZIhvcNAQELBQAwVDELMAkGA1UE
BhMCVVMxHjAcBgNVBAoTFUdvb2dsZSBUcnVzdCBTZXJ2aWNlczElMCMGA1UEAxMc
R29vZ2xlIEludGVybmV0IEF1dGhvcml0eSBHMzAeFw0xODEyMDQwOTMzMDBaFw0x
OTAyMjYwOTMzM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9n9ItLTXd1/LOfE2P9jfIh2P+ZDjna
P8hn96fd2oByZyJU4uMT/gNHXbtEuXeLXo2NXfTn7bNNf8Q3dKuVPZYHt/95UFkz
8RYEFtGZ0I2YqahOmr9M5dTbnMTt/X+u4TVI+MBbBJTlzuH8yvfich5Shp38VMAQ
iYAOubVPnQKONnkzclAb98er5yJQt6H0J83GP/tLoAH1KC1WvQb3j2mJzDoSd9Mi
UryEnqJA7x/jLu/sdQow6FI+EqO1BfjyVvpdAF5CkBRSGoKRjPCFXF3PNzeUJBMn
8Dq0tFrV
-----END CERTIFICATE-----
subject=C = US, ST = California, L = Mounta...

Read more...

Revision history for this message
Geir Isene (qc-e-9h) wrote :

After further research, this seems to actually not be Ruby version specific - because I purged my Ruby 2.5.1 that comes with Ubuntu 18.10 and installed 2.5.3 and 2.4.5 via ([ruby-install](https://github.com/postmodern/ruby-install) and tried both versions - and they both show up with the bug. So, my conclusion must be that there is something else wrong in 18.10, perhaps not Ruby specific at all (but still very odd that it works with Python and openssl directly).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.