openssl簡(jiǎn)介(八)--指令ca
八.????
指令
ca
? ? 模擬 CA 行為的工具 . 有了它,你就是一個(gè) CA, 不過(guò)估計(jì)是 nobody trusted CA. 可以用來(lái)給各種格式的 CSR 簽名,用來(lái)產(chǎn)生和維護(hù) CRL( 不記得 CRL 是什么了?去看證書(shū)那一章 ). 他還維護(hù)著一個(gè)文本數(shù)據(jù)庫(kù),記錄了所有經(jīng)手頒發(fā) 的證書(shū)及那些證書(shū)的狀態(tài)。
? ? 用法:
? ???openssl ca [-verbose] [-config filename] [-name section] [-gencrl]
? ?
? ???[-revoke file] [-crldays days] [-crlhours hours] [-crlexts section]
? ?
? ???[-startdate date] [-enddate date] [-days arg] [-md arg] [-policy arg]
? ?
? ???[-keyfile arg] [-key arg] [-passin arg] [-cert file] [-in file]
? ?
? ???[-out file] [-notext] [-outdir dir] [-infiles] [-spkac file]
? ?
? ???[-ss_cert file] [-preserveDN] [-batch] [-msie_hack] [-extensions section]
? ??? 哇噻,好復(fù)雜也。不過(guò)用過(guò) GCC 的人應(yīng)該覺(jué)得這么點(diǎn) flag 還是小 case.
? ?
-config filename
? ? 指定使用的 configure 文件。
? ?
? ? -in filename
? ? 要簽名的 CSR 文件。
? ?
? ? -ss_cert filename
? ? 一個(gè)有自簽名的證書(shū),需要我們 CA 簽名,就從這里輸入文件名。
? ?
? ? -spkac filename
? ? 這一段實(shí)在沒(méi)有看懂,也沒(méi)興趣,估計(jì)和 SPKAC 打交道可能性不大,奉送上英文原文。
? ? a file containing a single Netscape signed public key and challenge and additional field values to be signed by the CA.
SPKAC FORMAT
? ? The input to the -spkac command line option is a Netscape signed public key and challenge. This will usually come from the KEYGEN tag in an HTML form to create a new private key. It is however possible to create SPKACs using the spkac utility.
? ? The file should contain the variable SPKAC set to the value of the SPKAC and also the required DN components as name value pairs. If you need to include the same component twice then it can be preceded by a number and a .
? ? -infiles
? ? 如果你一次要給幾個(gè) CSR 簽名,就用這個(gè)來(lái)輸入,但記得這個(gè)選項(xiàng)一定要放在最后。這個(gè)項(xiàng)后面的所有東東都被認(rèn)為是 CSR 文件名參數(shù)。
? ? -out filename
? ? 簽名后的證書(shū)文件名。證書(shū)的細(xì)節(jié)也會(huì)給寫(xiě)進(jìn)去。
? ? -outdir directory
? ? 擺證書(shū)文件的目錄。證書(shū)名就是該證書(shū)的系列號(hào),后綴是 .pem
? ? -cert
? ? CA 本身的證書(shū)文件名
? ? -keyfile filename
? ? CA 自己的私有密鑰文件
? ? -key password
? ? CA 的私有密鑰文件的保護(hù)密碼。
? ? 在有的系統(tǒng)上,可以用 ps 看到你輸入的指令,所以這個(gè)參數(shù)要小心點(diǎn)用。
? ? -passin arg
? ? 也是一個(gè)輸入私有密鑰保護(hù)文件的保護(hù)密碼的一種方式,可以是文件名,設(shè)備名或者是有名管道。程序會(huì)把該文件的第一行作為密碼讀入。(也蠻危險(xiǎn)的)。
? ? -verbose
? ? 操作過(guò)程被詳細(xì) printf 出來(lái)
? ? -notext
? ? 不要把證書(shū)文件的明文內(nèi)容輸出到文件中去。
? ? -startdate date
? ? 指明證書(shū)的有效開(kāi)始日期。格式是 YYMMDDHHMMSSZ, 同 ASN1 的 UTCTime 結(jié)構(gòu)相同。
? ? -enddate date
? ? 指明證書(shū)的有效截止日期,格式同上。
? ? -days arg
? ? 指明給證書(shū)的有效時(shí)間,比如 365 天。
? ? -md alg
? ? 簽名用的哈希算法,比如 MD2, MD5 等。
? ? -policy arg
? ? 指定 CA 使用的策略。其實(shí)很簡(jiǎn)單,就是決定在你填寫(xiě)信息生成 CSR 的時(shí)候,哪些信息是我們必須的,哪些不是。看看 config 文件里面的 policy 這個(gè) item 就明白了。
? ? -msie_hack
? ? 為了和及其古老的證書(shū)版本兼容而做出的犧牲品,估計(jì)沒(méi)人會(huì)用的,不解釋了。
? ? -preserveDN
? ? 和 -msie_hack 差不多的一個(gè)選項(xiàng)。
? ? -batch
? ? 設(shè)置為批處理的模式,所有的 CSR 會(huì)被自動(dòng)處理。
? ? -extensions section
? ? 我們知道一般我們都用 X509 格式的證書(shū), X509 也有幾個(gè)版本的。如果你在這個(gè)選項(xiàng)后面帶的那個(gè)參數(shù)在 config 文件里有同樣名稱(chēng)的 key, 那么就頒發(fā) X509V3 證書(shū),否則頒發(fā) X509v1 證書(shū)。
? ? 還有幾個(gè)關(guān)于 CRL 的選項(xiàng),但我想一般很少人會(huì)去用。我自己也沒(méi)興趣去研究。
? ? 有興趣的自己看看英文吧。
? ?? ???
? ???CRL OPTIONS
? ?
? ???-gencrl
? ?
? ???this option generates a CRL based on information in the index file.
? ?? ?-crldays num
? ?
? ???the number of days before the next CRL is due. That is the days from
? ?
? ???now to place in the CRL nextUpdate field.
? ?
-crlhours num
? ?
? ???the number of hours before the next CRL is due.
? ?? ???
? ???-revoke filename
? ?
? ???a filename containing a certificate to revoke.
? ?? ???
? ???-crlexts section
? ?
? ???the section of the configuration file containing CRL extensions to
? ?
? ???include. If no CRL extension section is present then a V1 CRL is created,
? ?
? ???if the CRL extension section is present (even if it is empty) then a V2
? ?
? ???CRL is created. The CRL extensions specified are CRL extensions and not
? ?
? ???CRL entry extensions. It should be noted that some software (for example
? ?
? ???Netscape) can't handle V2 CRLs.
? ?
? ? 相信剛才大家都看到很多選項(xiàng)都和 config 文件有關(guān) , 那么我們來(lái)解釋一下 config 文件 make install 之后, openssl 會(huì)生成一個(gè)全是缺省值的 config 文件 penssl.cnf. 也長(zhǎng)的很,貼出來(lái)有賺篇幅之嫌, xgh 不屑。簡(jiǎn)單解釋一下其中與 CA 有關(guān)的 key.
與 CA 有關(guān)的 key 都在 ca 這個(gè) section 之中。
? ? [ ca ]
? ? default_ca = CA_default
? ? [ CA_default ]
? ? dir = ./demoCA # Where everything is kept
? ? certs = $dir/certs # Where the issued certs are kept
? ? crl_dir = $dir/crl # Where the issued crl are kept
? ? database = $dir/index.txt # database index file.
? ? new_certs_dir = $dir/newcerts # default place for new certs.
? ? certificate = $dir/cacert.pem # The CA certificate
? ? serial = $dir/serial # The current serial number
? ? crl = $dir/crl.pem # The current CRL
? ? private_key = $dir/private/cakey.pem# The private key
? ? RANDFILE = $dir/private/.rand # private random number file
? ? x509_extensions = usr_cert # The extentions to add to the cert
? ? # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
? ? # so this is commented out by default to leave a V1 CRL.
? ? # crl_extensions = crl_ext
? ? default_days = 365 # how long to certify for
? ? default_crl_days= 30 # how long before next CRL
? ? default_md = md5 # which md to use.
? ? preserve = no # keep passed DN ordering
? ? # A few difference way of specifying how similar the request should look
? ? # For type CA, the listed attributes must be the same, and the optional
? ? # and supplied fields are just that
? ? policy = policy_match
? ? # For the CA policy
? ? [ policy_match ]
? ? countryName = match
? ? stateOrProvinceName = match
? ? organizationName = match
? ? organizationalUnitName = optional
? ? commonName = supplied
? ? emailAddress = optional
? ? # At this point in time, you must list all acceptable 'object'
? ? # types.
? ? [ policy_anything ]
? ? countryName = optional
? ? stateOrProvinceName = optional
? ? localityName = optional
? ? organizationName = optional
? ? organizationalUnitName = optional
? ? commonName = supplied
? ? emailAddress = optional
? ? config 文件里 CA section 里面的很多 key 都和命令行參數(shù)是對(duì)應(yīng)的。
? ? 如果某個(gè) key 后面標(biāo)明 mandatory, 那就說(shuō)明這個(gè)參數(shù)是必須提供的,無(wú)論你通過(guò)命令行還是通過(guò) config 文件去提供。
new_certs_dir
? ? 本 key 同命令行的 -outdir 意義相同。 (mandatory)
? ? certificate
? ? 同命令行的 -cert 意義相同。 (mandatory)
? ? private_key
? ? 同命令行 -keyfile 意義相同 .(mandatory)
? ? RANDFILE
? ? 指明一個(gè)用來(lái)讀寫(xiě)時(shí)候產(chǎn)生 random key 的 seed 文件。具體意義在以后的 RAND 的 API 再給出解釋。 ( 不是我擺譜,我覺(jué)得重復(fù)解釋沒(méi)有必要 )
? ? default_days
? ? 意義和命令行的 -days 相同。
? ? default_startdate
? ? 意義同命令行的 -startdate 相同。如果沒(méi)有的話(huà)那么就使用產(chǎn)生證書(shū)的時(shí)間。
? ? default_enddate
? ? 意義同命令行的 -enddate 相同。 (mandatory).
? ? crl_extensions
? ? preserve
? ? default_crl_hours default_crl_days
? ? CRL 的東西 ..... 自己都沒(méi)弄懂 .....
? ? default_md
? ? 同命令行的 -md 意義相同 . (mandatory)
? ? database
? ? 記得 index.txt 是什么文件嗎?不記得自己往前找。這個(gè) key 就是指定 index.txt 的。初始化是空文件。
? ? serialfile
? ? 指明一個(gè) txt 文件,里面必須包含下一個(gè)可用的 16 進(jìn)制數(shù)字,用來(lái)給下一個(gè)證書(shū)做系列號(hào)。 (mandatory)
? ? x509_extensions
? ? 意義同 -extensions 相同。
? ? msie_hack
? ? 意義同 -msie_hack 相同。
? ? policy
? ? 意義同 -policy 相同。自己看看這一塊是怎么回事。 (mandatory)
? ? [ policy_match ]
? ? countryName = match
? ? stateOrProvinceName = match
? ? organizationName = match
? ? organizationalUnitName = optional
? ? commonName = supplied
? ? emailAddress = optional
? ? 其實(shí)如果你做過(guò) CSR 就會(huì)明白,這些項(xiàng)就是你做 CSR 時(shí)候填寫(xiě)的那些東西麻。
? ? 后面的 "match", "supplied" 等又是什么意思呢? "match" 表示說(shuō)明你填寫(xiě)的這一欄一定要和 CA 本身的證書(shū)里面的這一欄相同。 supplied 表示本欄必須, optional 就表示本欄可以不填寫(xiě)。
? ? 舉例時(shí)間到了:
? ? 注意,本例中我們先要在 $OPENSSL/misc 下面運(yùn)行過(guò) CA.sh -newca ,建立好相應(yīng)的目錄,所有需要的文件,包括 CA 的私有密鑰文件,證書(shū)文件,系列號(hào)文件,和一個(gè)空的 index 文件。并且文件都已經(jīng)各就各位。 放心把,產(chǎn)生文件和文件就位都由 CA.sh 搞定,你要做的就是運(yùn)行 CA.sh -nweca 就行了,甚至在你的系列號(hào)文件中還有個(gè) 01, 用來(lái)給下一個(gè)證書(shū)做系列號(hào)。
? ? 給一個(gè) CSR 簽名:
? ? openssl ca -in req.pem -out newcert.pem
? ? 給一個(gè) CSR 簽名 , 產(chǎn)生 x509v3 證書(shū):
? ? openssl ca -in req.pem -extensions v3_ca -out newcert.pem
? ? 同時(shí)給數(shù)個(gè) CSR 簽名:
? ? openssl ca -infiles req1.pem req2.pem req3.pem
? ? 注意:
? ? index.txt 文件是整個(gè)處理過(guò)程中很重要的一部分,如果這玩意壞了,很難修復(fù)。理論上根據(jù)已經(jīng)頒發(fā)的證書(shū)和當(dāng)前的 CRL 當(dāng)然是有辦法修復(fù)的啦,但 openssl 沒(méi)提供這個(gè)功能。
? ? openssl 還有倆大類(lèi)指令 : crl, crl2pkcs7, 都是和 CRL 有關(guān)的,
? ? 由于我們對(duì)這個(gè)沒(méi)有興趣,所以這倆大類(lèi)不做翻譯和解釋。
posted on 2006-10-17 15:27 捕風(fēng) 閱讀(653) 評(píng)論(0) 編輯 收藏 所屬分類(lèi): java安全