捕风之巢

统计

留言簿(3)

java友情链接

阅读排行榜

评论排行榜

openssl简介(八)--指令ca

 

八.     指令 ca

用途:
   
模拟 CA 行为的工具 . 有了它,你就是一个 CA, 不过估计是 nobody trusted CA. 可以用来给各种格式的 CSR 签名,用来产生和维护 CRL( 不记得 CRL 是什么了?去看证书那一章 ). 他还维护着一个文本数据库,记录了所有经手颁发 的证书及那些证书的状态。
   
用法:
     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]

     
哇噻,好复杂也。不过用过 GCC 的人应该觉得这么点 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 签名,就用这个来输入,但记得这个选项一定要放在最后。这个项后面的所有东东都被认为是 CSR 文件名参数。
    -out filename
   
签名后的证书文件名。证书的细节也会给写进去。
    -outdir directory
   
摆证书文件的目录。证书名就是该证书的系列号,后缀是 .pem
    -cert
    CA
本身的证书文件名
    -keyfile filename
    CA
自己的私有密钥文件
    -key password
    CA
的私有密钥文件的保护密码。
   
在有的系统上,可以用 ps 看到你输入的指令,所以这个参数要小心点用。
    -passin arg
   
也是一个输入私有密钥保护文件的保护密码的一种方式,可以是文件名,设备名或者是有名管道。程序会把该文件的第一行作为密码读入。(也蛮危险的)。
    -verbose
   
操作过程被详细 printf 出来
    -notext
   
不要把证书文件的明文内容输出到文件中去。
    -startdate date
   
指明证书的有效开始日期。格式是 YYMMDDHHMMSSZ, ASN1 UTCTime 结构相同。
    -enddate date
   
指明证书的有效截止日期,格式同上。
    -days arg
   
指明给证书的有效时间,比如 365 天。
    -md alg
   
签名用的哈希算法,比如 MD2, MD5 等。
    -policy arg
   
指定 CA 使用的策略。其实很简单,就是决定在你填写信息生成 CSR 的时候,哪些信息是我们必须的,哪些不是。看看 config 文件里面的 policy 这个 item 就明白了。
    -msie_hack
   
为了和及其古老的证书版本兼容而做出的牺牲品,估计没人会用的,不解释了。
    -preserveDN
   
-msie_hack 差不多的一个选项。
    -batch
   
设置为批处理的模式,所有的 CSR 会被自动处理。
    -extensions section
   
我们知道一般我们都用 X509 格式的证书, X509 也有几个版本的。如果你在这个选项后面带的那个参数在 config 文件里有同样名称的 key, 那么就颁发 X509V3 证书,否则颁发 X509v1 证书。
   
还有几个关于 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 文件有关 , 那么我们来解释一下 config 文件 make install 之后, openssl 会生成一个全是缺省值的 config 文件 penssl.cnf. 也长的很,贴出来有赚篇幅之嫌, xgh 不屑。简单解释一下其中与 CA 有关的 key.
CA 有关的 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 都和命令行参数是对应的。
   
如果某个 key 后面标明 mandatory, 那就说明这个参数是必须提供的,无论你通过命令行还是通过 config 文件去提供。

new_certs_dir
   
key 同命令行的 -outdir 意义相同。 (mandatory)
    certificate
   
同命令行的 -cert 意义相同。 (mandatory)
    private_key
   
同命令行 -keyfile 意义相同 .(mandatory)
    RANDFILE
   
指明一个用来读写时候产生 random key seed 文件。具体意义在以后的 RAND API 再给出解释。 ( 不是我摆谱,我觉得重复解释没有必要 )
    default_days
   
意义和命令行的 -days 相同。
    default_startdate
   
意义同命令行的 -startdate 相同。如果没有的话那么就使用产生证书的时间。
    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 进制数字,用来给下一个证书做系列号。 (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 ,建立好相应的目录,所有需要的文件,包括 CA 的私有密钥文件,证书文件,系列号文件,和一个空的 index 文件。并且文件都已经各就各位。 放心把,产生文件和文件就位都由 CA.sh 搞定,你要做的就是运行 CA.sh -nweca 就行了,甚至在你的系列号文件中还有个 01, 用来给下一个证书做系列号。
   
给一个 CSR 签名:
    openssl ca -in req.pem -out newcert.pem
   
给一个 CSR 签名 , 产生 x509v3 证书:
    openssl ca -in req.pem -extensions v3_ca -out newcert.pem
   
同时给数个 CSR 签名:
    openssl ca -infiles req1.pem req2.pem req3.pem
   
注意:
    index.txt
文件是整个处理过程中很重要的一部分,如果这玩意坏了,很难修复。理论上根据已经颁发的证书和当前的 CRL 当然是有办法修复的啦,但 openssl 没提供这个功能。
    openssl
还有俩大类指令 : crl, crl2pkcs7, 都是和 CRL 有关的,
   
由于我们对这个没有兴趣,所以这俩大类不做翻译和解释。

posted on 2006-10-17 15:27 捕风 阅读(634) 评论(0)  编辑  收藏 所属分类: java安全


只有注册用户登录后才能发表评论。


网站导航: