Commit a140f7f3 a140f7f39322bde37c71590a85fa4a040b5859c5 by Christian Gerdes

Snyggat till koden lite samt skriver ut fel även om debug inte är satt.

1 parent 269f3061
......@@ -568,8 +568,8 @@ namespace LIL_VSTT_Plugins
[DefaultValue("")]
public string pCertificatePasswordParameter { get; set; }
[DisplayName("Log Certificate Data")]
[Description("Sätt till True om certifikatinfo ska loggas i början av varje test")]
[DisplayName("Log Debug Info")]
[Description("Sätt till True om extra info ska loggas i början av varje test")]
[DefaultValue(false)]
public bool pDebug { get; set; }
......@@ -609,7 +609,7 @@ namespace LIL_VSTT_Plugins
certPass = pCertificatePassword;
}
if(string.IsNullOrWhiteSpace(certPass))
if(string.IsNullOrWhiteSpace(certPath))
{
// Cant continue, cert is missing
if (pDebug) e.WebTest.AddCommentToResult("No certificate loaded, since both Certificate Path and Certificate Path Parameter are empty");
......@@ -620,7 +620,7 @@ namespace LIL_VSTT_Plugins
myClientCert = new X509Certificate(certPath, certPass);
} catch (Exception ex)
{
if (pDebug) e.WebTest.AddCommentToResult("Exception during loading of certificate: " + certPath + " Exception: " + ex.Message);
e.WebTest.AddCommentToResult("Error during loading of certificate: " + certPath + " Message: " + ex.Message);
return;
}
......@@ -632,8 +632,12 @@ namespace LIL_VSTT_Plugins
if (pDebug) e.WebTest.AddCommentToResult("Certificate File " + certPath);
}
if (!string.IsNullOrWhiteSpace(myClientCert.GetCertHashString()))
if (string.IsNullOrWhiteSpace(myClientCert.GetCertHashString()))
{
if (pDebug) e.WebTest.AddCommentToResult("Certificate File " + certPath + " contains no SHA1 hash. Not using it.");
return;
}
if (pDebug) e.WebTest.AddCommentToResult("Loaded client certificate for Subject: [" + myClientCert.Subject + "] Issued by: [" + myClientCert.Issuer + "] Expires: [" + myClientCert.GetExpirationDateString() + "]");
// Check if the certificate is trusted (i.e. chain can be validated)
......@@ -646,15 +650,20 @@ namespace LIL_VSTT_Plugins
myCertTrusted = true;
} else
{
if (pDebug) e.WebTest.AddCommentToResult("Waring: Certificate is NOT TRUSTED by client. Might not be trusted on server either. Check that the Issuer/CA root and intermediary certificates are installed on the client and server.");
e.WebTest.AddCommentToResult("Warning: Certificate is NOT TRUSTED by client. Might not be trusted on server either. Check that the Issuer/CA root and intermediary certificates are installed on the client and server.");
myCertTrusted = false;
}
if(cer.NotAfter < DateTime.Now || cer.NotBefore > DateTime.Now)
{
e.WebTest.AddCommentToResult("Warning: Client Certificate has expired. Might not be trusted on server.");
}
// Check if we have a private key
if (!cer.HasPrivateKey)
{
// Cant use it without private key
if (pDebug) e.WebTest.AddCommentToResult("Certificate HAS NO PRIVATE KEY, cannot use it without one.");
e.WebTest.AddCommentToResult("Error: Certificate HAS NO PRIVATE KEY, cannot use it without one.");
return;
} else
{
......@@ -680,7 +689,7 @@ namespace LIL_VSTT_Plugins
if (pDebug) e.WebTest.AddCommentToResult("Certificate HAS BEEN INSTALLED in the Windows Certificate Store");
} catch (Exception ex)
{
if (pDebug) e.WebTest.AddCommentToResult("Error: COULD NOT INSTALL in the Windows Certificate Store, Exception: " + ex.Message);
e.WebTest.AddCommentToResult("Error: COULD NOT INSTALL in the Windows Certificate Store, Message: " + ex.Message);
return;
}
}
......@@ -690,11 +699,6 @@ namespace LIL_VSTT_Plugins
// Set the PreRequest method to add the certificate on requests
haveCert = true;
if (pDebug) e.WebTest.AddCommentToResult("Certificate will be ADDED TO REQUESTS");
} else
{
if (pDebug) e.WebTest.AddCommentToResult("Certificate File " + certPath + " contains no SHA1 hash. Not using it.");
return;
}
}
public override void PreRequest(object sender, PreRequestEventArgs e)
......