產生 PFX 憑證最簡單的方法(Windows)

產生 PFX 憑證最簡單的方法(Windows)

目前產生 PFX 證書,我使用 openssl 和:

  • 使用私鑰產生 CSR
  • 連接到我的 CA 網站 (Microsoft CA),然後提交 CSR 以及 (san:dns=) 附加屬性。
  • 我從證書頒發機構頒發待定證書(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 網頁以請求憑證。
  3. 提示使用者頒發待處理的憑證並將其匯出為base64
  4. 建立 PEM,然後將其匯出為 PKCS#12 (.pfx)

注意:您必須變更適用於 Win 32 位元的 Internet Explorer 的路徑,並且必須取代 < ServerName > 特定標記。

相關內容