產生並匯出憑證 - Linux (strongSwan)

VPN 閘道點對站連線可以使用憑證來進行驗證。 本文說明如何建立自我簽署的根憑證,以及使用 strongSwan 來產生用戶端憑證。 您也可以使用 PowerShellMakeCert

每個用戶端都必須在本機安裝用戶端憑證才能連線。 此外,根憑證公開金鑰資訊必須上傳至 Azure。 如需詳細資訊,請參閱點對站設定 - 憑證驗證

安裝 strongSwan

下列步驟可協助您安裝 strongSwan。

指定命令時會使用下列組態:

  • 電腦:Ubuntu Server 18.04
  • 相依項目:strongSwan

使用下列命令來安裝所需的 strongSwan 組態:

sudo apt-get update
sudo apt-get upgrade
sudo apt install strongswan
sudo apt install strongswan-pki
sudo apt install libstrongswan-extra-plugins
sudo apt install libtss2-tcti-tabrmd0

Linux CLI 指示 (strongSwan)

下列步驟可協助您使用 Linux CLI (strongSwan) 來產生並匯出憑證。 如需詳細資訊,請參閱 Azure CLI 附加安裝指南

產生 CA 憑證。

ipsec pki --gen --outform pem > caKey.pem
ipsec pki --self --in caKey.pem --dn "CN=VPN CA" --ca --outform pem > caCert.pem

列印 base64 格式的 CA 憑證。 這是 Azure 支援的格式。 您會在 P2S 設定步驟的過程中,將此憑證上傳至 Azure。

openssl x509 -in caCert.pem -outform der | base64 -w0 ; echo

產生使用者憑證。

export PASSWORD="password"
export USERNAME=$(hostnamectl --static)

ipsec pki --gen --outform pem > "${USERNAME}Key.pem"
ipsec pki --pub --in "${USERNAME}Key.pem" | ipsec pki --issue --cacert caCert.pem --cakey caKey.pem --dn "CN=${USERNAME}" --san "${USERNAME}" --flag clientAuth --outform pem > "${USERNAME}Cert.pem"

產生包含使用者憑證的 p12 組合。 在後續使用用戶端組態檔的步驟中將會用到此組合。

openssl pkcs12 -in "${USERNAME}Cert.pem" -inkey "${USERNAME}Key.pem" -certfile caCert.pem -export -out "${USERNAME}.p12" -password "pass:${PASSWORD}"

下一步

請繼續進行點對站設定,以便建立和安裝 VPN 用戶端組態檔 - Linux