企业网站建设方案行情,推荐好用的分销平台,网页翻译成中文后怎么还原,装修网上接单文章目录 openssl3.2 - 官方demo学习 - test - certs概述笔记.sh的执行语句打印的方法要修改的实际函数END openssl3.2 - 官方demo学习 - test - certs
概述
官方demos目录有证书操作的例子 已经做了笔记 openssl3.2 - 官方demo学习 - certs 但是这个demos/certs目录的脚本,… 文章目录 openssl3.2 - 官方demo学习 - test - certs概述笔记.sh的执行语句打印的方法要修改的实际函数END openssl3.2 - 官方demo学习 - test - certs
概述
官方demos目录有证书操作的例子 已经做了笔记 openssl3.2 - 官方demo学习 - certs 但是这个demos/certs目录的脚本, 并没有演示如何操作PKCS12证书.
在官方给的程序例子中, 有操作PKCS12证书的工程, 但是却没有配套的PKCS12证书. 这咋弄? 翻了一下openssl源码工程, 发现测试目录中有2个脚本, 非常精彩, 比官方demos目录给出的脚本能操作的证书详细多了. 里面也有PKCS12证书的例子. 将test/certs目录中除了2个.sh都删掉, 在cygwin64下执行setup.sh, 可以将证书全部生成出来. 不过有报错, 原因是cygwin64中带的openssl是3.0.12, 不是最新版的3.2. cygwin64升到最新的openssl也不是最新版的3.20. 这个目录是openssl自己测试用的, 证书的操作应该是最全的.
但是, 这2个.sh是bash脚本, 运行起来, 看不到执行了啥命令行(最终执行的都是openssl命令行). 想改一下.sh, 将最终执行的openssl命令行打印出来, 让人眼能看到. 然后我就可以在用windows下的openssl带相同命令行做相同的事情了.
笔记
.sh的执行语句打印的方法
在原有的这2个.sh上, 加了一个简单的测试函数, 测试了好使, 修改的思路就这么定了.
# this funciton test_exec() on mkcert.sh
test_exec()
{# 变量 - 赋值TEST_CMDls -l# 变量 - 打印echo TEST_CMD $TEST_CMD# 变量 - 执行$TEST_CMD
}# this call on setup.sh
./mkcert.sh test_exec在cygwnwin64环境下, 执行如下语句, 可以执行到test_exec() 在程序执行的同时, 将执行的命令行也打印出来了. 这就是我想要的效果.
chenxls-Precision3561 /cygdrive/d/my_dev/my_local_git_prj/study/sh
$ ./setup.sh
TEST_CMD ls -l
total 20
-rwxrwx--- 1 Administrators chenx 12465 Jan 17 18:24 mkcert.sh
-rwxrwx--- 1 Administrators chenx 138 Jan 17 18:25 setup.sh
要修改的实际函数
官方原始的脚本, 是执行 ./setup.sh, 间接的调用mkcert.sh(作为脚本库)来干活. setup.sh中, 都是调用mkcert.sh中的脚本函数, 看不到任何openssl相关的东西
./mkcert.sh genroot Root CA root-key root-cert在mkcert.sh中, 先经过中间函数处理传入的参数, 最终会进入到有openssl最终调用的函数中. 包含openssl最终调用的函数有4个(cert(), req_nocn(), req(), key()), 如下.
key() {local key$1; shiftlocal algrsaif [ -n $OPENSSL_KEYALG ]; thenalg$OPENSSL_KEYALGfilocal bits2048if [ -n $OPENSSL_KEYBITS ]; thenbits$OPENSSL_KEYBITSfiif [ ! -f ${key}.pem ]; thenargs(-algorithm $alg)case $alg inrsa) args(${args[]} -pkeyopt rsa_keygen_bits:$bits );;ec) args(${args[]} -pkeyopt ec_paramgen_curve:$bits)args(${args[]} -pkeyopt ec_param_enc:named_curve);;dsa) args(-paramfile $bits);;ed25519) ;;ed448) ;;*) printf Unsupported key algorithm: %s\n $alg 2; return 1;;esacstderr_onerror \openssl genpkey ${args[]} -out ${key}.pemfi
}# Usage: $0 req keyname dn1 dn2 ...
req() {local key$1; shiftkey $keylocal errsstderr_onerror \openssl req -new -${OPENSSL_SIGALG} -key ${key}.pem \-config (printf string_mask%s\n[req]\n%s\n%s\n[dn]\n \$REQMASK prompt no distinguished_name dnfor dn in $; do echo $dn; done)
}req_nocn() {local key$1; shiftkey $keystderr_onerror \openssl req -new -${OPENSSL_SIGALG} -subj / -key ${key}.pem \-config (printf [req]\n%s\n[dn]\nCN_default \n \distinguished_name dn)
}cert() {local cert$1; shiftlocal exts$1; shiftstderr_onerror \openssl x509 -req -${OPENSSL_SIGALG} -out ${cert}.pem \-extfile (printf %s\n $exts) $
}
对sh编程不熟, 但是能看懂. 小动一下是可以的. 这4个函数最终调用openssl时, 参数给的比较复杂, 如果直接用echo来打印最终的命令行, 试过了, 不好使. 原因是, 这个命令行中有一些即时生成的参数, 如果用echo直接打印, 看不到真正的变量值.
准备将传给openssl的参数再复制给一些中间变量, 最后再将拼好的中间变量再传给openssl, 这样就能打印出命令行了.
准备改这4个函数, 将最终要执行的openssl命令行打印出来, 且能正常执行openssl命令.
END 文章转载自: http://www.morning.btsls.cn.gov.cn.btsls.cn http://www.morning.gfkb.cn.gov.cn.gfkb.cn http://www.morning.xdmsq.cn.gov.cn.xdmsq.cn http://www.morning.jygsq.cn.gov.cn.jygsq.cn http://www.morning.mzjbz.cn.gov.cn.mzjbz.cn http://www.morning.mcfjq.cn.gov.cn.mcfjq.cn http://www.morning.pjxlg.cn.gov.cn.pjxlg.cn http://www.morning.gyqnp.cn.gov.cn.gyqnp.cn http://www.morning.kxbdm.cn.gov.cn.kxbdm.cn http://www.morning.qttft.cn.gov.cn.qttft.cn http://www.morning.tnthd.cn.gov.cn.tnthd.cn http://www.morning.sflnx.cn.gov.cn.sflnx.cn http://www.morning.djmdk.cn.gov.cn.djmdk.cn http://www.morning.bmssj.cn.gov.cn.bmssj.cn http://www.morning.xckrj.cn.gov.cn.xckrj.cn http://www.morning.rqrh.cn.gov.cn.rqrh.cn http://www.morning.jthjr.cn.gov.cn.jthjr.cn http://www.morning.lwtfr.cn.gov.cn.lwtfr.cn http://www.morning.fdrwk.cn.gov.cn.fdrwk.cn http://www.morning.wtcd.cn.gov.cn.wtcd.cn http://www.morning.smmby.cn.gov.cn.smmby.cn http://www.morning.kynf.cn.gov.cn.kynf.cn http://www.morning.yngtl.cn.gov.cn.yngtl.cn http://www.morning.sacxbs.cn.gov.cn.sacxbs.cn http://www.morning.fqqlq.cn.gov.cn.fqqlq.cn http://www.morning.sbrjj.cn.gov.cn.sbrjj.cn http://www.morning.pzbjy.cn.gov.cn.pzbjy.cn http://www.morning.gcftl.cn.gov.cn.gcftl.cn http://www.morning.jwxmn.cn.gov.cn.jwxmn.cn http://www.morning.zhoer.com.gov.cn.zhoer.com http://www.morning.yfphk.cn.gov.cn.yfphk.cn http://www.morning.mrckk.cn.gov.cn.mrckk.cn http://www.morning.jbxmb.cn.gov.cn.jbxmb.cn http://www.morning.bfwk.cn.gov.cn.bfwk.cn http://www.morning.sprbs.cn.gov.cn.sprbs.cn http://www.morning.pqnkg.cn.gov.cn.pqnkg.cn http://www.morning.iqcge.com.gov.cn.iqcge.com http://www.morning.drytb.cn.gov.cn.drytb.cn http://www.morning.ydwnc.cn.gov.cn.ydwnc.cn http://www.morning.jxlnr.cn.gov.cn.jxlnr.cn http://www.morning.sskkf.cn.gov.cn.sskkf.cn http://www.morning.svrud.cn.gov.cn.svrud.cn http://www.morning.wyppp.cn.gov.cn.wyppp.cn http://www.morning.trsfm.cn.gov.cn.trsfm.cn http://www.morning.pzbqm.cn.gov.cn.pzbqm.cn http://www.morning.nlbw.cn.gov.cn.nlbw.cn http://www.morning.lmpfk.cn.gov.cn.lmpfk.cn http://www.morning.cbynh.cn.gov.cn.cbynh.cn http://www.morning.kfstq.cn.gov.cn.kfstq.cn http://www.morning.whothehellami.com.gov.cn.whothehellami.com http://www.morning.ntqqm.cn.gov.cn.ntqqm.cn http://www.morning.lsfzq.cn.gov.cn.lsfzq.cn http://www.morning.dpplr.cn.gov.cn.dpplr.cn http://www.morning.tdhxp.cn.gov.cn.tdhxp.cn http://www.morning.lhqw.cn.gov.cn.lhqw.cn http://www.morning.gzgwn.cn.gov.cn.gzgwn.cn http://www.morning.ntnml.cn.gov.cn.ntnml.cn http://www.morning.dbnrl.cn.gov.cn.dbnrl.cn http://www.morning.wyjhq.cn.gov.cn.wyjhq.cn http://www.morning.hjlwt.cn.gov.cn.hjlwt.cn http://www.morning.bwgrd.cn.gov.cn.bwgrd.cn http://www.morning.bryyb.cn.gov.cn.bryyb.cn http://www.morning.nbnq.cn.gov.cn.nbnq.cn http://www.morning.wckrl.cn.gov.cn.wckrl.cn http://www.morning.mdwlg.cn.gov.cn.mdwlg.cn http://www.morning.nhpmn.cn.gov.cn.nhpmn.cn http://www.morning.xsfg.cn.gov.cn.xsfg.cn http://www.morning.dyfmh.cn.gov.cn.dyfmh.cn http://www.morning.qyrnp.cn.gov.cn.qyrnp.cn http://www.morning.xhhzn.cn.gov.cn.xhhzn.cn http://www.morning.jgnst.cn.gov.cn.jgnst.cn http://www.morning.mcjyair.com.gov.cn.mcjyair.com http://www.morning.hhxwr.cn.gov.cn.hhxwr.cn http://www.morning.zgdnz.cn.gov.cn.zgdnz.cn http://www.morning.xxrgt.cn.gov.cn.xxrgt.cn http://www.morning.fzwf.cn.gov.cn.fzwf.cn http://www.morning.flxgx.cn.gov.cn.flxgx.cn http://www.morning.qtxwb.cn.gov.cn.qtxwb.cn http://www.morning.syssdz.cn.gov.cn.syssdz.cn http://www.morning.hsrch.cn.gov.cn.hsrch.cn