none
Create a web plugin for passing client certificates RRS feed

  • Question

  • I have created a web performance project and have multiple services configured. Now, I need to change the URL and this new URL needs a client certificate to be attached.

    I got some posts which shows me how to create plugins. I need to display a drop down with all the client certificates displayed as a dropdown in my custom plugin. Once selected that needs to be passed. 

    Can anyone let me know if there is something similar already or any guidance ?

    Wednesday, May 31, 2017 2:28 AM

All replies

  • Hi Sameer,

    Can you pleese tell what type of you are trying to build WinForm, WPF, WCF, ASP.Net, UWP?


    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Wednesday, May 31, 2017 12:12 PM
  • I am creating a Web Performance and load testing project using Visual Studio 2017. Its a *.webtest.
    Wednesday, May 31, 2017 2:20 PM
  • Hi Sameer S Panicker,

    Thank you for posting here.

    For your question what is the type of your project?

    If you question is more related to ASP.NET, you could post a new thread in ASP.NET forum for suitable support.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 1, 2017 2:49 AM
  • Its a webtest project.
    Thursday, June 1, 2017 3:14 AM
  • Hi Sameer S Panicker,

    I will move it to Test Tools in Visual Studio 2010 and 2012 forum for suitable support.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 1, 2017 6:29 AM
  • I am not aware of anything that does what you want. There appear to be two parts to the problem: (a) Creating the popup list and selecting an entry; and, (b) Adding certificates to requests. It is not clear which you need help with in the plugin.

    For the popup. One of my tests was of a site that had a "Captcha" that could not be turned of during the initial test development. I wrote a plugin that used Windows Forms to open a Window into which the text from the image could be manually typed. The plugin then saved that text into a context parameter for use in the next request.

    For the certificates. You could base your plugin on the following. Note that the certificates probably need to be added to all requests including dependants.

    using Microsoft.VisualStudio.TestTools.WebTesting;
    using System;
    using System.ComponentModel;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    
    // Based on https://social.msdn.microsoft.com/Forums/en-US/e639498b-3e3b-4c47-8a38-b910a8be70fc/ssl-in-webtests-vsts-2008-and-2010?forum=vstswebtest
    
    namespace Plugins
    {
        [Description("This plugin will force the underlying System.Net ServicePointManager to negotiate the security protocol set in the code."
         +" WARNING: The servers X509 Certificate will be ignored as part of this process, so verify that you are testing the correct system.")]
        public class ForceSecurityProtocol : WebTestPlugin
        {
            public override void PreWebTest(object sender, PreWebTestEventArgs e)
            {
                base.PreWebTest(sender, e);
    
                // We're using SSL3 here and not TLS. Without this line, nothing works.
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    
                //we wire up the callback so we can override behavior and force it to accept the cert
                ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCB;
    
                //let them know we made changes to the service point manager
                e.WebTest.AddCommentToResult("ServicePointManager.SecurityProtocol set to " + ServicePointManager.SecurityProtocol.ToString());
            }
            public static bool RemoteCertificateValidationCB(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            {
                //If it is really important, validate the certificate issuer here.
                //This code will accept any certificate
                return true;
            }
    
            public override void PreRequest(object sender, PreRequestEventArgs e)
            {
                AddCertificates(e.Request);
            }
    
            private void AddCertificates(WebTestRequest wtr)
            {
                wtr.ClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate(@"c:\Certificates\test1.pfx","SomeName1"));
            }
    
            public override void PostRequest(object sender, PostRequestEventArgs e)
            {
                foreach (WebTestRequest rr in e.Request.DependentRequests)
                {
                    AddCertificates(rr);
                }
            }
        }
    }

    Regards

    Adrian

    Thursday, June 1, 2017 8:35 AM