5

現在、「pkitool」というスクリプトを変更しようとしています (openvpn を使用していないが、私も支援したいという人のために、pkitool は次のようになります: https://joinup.ec.europa. eu/svn/cube/trunk/cube/cube-integration/src/main/scripts/openvpn/pkitool )。私の目的は、同じスクリプトでエクスポートする変数 $1 (キー名) とパスワードを渡すことができるようにすることです。次のようになります。

export KEY_PASSWORD=$2
./pkitool --pass $1

現時点では、パスワードを入力して確認するよう求められています。それを変更して、パスワードをスクリプトに渡すだけで、スクリプトがパスフレーズの入力を求められるようにしたい... (変数 KEY_PASSWORD をエクスポートする理由は、後で使用するためです。)は、変更した pkitool の抜粋です。

# 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」を使用した理由は、私がかなり誤解していたこの man ページでした...

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.

これは、NODES_REQ が再び使用される pkitool の一部です。

# 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" )

pkitool の残りの部分は変更されておらず、説明のリンクを見ることができます。皆さんが私の問題を理解してくれることを願っています。HALP PLS、わかりません:(

編集: NODES_REQ がデフォルトの場合、次のようになります。

NODES_REQ = "-nodes"

そして、2 つの重要な部分 (-passin を使用している理由でもあります) は次のようになります。

-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).
4

1 に答える 1

4

-passin の代わりに -passout を使用する必要がありました... 微妙な点を理解するには、man ページを注意深く読む必要があります。-passin と -passout の 2 つのオプションがある理由は、passin は入力ファイルがパスワードで保護されていて、ロックを解除するためにパスワードを指定する必要がある場合に使用され、passout は出力ファイルをパスワードで保護する場合に使用されるためです。「req」は出力を生成するだけなので、必要なのは -passin ではなく -passout です。:)

于 2013-11-27T07:23:49.393 に答える