LoginSignup
21

More than 3 years have passed since last update.

[小ネタ]OpenSSLコマンドを使って色々確認する

Last updated at Posted at 2017-06-07

小ネタです。

参考

証明書発行者を確認する

$openssl s_client -connect www.yahoo.co.jp:443 < /dev/null |grep issuer
depth=1 /C=JP/O=Cybertrust Japan Co., Ltd./CN=Cybertrust Japan Public CA G3
verify error:num=20:unable to get local issuer certificate
verify return:0
DONE
issuer=/C=JP/O=Cybertrust Japan Co., Ltd./CN=Cybertrust Japan Public CA G3

発行者が Cybertrust 社だという事が分かりました。
grepコマンドを実行しなければ証明書の詳細が確認できます。

SSL/TLS バージョンを指定して接続する

SSL2.0

# エラー
$openssl s_client -connect www.yahoo.co.jp:443 -ssl2 < /dev/null
CONNECTED(00000003)
37974:error:1407F0E5:SSL routines:SSL2_WRITE:ssl handshake failure:/BuildRoot/Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-59.60.1/src/ssl/s2_pkt.c:427:

TLS1.0

# 成功の場合、エラーは出ない
$openssl s_client -connect www.yahoo.co.jp:443 -tls1 < /dev/null

他のSSL/TLSバージョンのオプション

  • SSL2.0->-ssl2
  • SSL3.0->-ssl3
  • TLS1.0->-tls1
  • TLS1.1->-tls1_1
  • TLS1.2->-tls1_1

なお、SNI(Server Name Indication)が必要な場合、上記コマンドではエラーとなり、-servername [domain name]オプションの指定が必要。

$openssl s_client -connect example.com:443 -tls1_2 -servername example.com < /dev/null

SNI については以下が参考になりました。

SNIで1台のサーバ上に複数のSSLサイトを運用 – 前編

暗号スイートがサポートされているか確認する

--cipherで暗号スイートをオプションで指定可能。
失敗の場合、以下のように「Cipher(NONE)」と表示されるよう。
また、「Secure Renegotiation IS NOT supported」と書いてある

# 失敗
$openssl s_client -connect www.google.com:443 -cipher RC4-MD5  < /dev/null
CONNECTED(00000003)
140735283146832:error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure:s23_clnt.c:802:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 99 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : 0000
    Session-ID:
    Session-ID-ctx:
    Master-Key:
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1528357633
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---

OKのような場合以下のような感じ。
「New, TLSv1/SSLv3, Cipher is DES-CBC3-SHA」、「Secure Renegotiation IS supported」とうい感じになっている。

# OK
$openssl s_client -connect www.google.com:443 -cipher DES-CBC3-SHA

CONNECTED(00000003)
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google LLC/CN=www.google.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-----
MIIEglLAdGCctAYr89nCdppZfO55jFJF8iej4E
kbtTXD3Xxxxxx
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Mountain View/O=Google LLC/CN=www.google.com
issuer=/C=US/O=Google Trust Services/CN=Google Internet Authority G3
---
No client certificate CA names sent
---
SSL handshake has read 2645 bytes and written 425 bytes
---
New, TLSv1/SSLv3, Cipher is DES-CBC3-SHA
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : DES-CBC3-SHA
    Session-ID: E967C142D8DCDD59A7F57FBA3C5AD59DE681334A926E20956204547A5E003BE9
    Session-ID-ctx:
    Master-Key: C2EDDC7D9BF2045A37074226F8CD44A29D897D10514C54459E9A8ADEB301E4F2682CA5FCCC0BDCC8C4F76999E76C18E6
    Key-Arg   : None
    Krb5 Principal: None
    PSK identity: None
    PSK identity hint: None
    TLS session ticket lifetime hint: 100800 (seconds)
    TLS session ticket:
    0000 - 00 4c a3 51 8e 5e 40 35-94 15 1c 04 2c de 8f 81   .L.Q.^@5....,...
    0010 - d4 03 f1 5f a7 b7 55 e6-51 dc b6 79 68 66 5d ed   ..._..U.Q..yhf].
    0020 - 5f db 5c c1 e9 19 7b c2-d8 1c 2f 92 62 08 54 3a   _.\...{.../.b.T:
    0030 - 2f 77 44 db bc e2 48 b4-6c e8 5f e3 00 4c c1 02   /wD...H.l._..L..
    0040 - bf f6 22 d3 0d 18 80 9f-87 1b f4 ff e8 57 56 da   .."..........WV.
    0050 - 9f 1a c4 4a 6a fc c7 78-ea 9a 89 ac df 72 84 06   ...Jj..x.....r..
    0060 - 6a 3a 36 e7 b5 74 90 13-fa 35 28 d0 58 da 82 6f   j:6..t...5(.X..o
    0070 - 4c 54 0b 7d 6f ee 7a 2e-56 10 da 55 98 04 a4 76   LT.}o.z.V..U...v
    0080 - 38 f7 c4 92 38 a1 9a 3e-ab 8c 9c b3 f9 fd 83 f8   8...8..>........
    0090 - d0 df ab 8c 17 dd 3c 7d-bc 31 02 cf ea 90 28 f3   ......<}.1....(.
    00a0 - 48 31 9a d9 4a a5 9d 80-e7 da bb aa 50 53 16 f8   H1..J.......PS..
    00b0 - dc 21 27 90 a2 05 36 88-cf 20 64 6a 48 be 31 72   .!'...6.. djH.1r
    00c0 - 22 54 29 d0 3d 02 6e 78-97 d3 20 71 0e 5e 9b 8d   "T).=.nx.. q.^..

    Start Time: 1528357860
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)

ある程度サーバー側でどの暗号スイートをサポートしているか判断するのは以下のスクリプトが良さげでした。

How do I list the SSL/TLS cipher suites a particular website offers?

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21