示例#1
0
 public void Dispose()
 {
     if (this.hashStream != null)
     {
         this.hashStream.Close();
         this.hashStream = null;
     }
 }
示例#2
0
        public void ApplyBodySecurity(XmlDictionaryWriter writer)
        {
            SignedMessage message    = this.SignedMessage;
            HashStream    hashStream = this.signer.TakeHashStream();

            message.WriteBodyToSign(hashStream, writer);
            this.signer.InclusivePrefixes = message.InclusivePrefixes;
            this.signer.AddReference(message.BodyId, hashStream.FlushHashAndGetValue());
        }
示例#3
0
        void ComputeHash(out AsymmetricAlgorithm privateKey, out SignatureDescription description, out HashAlgorithm hash)
        {
            privateKey  = this.Certificate.PrivateKey;
            description = CryptoConfig.CreateFromName(this.SHA1SignatureName) as SignatureDescription;
            if (description == null)
            {
                throw new CompactSignatureSecurityException(string.Format(
                                                                CultureInfo.CurrentCulture,
                                                                "Error creating SignatureDescription from the signature name {0}",
                                                                this.SHA1SignatureName));
            }

            hash = description.CreateDigest();
            if (hash == null)
            {
                throw new CompactSignatureSecurityException(string.Format(
                                                                CultureInfo.CurrentCulture,
                                                                "Error creating HashAlgorithm from the signature name {0}",
                                                                this.SHA1SignatureName));
            }

            HashStream hashStream = this.TakeHashStream(hash);

            // Create the references
            StringBuilder sb = new StringBuilder();

            if (!String.IsNullOrEmpty(this.InclusivePrefixesList))
            {
                for (int i = 0; i < this.references.Count; i++)
                {
                    sb.Append(string.Format(SignatureProcessor.ExtendedSignatureReferenceWithPrefixes,
                                            this.references[i].Id,
                                            this.InclusivePrefixesList,
                                            Convert.ToBase64String(this.references[i].Digest)));
                }
            }
            else
            {
                for (int i = 0; i < this.references.Count; i++)
                {
                    sb.Append(string.Format(SignatureProcessor.ExtendedSignatureReferenceNoPrefixes,
                                            this.references[i].Id,
                                            Convert.ToBase64String(this.references[i].Digest)));
                }
            }

            string expandedSignature = string.Format(
                ExpandedSignatureScheleton,
                // Replace the references
                sb.ToString());

            byte[] bytes = Encoding.UTF8.GetBytes(expandedSignature);
            hashStream.Write(bytes, 0, bytes.Length);
            hashStream.FlushHash();
        }
示例#4
0
        public HashStream TakeHashStream(HashAlgorithm hash)
        {
            if (this.hashStream == null)
            {
                this.hashStream = new HashStream(hash);
            }
            else
            {
                this.hashStream.Reset(hash);
            }

            return(this.hashStream);
        }
示例#5
0
        public void AddReference(string headerId, XmlDictionaryReader reader, XmlDictionaryWriter writer)
        {
            HashStream hashStream = this.TakeHashStream();

            writer.StartCanonicalization(hashStream, false, this.InclusivePrefixes);

            // The reader must be positioned on the start element of the header / body we want to canonicalize
            writer.WriteNode(reader, false);
            writer.EndCanonicalization();
            writer.Flush();

            // Add a reference for this block
            this.AddReference(headerId, hashStream.FlushHashAndGetValue());
        }
示例#6
0
        public void AddReference(
            MessageHeaders headers,
            int i,
            XmlDictionaryWriter writer,
            string headerId,
            bool idInserted)
        {
            HashStream hashStream = this.TakeHashStream();

            writer.StartCanonicalization(hashStream, false, this.InclusivePrefixes);
            headers.WriteStartHeader(i, writer);
            if (idInserted)
            {
                writer.WriteAttributeString(this.discoveryInfo.DiscoveryPrefix, ProtocolStrings.IdAttributeName, this.discoveryInfo.DiscoveryNamespace, headerId);
            }

            headers.WriteHeaderContents(i, writer);
            writer.WriteEndElement();
            writer.EndCanonicalization();
            writer.Flush();

            // Add a pre-digested reference for this header
            this.AddReference(headerId, hashStream.FlushHashAndGetValue());
        }
        public HashStream TakeHashStream(HashAlgorithm hash)
        {
            if (this.hashStream == null)
            {
                this.hashStream = new HashStream(hash);
            }
            else
            {
                this.hashStream.Reset(hash);
            }

            return this.hashStream;
        }
 public void Dispose()
 {
     if (this.hashStream != null)
     {
         this.hashStream.Close();
         this.hashStream = null;
     }
 }