簡體   English   中英

使CRL緩存無效

[英]Invalidate CRL cache

有沒有辦法立即使CRL(證書吊銷列表)緩存無效,導致客戶端再次下載CRL?

我想在C#中實現它,而無需使用命令行'certutil.exe'。

更好的是能夠設置失效時間(如UtcNow + 12hours)

我已經實現了這樣的解決方案,它每隔x小時更新客戶端計算機上的CRL緩存,具體取決於調度程序設置。 你可以在這里閱讀有關CRL的信息: http//social.technet.microsoft.com/wiki/contents/articles/4954.certificate-status-and-revocation-checking.aspx

CRL緩存存儲在客戶端計算機上的特殊文件夾中,由兩個存儲在元數據和內容文件夾中的文件組成。 這些文件夾位於“C:\\ Documents and Settings {用戶名} \\ Application Data \\ Microsoft \\ CryptnetUrlCache”中,每台計算機緩存位置為“%WINDIR%\\ System32 \\ config \\ SystemProfile \\ Application Data \\ Microsoft \\ CryptnetUrlCache” 。 Cahce文件以CRL url的MD5哈希值命名。 文件夾“元數據”中的文件包含一些常量數據,上次更新日期,CRL URL,CRL文件大小等。 “Content”文件夾中的文件是CRL文件本身,與“Metadata”中的文件同名。 我解析元文件,檢查它是否無效並通過CRL url加載新的CRL文件,將其放到“Content”文件夾並重建元數據文件。 我將BouncyCastle庫用於這些目的。 作為調度庫,我使用Quartz.Net。

我知道您不想使用certutil.exe但這樣您就可以在應用程序中運行它而不顯示cmd窗口,如果這是您不想要的。

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;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM