Bash 在openvpn中传递SSL密钥的密码

Bash 在openvpn中传递SSL密钥的密码,bash,shell,openssl,openvpn,Bash,Shell,Openssl,Openvpn,目前,我正准备更改一个名为“pkitool”的脚本(如果有人不使用openvpn,但也想帮助我,这就是pkitool的样子:)。我的目标是,我能够传递变量$1(Keyname)和在同一脚本中导出的密码。看起来是这样的: export KEY_PASSWORD=$2 ./pkitool --pass $1 NODES_REQ = "-nodes" -nodes if this option is specified then if a private key is cre

目前,我正准备更改一个名为“pkitool”的脚本(如果有人不使用openvpn,但也想帮助我,这就是pkitool的样子:)。我的目标是,我能够传递变量$1(Keyname)和在同一脚本中导出的密码。看起来是这样的:

export KEY_PASSWORD=$2
./pkitool --pass $1
NODES_REQ = "-nodes"
-nodes
           if this option is specified then if a private key is created it will not be
           encrypted.
-passin arg
           the input file password source. For more information about the format of arg see the
           PASS PHRASE ARGUMENTS section in openssl(1).
目前,我被要求输入密码,然后进行验证。我想更改它,只需将密码和密码传递给脚本,我希望脚本要求我输入密码短语。。。(我导出varibale KEY_密码的原因是我想稍后使用它。)这是我修改过的PKI工具的摘录:

# Process options while [ $# -gt 0 ]; do
    case "$1" in
        --keysize  ) KEY_SIZE=$2
                     shift;;
        --server   ) REQ_EXT="$REQ_EXT -extensions server"
                     CA_EXT="$CA_EXT -extensions server" ;;
        --batch    ) BATCH="-batch" ;;
        --interact ) BATCH="" ;;
        --inter    ) CA_EXT="$CA_EXT -extensions v3_ca" ;;
        --initca   ) DO_ROOT="1" ;;
        --pass     ) NODES_REQ="-passin env:KEY_PASSWORD" ;;
        --csr      ) DO_CA="0" ;;
        --sign     ) DO_REQ="0" ;;
        --pkcs12   ) DO_P12="1" ;;
        --pkcs11   ) DO_P11="1"
                     PKCS11_MODULE_PATH="$2"
                     PKCS11_SLOT="$3"
                     PKCS11_ID="$4"
                     PKCS11_LABEL="$5"
                     shift 4;;
显然,我将变量用于参数--“pass”。我之所以使用“-passin env:KEY_PASSWORD”是因为我误解了这个手册页

PASS PHRASE ARGUMENTS
       Several commands accept password arguments, typically using -passin and -passout for
       input and output passwords respectively. These allow the password to be obtained from a
       variety of sources. Both of these options take a single argument whose format is
       described below. If no password argument is given and a password is required then the
       user is prompted to enter one: this will typically be read from the current terminal with

env:var   obtain the password from the environment variable var. Since the environment of
                 other processes is visible on certain platforms (e.g. ps under certain Unix
                 OSes) this option should be used with caution.
这是PKI工具的一部分,再次使用节点_REQ:

# Build cert/key
        ( [ $DO_REQ -eq 0 ] || $OPENSSL req $BATCH -days $KEY_EXPIRE $NODES_REQ -new -newkey rsa:$KEY_SIZE \
                -keyout "$FN.key" -out "$FN.csr" $REQ_EXT -config "$KEY_CONFIG" $PKCS11_ARGS ) && \
            ( [ $DO_CA -eq 0 ]  || $OPENSSL ca $BATCH -days $KEY_EXPIRE -out "$FN.crt" \
                -in "$FN.csr" $CA_EXT -md sha1 -config "$KEY_CONFIG" ) && \
            ( [ $DO_P12 -eq 0 ] || $OPENSSL pkcs12 -export -inkey "$FN.key" \
                -in "$FN.crt" -certfile "$CA.crt" -out "$FN.p12" $NODES_P12 ) && \
            ( [ $DO_CA -eq 0 -o $DO_P11 -eq 1 ]  || chmod 0600 "$FN.key" ) && \
            ( [ $DO_P12 -eq 0 ] || chmod 0600 "$FN.p12" )
PKI工具的其余部分未修改,您可以在说明中查看链接。希望你们能理解我的问题。请停止,我想不出来:(

编辑:当NODES_REQ处于默认状态时,如下所示:

export KEY_PASSWORD=$2
./pkitool --pass $1
NODES_REQ = "-nodes"
-nodes
           if this option is specified then if a private key is created it will not be
           encrypted.
-passin arg
           the input file password source. For more information about the format of arg see the
           PASS PHRASE ARGUMENTS section in openssl(1).
两个重要部分(也是我使用-passin的原因)如下所示:

export KEY_PASSWORD=$2
./pkitool --pass $1
NODES_REQ = "-nodes"
-nodes
           if this option is specified then if a private key is created it will not be
           encrypted.
-passin arg
           the input file password source. For more information about the format of arg see the
           PASS PHRASE ARGUMENTS section in openssl(1).

我必须使用-passout而不是-passin…必须仔细阅读手册页才能理解其中的微妙之处。之所以有两个选项,-passin和-passout,是因为在输入文件受密码保护时使用passin,需要提供密码来解锁它,而在密码保护输出文件时使用passout。因为“req”只是生成输出,所以我需要的是-passout,而不是-passin.:)

如果您能提供一些实际的代码/最终有效的命令,那将非常有用。假设您最终不必修改
pkitool
。似乎他修改了pkitool中来自
--pass)节点的一行
--pass)节点_REQ=“-passout env:KEY_PASSWORD”