protected void MetaCheck_Click(object sender, EventArgs e)
    {
        if ((CheckBoxList1.Items.Cast <ListItem>().Count(li => li.Selected)) == 0)
        {
            Label2.Text          = "Please select WAP servers to view Metadata response.";
            Label2.ForeColor     = System.Drawing.ColorTranslator.FromHtml("#FF0000");
            GridView1.DataSource = null;
            GridView1.DataBind();
        }
        else
        {
            Label2.Text = "";
            AdfsSqlHelper stsName        = new AdfsSqlHelper();
            string        sts            = stsName.GetFarmName();
            var           SelectedWAPs   = CheckBoxList1.Items.Cast <ListItem>().Where(i => i.Selected).Select(i => i.ToString()).ToArray();
            DataTable     MetaCheckTable = new DataTable();
            MetaCheckTable.Columns.Add("WAP Server Name");
            MetaCheckTable.Columns.Add("IP");
            MetaCheckTable.Columns.Add("Response URL");
            MetaCheckTable.Columns.Add("Response");

            foreach (object WAP in SelectedWAPs)
            {
                IPAddress[] ipaddress = Dns.GetHostAddresses(WAP.ToString());

                DataRow row = MetaCheckTable.NewRow();
                row["WAP Server Name"] = WAP.ToString();
                foreach (IPAddress ip4 in ipaddress.Where(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork))
                {
                    row["IP"] = (ip4.ToString());
                    //
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://" + sts + "/federationmetadata/2007-06/federationmetadata.xml");//url and Host header
                    FieldInfo      field_ServicePoint_ProxyServicePoint = (typeof(ServicePoint))
                                                                          .GetField("m_ProxyServicePoint", BindingFlags.NonPublic | BindingFlags.Instance);
                    req.Proxy = new WebProxy(ip4.ToString() + ":443");//server IP and port
                    field_ServicePoint_ProxyServicePoint.SetValue(req.ServicePoint, false);
                    //req.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                    try
                    {
                        HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                        //Label9.Text = resp.Cookies.ToString();
                        row["Response URL"] = resp.ResponseUri.ToString();
                        row["Response"]     = resp.StatusCode.ToString();
                    }
                    catch (Exception MetadataExp)
                    {
                        //Label9.Text = MetadataExp.ToString();
                        row["Response URL"] = MetadataExp.Message.ToString();
                        row["Response"]     = MetadataExp.Message.ToString() + " Check Farname is correct under configuration tab and servers have correct SNI bindings.";
                        //Label1.Text = "Check Farname is correct under configuration tab and servers have correct SNI bindings.";
                        //Label1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF0000");
                    }
                }
                MetaCheckTable.Rows.Add(row);
            }

            GridView1.DataSource = MetaCheckTable;
            GridView1.DataBind();
        }
    }
    //Colour grid view end.

    protected void VipMetaCheck_Click(object sender, System.EventArgs e)
    {
        ServicePointManager.SecurityProtocol             = (SecurityProtocolType)3072; //Handle TLS.
        System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
        List <string> Selectedvips = new List <string>();

        DataTable MetaCheckTable = new DataTable();

        MetaCheckTable.Columns.Add("Site Name");
        MetaCheckTable.Columns.Add("IP");
        MetaCheckTable.Columns.Add("Response URL");
        MetaCheckTable.Columns.Add("Response");

        foreach (GridViewRow gvrow in GridView1.Rows)
        {
            var checkbox = gvrow.FindControl("CheckBoxSiteVip") as CheckBox;
            if (checkbox.Checked)
            {
                Label1.Text = "";
                AdfsSqlHelper stsName      = new AdfsSqlHelper();
                string        FarmEndpoint = stsName.GetFarmName();

                Selectedvips.Add((gvrow.FindControl("LabelVip") as Label).Text);
                DataRow row = MetaCheckTable.NewRow();
                foreach (object vip in Selectedvips)
                {
                    row["Site Name"] = (gvrow.FindControl("LabelSite") as Label).Text;
                    row["IP"]        = vip.ToString();
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://" + FarmEndpoint + "/federationmetadata/2007-06/federationmetadata.xml");//url and Host header
                    FieldInfo      field_ServicePoint_ProxyServicePoint = (typeof(ServicePoint))
                                                                          .GetField("m_ProxyServicePoint", BindingFlags.NonPublic | BindingFlags.Instance);
                    req.Proxy = new WebProxy(vip.ToString() + ":443");//server IP and port
                    field_ServicePoint_ProxyServicePoint.SetValue(req.ServicePoint, false);
                    try
                    {
                        HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                        row["Response URL"] = resp.ResponseUri.ToString();
                        row["Response"]     = resp.StatusCode.ToString();
                    }
                    catch (Exception MetadataExp)
                    {
                        row["Response URL"] = MetadataExp.Message.ToString();
                        row["Response"]     = MetadataExp.Message.ToString();
                    }
                }
                MetaCheckTable.Rows.Add(row);
            }
            else if (Selectedvips.Count == 0)
            {
                Label1.Text      = "Please select a VIP";
                Label1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF0000");
            }
        }//foreach
        GridView2.DataSource = MetaCheckTable;
        GridView2.DataBind();
    }//VipMetaCheck_Click end.
    protected void Page_Load(object sender, EventArgs e)
    {
        AdfsSqlHelper stsName = new AdfsSqlHelper();
        string        sts     = stsName.GetFarmName();

        Label2.Text = sts;
        if (sts != "")
        {
            Label2.Text      = sts;
            Label2.ForeColor = System.Drawing.ColorTranslator.FromHtml("#006400");
        }
        else
        {
            Label2.Text      = "No farm name found. Add a farm name under configuration.";
            Label2.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF0000");
        }

        if (!Page.IsPostBack)
        {
            refreshdata();
        }
    }
Beispiel #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        AdfsSqlHelper stsName = new AdfsSqlHelper();
        string        sts     = stsName.GetFarmName();

        Label1.Text = sts;
        if (sts != "")
        {
            Label1.Text      = sts;
            Label1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#006400");
        }
        else
        {
            Label1.Text      = "No farm name found. Add one.";
            Label1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF0000");
        }
        //
        if (!IsPostBack)
        {
            PopulateGridView();
        }
        //
    }
    protected void GetTokenasUser_Click(object sender, EventArgs e)
    {
        List <string> Selectedvips  = new List <string>();
        DataTable     VipTokenTable = new DataTable();

        VipTokenTable.Columns.Add("Site Name");
        VipTokenTable.Columns.Add("VIP");
        VipTokenTable.Columns.Add("TargetIdentifier");
        VipTokenTable.Columns.Add("TokenResponse");

        if (DropDownList1.SelectedItem != null)
        {
            foreach (GridViewRow gvrow in GridView1.Rows)
            {
                var checkbox = gvrow.FindControl("CheckBoxSiteVip") as CheckBox;
                if (checkbox.Checked)
                {
                    Label1.Text = "";
                    AdfsSqlHelper stsName      = new AdfsSqlHelper();
                    string        FarmEndpoint = stsName.GetFarmName();

                    Selectedvips.Add((gvrow.FindControl("LabelVip") as Label).Text);
                    DataRow row = VipTokenTable.NewRow();
                    foreach (object vip in Selectedvips)
                    {
                        row["Site Name"] = (gvrow.FindControl("LabelSite") as Label).Text;
                        row["VIP"]       = vip.ToString();

                        String appliesTo        = DropDownList1.SelectedItem.Text;
                        String federationServer = vip.ToString();
                        String endpoint         = "https://" + federationServer + "/adfs/services/trust/2005/usernamemixed";

                        string username = TextBox2.Text;
                        string password = TextBox3.Text.Protect();

                        //Crafted RST. Do not alter.
                        String RST = String.Format("<s:Envelope xmlns:s=" +
                                                   "\"http://www.w3.org/2003/05/soap-envelope\"" +
                                                   " " + "xmlns:a=" + "\"http://www.w3.org/2005/08/addressing\"" +
                                                   " " + "xmlns:u=" + "\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"" +
                                                   "><s:Header><a:Action s:mustUnderstand=" +
                                                   "\"1\"" + ">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue" +
                                                   "</a:Action><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand=" +
                                                   "\"1\"" + ">" + endpoint + "</a:To><o:Security s:mustUnderstand=" +
                                                   "\"1\"" + " " + "xmlns:o=" + "\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"" +
                                                   "><o:UsernameToken><o:Username>" + username + "</o:Username><o:Password Type=" +
                                                   "\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\"" +
                                                   ">" + password.Unprotect() + "</o:Password></o:UsernameToken></o:Security></s:Header><s:Body><t:RequestSecurityToken xmlns:t=" +
                                                   "\"http://schemas.xmlsoap.org/ws/2005/02/trust\"" + "><wsp:AppliesTo xmlns:wsp=" +
                                                   "\"http://schemas.xmlsoap.org/ws/2004/09/policy\"" + "><a:EndpointReference><a:Address>" + appliesTo +
                                                   "</a:Address></a:EndpointReference></wsp:AppliesTo><t:KeySize>0</t:KeySize><t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType><t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType><t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType></t:RequestSecurityToken></s:Body></s:Envelope>");

                        //String ComputedRST = String.Format(RST, endpoint, appliesTo);
                        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://" + FarmEndpoint + "/adfs/services/trust/2005/usernamemixed");//url and Host header
                        FieldInfo      field_ServicePoint_ProxyServicePoint = (typeof(ServicePoint))
                                                                              .GetField("m_ProxyServicePoint", BindingFlags.NonPublic | BindingFlags.Instance);
                        req.Proxy = new WebProxy(vip.ToString() + ":443");//server IP and port
                        field_ServicePoint_ProxyServicePoint.SetValue(req.ServicePoint, false);
                        req.Referer = "https://" + FarmEndpoint;
                        req.Headers.Add("Name", "https://" + FarmEndpoint + "/adfs/services/trust/2005/usernamemixed");
                        req.Method      = "POST";
                        req.ContentType = "application/soap+xml";
                        //req.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                        req.KeepAlive         = true;
                        req.AllowAutoRedirect = false;
                        byte[] data = Encoding.UTF8.GetBytes(RST);
                        req.ContentLength = data.Length;
                        req.Credentials   = CredentialCache.DefaultCredentials;
                        req.Credentials   = CredentialCache.DefaultNetworkCredentials;
                        try
                        {
                            Stream dataStream = req.GetRequestStream();
                            dataStream.Write(data, 0, data.Length);
                            dataStream.Close();
                            HttpWebResponse resp      = (HttpWebResponse)req.GetResponse();
                            byte[]          result    = null;
                            int             byteCount = Convert.ToInt32(resp.ContentLength);
                            using (BinaryReader reader = new BinaryReader(resp.GetResponseStream()))
                            {
                                result = reader.ReadBytes(byteCount);
                                row["TargetIdentifier"] = DropDownList1.SelectedItem.Value;
                                //Dirt way to extract claims
                                string      claims  = System.Text.Encoding.UTF8.GetString(result);
                                XmlDocument xmltest = new XmlDocument();
                                xmltest.LoadXml(claims);
                                string xmltoken = xmltest.InnerText;
                                if (xmltoken.Contains("SAML:1"))
                                {
                                    int    first      = xmltoken.IndexOf("tc:SAML:1.0:cm");
                                    int    last       = xmltoken.LastIndexOf("tc:SAML:1.0:cm");
                                    string Finaltoken = xmltoken.Substring(first, last - first);
                                    row["TokenResponse"] = Finaltoken;
                                }
                                else
                                {
                                    row["TokenResponse"] = xmltoken;
                                }
                            }
                        }
                        catch (Exception TokenExp)
                        {
                            row["TargetIdentifier"] = DropDownList1.SelectedItem.Value;
                            row["TokenResponse"]    = TokenExp.Message.ToString();
                        }
                    }
                    VipTokenTable.Rows.Add(row);
                }
                else if (Selectedvips.Count == 0)
                {
                    Label1.Text      = "Please select a VIP";
                    Label1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF0000");
                }
            }//foreach
            GridView4.DataSource = VipTokenTable;
            GridView4.DataBind();
        }
        else
        {
            Label4.Text          = "You have not selected an RP Identifier.";
            Label4.ForeColor     = System.Drawing.ColorTranslator.FromHtml("#FF0000");
            GridView4.DataSource = null;
            GridView4.DataBind();
        }
    }
Beispiel #6
0
    }//GetTokenAsSystem_Click end.

    protected void GetTokenAsUser_Click(object sender, EventArgs e)
    {
        if ((CheckBoxList2.Items.Cast <ListItem>().Count(li => li.Selected)) == 0)
        {
            Label3.Text          = "You have not selected a ADFS server. Please select ADFS servers to view Token response.";
            Label3.ForeColor     = System.Drawing.ColorTranslator.FromHtml("#FF0000");
            GridView6.DataSource = null;
            GridView6.DataBind();
        }
        if (DropDownList1.SelectedItem != null)
        {
            AdfsSqlHelper stsName      = new AdfsSqlHelper();
            string        FarmEndpoint = stsName.GetFarmName();

            var       SelectedADFS    = CheckBoxList2.Items.Cast <ListItem>().Where(i => i.Selected).Select(i => i.ToString()).ToArray();
            DataTable TokenCheckTable = new DataTable();
            TokenCheckTable.Columns.Add("ADFS Server Name");
            TokenCheckTable.Columns.Add("IP");
            TokenCheckTable.Columns.Add("Target Identifier");
            TokenCheckTable.Columns.Add("TokenResponse");

            foreach (object ADFS in SelectedADFS)
            {
                IPAddress[] ipaddress = Dns.GetHostAddresses(ADFS.ToString());
                DataRow     row       = TokenCheckTable.NewRow();
                row["ADFS Server Name"] = ADFS.ToString();
                foreach (IPAddress ip4 in ipaddress.Where(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork))
                {
                    row["IP"] = (ip4.ToString());
                    String   appliesTo        = DropDownList1.SelectedItem.Text;
                    String   federationServer = ip4.ToString();
                    String   endpoint         = "https://" + federationServer + "/adfs/services/trust/2005/usernamemixed";
                    DateTime now       = new DateTime();
                    DateTime FinalTime = now.AddMinutes(60);
                    string   username  = TextBox3.Text;
                    string   password  = TextBox4.Text.Protect();

                    //Request body RST. Do not alter.
                    String RST = String.Format("<s:Envelope xmlns:s=" +
                                               "\"http://www.w3.org/2003/05/soap-envelope\"" +
                                               " " + "xmlns:a=" + "\"http://www.w3.org/2005/08/addressing\"" +
                                               " " + "xmlns:u=" + "\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"" +
                                               "><s:Header><a:Action s:mustUnderstand=" +
                                               "\"1\"" + ">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue" +
                                               "</a:Action><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand=" +
                                               "\"1\"" + ">" + endpoint + "</a:To><o:Security s:mustUnderstand=" +
                                               "\"1\"" + " " + "xmlns:o=" + "\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"" +
                                               "><o:UsernameToken><o:Username>" + username + "</o:Username><o:Password Type=" +
                                               "\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\"" +
                                               ">" + password.Unprotect() + "</o:Password></o:UsernameToken></o:Security></s:Header><s:Body><t:RequestSecurityToken xmlns:t=" +
                                               "\"http://schemas.xmlsoap.org/ws/2005/02/trust\"" + "><wsp:AppliesTo xmlns:wsp=" +
                                               "\"http://schemas.xmlsoap.org/ws/2004/09/policy\"" + "><a:EndpointReference><a:Address>" + appliesTo +
                                               "</a:Address></a:EndpointReference></wsp:AppliesTo><t:KeySize>0</t:KeySize><t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType><t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType><t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType></t:RequestSecurityToken></s:Body></s:Envelope>");

                    //String RST = String.Format("<s:Envelope xmlns:s=" + "\"http://www.w3.org/2003/05/soap-envelope\"" + " " + "xmlns:a=" + "\"http://www.w3.org/2005/08/addressing\"" + " " + "xmlns:u=" + "\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"" + "><s:Header><a:Action s:mustUnderstand=" + "\"1\"" + ">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue" + "</a:Action><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand=" + "\"1\"" + ">" + endpoint + "</a:To><o:Security s:mustUnderstand=" + "\"1\"" + " " + "xmlns:o=" + "\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"" + "><o:UsernameToken><o:Username>" + username + "</o:Username><o:Password Type=" + "\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\"" + ">" + password + "</o:Password></o:UsernameToken></o:Security></s:Header><s:Body><t:RequestSecurityToken xmlns:t=" + "\"http://schemas.xmlsoap.org/ws/2005/02/trust\"" + "><wsp:AppliesTo xmlns:wsp=" + "\"http://schemas.xmlsoap.org/ws/2004/09/policy\"" + "><a:EndpointReference><a:Address>" + appliesTo + "</a:Address></a:EndpointReference></wsp:AppliesTo><t:KeySize>0</t:KeySize><t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType><t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType><t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType></t:RequestSecurityToken></s:Body></s:Envelope>");

                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://" + FarmEndpoint + "/adfs/services/trust/2005/usernamemixed");//url and Host header
                    FieldInfo      field_ServicePoint_ProxyServicePoint = (typeof(ServicePoint))
                                                                          .GetField("m_ProxyServicePoint", BindingFlags.NonPublic | BindingFlags.Instance);
                    req.Proxy = new WebProxy(ip4.ToString() + ":443");//server IP and port
                    field_ServicePoint_ProxyServicePoint.SetValue(req.ServicePoint, false);
                    req.Referer = "https://" + FarmEndpoint;
                    req.Headers.Add("Name", "https://" + FarmEndpoint + "/adfs/services/trust/2005/usernamemixed");
                    req.Method      = "POST";
                    req.ContentType = "application/soap+xml";
                    //req.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                    req.KeepAlive         = true;
                    req.AllowAutoRedirect = false;
                    byte[] data = Encoding.UTF8.GetBytes(RST);
                    req.ContentLength = data.Length;

                    try
                    {
                        Stream dataStream = req.GetRequestStream();
                        dataStream.Write(data, 0, data.Length);
                        dataStream.Close();
                        HttpWebResponse resp      = (HttpWebResponse)req.GetResponse();
                        byte[]          result    = null;
                        int             byteCount = Convert.ToInt32(resp.ContentLength);
                        using (BinaryReader reader = new BinaryReader(resp.GetResponseStream()))
                        {
                            result = reader.ReadBytes(byteCount);
                            row["Target Identifier"] = DropDownList1.SelectedItem.Value;

                            //Dirt way to extract claims
                            string      claims  = System.Text.Encoding.UTF8.GetString(result);
                            XmlDocument xmltest = new XmlDocument();
                            xmltest.LoadXml(claims);
                            string xmltoken = xmltest.InnerText;
                            if (xmltoken.Contains("SAML:1"))
                            {
                                int    first      = xmltoken.IndexOf("tc:SAML:1.0:cm");
                                int    last       = xmltoken.LastIndexOf("tc:SAML:1.0:cm");
                                string Finaltoken = xmltoken.Substring(first, last - first);
                                row["TokenResponse"] = Finaltoken;
                            }
                            else
                            {
                                row["TokenResponse"] = xmltoken;
                            }
                        }
                    }
                    catch (Exception TokenExp)
                    {
                        row["Target Identifier"] = DropDownList1.SelectedItem.Value;
                        row["TokenResponse"]     = TokenExp.Message.ToString();
                    }
                }
                TokenCheckTable.Rows.Add(row);
            }
            GridView6.DataSource = TokenCheckTable;
            GridView6.DataBind();
        }
        else
        {
            Label3.Text          = "You have not selected an RP Identifier.";
            Label3.ForeColor     = System.Drawing.ColorTranslator.FromHtml("#FF0000");
            GridView6.DataSource = null;
            GridView6.DataBind();
        }
    }//GetTokenAsUser_Click end.