使用活动目录登录客户端¶
| Compatible Nitrokeys | |||||||
|---|---|---|---|---|---|---|---|
| ✓ active | ⨯ inactive | ⨯ inactive | ⨯ inactive | ⨯ inactive | ⨯ inactive | ⨯ inactive | ⨯ inactive | 
This document explains how to use the PIV smart card of a Nitrokey 3 for logon with Active Directory. It is available as of firmware version 1.8 and higher.
在未来,这种手动配置可能会通过Windows MiniDriver自动进行。
先决条件¶
设置要求对运行 Active Directory 目录服务 (ADDS) 和 Active Directory 证书服务 (ADCS) 的计算机具有管理访问权限。在客户机上,只需访问用于登录的相应用户账户。
- Windows server (supported versions are Windows Server 2016, 2019, 2022, 2025 in Standard and Enterprise editions) - 已安装并配置 ADDS 角色。 
- 已安装 ADCS 角色,Enterprise-CA 并配置了根证书。 - 每个域控制器 (DC) 都必须有*域控制器* 、域控制器验证 和*Kerberos 验证* 证书。 
- 如果有客户离开公司网络,请确保已发布的完整和 delta 证书吊销列表 (CRL) 可从外部网络检索到。 
 
 
- Windows 客户端(支持的版本有 Windows 10、11,版本为*Professional* 和*Enterprise*) - 客户端必须是 Active Directory (AD) 域的域成员。 
 
- Nitrokey 3 with PIV smart card. 
配置智能卡登录,以便与 Active Directory (AD) 一起使用¶
智能卡登录需要域证书颁发机构(CA)的证书模板。该模板定义了用户证书的值和限制。它用于在配置 Nitrokey 时签署证书请求(CSR)。
- 签署智能卡登录证书请求需要在证书颁发机构创建证书模板。 - 从命令行、PowerShell 或运行中,键入``certtmpl.msc`` 并按 Enter。 
- 在详细信息窗格中选择模板**Smartcard Logon** 。 
- 在菜单栏中单击**操作 → 所有任务 → 复制模板** 。 
- 根据上述选项卡在模板上进行以下设置。 - Compatibility * Disable Show resulting changes * Set Certificate Authority and Certificate recipient to the oldest clients in the domain which are supposed to use smartcard logon. - 重要 - 如果要使用椭圆曲线 (EC) 密钥,客户机的版本必须不高于 Windows Server 2008 和 Windows Vista。 - General * Set a Template display name. * Set the Validity period and Renewal period. - Request handling * Set a purpose of Signature and smartcard logon. - Cryptography * Set a provider category of Key Storage Provider. * Set a algorithm name and minimum key size. - 重要 - Microsoft recommends to use the RSA algorithm with a key length of - 2048Bit. If you choose to use Elliptic Curve (EC) keys you need to make additional changes on your client computers.- Subject Name * Set Supply in the request. 
- 使用**OK** 确认模板创建。 
 
- 创建证书模板后,必须签发模板供客户使用。 - From the Command Line, PowerShell, or Run, type - certmgr.mscand press Enter.
- 在导航窗格中展开证书颁发机构 (CA),并导航至**Certificate Templates** 。 
- 在菜单栏中单击**操作 → 新建 → 签发证书模板** 。 
- 选择要签发的证书模板,并通过**OK** 确认。 
 
使用 Active Directory 为智能卡登录提供 Nitrokey 3¶
The smartcard logon requires to provision a Nitrokey for a user in Active Directory. The provisioning contains the private key and Certificate Singing Request (CSR) generation. The certificate is then written to the Nitrokey.
警告
在执行以下步骤之前,请确保要用于智能卡登录的 Active Directory 用户账户已经存在。证书创建时间早于用户账户创建时间将导致登录失败。
- 使用下面的命令生成私钥并将 CSR 写入文件。 - nitropy nk3 piv --experimental generate-key --key 9A --algo <algorithm> --subject-name <subject-name> --subject-alt-name-upn <subject-alternative-name> --path <file>- The value of - <algorithm>is the used algorithm with its key length, e.g.- rsa2048. The value of- <subject-name>corresponds to the value of the- distinguishedNameattribute of the Active Directory user account. In most cases it is only necessary to include the common name part of the distinguished name, e.g.- CN=John Doe. The value of- <subject-alternative-name>corresponds to the value of the- userPrincipalNameattribute of the Active Directory user account.
- 用下面的命令在域的证书颁发机构 (CA) 上签署 CSR。 - certreq -attrib CertificateTemplate:<template-name> -submit <file>- <template-name>的值是用于智能卡登录的证书模板名称。- <file>的值是证书演唱请求文件。
- 用下面的命令将签名证书写入 Nitrokey。 - nitropy nk3 piv --experimental write-certificate --key 9A --format PEM --path <file>- <file>的值是证书文件。
- 将证书与 Active Directory 用户账户进行映射。使用以下命令创建证书映射。 - nitropy nk3 piv --experimental get-windows-auth-mapping- Choose one of the offered certificate mappings. - 小技巧 - 微软建议使用``X509IssuerSerialNumber`` 映射。 - 将选择的映射写入 Active Directory 用户对象的``altSecurityIdentities`` 属性。您可以使用*Active Directory Users and Computers* 应用程序或 PowerShell 进行此操作。 - From the Command Line, PowerShell, or Run, type - dsa.mscand press Enter.
- In the menu bar click View → Advanced Features. 
- 选择相应的用户对象。 
- In the menu bar click Action → Properties. 
- 打开**Attribute Editor(属性编辑器)选项卡** 。 
- 选择属性``altSecurityIdentities``。 
- Click on Edit. 
- Insert the certificate mapping in the text field and click Add. 
- 点击**OK** 应用更改。 
 - 打开 PowerShell。 
- 用``Set-ADUser -Identity "<sAMAccountName>" -Add @{altSecurityIdentities="<certificate-mapping>"}`` 添加值,用用户登录名的值替换``<sAMAccountName>``,用上面选择的证书映射替换``<certificate-mapping>``。 
 - 重要 - 如果证书映射未正确设置,尝试登录时将收到错误信息``Logon screen message: Your credentials could not be verified.``。此外,您还会在 Windows 系统事件日志中看到以下事件消息。 - Source - Kerberos-Key-Distribution-Center - Message - The Key Distribution Center (KDC) encountered a user certificate that was valid but could not be mapped to a user in a secure way (such as via explicit mapping, key trust mapping, or a SID). Such certificates should either be replaced or mapped directly to the user via explicit mapping. See https://go.microsoft.com/fwlink/?linkid=2189925 to learn more. 
撤销智能卡登录,以便与 Active Directory (AD) 一起使用¶
已签发的用户登录证书列在 Active Directory 证书服务 (ADCS) 中。从 ADCS 中可以撤销证书,并将其添加到配置的证书撤销列表(CRL)中。这在 Nitrokey 丢失或损坏时是必需的。
重要
强烈建议不要在未撤销证书的情况下留下未使用的用户证书。
备注
可以暂时吊销证书,理由是*Certificate Hold* 。这种撤销可以恢复,因此不是永久性的。
- 从命令行、PowerShell 或运行中,键入``certsrv.msc`` 并按 Enter。 
- 在导航窗格中展开证书颁发机构 (CA),并导航至**Issued Certificates** 。 
- 在详细窗格中选择要撤销的用户证书。 
- 在菜单栏中单击**操作 → 所有任务 → 注销证书** 。 
- 指定撤销原因、日期和时间,并通过**Yes** 进行确认。 
- 在导航窗格中导航至**已撤销证书** 。 
- 在菜单栏中单击**操作 → 所有任务 → 发布** 。 
- 选择要发布的撤销列表,并通过**OK** 确认。 
备注
在每次智能卡登录尝试中,Windows 都会检查智能卡出示的证书是否列在证书吊销列表(CRL)中。如果在证书吊销列表中发现该证书,则拒绝登录。每个 CRL 都包含一个使其过期的有效期。Windows 会缓存获取的 CRL,并在 CRL 即将过期时更新它们。因此,证书吊销不会立即发生,而是取决于客户端所拥有的证书废止列表的过期时间。
将用户智能卡证书导入个人证书存储区¶
存储在 Nitrokey 上的用户证书可以导入到用户的个人证书存储空间。在某些情况下,这是必要的程序。
- 确保您已登录证书对应的用户账户。 
- 从命令行、PowerShell 或运行中,键入``certsrv.msc`` 并按 Enter。 
- 在导航窗格中展开**个人** 密钥存储,并导航至**证书** 。 
- 在菜单栏中单击**操作 → 所有任务 → 导入** 。 
- 按照导入向导操作,并按要求提供用户证书文件。 
- 导入完成后,检查导入证书的详细信息窗格。如果 Nitrokey 已连接,证书属性应显示*You have a private key that corresponds to this certificate(你有一个与此证书对应的私钥)。* 表明 Nitrokey 上的私钥可以被识别。 
- 确保您已登录证书对应的用户账户。 
- 打开 PowerShell。 
- Import the certificate with - Import-Certificate -CertStoreLocation Cert:\CurrentUser\My -FilePath <path>, replacing- <file>with the certificate file path.
- After the import completed check for the certificate with - Get-ChildItem Cert:\CurrentUser\My.