opensslコマンドでGMAILのPOPサービスにつないでみる

GMAILのPOPサービスは、POP over SSL を使っている。httpsが HTTP over SSL なのと同じ。
ターミナル窓(CUIってことね)を使ってhttpsで接続し、httpコマンドを使おうとすると手順はだいたい以下のとおり。

$ openssl s_client -connect www.example.jp.:443
CONNECTED(00000003)
[俺注: SSL関連の出力がぶええええっと出る。2行↓から俺入力。]
---
GET / HTTP/1.0
Host: www.example.jp

HTTP/1.1 200 OK
Server: ""
Date: Wed, 02 May 2007 19:45:20 GMT
Content-type: text/html
Connection: close

SSLセッションさえ張れればあとは普通のHTTPと同じ。SSLセッションを確立する手順を、キーボードぱちぱち叩いてやることは不可能ではないけど、とてもじゃないが人間にできる手順じゃないから、この部分は openssl コマンドの s_client を使うべし。

そしてタイトルに挙げたGMAILのPOPサービスなんですが。

$ openssl s_client -connect pop.gmail.com:995
CONNECTED(00000003)
[※SSL接続の出力は省略]
---
+OK Gpop ready for requests from xxx.xx.xx.xxx x20xx1401750xxx
USER [俺のid]
+OK send PASS
PASS [俺のpass]
+OK Welcome.
LIST
+OK 5 messages (24576 bytes)
1 4699
2 4315
3 6260
4 4474
5 4828
.
RETR 1
RENEGOTIATING
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
verify error:num=27:certificate not trusted
verify return:1
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
verify error:num=21:unable to verify the first certificate
verify return:1

接続・認証・LISTまでは普通なのに、RETRしようとするとSSLの再接続?のような事が起きていて、RETRがうまくいかない。知らないCAがSignした証明書ってことなんだろうなぁ、と思いつつもまだちゃんと調べてません。