You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ca.md 10 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. ### 证书管理
  2. `jdchain-cli`提供**`ED25519`,`RSA`,`ECDSA`,`SM2`**密钥算法的证书签发工具:[证书列表](#证书列表),[显示证书](#显示证书),[CSR](#CSR),[CRT](#CRT),[更新证书](#更新证书),[生成测试证书](#生成测试证书)
  3. > 目前支持创建`ED25519`,RSA`,`ECDSA`,`SM2`四种签名算法,请使用对应算法的公私钥
  4. ```bash
  5. :bin$ ./jdchain-cli.sh ca -h
  6. Usage: jdchain-cli ca [-hV] [--pretty] [--home=<path>] [COMMAND]
  7. List, create, update certificates.
  8. -h, --help Show this help message and exit.
  9. --home=<path> Set the home directory.
  10. Default: ../
  11. --pretty Pretty json print
  12. -V, --version Print version information and exit.
  13. Commands:
  14. list List all the certificates.
  15. show Show certificate.
  16. csr Create certificate signing request.
  17. crt Create new certificate.
  18. renew Update validity period.
  19. test Create certificates for a testnet.
  20. help Displays help information about the specified command
  21. ```
  22. - `home`,指定密钥和证书存储相关目录,`${home}/config/keys`
  23. #### 证书列表
  24. ```bash
  25. :bin$ ./jdchain-cli.sh ca list -h
  26. List all the certificates.
  27. Usage: jdchain-cli ca list [-hV] [--pretty] [--home=<path>]
  28. -h, --help Show this help message and exit.
  29. --home=<path> Set the home directory.
  30. --pretty Pretty json print
  31. -V, --version Print version information and exit.
  32. ```
  33. 如:
  34. ```bash
  35. :bin$ ./jdchain-cli.sh keys list
  36. NAME ALGORITHM ADDRESS PUBKEY
  37. ```
  38. - `NAME`,名称
  39. - `ALGORITHM`,算法
  40. - `ADDRESS`,地址
  41. - `PUBKEY`,公钥
  42. #### 显示证书
  43. ```bash
  44. :bin$ ./jdchain-cli.sh ca show -h
  45. Show certificate.
  46. Usage: jdchain-cli ca show [-hV] [--pretty] [--home=<path>] -n=<name>
  47. -h, --help Show this help message and exit.
  48. --home=<path> Set the home directory.
  49. -n, --name=<name> Name of the certificate
  50. --pretty Pretty json print
  51. -V, --version Print version information and exit.
  52. ```
  53. - `name`,证书名称
  54. 如显示`${home}/config/keys`下名为`G1`的证书信息:
  55. ```bash
  56. :bin$ ./jdchain-cli.sh ca show -n G1
  57. ./jdchain-cli.sh ca show -n G1
  58. NAME ALGORITHM TYPE ROLE PUBKEY
  59. G1 SM2 ROLE-TODO [GW] SFZ6LjGKVz6wdU4G9PAraojyzCYPJ1BXAg1XBwSPCMC6Ug6u5oom5zcLPUzWtz42aCp9PLGXpHweBjSu3EW2aDzsa4JoT
  60. [0] Version: 3
  61. SerialNumber: 440724497
  62. IssuerDN: O=JDT,OU=ROOT,C=CN,ST=BJ,L=BJ,CN=ROOT,E=imuge@jd.com
  63. Start Date: Fri Sep 03 16:43:01 GMT+08:00 2021
  64. Final Date: Thu May 30 16:43:01 GMT+08:00 2024
  65. SubjectDN: O=JDT,OU=GW,C=CN,ST=BJ,L=BJ,CN=G1,E=imuge@jd.com
  66. Public Key: EC Public Key [c0:b9:58:d1:35:3d:a9:bc:1d:85:2a:ea:bf:57:80:39:e9:f6:57:6d]
  67. X: 67e4a4afe0a5beb1e5fb6e915314a9ed94b74f449cc4f50314ff78ecf62ba786
  68. Y: 2d5c233bfcd582f0c1098dbe4f1319db074fcf00023fdc9f3461a8d01488d9f2
  69. Signature Algorithm: SM3WITHSM2
  70. Signature: 3046022100b70107554a723ec96569bbb23c65cb
  71. ac6d7934f47722aa50f18a5e9ca3a978b9022100
  72. 9b68e5f3bd14bf103248c8516c493e5e1d9a872c
  73. 39841c3704686ca85311bac0
  74. ```
  75. #### CSR
  76. 生成证书请求文件
  77. ```bash
  78. :bin$ ./jdchain-cli.sh ca csr -h
  79. Create certificate signing request.
  80. Usage: jdchain-cli ca csr [-hV] [--pretty] [--home=<path>] [-n=<name>]
  81. [--priv=<privPath>] [--pub=<pubPath>]
  82. -h, --help Show this help message and exit.
  83. --home=<path> Set the home directory.
  84. -n, --name=<name> Name of the key
  85. --pretty Pretty json print
  86. --priv=<privPath> Path of the private key file
  87. --pub=<pubPath> Path of the public key file
  88. -V, --version Print version information and exit.
  89. ```
  90. - `name`,密钥对名称,创建公私钥请参照[keys](keys.md)文档说明
  91. 如使用`${home}/config/keys`下名为`ROOT`的公私钥信息创建`CSR`:
  92. ```bash
  93. :bin$ ./jdchain-cli.sh ca csr -n ROOT
  94. // 选择证书角色,输入对应数字即可,多个角色使用半角逗号相隔
  95. input certificate roles (0 for ROOT, 1 for CA, 2 for PEER, 3 for GW, 4 for USER. multi values use ',' split):
  96. > 1
  97. input country:
  98. > CN
  99. input locality:
  100. > BJ
  101. input province:
  102. > BJ
  103. input organization name:
  104. > JDT
  105. input email address:
  106. > imuge@jd.com
  107. // 输入ROOT私钥密码
  108. input password of the key:
  109. > 1
  110. create [${home}/config/keys/ROOT.csr] success
  111. ```
  112. 成功后会创建`${home}/config/keys/ROOT.csr`文件。
  113. #### CRT
  114. 签发证书:
  115. ```bash
  116. :bin$ ./jdchain-cli.sh ca crt -h
  117. Create new certificate.
  118. Usage: jdchain-cli ca crt [-hV] [--pretty] [--csr=<csrPath>] --days=<days>
  119. [--home=<path>] [--issuer-crt=<issuerCrtPath>]
  120. [--issuer-name=<issuerName>]
  121. [--issuer-priv=<issuerPrivPath>] [-n=<name>]
  122. --csr=<csrPath> Path of the certificate signing request file
  123. --days=<days> Days of certificate validity
  124. -h, --help Show this help message and exit.
  125. --home=<path> Set the home directory.
  126. --issuer-crt=<issuerCrtPath>
  127. Path of the issuer certificate file
  128. --issuer-name=<issuerName>
  129. Name of the issuer key
  130. --issuer-priv=<issuerPrivPath>
  131. Path of the issuer private key file
  132. -n, --name=<name> Name of the certificate signing request file
  133. --pretty Pretty json print
  134. -V, --version Print version information and exit.
  135. ```
  136. - `name`,`CSR`文件名,不为空时要求在`${home}/config/keys`目录下存在`${name.csr}`文件
  137. - `csr`,`CSR`文件路径,与`name`二选一,优先使用`name`参数
  138. - `days`,证书有效天数,当前签发时间开始计算
  139. - `issuer-name`,签发者公私钥对名称,不为空时需要`${home}/config/keys`目录下至少存在`${issuer-name}.priv`,`${issuer-name}.crt`
  140. - `issuer-crt`,签发者证书文件
  141. - `issuer-priv`,签发者私钥文件
  142. > `issuer-name`为空时,`issuer-crt`和`issuer-priv`必须同时提供
  143. 如使用`${home}/config/keys`下名为`ROOT`签发自签名证书:
  144. ```bash
  145. ./jdchain-cli.sh ca crt -n CA --issuer-name ROOT --days 1000
  146. // 输入签发者私钥密码
  147. input password of the issuer:
  148. > 1
  149. create [${home}/config/keys/ROOT.crt] success
  150. ```
  151. #### 更新证书
  152. 仅可更新证书有效天数
  153. ```bash
  154. Update validity period.
  155. Usage: jdchain-cli ca renew [-hV] [--pretty] [--crt=<crtPath>] --days=<days>
  156. [--home=<path>] [--issuer-crt=<issuerCrtPath>]
  157. [--issuer-name=<issuerName>]
  158. [--issuer-priv=<issuerPrivPath>] [-n=<name>]
  159. --crt=<crtPath> File of the certificate
  160. --days=<days> Days of certificate validity
  161. -h, --help Show this help message and exit.
  162. --home=<path> Set the home directory.
  163. --issuer-crt=<issuerCrtPath>
  164. Path of the issuer certificate file
  165. --issuer-name=<issuerName>
  166. Name of the issuer key
  167. --issuer-priv=<issuerPrivPath>
  168. Path of the issuer private key file
  169. -n, --name=<name> Name of the certificate
  170. --pretty Pretty json print
  171. -V, --version Print version information and exit.
  172. ```
  173. - `name`,`CRT`文件名,不为空时要求在`${home}/config/keys`目录下存在`${name.crt}`文件
  174. - `crt`,`CRT`文件路径,与`name`二选一,优先使用`name`参数
  175. - `days`,证书有效天数,当前签发时间开始计算
  176. - `issuer-name`,签发者公私钥对名称,不为空时需要`${home}/config/keys`目录下至少存在`${issuer-name}.priv`,`${issuer-name}.crt`
  177. - `issuer-crt`,签发者证书文件
  178. - `issuer-priv`,签发者私钥文件
  179. > `issuer-name`为空时,`issuer-crt`和`issuer-priv`必须同时提供
  180. 如更新`${home}/config/keys`下名为`ROOT`证书有效期:
  181. ```bash
  182. ./jdchain-cli.sh ca crt -n ROOT --issuer-name ROOT --days 2000
  183. input password of the issuer:
  184. > 1
  185. renew [${home}/config/keys/ROOT.crt] success success
  186. ```
  187. #### 生成测试证书
  188. 一键生成可用于初始化`JD Chain`网络及使用需要的证书
  189. ```bash
  190. :bin$ ./jdchain-cli.sh ca test -h
  191. Create certificates for a testnet.
  192. Usage: jdchain-cli ca test [-hV] [--pretty] [-a=<algorithm>]
  193. --country=<country> --email=<email> [--gws=<gws>]
  194. [--home=<path>] --locality=<locality>
  195. [--nodes=<nodes>] --org=<organization>
  196. [-p=<password>] --province=<province>
  197. [--users=<users>]
  198. -a, --algorithm=<algorithm>
  199. Crypto algorithm
  200. --country=<country> Country
  201. --email=<email> Email address
  202. --gws=<gws> Gateway size
  203. -h, --help Show this help message and exit.
  204. --home=<path> Set the home directory.
  205. --locality=<locality> Locality
  206. --nodes=<nodes> Node size
  207. --org=<organization> Organization name
  208. -p, --password=<password> Password of the key
  209. --pretty Pretty json print
  210. --province=<province> Province
  211. --users=<users> Available user size
  212. -V, --version Print version information and exit.
  213. ```
  214. - `algorithm`,签名算法,默认`ED25519`,仅支持传入`ED25519`, `RSA`,`ECDSA`,`SM2`之一
  215. - `nodes`,共识节点个数,生成`nodes`个`PEER`类型的证书,可用于节点使用。默认:`4`
  216. - `gws`,网关节点个数,生成`gws`个`GW`类型的证书,可用于网关使用。默认:`1`
  217. - `users`,用户个数,生成`users`可个可用于普通用户使用的证书。默认:`10`
  218. 如创建基于`SM2`签名算法的一个`ROOT`类型证书,`4`个节点证书,`1`个网关证书,`10`个用户证书:
  219. ```bash
  220. :bin$ ./jdchain-cli.sh ca test --org JDT --country CN --locality BJ --province BJ --email jdchain@jd.com
  221. input private key password:
  222. // 输入操作过程中生成的私钥加密密码
  223. > 1
  224. create test certificates in [${home}/config/keys] success
  225. ```