ClickOnce配置マニフェストを動的に生成して署名するために使用しているThawteからのコード署名証明書を取得しました。問題は、IISを再起動するか、署名証明書を再インポートすると、これらのマニフェストを生成して署名するASP.NETアプリケーションが正常に機能することですが、時間の経過とともに、次の関数が証明書を見つけることができません。
private static X509Certificate2 GetSigningCertificate(string thumbprint)
{
X509Store x509Store = new X509Store(StoreLocation.CurrentUser);
try
{
x509Store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection x509Certificate2Collection = x509Store.Certificates.Find(
X509FindType.FindByThumbprint, thumbprint, false);
if (x509Certificate2Collection.Count == 0)
throw new ApplicationException(
"SigningThumbprint returned 0 results. Does the code signing certificate exist in the personal store?",
null);
if (x509Certificate2Collection.Count > 1)
throw new ApplicationException(
"SigningThumbprint returned more than 1 result. This isn't possible", null);
var retval = x509Certificate2Collection[0];
if(retval.PrivateKey.GetType() != typeof(RSACryptoServiceProvider))
throw new ApplicationException("Only RSA certificates are allowed for code signing");
return retval;
}
finally
{
x509Store.Close();
}
}
最終的に、アプリケーションは証明書を見つけることができないというエラーをスローし始めます。ASP.NETアプリケーションを起動したときに証明書が検出されるため、証明書が正しく(またはほとんど正しく)インストールされていると思うので困惑していますが、ある時点でCount == 0ブランチに到達し、それは正しくありません。証明書は、アプリケーションプールユーザーの「CurrentUser\Personal」証明書ストアにあります。
質問:証明書が突然「消える」か、見つからないのはなぜですか?