PFX 인증서를 생성하는 가장 쉬운 방법(Windows)

PFX 인증서를 생성하는 가장 쉬운 방법(Windows)

PFX 인증서를 생성하는 순간에는 openssl을 사용하고 다음을 수행합니다.

  • 개인 키를 사용하여 CSR 생성
  • 내 CA 웹사이트(Microsoft CA)에 연결하고 (san:dns=) 추가 속성과 함께 CSR을 제출합니다.
  • 인증 기관에서 보류 중인 인증서(Base 64)를 발급합니다.
  • 내 개인 키 PKCS8을 PKCS1로 변환
  • PEM(개인 키, 호스트 인증서, 중간 인증서 및 루트 인증서) 만들기
  • 마침내 내 PEM을 PKCS#12(.pfx 파일)로 변환했습니다.

이 과정은 꽤 길며 그렇게 하는 데 많은 시간을 낭비하고 있다고 생각합니다.

내부 Microsoft CA에서 서명된 인증서 체인(pfx)을 얻는 가장 빠른 방법이 무엇인지 알려주실 수 있습니까?

여기에 이미지 설명을 입력하세요

답변1

그렇죠, 그럼 제가 대본을 썼어요.

나는 여전히 certreq와 powershell을 사용하는 더 쉬운 방법이 있다고 믿지만 여기에는 bash 스크립트가 있습니다. 요구 사항: Cygwin, 표준 UNIX 유틸리티, 클립, 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 > 특정 태그를 바꿔야 합니다.

관련 정보