From 568379e781ec41aa2e2b6cc4b03975336c67a2c4 Mon Sep 17 00:00:00 2001 From: Jordan Pitlor Date: Wed, 6 Sep 2023 23:08:25 -0400 Subject: [PATCH] win_acl/Certificates: Rename CryptHandle to SafeCryptHandle --- plugins/module_utils/_CertACLHelper.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/module_utils/_CertACLHelper.cs b/plugins/module_utils/_CertACLHelper.cs index 1dac8fca..d8c6a05b 100644 --- a/plugins/module_utils/_CertACLHelper.cs +++ b/plugins/module_utils/_CertACLHelper.cs @@ -15,9 +15,9 @@ namespace ansible_collections.ansible.windows.plugins.module_utils._CertACLHelper { - internal class CryptHandle : SafeHandleZeroOrMinusOneIsInvalid + internal class SafeCryptHandle : SafeHandleZeroOrMinusOneIsInvalid { - public CryptHandle() + public SafeCryptHandle() : base(true) { } @@ -102,13 +102,13 @@ private enum KeySpec : uint } [DllImport("crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - private static extern bool CryptAcquireCertificatePrivateKey(IntPtr pCert, uint dwFlags, IntPtr pvParameters, out CryptHandle phCryptProvOrNCryptKey, out KeySpec pdwKeySpec, out bool pfCallerFreeProvOrNCryptKey); + private static extern bool CryptAcquireCertificatePrivateKey(IntPtr pCert, uint dwFlags, IntPtr pvParameters, out SafeCryptHandle phCryptProvOrNCryptKey, out KeySpec pdwKeySpec, out bool pfCallerFreeProvOrNCryptKey); [DllImport("ncrypt.dll", CharSet = CharSet.Unicode, SetLastError = true)] - private static extern int NCryptGetProperty(CryptHandle hObject, [MarshalAs(UnmanagedType.LPWStr)] string pszProperty, SafeSecurityDescriptorPtr pbOutput, uint cbOutput, ref uint pcbResult, SecurityInformationFlags dwFlags); + private static extern int NCryptGetProperty(SafeCryptHandle hObject, [MarshalAs(UnmanagedType.LPWStr)] string pszProperty, SafeSecurityDescriptorPtr pbOutput, uint cbOutput, ref uint pcbResult, SecurityInformationFlags dwFlags); [DllImport("ncrypt.dll", CharSet = CharSet.Unicode, SetLastError = true)] - private static extern int NCryptSetProperty(CryptHandle hObject, [MarshalAs(UnmanagedType.LPWStr)] string pszProperty, [MarshalAs(UnmanagedType.LPArray)] byte[] pbInput, uint cbInput, SecurityInformationFlags dwFlags); + private static extern int NCryptSetProperty(SafeCryptHandle hObject, [MarshalAs(UnmanagedType.LPWStr)] string pszProperty, [MarshalAs(UnmanagedType.LPArray)] byte[] pbInput, uint cbInput, SecurityInformationFlags dwFlags); private enum CryptProvParam : uint { @@ -117,18 +117,18 @@ private enum CryptProvParam : uint [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool CryptGetProvParam(CryptHandle safeProvHandle, CryptProvParam dwParam, SafeSecurityDescriptorPtr pbData, ref uint dwDataLen, SecurityInformationFlags dwFlags); + private static extern bool CryptGetProvParam(SafeCryptHandle safeProvHandle, CryptProvParam dwParam, SafeSecurityDescriptorPtr pbData, ref uint dwDataLen, SecurityInformationFlags dwFlags); [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool CryptSetProvParam(CryptHandle safeProvHandle, CryptProvParam dwParam, [MarshalAs(UnmanagedType.LPArray)] byte[] pbData, SecurityInformationFlags dwFlags); + private static extern bool CryptSetProvParam(SafeCryptHandle safeProvHandle, CryptProvParam dwParam, [MarshalAs(UnmanagedType.LPArray)] byte[] pbData, SecurityInformationFlags dwFlags); - CryptHandle handle; + SafeCryptHandle handle; bool ncrypt = false; public CertAclHelper(X509Certificate2 certificate) { - CryptHandle certPkeyHandle; + SafeCryptHandle certPkeyHandle; KeySpec keySpec; bool ownHandle;