ããã·ã¢ã®èªå®x509蚌ææžã衚瀺ããããã®è±èªã®ã¯ãã¹ãã©ãããã©ãŒã ãŠãŒãã£ãªãã£ããšãã
èšäºã«å¯Ÿãã圌ã®ã³ã¡ã³ãã§ã
Pasã¯ãèªåèªèº«ãæ°ããããšãã§ãããPKCSïŒ11ããŒã¯ã³ãéåžžã«æ£ç¢ºã«ææããŸããã ã¯ããããŒã¯ã³ã¯å®éã«ã¯æå·åã³ã³ãã¥ãŒã¿ãŒã§ãã ãããŠãPythonãPerlãRubyãªã©ãã¹ã¯ãªããèšèªã§ãããã®ã³ã³ãã¥ãŒã¿ãŒã䜿çšãããã®ã¯èªç¶ãªããšã§ãã 蚌ææžãªã¯ãšã¹ããäœæããããã«ãããã¥ã¡ã³ãã®çœ²åãšæå·åã®ããã«Pythonã§ãã·ã¢ã®æå·åããµããŒã
ããPKCSïŒ11ããŒã¯ã³ã®äœ¿çšãæ¢ã«äœããã®åœ¢ã§æ€èšããŠã
ãŸã ïŒ
ããã§ã¯ãTclèšèªã«é¢ããè°è«ãç¶ããŸãã åã®
èšäºã§ ãPKCSïŒ11ããŒã¯ã³/ã¹ããŒãã«ãŒãã«ä¿åããã蚌ææžã衚瀺ããã³æ€èšŒããéã
TclPKCS11ããŒãžã§ã³0.9.9ããã±ãŒãžã䜿çšããŠãããã«ã¢ã¯ã»ã¹ããŸããïŒèšŒææžïŒã æ¢ã«è¿°ã¹ãããã«ãæ®å¿µãªããããã®ããã±ãŒãžã¯RSAæå·åçšã«éçºãããPKCSïŒ11 v.2.20æšæºãèæ
®ã«å
¥ããŠããŸãã çŸåšãPKCSïŒ11 v.2.40èŠæ Œããã§ã«äœ¿çšãããŠãããTK-26æå·åæè¡å§å¡äŒããããæå°ãããã·ã¢ã®æå·åããµããŒãããããŒã¯ã³/ã¹ããŒãã«ãŒãã®åœå
ã¡ãŒã«ãŒã«æšå¥šäºé
ãçºè¡ããŠããŸãã ãããŠãããããã¹ãŠã®ããšã§ãæ°ãã
TclPKCS11ããã±ãŒãž
ããŒãžã§ã³1.0.1ãç»å ŽããŸãã ã RSAã®ãã¹ãŠã®æå·åã€ã³ã¿ãŒãã§ãŒã¹ãTclPKCS11 v.10.1ããã±ãŒãžã®æ°ããããŒãžã§ã³ã«ä¿åãããããã«ãããã«äºçŽããŸãã ããã±ãŒãžã©ã€ãã©ãªã¯Cèšèªã§èšè¿°ãããŠããŸãã
ããã§ã¯ãããã±ãŒãžã®æ°æ©èœã¯äœã§ããïŒ ãŸããæ¥ç¶ãããããŒã¯ã³ã§ãµããŒããããŠããæå·åã¡ã«ããºã ã®ãªã¹ããååŸã§ããã³ãã³ããè¿œå ãããŸããã
::pki::pkcs11::listmechs <handl> <slotid>
æ¥ç¶ãããããŒã¯ã³ãå«ãã¹ãããã®ãªã¹ããååŸããæ¹æ³ã¯ã
ããã«ç€ºãããŠã
ãŸã ïŒæé -proc :: slot_with_tokenïŒïŒ
proc ::slots_with_token {handle} { set slots [pki::pkcs11::listslots $handle] # puts "Slots: $slots" array set listtok [] foreach slotinfo $slots { set slotid [lindex $slotinfo 0] set slotlabel [lindex $slotinfo 1] set slotflags [lindex $slotinfo 2] if {[lsearch -exact $slotflags TOKEN_PRESENT] != -1} { set listtok($slotid) $slotlabel } } # parray listtok return [array get listtok] }
ç°¡åãªã¹ã¯ãªãããäœæããŸãã
#!/usr/bin/tclsh lappend auto_path . package require pki::pkcs11 # RuToken set lib "/usr/local/lib64/librtpkcs11ecp_2.0.so" <source lang="bash">set handle [pki::pkcs11::loadmodule $lib] # # set labslot [::slots_with_token $handle] if {[llength $labslot] == 0} { puts " " exit } set slotid 0 set lmech [pki::pkcs11::listmechs $handle $slotid] set i 0 foreach mm $lmech { # if {[string first "GOSTR3410" $mm] != -1} { puts -nonewline "[lindex $mm 0] " if {$i == 2} {puts "";set i 0} else { incr i} } } puts "\n" exit
ãã®ã¹ã¯ãªããã䜿çšãããšãRuTokenãã¡ããªããŒã¯ã³ã§ãµããŒããããŠããGOSTR3410æå·åã¡ã«ããºã ã®ãªã¹ããååŸã§ããŸãã ãŸãã
Pasã
èšäºã§æžããããã«ããããããçš®é¡ã®EDOã«æãããç¯æã®å
ããåãäžããŸãã
$ tclsh TEST_for_HABR.tcl listtok(0) = ruToken Lite 0 {ruToken Lite } $
ãããŠåœç¶ã圌ã¯èšŒæãããã¹ãGOSTã¡ã¶ããºã ãæ¯æããŠããªãããšãå€æããŸãã å¥ã®ããŒã¯ã³Rutoken EDSãååŸããŸãã
$ tclsh TEST_for_HABR.tcl listtok(0) = ruToken ECP } 0 {ruToken ECP } CKM_GOSTR3410_KEY_PAIR_GEN CKM_GOSTR3410 CKM_GOSTR3410_DERIVE CKM_GOSTR3410_WITH_GOSTR3411 $
ã¯ãããã®ããŒã¯ã³ã¯ãã·ã¢ã®æå·åããµããŒãããŠããŸãããGOST R 34.10-2001ã®çœ²åã®ã¿
ã䜿çšããŠããŸã ãããã¯ã»ãšãã©
䜿çšãããŠããŸãã ã ããããRutoken EDS-2.0ããŒã¯ã³ã䜿çšãããšããã¹ãŠãæ£åžžã«ãªããããŒ256ããã³512ãããé·ã®GOST R 34.10-2012ããµããŒããããŸãã
$ tclsh TEST_for_HABR.tcl listtok(0) = RuTokenECP20 0 {RuTokenECP20 } CKM_GOSTR3410_KEY_PAIR_GEN CKM_GOSTR3410 CKM_GOSTR3410_DERIVE CKM_GOSTR3410_512_KEY_PAIR_GEN CKM_GOSTR3410_512 CKM_GOSTR3410_12_DERIVE CKM_GOSTR3410_WITH_GOSTR3411 CKM_GOSTR3410_WITH_GOSTR3411_12_256 CKM_GOS TR3410_WITH_GOSTR3411_12_512 $
ã°ã©ã¹ããããŒããã°ãã®æå·åã¢ã«ãŽãªãºã ãå«ããã·ã¢ã®æå·åã1ã€ãŸãã¯å¥ã®ããŒã¯ã³ã§ãµããŒãããããšã«ã€ããŠè©±ãåã£ãå ŽåããœãããŠã§ã¢ãš
ã¯ã©ãŠãããŒã¯ã³ã§æãå®å
šã«ãµããŒããããŸãã
$ tclsh TEST_for_HABR.tcl listtok(0) = LS11SW2016_LIN_64 0 {LS11SW2016_LIN_64 }
ã¡ã«ããºã ã®ãªã¹ãCKM_GOSTR3410_KEY_PAIR_GEN
CKM_GOSTR3410_512_KEY_PAIR_GEN
CKM_GOSTR3410
CKM_GOSTR3410_512
CKM_GOSTR3410_WITH_GOSTR3411
CKM_GOSTR3410_WITH_GOSTR3411_12_256
CKM_GOSTR3410_WITH_GOSTR3411_12_512
CKM_GOSTR3410_DERIVE
CKM_GOSTR3410_12_DERIVE
CKM_GOSR3410_2012_VKO_256
CKM_GOSR3410_2012_VKO_512
CKM_KDF_4357
CKM_KDF_GOSTR3411_2012_256
CKM_KDF_TREE_GOSTR3411_2012_256
CKM_GOSTR3410_KEY_WRAP
CKM_GOSTR3410_PUBLIC_KEY_DERIVE
CKM_LISSI_GOSTR3410_PUBLIC_KEY_DERIVE
CKM_GOST_GENERIC_SECRET_KEY_GEN
CKM_GOST_CIPHER_KEY_GEN
CKM_GOST_CIPHER_ECB
CKM_GOST_CIPHER_CBC
CKM_GOST_CIPHER_CTR
CKM_GOST_CIPHER_OFB
CKM_GOST_CIPHER_CFB
CKM_GOST_CIPHER_OMAC
CKM_GOST_CIPHER_KEY_WRAP
CKM_GOST_CIPHER_ACPKM_CTR
CKM_GOST_CIPHER_ACPKM_OMAC
CKM_GOST28147_KEY_GEN
CKM_GOST28147
CKM_GOST28147_KEY_WRAP
CKM_GOST28147_PKCS8_KEY_WRAP
CKM_GOST_CIPHER_PKCS8_KEY_WRAP
CKM_GOST28147_ECB
CKM_GOST28147_CNT
CKM_GOST28147_MAC
CKM_KUZNYECHIK_KEY_GEN
CKM_KUZNYECHIK_ECB
CKM_KUZNYECHIK_CBC
CKM_KUZNYECHIK_CTR
CKM_KUZNYECHIK_OFB
CKM_KUZNYECHIK_CFB
CKM_KUZNYECHIK_OMAC
CKM_KUZNYECHIK_KEY_WRAP
CKM_KUZNYECHIK_ACPKM_CTR
CKM_KUZNYECHIK_ACPKM_OMAC
CKM_MAGMA_KEY_GEN
CKM_MAGMA_ECB
CKM_MAGMA_CBC
CKM_MAGMA_CTR
CKM_MAGMA_OFB
CKM_MAGMA_CFB
CKM_MAGMA_OMAC
CKM_MAGMA_KEY_WRAP
CKM_MAGMA_ACPKM_CTR
CKM_MAGMA_ACPKM_OMAC
CKM_GOSTR3411
CKM_GOSTR3411_12_256
CKM_GOSTR3411_12_512
CKM_GOSTR3411_HMAC
CKM_GOSTR3411_12_256_HMAC
CKM_GOSTR3411_12_512_HMAC
CKM_PKCS5_PBKD2
CKM_PBA_GOSTR3411_WITH_GOSTR3411_HMAC
CKM_TLS_GOST_KEY_AND_MAC_DERIVE
CKM_TLS_GOST_PRE_MASTER_KEY_GEN
CKM_TLS_GOST_MASTER_KEY_DERIVE
CKM_TLS_GOST_PRF
CKM_TLS_GOST_PRF_2012_256
CKM_TLS_GOST_PRF_2012_512
CKM_TLS12_MASTER_KEY_DERIVE
CKM_TLS12_KEY_AND_MAC_DERIVE
CKM_TLS_MAC
CKM_TLS_KDF
CKM_TLS_TREE_GOSTR3411_2012_256
CKM_EXTRACT_KEY_FROM_KEY
CKM_SHA_1
CKM_MD5
$
ããã±ãŒãžã«è¿œå ããã次ã®æ°æ©èœã«é²ã¿ãŸãã
set listcertsder [pki::pkcs11::listcertsder $handle $slotid]
ãã®é¢æ°ã¯ãããŒã¯ã³ãªãã§ä¿åããã蚌ææžã®ãªã¹ããè¿ããŸãã åé¡ã¯èªç¶ã«çºçããŸãããæ¢åã®é¢æ°pki :: pkcs11 :: listcertsãšã©ãéãã®ã§ããïŒ
ãŸããæ°ããé¢æ°ã¯:: pkiããã±ãŒãžã䜿çšããŸããã è¿ãããèŠçŽ ã®1ã€ã¯ãå®å
šãªèšŒææžãå«ãcert_derèŠçŽ ã§ãã ããã¯ãããšãã°ã蚌ææžããšã¯ã¹ããŒãããããæçŽãåãåã£ããããå Žåã«äŸ¿å©ã§ãã
以å㯠ãTBS蚌ææžãšãã®çœ²åããå®å
šãªèšŒææžãåéããå¿
èŠããããŸããã 1ã€ã®èšŒææžã®å
容ãå°å·ãããšãå蚌ææžã®è¿åã¢ã€ãã ã®å®å
šãªãªã¹ããæ確ã«è¡šç€ºãããŸãã
. . . array set derc [[pki::pkcs11::listcertsder $handle $slotid] 0] parray derc derc(cert_der) = 3082064a ⊠derc(pkcs11_handle) = pkcsmod0 derc(pkcs11_id) = 5882d64386211cf3a8367d2f87659f9330e5605d derc(pkcs11_label) = Thenderbird-60 derc(pkcs11_slotid) = 0 derc(type) = pkcs11 . . .
pkcs11_idèŠçŽ ã«ã¯ãå
¬éããŒããã®SHA-1ããã·ã¥ã®å€ã§ããå±æ§CKA_IDãæ ŒçŽãããŸãã cert_derãšã¬ã¡ã³ãã¯CKA_VALUE蚌ææžãpkcs11_labelã¯CKA_LABELã§ãã
pkcs11_idèŠçŽ ïŒPKCSïŒ11æšæºã®çšèªã§ã¯CKA_IDïŒã¯ãpkcs11_handleã©ã€ãã©ãªãšãšãã«ãpkcs11_slotidããŒã¯ã³ãæã€ã¹ãããèå¥åã¯ãããŒã¯ã³ã«æ ŒçŽãããããŒããã³èšŒææžã«
ã¢ã¯ã»ã¹ããããã®ããŒèŠçŽ
ã§ã ã
ãã®ããã蚌ææžãŸãã¯ããŒã®ã©ãã«ïŒpkcs11_labelïŒãå€æŽããå Žåã¯ã次ã®åœ¢åŒã®ã³ãã³ããå®è¡ããŸãã
pki::pkcs11::rname <cert|key|all> < >
蚌ææžãŸãã¯ããŒãããŒã¯ã³ããåé€ããã«ã¯ã次ã®åœ¢åŒã®ã³ãã³ããå®è¡ãããŸãã
pki::pkcs11::delete <cert|key|all> < >
ããŒèŠçŽ ã®ãªã¹ãã¯ã次ã®ããã«åœ¢æã§ããŸãã
set listparam {} lappend listparam pkcs11_handle lappend listparam $handle lappend listparam pkcs11_slotid lappend listparam $pkcs11_slotid lappend listparam pkcs11_id lappend listparam $pkcs11_id
ãªã©
ãã®å Žåã®é¢æ°åŒã³åºãã¯æ¬¡ã®ããã«ãªããŸãïŒèšŒææžãšããã«é¢é£ããããŒãåé€ããŸãïŒ
pki::pkcs11::delete all $listparam
èªè
ã¯ããããããã®ãªã¹ããèŸæžèŸæžãšããŠé
眮ã§ããããšããã§ã«æšæž¬ããŠããã§ãããã
set listparam [dict create pkcs11_handle $pkcs11_handle] dict set listparam pkcs11_slotid $pkcs11_slotid) dict set listparam pkcs11_id $pkcs11_id
ä»ã®æ¹æ³ãããšãã°é
åïŒé
åïŒããããŸãã
ç¹°ãè¿ããŸãããpkcs11_handleããã³pkcs11_slotidèŠçŽ ã¯ãæ¥ç¶ãããããŒã¯ã³ãäžæã«èå¥ããããŒèŠçŽ ã®ãªã¹ãã«åžžã«ååšããå¿
èŠãããããšã«æ³šæããŠãã ããã æ®ãã®æ§æã¯ãç¹å®ã®æ©èœã«ãã£ãŠæ±ºãŸããŸãã
次ã®é¢æ°ã䜿çšããŠãããŒã¯ã³ã«èšŒææžãã€ã³ã¹ããŒã«ããŸãã
set pkcs11_id_cert [::pki::pkcs11::importcert <cert_der_hex> < >
ãã®é¢æ°ã¯ãå€CKA_IDã16é²æ°ã§è¿ããŸãã éµãã©ã¡ãŒã¿ãŒã®ãªã¹ãã¯ã蚌ææžãé
眮ãããããŒã¯ã³ã決å®ããŸãã
{pkcs11_handle <handle> pkcs11_slotid <slotid>}
次ã¯ããã·ã¥èšç®ã§ãã ä»æ¥ã®ãã·ã¢ã®æå·ã§ã¯ã3çš®é¡ã®ããã·ã¥é¢æ°ã䜿çšãããŠããŸãã
-GOST R 34.11-94
-GOST R 34.11-2012ãããã·ã¥å€256ãããïŒstribog256ïŒ
-GOST R 34 .11-2012ãããã·ã¥å€512ãããïŒstribog512ïŒ
ã©ã®ããã·ã¥ãããŒã¯ã³ããµããŒããããã決å®ããããã«ãé¢æ°pki :: pkcs11 :: listmechsããããŸãã
ããã·ã¥èšç®é¢æ°ã®åœ¢åŒã¯æ¬¡ã®ãšããã§ãã
set <> [pki::pkcs11::digest <gostr3411|stribog256|stribog512|sha1> < > < >]
èšç®ã®èšç®çµæã¯16é²åœ¢åŒã§è¡šç€ºãããããšã«æ³šæããŠãã ããã
. . . set listparam [dict create pkcs11_handle $pkcs11_handle] dict set listparam pkcs11_slotid $pkcs11_slotid set res_hex [pki::pkcs11::digest stribog256 0123456789 $listparam] puts $res_hex 086f2776f33aae96b9a616416b9d1fe9a049951d766709dbe00888852c9cc021
æ€èšŒã®
ããã«ããã·ã¢ã®æå·åããµããŒããã
opensslã䜿çšããŠã¿ãŸãããã
$ echo -n "0123456789"|/usr/local/lirssl_csp_64/bin/lirssl_s tatic dgst -md_gost12_256 (stdin)= 086f2776f33aae96b9a616416b9d1fe9a0499 51d766709dbe00888852c9 cc021 $
ã芧ã®ãšãããçµæã¯åãã§ãã
蚌ææžã倱å¹ãã蚌ææžã®ãªã¹ãããŸãã¯åœ¢åŒã®çœ²åãããããã¥ã¡ã³ãã®ãããã§ãã£ãŠããé»å眲åãæ€èšŒããã«ã¯ã眲åæ€èšŒæ©èœã®ã¿ãå¿
èŠã§ãã
set result [pki::pkcs11::verify < > < > < >]]
眲åãæ€èšŒã«åæ Œããå Žåã¯ã1ãè¿ãããŸãããã以å€ã®å Žåã¯0ã§ããé»å眲åãæ€èšŒããã«ã¯ãããã¥ã¡ã³ãã®çœ²åèªäœã眲åã®ã¿ã€ãã«ãã£ãŠæ±ºå®ãããããã¥ã¡ã³ãããã·ã¥ãããã³çœ²åãäœæãããå
¬éããŒãšãã¹ãŠã®ãã©ã¡ãŒã¿ãŒïŒå€ãã¿ã€ãããã©ã¡ãŒã¿ãŒïŒãå¿
èŠã§ãã ã publickeyinfo asn1æ§é ã®åœ¢åŒã®ãã¹ãŠã®ããŒæ
å ±ã¯ãããŒèŠçŽ ã®ãªã¹ãã«å«ããå¿
èŠããããŸãã
lpkarïŒpkcs11_handleïŒ= pkcsmod0
lpkarïŒpkcs11_slotidïŒ= 0
lpkarïŒpubkeyinfoïŒ= 301f06082a85030701010101301306072a85030202240
006082a8503070101020203430004407d9306687af5a8e63af4b09443ed2e03794be
10eba6627bf5fb3da1bb474a3507d2ce2cd24b63c727a02521897d1dd6edbdc7084d
8886a39289c3f81bdf2e179
ASN1å
¬ééµæ§é ã¯ã眲åè
蚌ææžããååŸãããŸãã
proc ::pki::x509::parse_cert_pubkeyinfo {cert_hex} { array set ret [list] set wholething [binary format H* $cert_hex] ::asn::asnGetSequence wholething cert ::asn::asnPeekByte cert peek_tag if {$peek_tag != 0x02} { # Version number is optional, if missing assumed to be value of 0 ::asn::asnGetContext cert - asn_version ::asn::asnGetInteger asn_version ret(version) } ::asn::asnGetBigInteger cert ret(serial_number) ::asn::asnGetSequence cert data_signature_algo_seq ::asn::asnGetObjectIdentifier data_signature_algo_seq ret(data_signature_algo) ::asn::asnGetSequence cert issuer ::asn::asnGetSequence cert validity ::asn::asnGetUTCTime validity ret(notBefore) ::asn::asnGetUTCTime validity ret(notAfter) ::asn::asnGetSequence cert subject ::asn::asnGetSequence cert pubkeyinfo binary scan $pubkeyinfo H* ret(pubkeyinfo) return $ret(pubkeyinfo) }
ãã¡ã€ã«ããã®èšŒææžã®é»å眲åãæ€èšŒããããã®ã¹ã¯ãªããããã¹ãããããŸã
ãã£ã¡ #! /usr/bin/env tclsh package require pki lappend auto_path . package require pki::pkcs11 # PKCS#11 #set pkcs11_module "/usr/local/lib/libcackey.so" #set pkcs11_module "/usr/local/lib64/librtpkcs11ecp_2.0.so" set pkcs11_module "/usr/local/lib64/libls11sw2016.so" puts "Connect the Token and press Enter" gets stdin yes set handle [pki::pkcs11::loadmodule $pkcs11_module] set slots [pki::pkcs11::listslots $handle] foreach slotinfo $slots { set slotid [lindex $slotinfo 0] set slotlabel [lindex $slotinfo 1] set slotflags [lindex $slotinfo 2] if {[lsearch -exact $slotflags TOKEN_PRESENT] != -1} { set token_slotlabel $slotlabel set token_slotid $slotid # break } } # PEM DER proc ::cert_to_der {data} { if {[string first "-----BEGIN CERTIFICATE-----" $data] != -1} { set data [string map {"\r\n" "\n"} $data] } array set parsed_cert [::pki::_parse_pem $data "-----BEGIN CERTIFICATE-----" "-----END CERTIFICATE-----"] if {[string range $parsed_cert(data) 0 0 ] == "0" } { # DER- "0" == 0x30 set asnblock $parsed_cert(data) } else { set asnblock "" } return $asnblock } proc usage {use error} { puts "Copyright(C) Orlov Vladimir (http://soft.lissi.ru) 2019" if {$use == 1} { puts $error puts "Usage:\nverify_cert_with_pkcs11 <file with certificate> \[<file with CA certificate>\]\n" } } set countcert [llength $argv] if { $countcert < 1 || $countcert > 2 } { usage 1 "Bad usage!" exit } set file [lindex $argv 0] if {![file exists $file]} { usage 1 "File $file not exist" exit } # cert_user puts "Loading user certificate: $file" set fd [open $file] chan configure $fd -translation binary set cert_user [read $fd] close $fd if {$cert_user == "" } { usage 1 "Bad file with certificate user: $file" exit } set cert_user [cert_to_der $cert_user] if {$cert_user == ""} { puts "User certificate bad" exit } catch {array set cert_parse [::pki::x509::parse_cert $cert_user]} if {![info exists cert_parse]} { puts "User certificate bad" exit } #parray cert_parse if {$countcert == 1} { if {$cert_parse(issuer) != $cert_parse(subject)} { puts "Bad usage: not self signed certificate" } else { set cert_CA $cert_user } } else { set fileca [lindex $argv 1] if {![file exists $fileca]} { usage 1 "File $fileca not exist" exit } # cert_CA puts "Loading CA certificate: $fileca" set fd [open $fileca] chan configure $fd -translation binary set cert_CA [read $fd] close $fd if {$cert_CA == "" } { usage 1 "Bad file with certificate CA=$fileca" exit } set cert_CA [cert_to_der $cert_CA] if {$cert_CA == ""} { puts "CA certificate bad" exit } } foreach slotinfo $slots { set slotid [lindex $slotinfo 0] set slotlabel [lindex $slotinfo 1] set slotflags [lindex $slotinfo 2] if {[lsearch -exact $slotflags TOKEN_PRESENT] != -1} { set token_slotlabel $slotlabel set token_slotid $slotid } } # #array set cert_parse_CA [::pki::x509::parse_cert $cert_CA] catch {array set cert_parse_CA [::pki::x509::parse_cert $cert_CA]} #array set cert_parse_CA [::pki::x509::parse_cert $cert_CA_256] #array set cert_parse_CA [::pki::x509::parse_cert $CA_12_512] if {![info exists cert_parse_CA]} { puts "CA certificate bad" exit } ############################### set aa [dict create pkcs11_handle $handle pkcs11_slotid $token_slotid] set tbs_cert [binary format H* $cert_parse(cert)] #puts "SIGN_ALGO1=$cert_parse(signature_algo)" catch {set signature_algo_number [::pki::_oid_name_to_number $cert_parse(signature_algo)]} if {![info exists signature_algo_number]} { set signature_algo_number $cert_parse(signature_algo) } #puts "SIGN_ALGO=$signature_algo_number" switch -- $signature_algo_number { "1.2.643.2.2.3" - "1 2 643 2 2 3" { # "GOST R 34.10-2001 with GOST R 34.11-94" set digest_algo "gostr3411" } "1.2.643.7.1.1.3.2" - "1 2 643 7 1 1 3 2" { # "GOST R 34.10-2012-256 with GOSTR 34.11-2012-256" set digest_algo "stribog256" } "1.2.643.7.1.1.3.3" - "1 2 643 7 1 1 3 3" { # "GOST R 34.10-2012-512 with GOSTR 34.11-2012-512" set digest_algo "stribog512" } default { puts " :$signature_algo_number" exit } } # tbs-!!!! set digest_hex [pki::pkcs11::digest $digest_algo $tbs_cert $aa] puts "digest_hex=$digest_hex" puts [string length $digest_hex] # asn- # binary scan $cert_CA H* cert_CA_hex array set infopk [pki::pkcs11::pubkeyinfo $cert_CA_hex [list pkcs11_handle $handle pkcs11_slotid $token_slotid]] parray infopk set lpk [dict create pkcs11_handle $handle pkcs11_slotid $token_slotid] # pybkeyinfo lappend lpk "pubkeyinfo" #lappend lpk $pubinfo lappend lpk $infopk(pubkeyinfo) array set lpkar $lpk parray lpkar puts "Enter PIN user for you token \"$token_slotlabel\":" #set password "01234567" gets stdin password if { [pki::pkcs11::login $handle $token_slotid $password] == 0 } { puts "Bad password" exit } if {[catch {set verify [pki::pkcs11::verify $digest_hex $cert_parse(signature) $lpk]} res] } { puts $res exit } if {$verify != 1} { puts "BAD SIGNATURE=$verify" } else { puts "SIGNATURE OK=$verify" } puts "!" exit
ã¹ã¯ãªããããã¡ã€ã«ã«ä¿åããå®è¡ããŠã¿ãŠãã ããã
$./verify_cert_with_pkcs11.tcl Copyright(C) Orlov Vladimir (http://museum.lissi-crypto.ru/) Usage: verify_cert_with_pkcs11 <file with certificate> <file with CA certificate> $
ããŒã¯ã³äžã®èšŒææžã«ã€ããŠã¯ã©ãã§ããããïŒ ãŸããPKCSïŒ11æå·åãã·ã³ã䜿çšããåé¡ã解決ããŸããã ãããã䜿çšããŸããã ãŸããããŒã¯ã³ä»ãã®èšŒææžãæŸéããããã«ãpki :: pkcs11 :: listcertsderããã±ãŒãžã®æ©èœããããŸããããã«ãããç®çã®èšŒææžãéžæããŠæ€èšŒããããšãã§ããŸãã ããã¯å®¿é¡ãšèããããšãã§ããŸãã
TclPKCS11v.1.0.1ããã±ãŒãžã®æ°ããããŒãžã§ã³ã®ç»å Žã«ãããããŒã¯ã³ã®èšŒææžãã€ã³ããŒãããæ©èœãããŒã¯ã³ãã蚌ææžãšé¢é£ããŒãåé€ããæ©èœã蚌ææžãšããŒã®ã©ãã«ãå€æŽããæ©èœãªã©ãè¿œå ããããš
ã«ãã ã蚌ææž
衚瀺ãŠãŒãã£ãªãã£ãæ¹è¯ããããšãå¯èœã«ãªããŸããïŒ
è¿œå ãããæãéèŠãªæ©èœã¯ã蚌ææžã®ããžã¿ã«çœ²åæ€èšŒã§ãã
æ°é
ãã®ããèªè
ã¯ãããŒãã¢ã®çæã«ã€ããŠã¯äœãèšãããŠããªãããšãæ£ããææããŸããã ãã®æ©èœã¯ãTclPKCS11ããã±ãŒãžã«ãè¿œå ãããŸãã
array set genkey [pki::pkcs11::keypair < > <> < >]
ãã¡ãããTclPKCS11ããã±ãŒãžã®æ©èœãã©ã®ããã«äœ¿çšããããã¯ããŠãŒãã£ãªãã£ã®ãœãŒã¹ã³ãŒãã«èšèŒãããŠããŸãã
ããŒãã¢ãçæããæ©èœã«ã€ããŠã¯ã次ã®èšäºã§è©³ãã説æããŸããPKCSïŒ11ããŒã¯ã³ã§ããŒãã¢ãçæããããšã«ãããè³æ ŒèšŒææžã®ãªã¯ãšã¹ããäœæãããŠãŒãã£ãªãã£ãèªèšŒã»ã³ã¿ãŒïŒ
CA ïŒã§èšŒææžãååŸããŠããŒã¯ã³ã«ã€ã³ããŒãããã¡ã«ããºã ã«ã€ããŠèª¬æããŸãïŒ
åãèšäºã§ã¯ãææžã«çœ²åããæ©èœãèæ
®ãããŸãã ããã¯ããã®ã·ãªãŒãºã®æåŸã®èšäºã«ãªããŸãã 次ã«ãçŸåšæµè¡ããŠããRubyã¹ã¯ãªããèšèªã§ãã·ã¢ã®æå·åããµããŒãããäžé£ã®èšäºãèšç»ãããŠããŸãã ããããïŒ