Example #1
0
        void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            switch (status)
            {
            case 0:
                if (encryptedElements <= elementsToEncrypt.Length)
                {
                    actElementToEncrypt = elementsToEncrypt[encryptedElements];
                    presentation.AddTextToInformationBox("Actual Element to encrypt is:" + actElementToEncrypt.Name);
                    itemToEncrypt            = this.animateElement(actElementToEncrypt.Name);
                    dispatcherTimer.Interval = new TimeSpan(0, 0, 5);
                    status = 1;
                }
                break;

            case 1:
                presentation.AddTextToInformationBox("Generate 256 AES Session Key to encrypt the element");
                status = 2;
                break;

            case 2:
                presentation.AddTextToInformationBox("Session Key is: " + soap.LastSessionKey);

                status = 3;
                break;

            case 3:

                if (!soap.GetIsEncryptContent())
                {
                    string id = checkForID(itemToEncrypt);
                    if (id != null)
                    {
                        presentation.AddTextToInformationBox("The " + actElementToEncrypt.Name + " has already an id: " + id);
                        actId = id;
                    }
                    else
                    {
                        actId = soap.GetIdToElement(actElementToEncrypt.Name);

                        presentation.AddTextToInformationBox("The " + actElementToEncrypt.Name + " gets the id: " + actId);
                        createAttributeForElement(itemToEncrypt, "URI", "#" + actId);
                    }
                }
                else
                {
                    XmlNode encryptedElement = soap.SecuredSoap.GetElementsByTagName(actElementToEncrypt.Name)[0];
                    foreach (XmlAttribute att in encryptedElement.FirstChild.Attributes)
                    {
                        if (att.Name.Equals("Id"))
                        {
                            actId = att.Value;
                        }
                    }
                    presentation.AddTextToInformationBox("The Id for the EncryptedData Element will be: " + actId);
                }
                status = 4;
                break;

            case 4:
                presentation.AddTextToInformationBox("Calculate cipher value of the element");
                status = 5;
                break;

            case 5:
                XmlNodeList encryptedDataElements = soap.SecuredSoap.GetElementsByTagName("xenc:EncryptedData");

                foreach (XmlNode node in encryptedDataElements)
                {
                    foreach (XmlAttribute att in node.Attributes)
                    {
                        if (att.Name.Equals("Id") && att.Value.Equals(actId))
                        {
                            actEncryptedDataElement = node;
                            foreach (XmlNode child in node.ChildNodes)
                            {
                                if (child.Name.Equals("xenc:CipherData"))
                                {
                                    cipherValueOfElement = child.FirstChild.InnerText;
                                }
                            }
                        }
                    }
                }
                presentation.AddTextToInformationBox("CipherValue is:" + cipherValueOfElement);
                status = 6;
                break;

            case 6:
                presentation.AddTextToInformationBox("Create EncryptedData Element");
                rootItem = (TreeViewItem)presentation.treeView.Items[0];
                presentation.treeView.Items.Clear();
                header = new TreeViewItem();
                StackPanel panel = new StackPanel();
                TextBlock  block = new TextBlock();
                block.FontSize = 16;
                block.Text     = "Encrypted Data Element";
                panel.Children.Add(block);
                header.Header = panel;
                presentation.treeView.Items.Add(header);
                actEncDataItem = addChildElement(header, actEncryptedDataElement, true);
                status         = 7;
                break;

            case 7:
                presentation.AddTextToInformationBox("Create the EncryptionMethod Element ");
                addChildElement(actEncDataItem, actEncryptedDataElement.FirstChild, false);
                status = 8;
                break;

            case 8:
                presentation.AddTextToInformationBox("Create the CipherData Element ");
                foreach (XmlNode node in actEncryptedDataElement.ChildNodes)
                {
                    if (node.Name.Equals("xenc:CipherData"))
                    {
                        actcipherdata = node;
                    }
                }
                actcipherdataitem = addChildElement(actEncDataItem, actcipherdata, false);
                status            = 9;
                break;

            case 9:
                presentation.AddTextToInformationBox("Create the CipherValue Element");
                actciphervalueitem = addChildElement(actcipherdataitem, actcipherdata.FirstChild, false);
                status             = 10;
                break;

            case 10:
                presentation.AddTextToInformationBox("Insert the cipher value");
                createValue(actciphervalueitem, actcipherdata.FirstChild.InnerText);
                status = 11;
                break;

            case 11:
                presentation.treeView.Items.Clear();
                presentation.treeView.Items.Add(rootItem);
                status = 12;
                break;

            case 12:
                if (soap.GetIsEncryptContent())
                {
                    presentation.AddTextToInformationBox("Replase the content of the " + actElementToEncrypt.Name);
                    presentation.AddTextToInformationBox("Element with the created EncryptedData Element");
                    itemToEncrypt.Items.Clear();
                    TreeViewItem parent1 = (TreeViewItem)actEncDataItem.Parent;
                    parent1.Items.Remove(actEncDataItem);
                    itemToEncrypt.Items.Add(actEncDataItem);
                }
                else
                {
                    TreeViewItem parent = (TreeViewItem)itemToEncrypt.Parent;
                    index = parent.Items.IndexOf(itemToEncrypt);
                    TreeViewItem parent1 = (TreeViewItem)actEncDataItem.Parent;
                    parent1.Items.Remove(actEncDataItem);

                    parent.Items.RemoveAt(index);
                    parent.Items.RemoveAt(index);
                    presentation.AddTextToInformationBox("Replase the the " + actElementToEncrypt.Name + " Element");
                    parent.Items.Insert(index, actEncDataItem);
                    TextBlock tb  = new TextBlock();
                    TextBlock tb1 = new TextBlock();
                    TextBlock tb2 = new TextBlock();

                    tb.Name  = "tbNameClose";
                    tb.Text  = "/xenc:EncryptedData";
                    tb1.Text = "<";
                    tb2.Text = ">";


                    StackPanel panel1 = new StackPanel();

                    panel1.Orientation = System.Windows.Controls.Orientation.Horizontal;
                    panel1.Children.Add(tb1);
                    panel1.Children.Add(tb);
                    panel1.Children.Add(tb2);
                    tb.Foreground  = elemBrush;
                    tb1.Foreground = elemBrush;
                    tb2.Foreground = elemBrush;

                    TreeViewItem closeItem = new TreeViewItem();
                    closeItem.Header = panel1;

                    parent.Items.Insert(index + 1, closeItem);
                }
                status = 13;
                break;

            case 13:
                presentation.AddTextToInformationBox("Check for Header");

                if (!soap.HadHeader)
                {
                    this.secHeader = false;
                    status         = 14;
                }
                else
                {
                    this.secHeader = true; status = 15;
                }

                break;

            case 14:
                presentation.AddTextToInformationBox("No Header found. Create SOAP and Security Header");
                addChildElement("s:Envelope", soap.SecuredSoap.GetElementsByTagName("s:Header")[0], true);
                addChildElement("s:Header", soap.SecuredSoap.GetElementsByTagName("wsse:Security")[0], true);
                status = 15;
                break;

            case 15:
                presentation.AddTextToInformationBox("Create Encrypted Key");
                actEncKey = addChildElement("wsse:Security", soap.SecuredSoap.GetElementsByTagName("xenc:EncryptedKey")[0], true);
                status    = 16;
                break;

            case 16:
                presentation.AddTextToInformationBox("Create Encryption Method Element");
                addChildElement(actEncKey, soap.SecuredSoap.GetElementsByTagName("xenc:EncryptionMethod")[0], true);
                status = 17;
                break;

            case 17:
                presentation.AddTextToInformationBox("Add Key Info Element");
                TreeViewItem keyInfo = addChildElement(actEncKey, soap.SecuredSoap.GetElementsByTagName("ds:KeyInfo")[0], true);
                keyInfo.IsExpanded = true;
                presentation.CopyXmlToTreeView(soap.SecuredSoap.GetElementsByTagName("ds:KeyInfo")[0].FirstChild, keyInfo);
                status = 18;
                break;

            case 18:
                presentation.AddTextToInformationBox("Create CipherData Element");
                actcipherdataitem = addChildElement(actEncKey, soap.SecuredSoap.GetElementsByTagName("xenc:CipherData")[0], false);
                status            = 19;
                break;

            case 19:
                presentation.AddTextToInformationBox("Create CipherValue Element");
                actciphervalueitem = addChildElement(actcipherdataitem, soap.SecuredSoap.GetElementsByTagName("xenc:CipherValue")[0], false);
                status             = 20;
                break;

            case 20:
                presentation.AddTextToInformationBox("Create CipherValue Element by encrypting the session key with the public key of the web service");
                status = 21;
                break;

            case 21:
                presentation.AddTextToInformationBox("Cipher Value is: " + soap.SecuredSoap.GetElementsByTagName("xenc:CipherValue")[0].InnerText);
                status = 22;
                break;

            case 22:
                presentation.AddTextToInformationBox("Insert Cipher Value");
                createValue(actciphervalueitem, soap.SecuredSoap.GetElementsByTagName("xenc:CipherValue")[0].InnerText);
                status = 23;
                break;

            case 23:
                presentation.AddTextToInformationBox("Create Reference List");
                actRefList = addChildElement(actEncKey, soap.SecuredSoap.GetElementsByTagName("xenc:ReferenceList")[0], false);
                status     = 24;
                break;

            case 24:
                status = 25;
                presentation.AddTextToInformationBox("Insert Data Reference");
                addChildElement(actRefList, soap.SecuredSoap.GetElementsByTagName("xenc:ReferenceList")[0], false);
                status = 25;
                break;

            case 25:
                dispatcherTimer.Stop();
                presentation._namespacesTable.Clear();
                presentation.animationRunning = false;
                status = 0;
                soap.ShowSecuredSoap();
                break;
            }
        }
Example #2
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;
            }
        }