キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 
cancel
5940
閲覧回数
10
いいね!
0
コメント
hiryokoy
Cisco Employee
Cisco Employee

はじめに

以前、OpenSSLによる証明書検証環境構築(802.1x,CRL,OCSP) を投稿しましたが、ISEへの適用とよりシンプルな内容で書き直しました。
今回はWindows 10のWSL(Ubuntu 18.04.LTS)をopensslの環境として使用しています。ISEは2.4/2.6で確認しています。

なるべく既存の環境への考慮が不要でやり直しが手軽な方法を目指します。

準備

  • opensslにpathが通っている環境であれば問題ありません。
  • 検証用のdirectoryを作成。
  • そのdirecotryに以下のファイルをopenssl.cfgとして作成。
HOME     = .
RANDFILE = $ENV::HOME/.rnd

[ ca ]
default_ca = CA_default
[ CA_default ]
database	= ./index.txt
new_certs_dir	= .
serial		= ./serial
crlnumber	= ./crlnumber
RANDFILE	= ./.rand
crl_extensions	= crl_ext
preserve	= no
policy		= policy_match
copy_extensions = copy

[ policy_match ]
countryName         = match
stateOrProvinceName	= match
organizationName	  = match
organizationalUnitName	= optional
commonName          = supplied
emailAddress        = optional

[ req ]
distinguished_name = req_distinguished_name
string_mask = utf8only
[ req_distinguished_name ]

[ rca ]
subjectKeyIdentifier = hash
basicConstraints     = critical, CA:true
keyUsage             = critical, digitalSignature, cRLSign, keyCertSign

[ ica ]
subjectKeyIdentifier   = hash
authorityKeyIdentifier = keyid:always, issuer
basicConstraints       = critical, CA:TRUE, pathlen:0
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

[ usr ]
subjectKeyIdentifier   = hash
authorityKeyIdentifier = keyid, issuer
basicConstraints       = CA:FALSE

[ crl_ext ]
authorityKeyIdentifier=keyid:always,issuer

[ ocsp ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
basicConstraints = CA:FALSE
keyUsage = critical, digitalSignature, keyEncipherment, nonRepudiation
extendedKeyUsage = critical, OCSPSigning
#noCheck=yes
authorityInfoAccess = OCSP;URI:http://ocsp.hogetrust.com:2560
  • そのdirectoryで以下を実行。
echo '01' > ./serial && echo '00' > ./crlnumber && touch ./index.txt 

証明書chainを作り直す場合は、別のdirectoryを作成し上記を繰りかえす(不要になればdirectoryごと削除)。他への影響は考慮不要。

CA証明書作成

RootCA証明書

openssl req -new -x509 -config openssl.cfg -extensions rca -passout pass:cisco123 -newkey rsa:2048 -subj "/C=JP/ST=Tokyo/L=Roppongi/O=HogeSystems/OU=RCA191021/CN=rca.hogesystems.com/emailAddress=rca-admin@hogesystems.com" -days 3650 -keyout rcakey.pem > rcacrt.pem -batch
  • "/C=JP/ST=Tokyo/L=Roppongi/O=HogeSystems/OU=RCA191021/CN=rca.hogesystems.com/emailAddress=rca-admin@hogesystems.com" の部分は証明書のsubjectになるので適当に変更。

  • 自分で自分に署名するのでCSRは不要。

  • ISEではSubjectが既存と被ると問題が出る時があるのでOUだけ日時で変えておくというのも手です。証明書の有効期限等他にもcustomize可能ですが、opensslに関してはInternetに多くの記事があるので必要に応じて確認下さい。

中間CA証明書

openssl req -new -config openssl.cfg -sha256 -passout pass:cisco123 -newkey rsa:2048 -subj "/C=JP/ST=Tokyo/L=Roppongi/O=HogeSystems/OU=ICA191021/CN=ica.hogesystems.com/emailAddress=ica-admin@hogesystems.com" -keyout icakey.pem > icacsr.pem -batch

openssl ca -config openssl.cfg -notext -extensions ica -md sha256 -passin pass:cisco123 -keyfile rcakey.pem -cert rcacrt.pem -in icacsr.pem -days 1825 > icacrt.pem -batch
  • "/C=JP/ST=Tokyo/L=Roppongi/O=HogeSystems/OU=ICA191021/CN=ica.hogesystems.com/emailAddress=ica-admin@hogesystems.com" の部分が証明書のsubject。

ここまでで以下のようにファイルが生成。

[19/10/21 23:40] 191021$ ls -la
total 0
drwxrwxrwx 1 hiyoko hiyoko 4096 Oct 21 23:40 .
drwxr-xr-x 1 hiyoko hiyoko 4096 Oct 21 22:54 ..
-rw-rw-rw- 1 hiyoko hiyoko 1476 Oct 21 23:40 01.pem
-rw-rw-rw- 1 hiyoko hiyoko    3 Oct 21 22:56 crlnumber
-rw-rw-rw- 1 hiyoko hiyoko 1476 Oct 21 23:40 icacrt.pem
-rw-rw-rw- 1 hiyoko hiyoko 1086 Oct 21 23:36 icacsr.pem
-rw------- 1 hiyoko hiyoko 1854 Oct 21 23:36 icakey.pem
-rw-rw-rw- 1 hiyoko hiyoko  132 Oct 21 23:40 index.txt
-rw-rw-rw- 1 hiyoko hiyoko   21 Oct 21 23:40 index.txt.attr
-rw-rw-rw- 1 hiyoko hiyoko    0 Oct 21 22:56 index.txt.old
-rw-r--r-- 1 hiyoko hiyoko 1439 Oct 21 22:56 openssl.cfg
-rw-rw-rw- 1 hiyoko hiyoko 1464 Oct 21 23:35 rcacrt.pem
-rw------- 1 hiyoko hiyoko 1854 Oct 21 23:35 rcakey.pem
-rw-rw-rw- 1 hiyoko hiyoko    3 Oct 21 23:40 serial
-rw-rw-rw- 1 hiyoko hiyoko    3 Oct 21 22:56 serial.old
[19/10/21 23:40] 191021$
  • 本投稿ではXXXcrt.pemが証明書、XXXkey.pemが秘密鍵、XXXcsr.pemがCSRとする。

  • CA証明書の秘密鍵のpassphraseはcisco123, 証明書の秘密鍵のpassphraseはcisco とする。

証明書作成

クライアント証明書

openssl req -new -sha256 -newkey rsa:2048 -passout pass:cisco -subj "/C=JP/ST=Tokyo/L=Roppongi/O=HogeSystems/OU=CX/CN=cse01/emailAddress=cse01@hogesystems.com" -reqexts EXTS -config <(cat ./openssl.cfg <(printf "\n[EXTS]\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=clientAuth,emailProtection")) -keyout usr01key.pem -out usr01csr.pem -batch

openssl ca -config openssl.cfg -notext -extensions usr -passin pass:cisco123 -md sha256 -keyfile icakey.pem -cert icacrt.pem -in usr01csr.pem -days 365 -out usr01crt.pem -batch
  • extendedKeyUsageにcilentAuthを含む。

  • usr01の部分をusr02,usr03と変更していけば複数の証明書を作成可能。

  • subjectは適宜変更可能。

サーバ証明書

openssl req -new -sha256 -newkey rsa:2048 -passout pass:cisco -subj "/C=JP/ST=Tokyo/L=Roppongi/O=HogeSystems/OU=CX/CN=svr01.hogesystems.com" -reqexts EXTS -config <(cat ./openssl.cfg <(printf "\n[EXTS]\nsubjectAltName=DNS:ise22.hogesystems.com,DNS:www.hogesystems.com,IP:1.1.1.1\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=serverAuth")) -keyout svr01key.pem -out svr01csr.pem -batch

openssl ca -config openssl.cfg -notext -extensions usr -passin pass:cisco123 -md sha256 -keyfile icakey.pem -cert icacrt.pem -in svr01csr.pem -days 365 -out svr01crt.pem -batch
  • extendedKeyUsageにserverAuthを含む。

  • subjectは既存のものと被らないようにする。

  • SANはbrowserに入力する可能性のあるFQDNやIPを設定します。複数入れることも可能(特にadmin/portal usage)

  • -passin は署名に使用するca証明書の秘密鍵のpassphrase, -passoutはCSRを作成する際のpassphraseで-batchでy入力を省略できるようにしている。

bashの内部コマンドのprintfでEKUやSubject/SANを証明書ごとに自由に設定できるようにしている。

CRL/OCSP設定

証明書のrevoke

openssl ca -config openssl.cfg -md sha256 -cert icacrt.pem -passin pass:cisco123 -keyfile icakey.pem -revoke usr01crt.pem
[19/10/22 08:23] 191021$ cat index.txt
V       241019144042Z           01      unknown /C=JP/ST=Tokyo/O=HogeSystems/OU=ICA191021/CN=ica.hogesystems.com/emailAddress=ica-admin@hogesystems.com
R       201020145717Z   191021232303Z   02      unknown /C=JP/ST=Tokyo/O=HogeSystems/OU=CX/CN=cse01/emailAddress=cse01@hogesystems.com
V       201020151054Z           03      unknown /C=JP/ST=Tokyo/O=HogeSystems/OU=JTAC/CN=svr01.hogesystems.com
V       201020151720Z           04      unknown /C=JP/ST=Tokyo/O=HogeSystems/OU=CX/CN=cse02/emailAddress=cse02@hogesystems.com
[19/10/22 08:23] 191021$
  • usr01の証明書がindex.txt内でrevokeされていることがわかる。

CRL作成

openssl ca -gencrl -config openssl.cfg -md sha256 -cert icacrt.pem -passin pass:cisco123 -keyfile icakey.pem -crldays 30 > icacrl.pem
  • usr01をrevokeしたことが反映されたCRL(icacrl.pem)を作成。
[19/10/22 15:01] 191021-2$ openssl verify -crl_check -CRLfile icacrl.pem -CAfile <(cat rcacrt.pem icacrt.pem) usr01crt.pem
C = JP, ST = Tokyo, O = HogeSystems, OU = CX, CN = cse01, emailAddress = cse01@hogesystems.com
error 23 at 0 depth lookup: certificate revoked
error usr01crt.pem: verification failed
  • usr01がrevokeされていることをCRLから確認。

OCSP responder証明書作成

openssl req -new -config openssl.cfg -sha256 -newkey rsa:2048 -subj "/C=JP/ST=Tokyo/L=Roppongi/O=HogeSystems/OU=CX/CN=iocsp.hogesystems.com" -passout pass:cisco -keyout iocspkey.pem -out iocspcsr.pem -batch

openssl ca -config openssl.cfg -extensions ocsp -md sha256 -passin pass:cisco123 -keyfile icakey.pem -cert icacrt.pem -in iocspcsr.pem -days 365 -out iocspcrt.pem -batch
  • 通常の証明書と同様にcsrを作成してから署名。

OCSP responder動作確認

openssl ocsp -ignore_err -index index.txt -CA icacrt.pem -rsigner iocspcrt.pem -passin pass:cisco -rkey iocspkey.pem -port 2560
  • opensslはコマンド一つでocsp responderとして動作する。
  • tcp port番号は2560としている。
openssl ocsp -issuer icacrt.pem -nonce -CAfile <(cat rcacrt.pem icacrt.pem) -url http://localhost:2560 -serial 2
  • index.txtにあるserial(左から3列目)を指定して証明書のrevoke状況を確認。
[19/10/22 14:21] 191021-2$ openssl ocsp -issuer icacrt.pem -nonce -CAfile <(cat rcacrt.pem icacrt.pem) -url http://localhost:2560 -serial 2
Response verify OK
2: revoked
        This Update: Oct 22 05:21:11 2019 GMT
        Revocation Time: Oct 22 03:44:00 2019 GMT
[19/10/22 14:21] 191021-2$ openssl ocsp -issuer icacrt.pem -nonce -CAfile <(cat rcacrt.pem icacrt.pem) -url http://localhost:2560 -serial 3
Response verify OK
3: good
        This Update: Oct 22 05:21:35 2019 GMT

  • OCSP responderを起動したのとは別terminalで自host tcp:2560にOCSP requestを送信するとresponseを受信。
  • 正常なものとrevokeしているものの差がわかる。

ISE/端末への証明書import

CA証明書のimport

ise_trusted_certificates.png

Administration > System > Certificates > Certificate Management > Trusted Certificates > Import

  • RootCA/中間CAのPEMファイルをImport。
  • EAP-TLSであればclient認証に使用するため、Trust for client authentication and Syslog にcheckが必要。
  • RootCA/中間CAを連結したPEMもImport可。

サーバ証明書のimport

ise_system_certificates.png

Administration > System > Certificates > Certificate Management > System Certificates > Import

  • Import先のNodeを選択し、証明書/秘密鍵(とpassphrase)のPEMファイルをImport。
  • EAP-TLSであればEAP Authenticationにcheckが必要(Usageは後から追加/変更可)。

(PCへの)クライアント証明書のimport

client_cert_import_windowscertmgr.png

  • pkcs12ファイル(p12/pfx)をダブルクリックするとcertificate import wizardが開始されるので、それに従ってImport。

windows_eap-tls.png

  • Control panel > Network Connections (ncpa.cpl)から当該NICで

  • 右クリック -> Properties > Authentication で、802.1x設定

  • Verify the server's Identity by validating the certificate にcheckが入っている場合は端末がISEのEAP server証明書を信頼している必要があるので、

windows_eap-tls_verifysrv.png

  • Trusted Root Certification Authorities(信頼されたルート証明機関)にRootCA証明書と中間CA証明書のimportが必要。

Client証明書のCRL/OCSP check

ise_clientauthentication_crlocsp.png

Administration > System > Certificates > Certificate Management > Trusted Certificates

  • Client証明書を署名した中間CAでOCSP/CRLのcheckを有効化。
  • CRL/OCSP、どちらか片方の使用でもよい。
  • 別のWeb serverに作成したCRL(PEM形式)を置き、それをCRL Distribution URLとする。(前記事ではCRLを作成したdirectoryでpythonのSimpleHTTPServerを使用する方法を紹介)
  • OCSP serviceで指定しているOCSP_opensslは次の手順で作成

ise_clientauthentication_ocspprofile.png

Administration > System > Certificates > Certificate Management > OCSP Client Profile

  • URLはopensslをOCSP responderとして使用したPCのIPとtcp port番号。

よく使うコマンド

openssl verify (証明書の検証確認)

[19/10/22 14:59] 191021-2$ openssl verify -CAfile <(cat rcacrt.pem icacrt.pem) usr01crt.pem
usr01crt.pem: OK

openssl x509 -text -noout (証明書の内容確認)

[19/10/22 15:02] 191021-2$ openssl x509 -text -noout < usr01crt.pem
Certificate:
   Data:
       Version: 3 (0x2)
       Serial Number: 2 (0x2)
   Signature Algorithm: sha256WithRSAEncryption
       Issuer: C = JP, ST = Tokyo, O = HogeSystems, OU = ICA191021, CN = ica.hogesystems.com, emailAddress = ica-admin@hogesystems.com
       Validity
           Not Before: Oct 22 03:41:34 2019 GMT
           Not After : Oct 21 03:41:34 2020 GMT
       Subject: C = JP, ST = Tokyo, O = HogeSystems, OU = CX, CN = cse01, emailAddress = cse01@hogesystems.com
       Subject Public Key Info:
           Public Key Algorithm: rsaEncryption
               Public-Key: (2048 bit)
(snip)

openssl pkcs12 -export (証明書と秘密鍵をpkcs12に変換、Windowsにclient証明書としてimport)

[19/10/22 15:11] 191021-2$ openssl pkcs12 -export -passout pass:cisco -passin pass:cisco -inkey usr01key.pem < usr01crt.pem > usr01crt.p12

openssl x509 -inform pem -outform der < usr01crt.pem > usr01crt.der (PEMからDERに変換)

市販の証明書で使われている多くのattribute/機能はopensslで大部分カバーできます。証明書関連の問題が発生しているときに検証環境を構築する敷居が下がればと思います。

Getting Started

検索バーにキーワード、フレーズ、または質問を入力し、お探しのものを見つけましょう

シスコ コミュニティをいち早く使いこなしていただけるよう役立つリンクをまとめました。みなさんのジャーニーがより良いものとなるようお手伝いします