PFX 証明書を生成する最も簡単な方法 (Windows)

PFX 証明書を生成する最も簡単な方法 (Windows)

現時点では、PFX 証明書を生成するために openssl と以下を使用します。

  • 秘密鍵を使用してCSRを生成する
  • 私の CA Web サイト (Microsoft CA) に接続し、(san:dns=) 追加属性とともに CSR を送信します。
  • 証明機関から保留中の証明書 (Base 64) を発行します。
  • 秘密鍵 PKCS8 を PKCS1 に変換する
  • PEM (秘密鍵、ホスト証明書、中間証明書、ルート証明書) を作成する
  • そしてついにPEMをPKCS#12(.pfxファイル)に変換します

このプロセスは非常に長く、多くの時間を無駄にしていると思います。

内部の Microsoft CA から署名された証明書チェーン (pfx) を取得するより速い方法を教えてください。

ここに画像の説明を入力してください

答え1

そうですね、それではスクリプトを書きました。

certreq と powershell を使えばもっと簡単な方法があると思いますが、ここに bash スクリプトがあります。 要件: Cygwin、標準 UNIX ユーティリティ、clip、openssl

#!/bin/bash
iexplore='/cygdrive/c/Program\ Files\ \(x86\)/Internet\ Explorer/iexplore.exe';
printf "\033c";
echo -e "This function automates IIS7 certificate generation for <YourCompany>";
type openssl > /dev/null 2>&1 || { 
    echo "Cannot find OpensSSL, it is required to generate certificates.  Aborting..." 1>&2;
    exit 1
};
openssl version;
echo -e "\n";
read -p "What is the server hostname (NOT FQDN!): " Hostname;
if [[ $Hostname =~ ^[A-Za-z0-9]+$ ]]; then
    echo -e "Server name:\t"$Hostname"\nFQDN:\t\t"$Hostname".<yourDomain>\n";
else
    echo ""$Hostname" doesn't look quite right... Exiting";
    sleep 3;
    exit 1;
fi;
mkdir ~/Desktop/certs_temp > /dev/null 2>&1;
cd ~/Desktop/certs_temp;
echo "
[ req ]
default_md = sha512
default_bits = 2048
default_keyfile = rui.key
distinguished_name = req_distinguished_name
encrypt_key = no
prompt = no
string_mask = nombstr
req_extensions = v3_req
input_password = testpassword
output_password = testpassword

[ v3_req ]
basicConstraints = CA:false
keyUsage = digitalSignature, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectAltName = DNS:"$Hostname"

[ req_distinguished_name ]
countryName = AU
stateOrProvinceName = NSW
localityName = Sydney
0.organizationName = <OrgName>
organizationalUnitName = <OrgUName>
commonName = "$Hostname".<YourDomain>" > openssl.cfg;
openssl req -out openssl.csr -new -newkey rsa:2048 -nodes -keyout pk.key -config openssl.cfg > /dev/null 2>&1;
openssl rsa -in pk.key -out openssl.key > /dev/null 2>&1; rm pk.key;
echo -e "Now, upload this Code Signing Request to the Internal Certificate Authority: \n\t- The CSR content has been copied into your clipboard\n\t- You do not require to set any subject alternate name\n\t- Once submitted, open "Certificate Authority" via MMC (<ServerName>), issue pending certificate and export it (Open / Details / Copy To File) Base64 to ~/Desktop/certs_temp/openssl.cer\n";
eval $iexplore https://<ServerName>/certsrv/certrqxt.asp;
cat openssl.csr | clip;
read -p "Press [Enter] when openssl.cer certificate has been place in ~/Desktop/certs_temp";
if [ -f 'openssl.cer' ]; then
    cat openssl.cer >> openssl.key;
    echo '
-----BEGIN CERTIFICATE-----
<CompanyIntermediate>
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
<CompanyRoot>
-----END CERTIFICATE-----' >> openssl.key;
    mv openssl.key ""$Hostname".pem";
    echo "Converting PEM Chain certificate to PKCS#12 (.pfx)";
    openssl pkcs12 -export -out ""$Hostname".pfx" -in ""$Hostname".pem";
    explorer .
else
    echo "Cannot find openssl.cer in ~/Desktop/certs_temp... Exiting";
    sleep 3;
    exit 1;
fi

スクリプト :

  1. 設定ファイルに基づいて秘密鍵とコード署名要求を生成します。
  2. CSR をクリップボードにコピーし、IIS Web ページを開いて証明書を要求します。
  3. 保留中の証明書を発行し、それをbase64でエクスポートするようユーザーに促します。
  4. PEM を作成し、PKCS#12 (.pfx) としてエクスポートします。

注意: Win 32 ビット版の Internet Explorer のパスを変更し、< ServerName > 固有のタグを置き換える必要があります。

関連情報