跳到内容

在客户端使用您自己的证书签署RDP文件

为了简化程序,已经为您编写了多个 PowerShell 脚本。请在使用之前先将变量的值更改为您自己的值。

第一步

您需要首先创建自己的签名证书,并带有可导出的私钥。

这需要管理员权限。

请注意,证书的指纹将在用户配置侧。

$organization = "MyCompany"
$commonName = "RDP Signer"
$friendlyName = "RDP Signing Certificate"
$pfxPassword = "MyStrongPassword!"
$pfxFilePath = [Environment]::CurrentDirectory + "\signer.pfx"
# In years
$validityDuration = 3
Write-Host Certificate will be created in $pfxFilePath
# Generate the signing certificate
$cert = New-SelfSignedCertificate `
-Type CodeSigningCert `
-Subject "CN=$commonName, O=$organization" `
-KeyUsage DigitalSignature `
-KeyExportPolicy Exportable `
-FriendlyName $friendlyName `
-CertStoreLocation "Cert:\LocalMachine\My" `
-NotAfter (Get-Date).AddYears($validityDuration)
# Generate the pfx file to import on client computer
$thumb = $cert.Thumbprint
Write-Host Certificate thumbprint: $thumb
$pwd = ConvertTo-SecureString -String $pfxPassword -Force -AsPlainText
Get-ChildItem -Path Cert:\LocalMachine\My\$thumb |
Export-PfxCertificate -FilePath "$pfxFilePath" -Password $pwd

第二步(在用户工作站上)

一旦生成签名证书,为了让您的客户使用它,他们需要执行以下操作:

  • 将证书导入“CurrentUser\My”存储,以便能够使用证书指纹通过rdpsign签署rdp文件。
  • 将证书导入“CurrentUser\Root”存储,以便使用此证书签名的rdp被识别。
$pfxFilePath = [Environment]::CurrentDirectory + "\signer.pfx"
$pfxPassword = "MyStrongPassword!"
$pwd = ConvertTo-SecureString -String $pfxPassword -Force -AsPlainText
# Import pfx in CurrentUser\My certificate store to be able to sign with rdpsign using the thumbprint
Import-PfxCertificate -FilePath "$pfxFilePath" -CertStoreLocation "Cert:\CurrentUser\My" -Password $pwd
# Import pfx to the trusted root certificate authority of the user, so that signed rdp with this certificate are recognized.
# Note: this triggers a windows confirmation popup
Import-PfxCertificate -FilePath "$pfxFilePath" -CertStoreLocation "Cert:\CurrentUser\Root" -Password $pwd

第三步(在用户工作站上)

要使计算机完全信任使用此证书签名的rdp文件,您需要将其添加到注册表的受信任证书指纹列表中。
位置:“HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows NT\Terminal Services”
密钥:“TrustedCertThumbprints”
类型:字符串

注意:由于我们在 HKEY_LOCAL_MACHINE 中进行写入,因此需要管理员权限。

$thumbprint = "YOUR_THUMBPRINT"
$regPath = "HKLM:\Software\Policies\Microsoft\Windows NT\Terminal Services"
$keyName = "TrustedCertThumbprints"
$current = (Get-ItemProperty -Path $regPath -Name $keyName -ErrorAction SilentlyContinue).$keyName
$newValue = if ([string]::IsNullOrWhiteSpace($current)) { $thumbprint } else { "$current,$thumbprint" }
New-Item -Path $regPath -Force | Out-Null
New-ItemProperty -Path $regPath -Name $keyName -Value $newValue -PropertyType String -Force | Out-Null

第四步(在用户工作站上)

最后,要告诉“Connection Client”程序使用您的证书进行签名并使用其指纹进行签名,您需要设置以下注册表项: 位置:“HKEY_CURRENT_USER\Software\Digital River\ConnectionClient”
或
位置: “HKEY_LOCAL_MACHINE\Software\Digital River\ConnectionClient”

key: “证书指纹”
类型:字符串
值:您的指纹

$thumbprint = "YOUR_THUMBPRINT"
New-ItemProperty -Path "HKCU:\Software\Digital River\ConnectionClient" -Name "CertThumbprint" -PropertyType String -Value $thumbprint -Force