public void SetAccessRules(string thumbprint, IList<ApplicationAccessRule> rules, bool replaceExisting)
{
lock (m_lock)
{
IntPtr hStore = IntPtr.Zero;
try
{
// open store.
hStore = OpenStore(true, false, true);
// get the container information.
CspKeyContainerInfo container = GetCspKeyContainerInfo(hStore, thumbprint, m_symbolicName, m_storeType);
if (container == null)
{
throw ServiceResultException.Create(
StatusCodes.BadUnexpectedError,
"Could not get CspKeyContainerInfo for certificate (does the certificate exist?).\r\nType={0}, Name={1}",
m_storeType,
m_symbolicName);
}
// get the key file.
FileInfo keyFile = GetKeyFileInfo(
container.UniqueKeyContainerName,
m_storeType,
m_serviceNameOrUserSid);
// set the access rules on the file.
ApplicationAccessRule.SetAccessRules(keyFile.FullName, rules, replaceExisting);
}
finally
{
if (hStore != IntPtr.Zero)
{
NativeMethods.CertCloseStore(hStore, 0);
}
}
}
}