零全零美(www.zzgwt.com)
          生活中的很多事情,并不像If...Else那么簡單!
          posts - 96,comments - 52,trackbacks - 0
          用途:
          模擬CA行為的工具.有了它,你就是一個CA,不過估計是nobody trusted CA.可以用來給各種格式的CSR簽名,用來產(chǎn)生和維護CRL(不記得CRL是什么了?去看證書那一章).他還維護著一個文本數(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)該覺得這么點flag還是小case.

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

          -in filename
          要簽名的CSR文件。

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

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

          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.

          相信剛才大家都看到很多選項都和config文件有關(guān),那么我們來解釋一下config文件make install之后,openssl會生成一個全是缺省值的config文件:openssl.cnf.也長的很,貼出來有賺篇幅之嫌,xgh不屑。簡單解釋一下其中與CA有關(guān)的key.
          與CA有關(guān)的key都在ca這個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)的。
          如果某個key后面標(biāo)明mandatory,那就說明這個參數(shù)是必須提供的,無論你通過命令行還是通過config文件去提供。

          new_certs_dir
          本key同命令行的 -outdir意義相同。(mandatory)
          certificate
          同命令行的 -cert意義相同。(mandatory)
          private_key
          同命令行-keyfile意義相同.(mandatory)
          RANDFILE
          指明一個用來讀寫時候產(chǎn)生random key的seed文件。具體意義在以后的RAND的API再給出解釋。(不是我擺譜,我覺得重復(fù)解釋沒有必要)
          default_days
          意義和命令行的 -days相同。
          default_startdate
          意義同命令行的 -startdate相同。如果沒有的話那么就使用產(chǎn)生證書的時間。
          default_enddate
          意義同命令行的 -enddate相同。(mandatory).
          crl_extensions
          preserve
          default_crl_hours default_crl_days
          CRL的東西.....自己都沒弄懂.....
          default_md
          同命令行的-md意義相同. (mandatory)
          database
          記得index.txt是什么文件嗎?不記得自己往前找。這個key就是指定index.txt的。初始化是空文件。
          serialfile
          指明一個txt文件,里面必須包含下一個可用的16進制數(shù)字,用來給下一個證書做系列號。(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
          其實如果你做過CSR就會明白,這些項就是你做CSR時候填寫的那些東西麻。
          后面的"match", "supplied"等又是什么意思呢?"match"表示說明你填寫的這一欄一定要和CA本身的證書里面的這一欄相同。supplied表示本欄必須,optional就表示本欄可以不填寫。
          舉例時間到了:
          注意,本例中我們先要在 $OPENSSL/misc下面運行過CA.sh -newca,建立好相應(yīng)的目錄,所有需要的文件,包括CA的私有密鑰文件,證書文件,系列號文件,和一個空的index文件。并且文件都已經(jīng)各就各位。放心把,產(chǎn)生文件和文件就位都由CA.sh搞定,你要做的就是運行CA.sh -nweca就行了,甚至在你的系列號文件中還有個01,用來給下一個證書做系列號。
          給一個CSR簽名:
          openssl ca -in req.pem -out newcert.pem
          給一個CSR簽名, 產(chǎn)生x509v3證書:
          openssl ca -in req.pem -extensions v3_ca -out newcert.pem
          同時給數(shù)個CSR簽名:
          openssl ca -infiles req1.pem req2.pem req3.pem
          注意:
          index.txt文件是整個處理過程中很重要的一部分,如果這玩意壞了,很難修復(fù)。理論上根據(jù)已經(jīng)頒發(fā)的證書和當(dāng)前的CRL當(dāng)然是有辦法修復(fù)的啦,但openssl沒提供這個功能。:(
          openssl還有倆大類指令: crl, crl2pkcs7, 都是和CRL有關(guān)的,
          由于我們對這個沒有興趣,所以這倆大類不做翻譯和解釋。
          posted on 2009-11-27 17:34 零全零美 閱讀(591) 評論(0)  編輯  收藏 所屬分類: 安全相關(guān)
          主站蜘蛛池模板: 宜章县| 武城县| 禄丰县| 泗水县| 沙田区| 枞阳县| 崇仁县| 鸡东县| 南京市| 云阳县| 牡丹江市| 化州市| 滁州市| 穆棱市| 牡丹江市| 常宁市| 岚皋县| 渝中区| 万宁市| 德惠市| 共和县| 同江市| 永善县| 海门市| 雅安市| 边坝县| 开鲁县| 如东县| 盐城市| 墨脱县| 广南县| 五峰| 阿拉善盟| 防城港市| 洞口县| 武冈市| 晋中市| 灵台县| 西昌市| 海南省| 信丰县|