Hello,
"Victor Duchovni" <victor.ducho...@morganstanley.com> wrote: > > 1. How to get SSL certificate of smtp.iol.cz > > (and save it to > > > file). > > Use "openssl s_client -showcerts" Thanks - it works. Interesting is, that I get this way only 2 certificates: CN=smtp.iol.cz (issuer CN=Thawte SSL CA) and CN=Thawte SSL CA (issuer CN=thawte Primary Root CA) it is missing the Thawte root certicate CN=thawte Primary Root CA. Fortunately I have found this certificate is in /etc/ssl/certs. So .. I had to copy these tree certificates in /var/lib/stunnel4/certs (chroot of stunnel4), make the "hash" links (with help of openssl x509 -subject_hash -noout -in xyz), modify my stunnel.conf: [ssmtp_client_iol] client = yes accept = 10465 connect = smtp.iol.cz:465 verify = 3 CApath = /certs restart the service, cross my fingers :-) $ telnet 127.0.0.1 10465 and ... SUCCESS - the log shows: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 2011.03.09 09:27:15 LOG7[2608:3078739648]: ssmtp_client_iol accepted FD=14 from 127.0.0.1:58775 2011.03.09 09:27:15 LOG7[2608:3078736752]: ssmtp_client_iol started 2011.03.09 09:27:15 LOG7[2608:3078736752]: FD 14 in non-blocking mode 2011.03.09 09:27:15 LOG7[2608:3078736752]: TCP_NODELAY option set on local socket 2011.03.09 09:27:15 LOG7[2608:3078736752]: Waiting for a libwrap process 2011.03.09 09:27:15 LOG7[2608:3078736752]: Acquired libwrap process #0 2011.03.09 09:27:15 LOG7[2608:3078736752]: Releasing libwrap process #0 2011.03.09 09:27:15 LOG7[2608:3078736752]: Released libwrap process #0 2011.03.09 09:27:15 LOG7[2608:3078736752]: ssmtp_client_iol permitted by libwrap from 127.0.0.1:58775 2011.03.09 09:27:15 LOG5[2608:3078736752]: ssmtp_client_iol accepted connection from 127.0.0.1:58775 2011.03.09 09:27:15 LOG7[2608:3078736752]: FD 15 in non-blocking mode 2011.03.09 09:27:15 LOG6[2608:3078736752]: connect_blocking: connecting 194.228.2.82:465 2011.03.09 09:27:15 LOG7[2608:3078736752]: connect_blocking: s_poll_wait 194.228.2.82:465: waiting 10 seconds 2011.03.09 09:27:15 LOG5[2608:3078736752]: connect_blocking: connected 194.228.2.82:465 2011.03.09 09:27:15 LOG5[2608:3078736752]: ssmtp_client_iol connected remote server from 10.6.6.6:50305 2011.03.09 09:27:15 LOG7[2608:3078736752]: Remote FD=15 initialized 2011.03.09 09:27:15 LOG7[2608:3078736752]: TCP_NODELAY option set on remote socket 2011.03.09 09:27:15 LOG7[2608:3078736752]: SSL state (connect): before/connect initialization 2011.03.09 09:27:15 LOG7[2608:3078736752]: SSL state (connect): SSLv3 write client hello A 2011.03.09 09:27:15 LOG7[2608:3078736752]: SSL state (connect): SSLv3 read server hello A 2011.03.09 09:27:15 LOG5[2608:3078736752]: CRL: verification passed 2011.03.09 09:27:15 LOG5[2608:3078736752]: VERIFY OK: depth=2, /C=US/O=thawte, Inc./OU=Certification Services Division/OU=(c) 2006 thawte, Inc. - For authorized use only/CN=thawte Primary Root CA 2011.03.09 09:27:15 LOG5[2608:3078736752]: CRL: verification passed 2011.03.09 09:27:15 LOG5[2608:3078736752]: VERIFY OK: depth=1, /C=US/O=Thawte, Inc./CN=Thawte SSL CA 2011.03.09 09:27:15 LOG5[2608:3078736752]: CRL: verification passed 2011.03.09 09:27:15 LOG5[2608:3078736752]: VERIFY OK: depth=0, /C=CZ/ST=Praha/L=Praha 4/O=Telefonica O2 Czech Republic, a.s./OU=Operations/CN=smtp.iol.cz 2011.03.09 09:27:15 LOG7[2608:3078736752]: SSL state (connect): SSLv3 read server certificate A 2011.03.09 09:27:15 LOG7[2608:3078736752]: SSL state (connect): SSLv3 read server done A 2011.03.09 09:27:15 LOG7[2608:3078736752]: SSL state (connect): SSLv3 write client key exchange A 2011.03.09 09:27:15 LOG7[2608:3078736752]: SSL state (connect): SSLv3 write change cipher spec A 2011.03.09 09:27:15 LOG7[2608:3078736752]: SSL state (connect): SSLv3 write finished A 2011.03.09 09:27:15 LOG7[2608:3078736752]: SSL state (connect): SSLv3 flush data 2011.03.09 09:27:15 LOG7[2608:3078736752]: SSL state (connect): SSLv3 read finished A 2011.03.09 09:27:15 LOG7[2608:3078736752]: 1 items in the session cache 2011.03.09 09:27:15 LOG7[2608:3078736752]: 1 client connects (SSL_connect()) 2011.03.09 09:27:15 LOG7[2608:3078736752]: 1 client connects that finished 2011.03.09 09:27:15 LOG7[2608:3078736752]: 0 client renegotiations requested 2011.03.09 09:27:15 LOG7[2608:3078736752]: 0 server connects (SSL_accept()) 2011.03.09 09:27:15 LOG7[2608:3078736752]: 0 server connects that finished 2011.03.09 09:27:15 LOG7[2608:3078736752]: 0 server renegotiations requested 2011.03.09 09:27:15 LOG7[2608:3078736752]: 0 session cache hits 2011.03.09 09:27:15 LOG7[2608:3078736752]: 0 external session cache hits 2011.03.09 09:27:15 LOG7[2608:3078736752]: 0 session cache misses 2011.03.09 09:27:15 LOG7[2608:3078736752]: 0 session cache timeouts 2011.03.09 09:27:15 LOG6[2608:3078736752]: SSL connected: new session negotiated 2011.03.09 09:27:15 LOG6[2608:3078736752]: Negotiated ciphers: RC4-SHA SSLv3 Kx=RSA Au=RSA Enc=RC4(128) Mac=SHA1 2011.03.09 09:27:24 LOG7[2608:3078736752]: SSL socket closed on SSL_read 2011.03.09 09:27:24 LOG7[2608:3078736752]: Socket write shutdown 2011.03.09 09:27:24 LOG5[2608:3078736752]: Connection closed: 17 bytes sent to SSL, 137 bytes sent to socket 2011.03.09 09:27:24 LOG7[2608:3078736752]: ssmtp_client_iol finished (0 left) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx it is good to see, that whole chain of 3 certificates is checked :-) The other thing: > > > > You can even generate a > > >cert such a self-signed certificate yourself > > >and throw away the > > >> >private > > >>key. Provided the subject DN matches the > > >>peer's subject DN you're > > >>> >set. > > > > > You are again talking about generating own > > certificate, but as I > > > wrote - I just need to connect to this SMTP > > server which use simple > > > SASL PLAIN/LOGIN authentication, so I need not > > own certificate to > > > authenticate me, I thing. (?) > > For stunnel, you can generate the peer's > certificate, it won't actually > check that the public keys match, only the subject > DN needs to be the > same: > > $ openssl req -new -x509 -nodes -newkey rsa:1024 > -keyout /dev/null \ > -out smtp.iol.cz.pem \ > -subj "/C=CZ/ST=Praha/L=Praha 4/O=Telefonica O2 > Czech Republic, a.s./OU=Operations/CN=smtp.iol.cz" > > Of course this DN can only be obtained by > connecting to the site, so you > can grab their cert if your prefer. > > -- > Viktor. If I understand you right, then you mean, that I could generate "fake" peers certificate with just correct CN=smtp.iol.cz (or whole subject). But I do not understand, how it could work ? After all, stunnel4 gets from other side proper certificate, which differs from that I have generate. So stunnel would be not confused, if the local copy of peers certificate (my fake selfgenerated) will differ from that, get from peer by SSL communication ?! I have read the manpage of stunnel4 (the part of "-verify"), but I can't understand the sense of security, if stunnel4 would allow such connection, where by level 3 would local copy differs from the one supplied by peer ?! Example: I have now real, correct certificate of smpt.iol.cz as local copy for verify level 3. Attacker generates fake certificate with same CN/subject as in original. I make a connection and stunnel4 will be satisfied ?! It is crazy. isn't it ? Where is the security ? --kapetr