community.windows.win_certificate_info 模块 – 从 Windows 证书存储区获取证书信息

注意

此模块是 community.windows 集合 (版本 2.3.0) 的一部分。

如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install community.windows

要在 playbook 中使用它,请指定: community.windows.win_certificate_info

概要

  • 返回有关 Windows 证书存储区中证书的信息。

参数

参数

注释

store_location

字符串

要搜索的存储区位置。

选项

  • "CurrentUser"

  • "LocalMachine" ← (默认)

store_name

字符串

要搜索的存储区名称。

有关内置存储区名称列表,请参阅 https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.storename

默认值: "My"

thumbprint

字符串

要查找的证书的十六进制字符串指纹。

指定后,会将 *certificates* 返回值过滤为单个证书

请参阅示例,了解如何设置指纹格式。

另请参阅

另请参阅

ansible.windows.win_certificate_store

管理证书存储区。

示例

- name: Obtain information about a particular certificate in the computer's personal store
  community.windows.win_certificate_info:
    thumbprint: BD7AF104CF1872BDB518D95C9534EA941665FD27
  register: mycert

# thumbprint can also be lower case
- name: Obtain information about a particular certificate in the computer's personal store
  community.windows.win_certificate_info:
    thumbprint: bd7af104cf1872bdb518d95c9534ea941665fd27
  register: mycert

- name: Obtain information about all certificates in the root store
  community.windows.win_certificate_info:
    store_name: Root
  register: ca

# Import a pfx and then get information on the certificates
- name: Import pfx certificate that is password protected
  ansible.windows.win_certificate_store:
    path: C:\Temp\cert.pfx
    state: present
    password: VeryStrongPasswordHere!
  become: true
  become_method: runas
  register: mycert

- name: Obtain information on each certificate that was touched
  community.windows.win_certificate_info:
    thumbprint: "{{ item }}"
  register: mycert_stats
  loop: "{{ mycert.thumbprints }}"

返回值

常见的返回值已在此处记录 此处,以下是此模块独有的字段

描述

certificates

列表 / 元素=字典

存储区中找到的证书信息的列表,按指纹排序。

已返回:成功

archived

布尔值

指示证书是否已存档。

已返回:成功

示例: false

cert_data

字符串

整个证书的 Base64 编码数据。

已返回:成功

dns_names

列表 / 元素=字符串

列出证书的已注册 DNS 名称。

已返回:成功

示例: ["*.m.wikiquote.org", "*.wikipedia.org"]

extensions

列表 / 元素=字典

证书扩展的集合。

已返回:成功

示例: [{"critical": false, "field": "主题密钥标识符", "value": "88 27 17 09 a9 b6 18 60 8b ec eb ba f6 47 59 c5 52 54 a3 b7"}, {"critical": true, "field": "基本约束", "value": "主题类型=CA,路径长度约束=无"}, {"critical": false, "field": "授权密钥标识符", "value": "KeyID=2b d0 69 47 94 76 09 fe f4 6b 8d 2e 40 a6 f7 47 4d 7f 08 5e"}, {"critical": false, "field": "CRL分发点", "value": "[1]CRL分发点:分发点名称:完整名称:URL=http://crl.apple.com/root.crl"}, {"critical": true, "field": "密钥用法", "value": "数字签名,证书签名,脱机CRL签名,CRL签名(86)"}, {"critical": false, "field": null, "value": "05 00"}]

friendly_name

字符串

证书的关联别名。

已返回:成功

示例: "Microsoft Root Authority"

has_private_key

布尔值

指示证书是否包含私钥。

已返回:成功

示例: false

intended_purposes

列表 / 元素=字符串

列出证书的预期用途。

返回:存在增强密钥使用扩展。

示例: ["Server Authentication"]

is_ca

布尔值

指示证书是否为证书颁发机构 (CA) 证书。

返回:存在基本约束扩展。

示例: true

issued_by

字符串

证书颁发者的常用名。

已返回:成功

示例: "Apple Root CA"

issued_to

字符串

证书的常用名。

已返回:成功

示例: "Apple Worldwide Developer Relations Certification Authority"

issuer

字符串

证书颁发者的可分辨名称。

已返回:成功

示例: "CN=Apple Root CA, OU=Apple Certification Authority, O=Apple Inc., C=US"

key_usages

列表 / 元素=字符串

定义证书密钥的使用方式。

如果未定义此值,则密钥可用于任何目的。

返回:存在密钥使用扩展。

示例: ["CrlSign", "KeyCertSign", "DigitalSignature"]

path_length_constraint

整数

证书路径中允许的级别数。

如果此值为 0,则证书没有限制。

返回:存在基本约束扩展

示例: 0

public_key

字符串

证书的base64编码公钥。

已返回:成功

serial_number

字符串

以十六进制字符串表示的证书序列号

已返回:成功

示例: "01DEBCC4396DA010"

signature_algorithm

字符串

用于创建证书签名的算法

已返回:成功

示例: "sha1RSA"

ski

字符串

证书的主题密钥标识符

返回:存在主题密钥标识符扩展。

示例: "88271709A9B618608BECEBBAF64759C55254A3B7"

subject

字符串

证书的可分辨名称。

已返回:成功

示例: "CN=Apple Worldwide Developer Relations Certification Authority, OU=Apple Worldwide Developer Relations, O=Apple Inc., C=US"

thumbprint

字符串

证书的十六进制指纹字符串。

返回格式始终为大写。

已返回:成功

示例: "FF6797793A3CD798DC5B2ABEF56F73EDC9F83A64"

valid_from

浮点数

以自纪元以来的秒数表示的证书开始日期。

已返回:成功

示例: 1360255727.0

valid_from_iso8601

字符串

以ISO8601格式表示的证书开始日期。

已返回:成功

示例: "2017-12-15T08:39:32Z"

valid_to

浮点数

以自纪元以来的秒数表示的证书过期日期。

已返回:成功

示例: 1675788527.0

valid_to_iso8601

字符串

以ISO8601格式表示的证书过期日期。

已返回:成功

示例: "2086-01-02T08:39:32Z"

version

整数

证书的X.509格式版本

已返回:成功

示例: 3

exists

布尔值

存储区中是否存在任何证书。

当指定了 *thumbprint* 时,只有在与指纹匹配的证书存在时才返回 true。

已返回:成功

示例: true

作者

  • Micah Hunsberger (@mhunsber)