1

I am currently programming a pop3 email client to learn more about email clients and the RFC... The command: openssl s_client -connect pop.gmail.com:995 would connect to google server and will enable you to retrieve and check email after authentication. How would I do this in Java after initiating a TCP socket connection? A really bad alternative is to spawn a process that runs that command externally

Thanks

1 Answers1

3

You would open a SSL Socket instead of a regular socket. SSLSockets require you to do a couple of extra things like setup the private key and a cert. If you search for "SSLSocket java examples" you should get a bunch of sample code to help you set it up. After you've created a SSLSocket and connected to gmail, you can get Input/Output streams from the socket just like you would with a regular Socket.

Also see: Java client certificates over HTTPS/SSL

Community
  • 1
  • 1
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • 1
    @JohnSmith If you're brave, you can also use `SSLEngine` with NIO. This being said, don't use the trustmanager mentioned in the most upvoted answer in the linked question, this will disable the verification of the server cert and make the connection open to MITM attacks. (The cert for `pop.gmail.com` should be verifiable using the default trust store anyway. Not specific configuration required here: just use the default `SSLSocketFactory`.) – Bruno Apr 30 '12 at 09:08
  • 1
    @JohnSmith the statement above that "SSLSockets require you to do a couple of extra things like setup the private key and a cert" is not correct. This is only required if the server requires client authentication. Otherwise you only have to deal with the issue of trusting the server certificate, which at worst is a simple export/import step. – user207421 Apr 30 '12 at 10:15