Skip to content

Commit

Permalink
win_certificate_store - fix CertificateAuthority -> CA (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
jborean93 authored May 8, 2021
1 parent 2a4950c commit a21cdc7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/win_certificate_store-ca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- >-
win_certificate_store - Make sure `store_name: CertificateAuthority` refers to the `CA` store for backwards
compatibility - https://github.com/ansible-collections/ansible.windows/pull/216
7 changes: 7 additions & 0 deletions plugins/modules/win_certificate_store.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ $module.Result.thumbprints = @()
[Security.Cryptography.X509Certificates.OpenFlags]$open_flags = if ($state -eq 'exported') { 'ReadOnly' } else { 'ReadWrite' }
$open_flags = [int]$open_flags -bor [int][Security.Cryptography.X509Certificates.OpenFlags]::OpenExistingOnly

# We originally opened the store with [X509]::new($name, $location). Now that we call the necessary Win32 APIs we need
# map any of the StoreName enum values to the proper string name. Luckily that is just CertificateAuthority -> CA.
# https://github.com/microsoft/referencesource/blob/master/System/security/system/security/cryptography/x509/x509store.cs#L67-L91
if ($store_name -eq 'CertificateAuthority') {
$store_name = 'CA'
}

$cert_params = @{
Name = $store_name
}
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/targets/win_certificate_store/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,17 @@
win_certificate_store:
path: '{{win_cert_dir}}\chain.p7b'
state: present
store_name: TrustedPeople
store_name: CertificateAuthority
store_location: CurrentUser
register: import_der_p7b_check
check_mode: yes

- name: get result of subj in p7b chain in custom store (check)
win_shell: if (Get-ChildItem -Path Cert:\CurrentUser\TrustedPeople | Where-Object { $_.Thumbprint -eq "{{subj_thumbprint}}" }) { $true } else { $false }
win_shell: if (Get-ChildItem -Path Cert:\CurrentUser\CA | Where-Object { $_.Thumbprint -eq "{{subj_thumbprint}}" }) { $true } else { $false }
register: import_der_p7b_subj_result_check

- name: get result of root in p7b chain in custom store (check)
win_shell: if (Get-ChildItem -Path Cert:\CurrentUser\TrustedPeople | Where-Object { $_.Thumbprint -eq "{{root_thumbprint}}" }) { $true } else { $false }
win_shell: if (Get-ChildItem -Path Cert:\CurrentUser\CA | Where-Object { $_.Thumbprint -eq "{{root_thumbprint}}" }) { $true } else { $false }
register: import_der_p7b_root_result_check

- name: assert results of import DER encoded p7b chain into custom store (check)
Expand All @@ -326,16 +326,16 @@
win_certificate_store:
path: '{{win_cert_dir}}\chain.p7b'
state: present
store_name: TrustedPeople
store_name: CertificateAuthority
store_location: CurrentUser
register: import_der_p7b

- name: get result of subj in p7b chain in custom store
win_shell: if (Get-ChildItem -Path Cert:\CurrentUser\TrustedPeople | Where-Object { $_.Thumbprint -eq "{{subj_thumbprint}}" }) { $true } else { $false }
win_shell: if (Get-ChildItem -Path Cert:\CurrentUser\CA | Where-Object { $_.Thumbprint -eq "{{subj_thumbprint}}" }) { $true } else { $false }
register: import_der_p7b_subj_result

- name: get result of root in p7b chain in custom store
win_shell: if (Get-ChildItem -Path Cert:\CurrentUser\TrustedPeople | Where-Object { $_.Thumbprint -eq "{{root_thumbprint}}" }) { $true } else { $false }
win_shell: if (Get-ChildItem -Path Cert:\CurrentUser\CA | Where-Object { $_.Thumbprint -eq "{{root_thumbprint}}" }) { $true } else { $false }
register: import_der_p7b_root_result

- name: assert results of import DER encoded p7b chain into custom store
Expand All @@ -352,7 +352,7 @@
win_certificate_store:
path: '{{win_cert_dir}}\chain.p7b'
state: present
store_name: TrustedPeople
store_name: CertificateAuthority
store_location: CurrentUser
register: import_der_p7b_again

Expand All @@ -365,7 +365,7 @@
win_certificate_store:
thumbprint: '{{item}}'
state: absent
store_name: TrustedPeople
store_name: CertificateAuthority
store_location: CurrentUser
with_items:
- '{{subj_thumbprint}}'
Expand Down

0 comments on commit a21cdc7

Please sign in to comment.