有没有一种方法可以立即使CRL(证书吊销列表)缓存失效,从而导致客户端重新下载CRL?
我希望在不使用命令行“certutil.exe”的情况下,在C#中实现它。
更好的做法是能够设置失效时间(例如UtcNow + 12小时)
有没有一种方法可以立即使CRL(证书吊销列表)缓存失效,从而导致客户端重新下载CRL?
我希望在不使用命令行“certutil.exe”的情况下,在C#中实现它。
更好的做法是能够设置失效时间(例如UtcNow + 12小时)
我已经实现了这样的解决方案,它会根据计划程序设置每隔x小时更新客户端机器上的CRL缓存。您可以在此处阅读有关CRL的更多信息: http://social.technet.microsoft.com/wiki/contents/articles/4954.certificate-status-and-revocation-checking.aspx
CRL缓存存储在客户端机器的特殊文件夹中,由Metadata和Content文件夹中的两个文件组成。这些文件夹位于“C:\Documents and Settings{user name}\Application Data\Microsoft\CryptnetUrlCache”中,而机器级别的缓存位置为“%WINDIR%\System32\config\SystemProfile\Application Data\Microsoft\CryptnetUrlCache”。 缓存文件以CRL URL的MD5哈希值命名。 “Metadata”文件夹中的文件包含一些常量数据、上次更新日期、CRL URL、CRL文件大小等信息。而“Content”文件夹中的文件是CRL文件本身,并与“Metadata”文件夹中的文件同名。 我解析元文件,检查其是否无效,并通过CRL URL加载新的CRL文件,将其放置在“Content”文件夹中并重建元数据文件。 我使用BouncyCastle库来完成这些操作。作为计划程序库,我使用Quartz.Net。
我知道你不想使用certutil.exe
,但是这种方式可以让你在应用程序中运行它,而无需出现命令窗口,如果这就是你不想要的。
public bool ClearCRLCache()
{
var pw = new ProcessWrapper();
var result = pw.Start("certutil.exe", "-urlcache * delete");
// -2147024637 is the exitcode when the urlcache is empty
return (result == 0 || result == -2147024637);
}
ProcessWrapper类:
public class ProcessWrapper
{
/// <summary>
/// Output from stderr
/// </summary>
public string StdErr { get; private set; }
/// <summary>
/// Output from stdout
/// </summary>
public string StdOut { get; private set; }
/// <summary>
/// Starts a process
/// </summary>
/// <param name="command">Executable filename</param>
/// <returns>Process exitcode</returns>
public int Start(string command)
{
return Start(command, "");
}
/// <summary>
/// Starts a process with commandline arguments
/// </summary>
/// <param name="command">Executable filename</param>
/// <param name="arguments">Commanline arguments for the process</param>
/// <returns>Process exitcode</returns>
public int Start(string command, string arguments)
{
return Start(command, arguments, "");
}
/// <summary>
/// Starts a process with commandline arguments and working directory
/// </summary>
/// <param name="command">Executable filename</param>
/// <param name="arguments">Commanline arguments for the process</param>
/// <param name="workingDirectory">Working directory for the process</param>
/// <returns>Process exitcode</returns>
public int Start(string command, string arguments, string workingDirectory)
{
StdErr = "";
StdOut = "";
var proc = new Process();
proc.StartInfo.FileName = command;
proc.StartInfo.Arguments = arguments;
proc.StartInfo.WorkingDirectory = workingDirectory;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.EnableRaisingEvents = true;
proc.StartInfo.CreateNoWindow = true;
// Write messages from stderr to StdErr property
proc.ErrorDataReceived += (sender, e) =>
{
StdErr += e.Data + Environment.NewLine;
};
// Write messages from stdout to StdOut property
proc.OutputDataReceived += (sender, e) =>
{
StdOut += e.Data + Environment.NewLine;
};
proc.Start();
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
proc.WaitForExit();
return proc.ExitCode;
}
}