Пример #1
0
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            switch (status)
            {
            case 0:
                //Start and HeaderCheck
                dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 6, 0);
                presentation.AddTextToInformationBox("Check Envelope for SOAP-Header");
                bool secHead = soap.CheckSecurityHeader();
                if (!secHead)
                {
                    presentation.AddTextToInformationBox("No SOAP-Header found");
                    status = 1;
                }
                else
                {
                    presentation.AddTextToInformationBox("SOAP-Header already exists");
                    animateElement("s:Header");
                    status = 2;
                }
                break;

            case 1:
                //Create Soap Header
                presentation.AddTextToInformationBox("Add Soap-Header to Envelope");
                soap.CreateSecurityHeaderAndSoapHeader();
                addChildElement("s:Envelope", soap.SecuredSoap.GetElementsByTagName("s:Header")[0], true);
                status = 3;
                //  slider1.Value++;
                break;

            case 2:
                //Check Security Header -> Found -> Animate
                presentation.AddTextToInformationBox("Check for Security-Header");
                presentation.AddTextToInformationBox("Security-Header found");
                animateElement("wsse:Security");
                status = 4;
                break;

            case 3:
                //Create Security Header
                presentation.AddTextToInformationBox("Create Security-Header as child of SOAP-Header");
                addChildElement("s:Header", soap.SecuredSoap.GetElementsByTagName("wsse:Security")[0], true);
                status = 4;
                break;

            case 4:
                //Create Signature Element
                presentation.AddTextToInformationBox("Create a ds:Signature-Element as first child of the Security-Header");
                soap.SignElementsManual(this.elementsToSign);
                signed = true;
                addChildElement("wsse:Security", soap.SecuredSoap.GetElementsByTagName("ds:Signature")[0], true);
                //Signature TreeViewItem is saved in actSignatureItem var
                status = 5;
                break;

            case 5:
                //Create SignedInfo Element
                presentation.AddTextToInformationBox("Create a ds:SignedInfo Element");
                useactSigItem = true;
                addChildElement("ds:Signature", soap.SecuredSoap.GetElementsByTagName("ds:SignedInfo")[0], false);
                status = 6;
                break;

            case 6:
                //Textoutput for Canonic. Method
                presentation.AddTextToInformationBox("Create Canonicalization Method Element");
                presentation.AddTextToInformationBox("This Element specifies the canonicalization method for the Signed-Info Element");
                status = 7;

                break;

            case 7:
                //Create Canon
                useactSigItem = true;
                addChildElement("ds:SignedInfo", soap.SecuredSoap.GetElementsByTagName("ds:CanonicalizationMethod")[0], false);
                status = 8;
                break;

            case 8:
                //Textoutput Signature Method
                presentation.AddTextToInformationBox("Create Signature Method Element with the choosen signature algorithm");
                string s = "";
                if (soap.GetSignatureAlgorithm().Equals("1"))
                {
                    s = "RSA-SHA1";
                }
                else
                {
                    s = "DSA-SHA1";
                }
                presentation.AddTextToInformationBox("The signature algorithm is: " + s);
                status = 9;
                break;

            case 9:
                //Create Signature Method
                useactSigItem = true;
                addChildElement("ds:SignedInfo", soap.SecuredSoap.GetElementsByTagName("ds:SignatureMethod")[0], false);
                status = 10;
                break;

            case 10:
                //Start Reference Elements
                presentation.AddTextToInformationBox("Create Reference-Elements for the elements to sign");
                referencesCounter = 0;
                referencesTimer.Start();
                actTimer = referencesTimer;
                dispatcherTimer.Stop();

                status = 11;
                break;

            case 11:
                presentation.AddTextToInformationBox("Create Signature Value Element");
                actSignatureValue = addChildElement(actSignatureItem, soap.SecuredSoap.GetElementsByTagName("ds:SignatureValue")[0], false);
                status            = 12;
                break;

            case 12:
                presentation.AddTextToInformationBox("Canonicalize the SignedInfo Element");
                rootItem = (TreeViewItem)presentation.treeView.Items[0];
                TreeViewItem canon       = new TreeViewItem();
                StreamReader sreader     = new StreamReader(soap.CanonicalizeNodeWithExcC14n((XmlElement)soap.SecuredSoap.GetElementsByTagName("ds:SignedInfo")[0]));
                string       canonString = sreader.ReadToEnd();
                XmlDocument  doc         = new XmlDocument();
                XmlElement   elem        = doc.CreateElement("temp");
                elem.InnerXml = canonString;
                TextBlock tb = new TextBlock();
                tb.FontSize = 14;
                tb.Text     = "Canonicalized Element: ";
                StackPanel panel = new StackPanel();
                panel.Children.Add(tb);
                canon.Header = panel;
                XmlNode node = (XmlNode)elem.ChildNodes[0];
                presentation.CopyXmlToTreeView(node, canon);
                presentation.treeView.Items.Clear();
                canon.IsExpanded = true;
                presentation.treeView.Items.Add(canon);
                status = 13;
                break;

            case 13:
                presentation.AddTextToInformationBox("Calculate SHA-1 Hash Value of this Element");
                status = 14;
                break;

            case 14:
                XmlElement signedInfo = (XmlElement)soap.SecuredSoap.GetElementsByTagName("ds:SignedInfo")[0];
                byte[]     temp       = soap.GetDigestValueForElementWithSha1(signedInfo);
                string     value      = Convert.ToBase64String(temp);
                presentation.AddTextToInformationBox("SHA-1 Hash Value of the ds:SignedInfo Element is: " + value);
                status = 15;
                break;

            case 15:
                presentation.AddTextToInformationBox("Encrypt the calculated SHA-1 hash value to get die signature value");
                status = 16;
                break;

            case 16:
                XmlNode signatureValue = soap.SecuredSoap.GetElementsByTagName("ds:SignatureValue")[0];
                presentation.AddTextToInformationBox("The Signature Value is: " + signatureValue.InnerText);
                presentation.treeView.Items.Clear();
                presentation.treeView.Items.Add(rootItem);
                createValue(actSignatureValue, signatureValue.InnerText);
                status = 17;
                break;

            case 17:
                animateElement(actSignatureValue);
                presentation.AddTextToInformationBox("Add KeyInfo Element");

                status = 18;
                break;

            case 18:
                TreeViewItem keyInfo    = new TreeViewItem();
                XmlNode      keyInfoXML = soap.SecuredSoap.GetElementsByTagName("ds:KeyInfo")[0];
                StackPanel   panel1     = new StackPanel();
                panel1.Orientation = System.Windows.Controls.Orientation.Horizontal;
                TextBlock tbTagOpen  = new TextBlock();
                TextBlock tbTagClose = new TextBlock();
                TextBlock tbName     = new TextBlock();
                tbTagOpen.Name  = "tbTagOpen";
                tbTagClose.Name = "tbTagClose";
                tbName.Name     = "tbName";
                tbTagOpen.Text  = "<";
                tbTagClose.Text = ">";
                tbName.Text     = "ds:KeyInfo";

                panel1.Children.Add(tbTagOpen);
                panel1.Children.Add(tbName);
                panel1.Children.Add(tbTagClose);

                tbName.Foreground     = elemBrush;
                tbTagClose.Foreground = elemBrush;
                tbTagOpen.Foreground  = elemBrush;

                presentation.InsertNamespace(panel1, keyInfoXML.NamespaceURI, "ds");
                keyInfo.Header = panel1;
                presentation.CopyXmlToTreeView(keyInfoXML, keyInfo);
                actSignatureItem.Items.Add(keyInfo);
                animateElement(keyInfo);
                status = 19;
                break;

            case 19:
                status = 0;
                dispatcherTimer.Stop();
                presentation.animationRunning = false;
                soap.ShowSecuredSoap();
                this.animationRunning = false;
                break;
            }
        }