Exemplo n.º 1
0
        public SignatureValidator(WebService webService)
        {
            this._valid                  = true;
            this._inputDocument          = (XmlDocument)webService.InputString.Clone();
            this._canonicalizator        = new Canonicalizator(this._inputDocument);
            this._tempdocument           = (XmlDocument)this._inputDocument.Clone();
            this._wsSecurityHeaderList   = new ArrayList();
            this._encryptedDataList      = new ArrayList();
            this._decryptedDataList      = new ArrayList();
            this._encryptedKeyElements   = new ArrayList();
            this._referenceList          = new ArrayList();
            this._webService             = webService;
            this._signedXml              = new SignedXml(this._inputDocument);
            this._signatureReferenceList = new ArrayList();
            this._securityHeader         = this._inputDocument.GetElementsByTagName("wsse:Security")[0];
            if (this._securityHeader != null)
            {
                foreach (XmlElement securityHeader in this._securityHeader)
                {
                    if (securityHeader.Name.Equals("xenc:EncryptedData"))
                    {
                        this.DercryptSingleXmlElement((XmlElement)this._wsSecurityHeaderList[0]);
                        this.FillSecurityHeaderElementsList();
                    }
                    this._wsSecurityHeaderList.Add(securityHeader);
                }
            }

            this._tracer = new WSSecurityTracer();


            foreach (XmlElement tempElement in this._wsSecurityHeaderList)
            {
                if (tempElement.Name.Equals("xenc:EncryptedKey"))
                {
                    try
                    {
                        string decryptedElement = this.DercryptSingleXmlElement(tempElement);
                    }
                    catch (Exception e)
                    {
                        this._webService.ShowError(e.Message);
                        this._valid = false;
                    }
                }
                if (tempElement.Name.Equals("ds:Signature"))
                {
                    this.ValidateSignature(tempElement);
                }
            }
            this._webService.presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
            {
                this._webService.presentation.txtTrace.Text += this._tracer.signatureTrace;
                this._webService.presentation.txtTrace.Text += this._tracer.decryptionTrace;
            }, null);
            this._webService.ModifiedInputDocument = this._inputDocument;
        }
Exemplo n.º 2
0
        public void CanonicalizeSignedInfo(XmlElement SignedInfo)
        {
            Canonicalizator canonicalizator           = new Canonicalizator(this._inputDocument);
            Stream          stream                    = canonicalizator.CanonicalizeNode(SignedInfo);
            StreamReader    canonicalizedStreamReader = new StreamReader(stream);
            string          canonicalizedString       = canonicalizedStreamReader.ReadToEnd();

            this._canonicalizedSignedInfo = canonicalizedString;
            this.ValidateSignature(this._signedXml.Signature, this._signedXml.SignatureValue);
        }
Exemplo n.º 3
0
        public string CanonicalizeSignedInfo(int signatureNumber)
        {
            XmlElement signedInfo = (XmlElement)this._inputDocument.GetElementsByTagName("ds:SignedInfo")[signatureNumber];

            this._canonicalizator = new Canonicalizator(this._inputDocument);
            Stream       stream      = this._canonicalizator.CanonicalizeNode(signedInfo);
            StreamReader sreader     = new StreamReader(stream);
            string       canonString = sreader.ReadToEnd();

            return(canonString);
        }
Exemplo n.º 4
0
        public byte[] DigestElement(XmlElement element, string hashAlgorithm, string canonicalizationAlgorithm)
        {
            Canonicalizator canonicalizator = new Canonicalizator(this._inputDocument);
            Stream          canonicalStream = canonicalizator.CanonicalizeNode(element);

            canonicalStream.Position = 0;
            StreamReader canonicalStreamReader = new StreamReader(canonicalStream);
            string       canonString           = canonicalStreamReader.ReadToEnd();
            SHA1CryptoServiceProvider sha1CryptoServiceProvider = new SHA1CryptoServiceProvider();

            canonicalStream.Position = 0;
            byte[] hash = sha1CryptoServiceProvider.ComputeHash(canonicalStream);
            string base64ConvertedHashValue = Convert.ToBase64String(hash);

            return(hash);
        }