検索条件
全1件
(1/1ページ)
-----BEGIN CERTIFICATE----- MIIC4TCCAkqgAwIBAgIBADANBgkqhkiG9w0BAQUFADB4MQswCQYDVQQGEwJKUDER MA8GA1UECBMISG9ra2FpZG8xGzAZBgNVBAoTEkJhc2UgS2VybmVsIENvIEx0ZDEg MB4GA1UECxMXTmV0d29yayBPcHJhdGlvbiBDZW50ZXIxFzAVBgNVBAMTDkJhc2Ug S2VybmVsIENBMB4XDTA4MDcxMzEzMTU0NVoXDTI4MDcxMzEzMTU0NVoweDELMAkG ・・・・一部省略・・・・ A1UEBhMCSlAxETAPBgNVBAgTCEhva2thaWRvMRswGQYDVQQKExJCYXNlIEtlcm5l +6EEruiOlNKYnViRTdjEoAPRYfgM+eqjnfbVOxB0wEV7w5GjcqbGe9ePrEUs1wYS ktnZC7H0p5H01z92udKE3BaCEACQ -----END CERTIFICATE-----これは、pem 形式と呼ばれるディジタル証明書で、通常はこの形式で管理します。
#!/usr/local/bin/perl use MIME::Base64 ; # Base64ライブラリ使用宣言 use Crypt::X509 ; # 証明書内容参照ライブラリ使用宣言 $csr_pem = "" ; $status = open (CSRPEM,"hoge.pem") ; if ($status) { local $/ = undef ; $csr_pem = <CSRPEM> ; close(CSRPEM) ; } $csr_pem =~ /\-\-\-\-\-BEGIN\s+CERTIFICATE\-\-\-\-\-(.+)\-\-\-\-\-END\s+CERTIFICATE\-\-\-\-\-/s ; $x509_tmp = $1 ; %outstr = {} ; $x509_decode = Crypt::X509->new(cert => decode_base64($x509_tmp)) ; @nb = localtime($x509_decode->not_before) ; @na = localtime($x509_decode->not_after) ; @jw = ('日','月','火','水','木','金','土') ; $outstr{'not_before'} = sprintf("%d/%02d/%02d(%s) %02d:%02d:%02d",$nb[5] + 1900,$nb[4] + 1,$nb[3],$jw[$nb[6]],$nb[2],$nb[1],$nb[0]) ; $outstr{'not_after'} = sprintf("%d/%02d/%02d(%s) %02d:%02d:%02d",$na[5] + 1900,$na[4] + 1,$na[3],$jw[$na[6]],$na[2],$na[1],$na[0]) ; $outstr{'subj_country'} = $x509_decode->subject_country ; $outstr{'subj_state'} = $x509_decode->subject_state ; $outstr{'subj_local'} = $x509_decode->subject_locality ; $outstr{'subj_org'} = $x509_decode->subject_org ; $outstr{'subj_ou'} = $x509_decode->subject_ou ; $outstr{'subj_cn'} = $x509_decode->subject_cn ; $outstr{'issuer_cn'} = $x509_decode->issuer_cn ; $serial16 = sprintf("%X",$x509_decode->serial) ; $serial16 = '0' . $serial16 if (length($serial16) % 2) ; 1 while $serial16 =~ s/^([\da-fA-F]+)([\da-fA-F][\da-fA-F])/$1\:$2/ ; $outstr{'issuer_serial'} = $serial16 ; $outstr{'issuer_country'} = $x509_decode->issuer_country ; $outstr{'issuer_state'} = $x509_decode->issuer_state ; $outstr{'issuer_local'} = $x509_decode->issuer_locality ; $outstr{'issuer_org'} = $x509_decode->issuer_org ; $outstr{'sigalgo'} = $x509_decode->sig_algorithm ;上記サンプルにて、連想配列 %outstr に表示可能な文字列にて解析内容が入ります。