Snyggat till koden lite samt skriver ut fel även om debug inte är satt.
Showing
1 changed file
with
17 additions
and
13 deletions
... | @@ -568,8 +568,8 @@ namespace LIL_VSTT_Plugins | ... | @@ -568,8 +568,8 @@ namespace LIL_VSTT_Plugins |
568 | [DefaultValue("")] | 568 | [DefaultValue("")] |
569 | public string pCertificatePasswordParameter { get; set; } | 569 | public string pCertificatePasswordParameter { get; set; } |
570 | 570 | ||
571 | [DisplayName("Log Certificate Data")] | 571 | [DisplayName("Log Debug Info")] |
572 | [Description("Sätt till True om certifikatinfo ska loggas i början av varje test")] | 572 | [Description("Sätt till True om extra info ska loggas i början av varje test")] |
573 | [DefaultValue(false)] | 573 | [DefaultValue(false)] |
574 | public bool pDebug { get; set; } | 574 | public bool pDebug { get; set; } |
575 | 575 | ||
... | @@ -609,7 +609,7 @@ namespace LIL_VSTT_Plugins | ... | @@ -609,7 +609,7 @@ namespace LIL_VSTT_Plugins |
609 | certPass = pCertificatePassword; | 609 | certPass = pCertificatePassword; |
610 | } | 610 | } |
611 | 611 | ||
612 | if(string.IsNullOrWhiteSpace(certPass)) | 612 | if(string.IsNullOrWhiteSpace(certPath)) |
613 | { | 613 | { |
614 | // Cant continue, cert is missing | 614 | // Cant continue, cert is missing |
615 | if (pDebug) e.WebTest.AddCommentToResult("No certificate loaded, since both Certificate Path and Certificate Path Parameter are empty"); | 615 | 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 | ... | @@ -620,7 +620,7 @@ namespace LIL_VSTT_Plugins |
620 | myClientCert = new X509Certificate(certPath, certPass); | 620 | myClientCert = new X509Certificate(certPath, certPass); |
621 | } catch (Exception ex) | 621 | } catch (Exception ex) |
622 | { | 622 | { |
623 | if (pDebug) e.WebTest.AddCommentToResult("Exception during loading of certificate: " + certPath + " Exception: " + ex.Message); | 623 | e.WebTest.AddCommentToResult("Error during loading of certificate: " + certPath + " Message: " + ex.Message); |
624 | return; | 624 | return; |
625 | } | 625 | } |
626 | 626 | ||
... | @@ -632,8 +632,12 @@ namespace LIL_VSTT_Plugins | ... | @@ -632,8 +632,12 @@ namespace LIL_VSTT_Plugins |
632 | if (pDebug) e.WebTest.AddCommentToResult("Certificate File " + certPath); | 632 | if (pDebug) e.WebTest.AddCommentToResult("Certificate File " + certPath); |
633 | } | 633 | } |
634 | 634 | ||
635 | if (!string.IsNullOrWhiteSpace(myClientCert.GetCertHashString())) | 635 | if (string.IsNullOrWhiteSpace(myClientCert.GetCertHashString())) |
636 | { | 636 | { |
637 | if (pDebug) e.WebTest.AddCommentToResult("Certificate File " + certPath + " contains no SHA1 hash. Not using it."); | ||
638 | return; | ||
639 | } | ||
640 | |||
637 | if (pDebug) e.WebTest.AddCommentToResult("Loaded client certificate for Subject: [" + myClientCert.Subject + "] Issued by: [" + myClientCert.Issuer + "] Expires: [" + myClientCert.GetExpirationDateString() + "]"); | 641 | if (pDebug) e.WebTest.AddCommentToResult("Loaded client certificate for Subject: [" + myClientCert.Subject + "] Issued by: [" + myClientCert.Issuer + "] Expires: [" + myClientCert.GetExpirationDateString() + "]"); |
638 | 642 | ||
639 | // Check if the certificate is trusted (i.e. chain can be validated) | 643 | // Check if the certificate is trusted (i.e. chain can be validated) |
... | @@ -646,15 +650,20 @@ namespace LIL_VSTT_Plugins | ... | @@ -646,15 +650,20 @@ namespace LIL_VSTT_Plugins |
646 | myCertTrusted = true; | 650 | myCertTrusted = true; |
647 | } else | 651 | } else |
648 | { | 652 | { |
649 | 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."); | 653 | 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."); |
650 | myCertTrusted = false; | 654 | myCertTrusted = false; |
651 | } | 655 | } |
652 | 656 | ||
657 | if(cer.NotAfter < DateTime.Now || cer.NotBefore > DateTime.Now) | ||
658 | { | ||
659 | e.WebTest.AddCommentToResult("Warning: Client Certificate has expired. Might not be trusted on server."); | ||
660 | } | ||
661 | |||
653 | // Check if we have a private key | 662 | // Check if we have a private key |
654 | if (!cer.HasPrivateKey) | 663 | if (!cer.HasPrivateKey) |
655 | { | 664 | { |
656 | // Cant use it without private key | 665 | // Cant use it without private key |
657 | if (pDebug) e.WebTest.AddCommentToResult("Certificate HAS NO PRIVATE KEY, cannot use it without one."); | 666 | e.WebTest.AddCommentToResult("Error: Certificate HAS NO PRIVATE KEY, cannot use it without one."); |
658 | return; | 667 | return; |
659 | } else | 668 | } else |
660 | { | 669 | { |
... | @@ -680,7 +689,7 @@ namespace LIL_VSTT_Plugins | ... | @@ -680,7 +689,7 @@ namespace LIL_VSTT_Plugins |
680 | if (pDebug) e.WebTest.AddCommentToResult("Certificate HAS BEEN INSTALLED in the Windows Certificate Store"); | 689 | if (pDebug) e.WebTest.AddCommentToResult("Certificate HAS BEEN INSTALLED in the Windows Certificate Store"); |
681 | } catch (Exception ex) | 690 | } catch (Exception ex) |
682 | { | 691 | { |
683 | if (pDebug) e.WebTest.AddCommentToResult("Error: COULD NOT INSTALL in the Windows Certificate Store, Exception: " + ex.Message); | 692 | e.WebTest.AddCommentToResult("Error: COULD NOT INSTALL in the Windows Certificate Store, Message: " + ex.Message); |
684 | return; | 693 | return; |
685 | } | 694 | } |
686 | } | 695 | } |
... | @@ -690,11 +699,6 @@ namespace LIL_VSTT_Plugins | ... | @@ -690,11 +699,6 @@ namespace LIL_VSTT_Plugins |
690 | // Set the PreRequest method to add the certificate on requests | 699 | // Set the PreRequest method to add the certificate on requests |
691 | haveCert = true; | 700 | haveCert = true; |
692 | if (pDebug) e.WebTest.AddCommentToResult("Certificate will be ADDED TO REQUESTS"); | 701 | if (pDebug) e.WebTest.AddCommentToResult("Certificate will be ADDED TO REQUESTS"); |
693 | } else | ||
694 | { | ||
695 | if (pDebug) e.WebTest.AddCommentToResult("Certificate File " + certPath + " contains no SHA1 hash. Not using it."); | ||
696 | return; | ||
697 | } | ||
698 | } | 702 | } |
699 | 703 | ||
700 | public override void PreRequest(object sender, PreRequestEventArgs e) | 704 | public override void PreRequest(object sender, PreRequestEventArgs e) | ... | ... |
-
Please register or sign in to post a comment