Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround to verify intermediate certs (for e.g. imap.googlemail.com) #2

Open
alkisg opened this issue Mar 11, 2018 · 2 comments
Open

Comments

@alkisg
Copy link

alkisg commented Mar 11, 2018

Hi, I'm trying to test pam-imap, but I haven't been able to make ./check_user alkisg not show the following error message:

*** WARNING *** There is no way to verify this certificate. It is
possible that a hostile attacker has replaced the
server certificate. Contrinue at your own risk!
Accept this certificate anyway [no]: yes

If I type yes, I can get properly Authenticated, but how can I avoid that error? Could you write a small how-to get and install the imap server certificate, either on Debian or on Ubuntu?

@wdoekes
Copy link
Owner

wdoekes commented Mar 12, 2018

Hi,

from what I gather, the verify_cert function is incomplete.

I believe not only the cert = SSL_get_peer_certificate (ssl); has to be called but rather SSL_get_peer_cert_chain (ssl). Then the chain of certificates can be traversed.

By default the certificates found in /etc/ssl/certs (on Debian/Ubuntu) is read by OpenSSL, but the intermediate you're looking at, is not in there.

See this:

openssl s_client -showcerts -connect imap.googlemail.com:993
...
(certs...)
...
QUIT

and:

$ cat > imap.googlemail.com.crt  <<EOF
-----BEGIN CERTIFICATE-----
MIIEjDCCA3SgAwIBAgIIY3J9TE8xFgwwDQYJKoZIhvcNAQELBQAwVDELMAkGA1UE
BhMCVVMxHjAcBgNVBAoTFUdvb2dsZSBUcnVzdCBTZXJ2aWNlczElMCMGA1UEAxMc
R29vZ2xlIEludGVybmV0IEF1dGhvcml0eSBHMzAeFw0xODAyMjAxNDUzMjFaFw0x
ODA1MTUxNDA5MDBaMG0xCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlh
MRYwFAYDVQQHDA1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKDApHb29nbGUgSW5jMRww
GgYDVQQDDBNpbWFwLmdvb2dsZW1haWwuY29tMIIBIjANBgkqhkiG9w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dIwQYMBaAFJviB1dnHB7AagbeWbSaLd/cGYYu
MDUGCCsGAQUFBwEBBCkwJzAlBggrBgEFBQcwAYYZaHR0cDovL29jc3AucGtpLmdv
b2cvZ3NyMjAyBgNVHR8EKzApMCegJaAjhiFodHRwOi8vY3JsLnBraS5nb29nL2dz
cjIvZ3NyMi5jcmwwPwYDVR0gBDgwNjA0BgZngQwBAgIwKjAoBggrBgEFBQcCARYc
aHR0cHM6Ly9wa2kuZ29vZy9yZXBvc2l0b3J5LzANBgkqhkiG9w0BAQsFAAOCAQEA
HLeJluRT7bvs26gyAZ8so81trUISd7O45skDUmAge1cnxhG1P2cNmSxbWsoiCt2e
ux9LSD+PAj2LIYRFHW31/6xoic1k4tbWXkDCjir37xTTNqRAMPUyFRWSdvt+nlPq
wnb8Oa2I/maSJukcxDjNSfpDh/Bd1lZNgdd/8cLdsE3+wypufJ9uXO1iQpnh9zbu
FIwsIONGl1p3A8CgxkqI/UAih3JaGOqcpcdaCIzkBaR9uYQ1X4k2Vg5APRLouzVy
7a8IVk6wuy6pm+T7HT4LY8ibS5FEZlfAFLSW8NwsVz9SBK2Vqn1N0PIMn5xA6NZV
c7o835DLAFshEWfC7TIe3g==
-----END CERTIFICATE-----
EOF

and:

$ openssl verify imap.googlemail.com.crt
imap.googlemail.com.crt: C = US, ST = California, L = Mountain View, O = Google Inc, CN = imap.googlemail.com
error 20 at 0 depth lookup:unable to get local issuer certificate

$ openssl verify -untrusted imap.googlemail.com.intermediate imap.googlemail.com.crt
imap.googlemail.com.crt: OK

But, until the verify_cert function is fixed/changed to do parent-chain traversal, what you can do is the following workaround:

  • fetch the intermediate cert from google (see the 2nd ssl blob above)
  • add it into the ca-certificates

Updating the ca-certificates is a matter of reading update-ca-certificates(8), reading /usr/share/doc/ca-certificates/README.Debian and then doing:

$ sudo cp imap.googlemail.com.intermediate /usr/local/share/ca-certificates/Google_Internet_Authority_G3-for-imap.googlemail.com.crt

$ sudo update-ca-certificates 
Updating certificates in /etc/ssl/certs...
...
Adding debian:Google_Internet_Authority_G3-for-imap.googlemail.com.pem

after which this works, and the verify_cert in pam-imap should too (I think?):

$ openssl verify imap.googlemail.com.crt
imap.googlemail.com.crt: OK

@wdoekes wdoekes changed the title Example usage for e.g. imap.googlemail.com? Workaround to verify intermediate certs (for e.g. imap.googlemail.com) Mar 12, 2018
@wdoekes
Copy link
Owner

wdoekes commented Mar 12, 2018

P.S. The verify_cert also looks like it leaks a small bit of memory, see #3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants