零全零美(www.zzgwt.com)
          生活中的很多事情,并不像If...Else那么簡單!
          posts - 96,comments - 52,trackbacks - 0
          用途:
          模擬CA行為的工具.有了它,你就是一個(gè)CA,不過估計(jì)是nobody trusted CA.可以用來給各種格式的CSR簽名,用來產(chǎn)生和維護(hù)CRL(不記得CRL是什么了?去看證書那一章).他還維護(hù)著一個(gè)文本數(shù)據(jù)庫,記錄了所有經(jīng)手頒發(fā)的證書及那些證書的狀態(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ù)雜也。不過用過GCC的人應(yīng)該覺得這么點(diǎn)flag還是小case.

          -config filename
          指定使用的configure文件。

          -in filename
          要簽名的CSR文件。

          -ss_cert filename
          一個(gè)有自簽名的證書,需要我們CA簽名,就從這里輸入文件名。

          -spkac filename
          這一段實(shí)在沒有看懂,也沒興趣,估計(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è)來輸入,但記得這個(gè)選項(xiàng)一定要放在最后。這個(gè)項(xiàng)后面的所有東東都被認(rèn)為是CSR文件名參數(shù)。
          -out filename
          簽名后的證書文件名。證書的細(xì)節(jié)也會(huì)給寫進(jìn)去。
          -outdir directory
          擺證書文件的目錄。證書名就是該證書的系列號,后綴是.pem
          -cert
          CA本身的證書文件名
          -keyfile filename
          CA自己的私有密鑰文件
          -key password
          CA的私有密鑰文件的保護(hù)密碼。
          在有的系統(tǒng)上,可以用ps看到你輸入的指令,所以這個(gè)參數(shù)要小心點(diǎn)用。
          -passin arg
          也是一個(gè)輸入私有密鑰保護(hù)文件的保護(hù)密碼的一種方式,可以是文件名,設(shè)備名或者是有名管道。程序會(huì)把該文件的第一行作為密碼讀入。(也蠻危險(xiǎn)的)。
          -verbose
          操作過程被詳細(xì)printf出來
          -notext
          不要把證書文件的明文內(nèi)容輸出到文件中去。
          -startdate date
          指明證書的有效開始日期。格式是YYMMDDHHMMSSZ, 同ASN1的UTCTime結(jié)構(gòu)相同。
          -enddate date
          指明證書的有效截止日期,格式同上。
          -days arg
          指明給證書的有效時(shí)間,比如365天。
          -md alg
          簽名用的哈希算法,比如MD2, MD5等。
          -policy arg
          指定CA使用的策略。其實(shí)很簡單,就是決定在你填寫信息生成CSR的時(shí)候,哪些信息是我們必須的,哪些不是。看看config文件里面的policy這個(gè)item就明白了。
          -msie_hack
          為了和及其古老的證書版本兼容而做出的犧牲品,估計(jì)沒人會(huì)用的,不解釋了。
          -preserveDN
          和-msie_hack差不多的一個(gè)選項(xiàng)。
          -batch
          設(shè)置為批處理的模式,所有的CSR會(huì)被自動(dòng)處理。
          -extensions section
          我們知道一般我們都用X509格式的證書,X509也有幾個(gè)版本的。如果你在這個(gè)選項(xiàng)后面帶的那個(gè)參數(shù)在config文件里有同樣名稱的key,那么就頒發(fā)X509V3證書,否則頒發(fā)X509v1證書。
          還有幾個(gè)關(guān)于CRL的選項(xiàng),但我想一般很少人會(huì)去用。我自己也沒興趣去研究。
          有興趣的自己看看英文吧。

          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),那么我們來解釋一下config文件make install之后,openssl會(huì)生成一個(gè)全是缺省值的config文件:openssl.cnf.也長的很,貼出來有賺篇幅之嫌,xgh不屑。簡單解釋一下其中與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ù)是對應(yīng)的。
          如果某個(gè)key后面標(biāo)明mandatory,那就說明這個(gè)參數(shù)是必須提供的,無論你通過命令行還是通過config文件去提供。

          new_certs_dir
          本key同命令行的 -outdir意義相同。(mandatory)
          certificate
          同命令行的 -cert意義相同。(mandatory)
          private_key
          同命令行-keyfile意義相同.(mandatory)
          RANDFILE
          指明一個(gè)用來讀寫時(shí)候產(chǎn)生random key的seed文件。具體意義在以后的RAND的API再給出解釋。(不是我擺譜,我覺得重復(fù)解釋沒有必要)
          default_days
          意義和命令行的 -days相同。
          default_startdate
          意義同命令行的 -startdate相同。如果沒有的話那么就使用產(chǎn)生證書的時(shí)間。
          default_enddate
          意義同命令行的 -enddate相同。(mandatory).
          crl_extensions
          preserve
          default_crl_hours default_crl_days
          CRL的東西.....自己都沒弄懂.....
          default_md
          同命令行的-md意義相同. (mandatory)
          database
          記得index.txt是什么文件嗎?不記得自己往前找。這個(gè)key就是指定index.txt的。初始化是空文件。
          serialfile
          指明一個(gè)txt文件,里面必須包含下一個(gè)可用的16進(jìn)制數(shù)字,用來給下一個(gè)證書做系列號。(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í)如果你做過CSR就會(huì)明白,這些項(xiàng)就是你做CSR時(shí)候填寫的那些東西麻。
          后面的"match", "supplied"等又是什么意思呢?"match"表示說明你填寫的這一欄一定要和CA本身的證書里面的這一欄相同。supplied表示本欄必須,optional就表示本欄可以不填寫。
          舉例時(shí)間到了:
          注意,本例中我們先要在 $OPENSSL/misc下面運(yùn)行過CA.sh -newca,建立好相應(yīng)的目錄,所有需要的文件,包括CA的私有密鑰文件,證書文件,系列號文件,和一個(gè)空的index文件。并且文件都已經(jīng)各就各位。放心把,產(chǎn)生文件和文件就位都由CA.sh搞定,你要做的就是運(yùn)行CA.sh -nweca就行了,甚至在你的系列號文件中還有個(gè)01,用來給下一個(gè)證書做系列號。
          給一個(gè)CSR簽名:
          openssl ca -in req.pem -out newcert.pem
          給一個(gè)CSR簽名, 產(chǎn)生x509v3證書:
          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è)處理過程中很重要的一部分,如果這玩意壞了,很難修復(fù)。理論上根據(jù)已經(jīng)頒發(fā)的證書和當(dāng)前的CRL當(dāng)然是有辦法修復(fù)的啦,但openssl沒提供這個(gè)功能。:(
          openssl還有倆大類指令: crl, crl2pkcs7, 都是和CRL有關(guān)的,
          由于我們對這個(gè)沒有興趣,所以這倆大類不做翻譯和解釋。
          posted on 2009-11-27 17:34 零全零美 閱讀(599) 評論(0)  編輯  收藏 所屬分類: 安全相關(guān)
          主站蜘蛛池模板: 若尔盖县| 游戏| 建德市| 礼泉县| 濮阳市| 金寨县| 射洪县| 合阳县| 囊谦县| 鞍山市| 兴和县| 巴彦淖尔市| 遵义市| 宜川县| 化隆| 宁陕县| 江津市| 合山市| 黎川县| 霍州市| 崇信县| 边坝县| 磐安县| 丰镇市| 昌都县| 庆安县| 井研县| 开原市| 桐梓县| 连南| 潍坊市| 鹿泉市| 星子县| 恩施市| 和硕县| 察哈| 明星| 巴里| 缙云县| 正阳县| 双城市|