Exemple #1
0
        private void referenceElementsTimer_Tick(object sender, EventArgs e)
        {
            switch (referencesSteps)
            {
            case 0:
                TreeViewItem element = findItem(presentation.SecuredSoapItem, actElementToReference.Name);
                element.BringIntoView();
                actElementToReferenceTVI = element;
                if (!soap.GetXPathTransForm())
                {
                    actElementToReference = elementsToSign[referencesCounter];
                    presentation.AddTextToInformationBox("Check if the " + actElementToReference.Name + "-Element has an ID");

                    string id = checkForID(element);
                    if (id != null)
                    {
                        presentation.AddTextToInformationBox("The Element already has an ID: " + id);
                        animateElement(actElementToReference.Name);
                        referencesSteps = 2;
                    }
                    else
                    {
                        presentation.AddTextToInformationBox("The Element has no ID");
                        referencesSteps = 1;
                    }
                }
                else
                {
                    presentation.AddTextToInformationBox("The " + actElementToReference.Name + " Element is referenced by a xPath transform");
                    referencesSteps = 3;
                }
                break;

            case 1:
                //Generate ID for Act Element
                presentation.AddTextToInformationBox("Create Id for the Element");
                TreeViewItem element1 = findItem(presentation.SecuredSoapItem, actElementToReference.Name);
                createAttributeForElement(actElementToReference.Name, "Id", soap.GetIdToElement(actElementToReference.Name));
                referencesSteps = 2;
                break;


            case 2:
                presentation.AddTextToInformationBox("Create Reference Element for " + actElementToReference.Name + " Element");
                actReferenceElementTVI = addChildElement("ds:SignedInfo", soap.SecuredSoap.GetElementsByTagName("ds:Reference")[referencesCounter], false);
                actReferenceElement    = (XmlElement)soap.SecuredSoap.GetElementsByTagName("ds:Reference")[referencesCounter];

                referencesSteps = 5;

                break;

            case 3:
                //XPAth Reference Element
                presentation.AddTextToInformationBox("Create Reference Element for " + actElementToReference.Name + " Element");
                actReferenceElementTVI = addChildElement("ds:SignedInfo", soap.SecuredSoap.GetElementsByTagName("ds:Reference")[referencesCounter], false);
                actReferenceElement    = (XmlElement)soap.SecuredSoap.GetElementsByTagName("ds:Reference")[referencesCounter];
                referencesSteps        = 4;
                break;

            case 4:
                presentation.AddTextToInformationBox("The Reference Element needs no URI cause of the XPath Transform");
                referencesSteps = 5;
                break;

            case 5:
                presentation.AddTextToInformationBox("Create a Transforms Element");
                useactSigItem           = true;
                actTransformsElementTVI = addChildElement("ds:Reference", soap.SecuredSoap.GetElementsByTagName("ds:Transforms")[referencesCounter], false);
                referencesSteps         = 6;
                break;

            case 6:
                transformsCounter = actReferenceElement.FirstChild.ChildNodes.Count;
                actTransformsElementTVI.BringIntoView();
                referencesSteps = 7;
                TransformsTimer.Start();
                actTimer = TransformsTimer;
                referenceElementsTimer.Stop();
                break;

            case 7:
                presentation.AddTextToInformationBox("Create the DigestMethod-Element");
                addChildElement("ds:Reference", soap.SecuredSoap.GetElementsByTagName("ds:DigestMethod")[referencesCounter], false);
                referencesSteps = 8;
                break;

            case 8:
                presentation.AddTextToInformationBox("Calculate the DigestValue for the Referenced Element");
                referencesSteps = 9;
                break;

            case 9:
                presentation.AddTextToInformationBox("Find the referenced element");
                referencesSteps = 10;
                break;

            case 10:
                if (soap.GetXPathTransForm())
                {
                    presentation.AddTextToInformationBox("URI is empty, so the complete document is referenced");
                    TreeViewItem temp = (TreeViewItem)presentation.treeView.Items[0];
                    temp.BringIntoView();
                    animateElement(temp);
                    referencesSteps = 11;
                }
                else
                {
                    presentation.AddTextToInformationBox("The referenced element is: " + actElementToReference.Name);
                    actElementToReferenceTVI.BringIntoView();
                    animateElement(actElementToReferenceTVI);
                    referencesSteps = 13;
                }
                break;

            case 11:
                presentation.AddTextToInformationBox("Do the XPath Transform on the referenced element");
                xPathSteps        = xPath.Split(new char[] { '/' });
                xPathArrayCounter = 1;
                referencesSteps   = 12;
                break;

            case 12:
                if (xPathArrayCounter <= xPathSteps.Length - 1)
                {
                    presentation.AddTextToInformationBox("Actual element: " + xPathSteps[xPathArrayCounter]);
                    animateItemInclChilds(xPathSteps[xPathArrayCounter]);
                    xPathArrayCounter++;
                }
                else
                {
                    referencesSteps = 13;
                }
                break;

            case 13:
                presentation.AddTextToInformationBox("Canonicalize the actual Element");
                referencesSteps = 14;
                break;

            case 14:
                presentation.AddTextToInformationBox("The canonicalized element is:");
                rootItem = (TreeViewItem)presentation.treeView.Items[0];
                TreeViewItem canon       = new TreeViewItem();
                StreamReader sreader     = new StreamReader(soap.CanonicalizeNodeWithExcC14n(actElementToReference));
                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";
                XmlNode node = (XmlNode)elem.ChildNodes[0];
                presentation.CopyXmlToTreeView(node, canon);
                presentation.treeView.Items.Clear();
                canon.IsExpanded = true;
                presentation.treeView.Items.Add(canon);
                referencesSteps = 15;
                break;

            case 15:
                referencesSteps = 16;
                break;

            case 16:
                presentation.AddTextToInformationBox("Calculate SHA-1 Hash of this Element:");
                referencesSteps = 17;
                break;

            case 17:
                XmlNode digest = soap.SecuredSoap.GetElementsByTagName("ds:DigestValue")[referencesCounter];
                presentation.AddTextToInformationBox("SHA-1 Value:" + digest.InnerText);
                referencesSteps = 18;

                break;

            case 18:
                presentation.treeView.Items.Clear();
                presentation.treeView.Items.Add(rootItem);

                presentation.AddTextToInformationBox("Create Digest Value Element");
                actDigestValue  = addChildElement(actReferenceElementTVI, soap.SecuredSoap.GetElementsByTagName("ds:DigestValue")[referencesCounter], false);
                referencesSteps = 19;
                break;

            case 19:
                presentation.AddTextToInformationBox("Add Digest Value to Digest Value Element");
                createValue(actDigestValue, soap.SecuredSoap.GetElementsByTagName("ds:DigestValue")[referencesCounter].InnerText);
                referencesSteps = 20;
                break;

            case 20:
                referencesSteps = 0;
                referencesCounter++;
                referenceElementsTimer.Stop();
                referencesTimer.Start();
                actTimer = referencesTimer;
                break;
            }
        }