启用证书注册策略并使用PowerShell请求证书


9

现在,我正在执行以下操作以从CEP服务器请求证书:

  • 打开gpedit.msc
  • 在“计算机配置”>“ Windows设置”>“安全设置”>“公钥策略”下,双击“证书服务客户端-证书注册策略”
  • 启用
  • 输入CEP URI
  • 切换到用户名/密码验证
  • 验证(提供凭据)
  • 打开MMC,然后导入“证书”管理单元
  • 转到证书>个人
  • 右键单击>请求新证书
  • 输入“更多信息”(CN,DNS名称等)
  • 提供信用

之后,我获得了CEP的证书;但是,这是手动执行的痛苦过程。在Server 2008(和2012)中,有什么方法可以自动执行此操作?我能找到的所有信息都告诉您如何安装CEP服务,以使服务器成为注册策略服务器(与实际请求新证书或在客户端启用它无关)。可以自动化吗?

似乎此过程在HKEY_LOCAL_MACHINE \ SOFTWARE \ Policies \ Microsoft \ Cryptography下添加了许多数据。我可以手动添加(并欺骗GUID / ServiceID)吗?


1
不要气your您的热情,因为我也喜欢将所有东西都粉碎掉!但该组策略cmdlet仍然绝对可怕的,和PKI的cmdlet在V4在V3很大的提高,所以... :(不过,我确实发现了PowerShell的模块这个第三方PKI模块是有用的,它可能需要一些手动痛苦出你想做什么
HopelessN00b 2014年

Answers:


3

我想您的证书申请是使用模板进行的。如果是这种情况,请使用Public Key Policies/Certificate Services Client - Auto-Enrollment SettingsGPO强制执行自动注册。您还需要确保模板ACL具有EnrollAutoEnroll标记为域计算机或域用户(或任何acl对象,具体取决于目标受众),并根据其是否是计算机来利用用户配置和计算机配置策略您要推送的证书或用户证书。在关联并强制执行GPO后,通常在推送政策后(通常大约15分钟)就开始注册。


2
好吧,嗯 我对PowerShell部分非常着迷,因为我已经建立了很多很多GPO来自动进行证书注册多年,所以我完全空白。天哪!接得好。
HopelessN00b 2014年

这绝对是一个选项(可能是最佳选择),但是我希望设置一个本地组策略设置。这可能吗?
2014年

2
@EGr为什么要在世界上这样做?
MDMoore313 2014年

@ HopelessN00b我做了同样的事情,但是,至少有一种Powershell的方法来进行故障排除是很酷的,所以这仍然是一个很好的问题。
MDMoore313 2014年

1

这是我在Windows 2012 R2和更高版本上使用的过程。所有PowerShell代码都是从提升的PowerShell提示符运行的。完全自动化留给用户练习。

先决条件

确保您的证书服务器上有一个模板,并且在“主题”选项卡中选中了“在请求中提供”单选按钮。因为这不是AD机器,所以证书服务器无法充分查询Active Directory中的信息。

导出根

在证书服务器上导出受信任的根证书颁发机构证书,然后将该证书文件复制到目标服务器

certutil --% -ca.cert <name of certificate file>

信任根

将该证书导入到目标服务器上的受信任的根证书颁发机构

$PathToCertificate=<name of certificate file>
$RootCertificate=Get-PfxCertificate -FilePath $PathToCertificate
$AlreadyExists=Get-ChildItem -Path "Cert:\LocalMachine\Root" | Where-Object { $_.Thumbprint -eq $RootCertificate.Thumbprint }
if ($AlreadyExists -eq $null) { Import-Certificate -CertStoreLocation "Cert:\LocalMachine\Root" -FilePath $PathToCertificate }
else { Write-Warning "Root certificate already installed" }

Active Directory策略提供者

确定Active Directory策略提供程序的URL

# Get AD Configuration Context
$RootDSE=[System.DirectoryServices.DirectoryEntry]::new("LDAP://RootDSE")
$ConfigContext="CN=Enrollment Services,CN=Public Key Services,CN=Services,"+$RootDSE.configurationNamingContext
# Get name of Enterprise Root Certificate Autority server
$Server=Get-ADObject -SearchBase $ConfigContext -Filter "*"
if ($Server.Count -eq 1) { throw "No Enterprise Root Certificate Autority server exists" }
else { $Server=$Server[1].Name }
# Get Enrollment URL
$ConfigContext="CN=$Server,"+$ConfigContext
$EnrollmentURL=(Get-ADObject -SearchBase $ConfigContext -Filter "*" -Properties "msPKI-Enrollment-Servers" | Select-Object -ExpandProperty "msPKI-Enrollment-Servers").Split("`n") | Where-Object { $_ -like "http*" }
if ($EnrollmentURL -eq $null) { $EnrollmentURL="" }
# Get AD Enrollment Policy URL
$Server=$Server+$RootDSE.configurationNamingContext.Value.Replace("CN=Configuration","").Replace(",DC=",".")
$WMI=Get-WmiObject -ComputerName $Server -Namespace "root\WebAdministration" -Class Application | Where-Object { $_.Path -eq "/ADPolicyProvider_CEP_UsernamePassword" }
if ($WMI -ne $null) { $PolicyURL="https://"+$Server+$WMI.Path+"/service.svc/CEP" }
else { $PolicyURL="" }
Write-Output "Enrollment URL = $EnrollmentURL"
Write-Output "Policy URL = $PolicyURL"

招生政策

将注册策略添加到目标服务器(仅适用于Windows 2012及更高版本。有关GUI的说明,请参见下文)。确保在创建非域模板之后添加了策略,否则将不会显示该策略,因为它不会刷新。

$User="<your domain name>\<your domain user name>"
$Pass="<Your domain password>"
$SecPass=ConvertTo-SecureString -String $Pass -AsPlainText -Force
$Cred=[System.Management.Automation.PSCredential]::new($User,$SecPass)
Add-CertificateEnrollmentPolicyServer -Url $PolicyURL -context Machine -NoClobber -AutoEnrollmentEnabled -Credential $Cred

取得证书

现在,您应该可以使用所需的模板注册证书

$DNS="<FQDN of your server>"
$URL=Get-CertificateEnrollmentPolicyServer -Scope All -Context Machine | Select-Object -ExpandProperty Url | Select-Object -ExpandProperty AbsoluteUri
$Enrollment=Get-Certificate -Url $URL -Template "<Template name (not display name)>" -SubjectName "CN=$DNS" -DnsName $DNS -Credential $Cred -CertStoreLocation cert:\LocalMachine\My
$Enrollment.Certificate.FriendlyName=$DNS

Windows 2012 R2之前的注册策略

  1. 打开证书MMC
  2. 深入到个人证书存储
  3. 右键单击“证书”,然后选择“所有任务/高级操作/管理”
  4. 上下文菜单中的注册策略
  5. 点击“添加”按钮
  6. 粘贴注册政策的网址
  7. 选择用户名/密码作为身份验证类型
  8. 单击“验证服务器”按钮,然后输入您的域凭据,包括域
  9. 假设您已经能够成功验证,请单击“添加”按钮
  10. 选择注册策略,然后单击“属性”按钮
  11. 确保选中“启用自动注册和续订”框
  12. 我从未检查过“在注册过程中需要强力验证”,所以我不知道它的作用

0

我没有完整的解决方案,但是,我可以建议起点。我的PowerShell PKI模块具有从Windows 7 / Windows Server 2008 R2开始注册注册服务终结点的能力(请注意Windows Server 2008不支持注册服务)。以下是如何注册策略的示例: http //en-us.sysadmins.lv/Lists/Posts/Post.aspx?ID=101

关于入学。本系列博客文章可能会给您一些有关如何利用CertEnroll COM接口在PowerShell中执行证书注册的见解。不幸的是,关于注册Web服务并没有什么,但是技术是相同的。您将需要从以下接口开始:IX509CertificateRequestPkcs10V2

高温超导

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.