Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. @ericlaw1979 ericlaw1979 revised this gist Jan 25, 2016. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion WarningBeforeCertExpires.js
    Original file line number Diff line number Diff line change
    @@ -10,8 +10,13 @@
    new System.Security.Cryptography.X509Certificates.X509Certificate2(e.ServerCertificate);

    // Cert expires in next 30 days
    if (DateTime.Now.AddDays(30) > X2.NotAfter)
    if (DateTime.UtcNow.AddDays(30) > X2.NotAfter)
    {
    if (DateTime.UtcNow.AddDays(5) > X2.NotAfter)
    {
    FiddlerApplication.AlertUser("Certificate Expiring!",
    "The certificate for " + e.Session.hostname + " is expiring " + X2.NotAfter.ToShortDateString() + "!");
    }
    e.Session["ui-backcolor"] = "red";

    e.Session["ui-Comments"] = "Cert Expires:" + e.ServerCertificate.GetExpirationDateString();
  2. @ericlaw1979 ericlaw1979 created this gist Jan 23, 2016.
    25 changes: 25 additions & 0 deletions WarningBeforeCertExpires.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    // Inside Rules > Customize Rules > OnBoot, add the following line:
    FiddlerApplication.add_OnValidateServerCertificate(onEvalCert);

    // Just before that function, add the following new function:
    static function onEvalCert(o: Object, e: ValidateServerCertificateEventArgs)
    {
    try
    {
    var X2: System.Security.Cryptography.X509Certificates.X509Certificate2 =
    new System.Security.Cryptography.X509Certificates.X509Certificate2(e.ServerCertificate);

    // Cert expires in next 30 days
    if (DateTime.Now.AddDays(30) > X2.NotAfter)
    {
    e.Session["ui-backcolor"] = "red";

    e.Session["ui-Comments"] = "Cert Expires:" + e.ServerCertificate.GetExpirationDateString();
    e.Session.RefreshUI();
    }
    }
    catch (ex)
    {
    FiddlerApplication.Log.LogFormat("Failed to evaluate certificate: {0}", ex.Message);
    }
    }