public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager, bool preserveComments) { reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; bool isEmptyElement = reader.IsEmptyElement; string algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (algorithm != this.Algorithm) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.AlgorithmMismatchForTransform))); } reader.MoveToContent(); reader.Read(); if (!isEmptyElement) { if (reader.IsStartElement(XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace)) { this.transformationParameters.ReadFrom(reader, dictionaryManager); } reader.MoveToContent(); reader.ReadEndElement(); } }
// Interface to plug in external Dictionaries. The external // dictionary should already be populated with all strings // required by this assembly. public void PopulateDictionary(IXmlDictionary dictionary) { if (dictionary == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionary"); this.dictionaryManager = new DictionaryManager(dictionary); }
public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager) { XmlTokenStream tokenStream = input as XmlTokenStream; if (tokenStream != null) { tokenStream.SetElementExclusion(XmlSignatureStrings.Signature, XmlSignatureStrings.Namespace); return tokenStream; } WrappedReader reader = input as WrappedReader; if ( reader != null ) { // The Enveloped Signature Transform is supposed to remove the // Signature which encloses the transform element. Previous versions // of this code stripped out all Signature elements at any depth, // which did not allow nested signed structures. By specifying '1' // as the depth, we narrow our range of support so that we require // that the enveloped signature be a direct child of the element // being signed. reader.XmlTokens.SetElementExclusion( XmlSignatureConstants.Elements.Signature, XmlSignatureConstants.Namespace, 1 ); return reader; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedInputTypeForTransform, input.GetType()))); }
public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager) { XmlDictionaryString localName = this.isCanonicalizationMethod ? dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod : dictionaryManager.XmlSignatureDictionary.Transform; reader.MoveToStartElement(localName, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; bool isEmptyElement = reader.IsEmptyElement; if (reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null) != this.Algorithm) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("AlgorithmMismatchForTransform"))); } reader.Read(); reader.MoveToContent(); if (!isEmptyElement) { if (reader.IsStartElement(dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace)) { reader.MoveToStartElement(dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace); this.inclusiveListElementPrefix = reader.Prefix; bool flag2 = reader.IsEmptyElement; this.InclusiveNamespacesPrefixList = reader.GetAttribute(dictionaryManager.ExclusiveC14NDictionary.PrefixList, null); reader.Read(); if (!flag2) { reader.ReadEndElement(); } } reader.MoveToContent(); reader.ReadEndElement(); } }
public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager) { reader.MoveToContent(); if (XmlHelper.ReadEmptyElementAndRequiredAttribute(reader, dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace, dictionaryManager.XmlSignatureDictionary.Algorithm, out this.prefix) != this.Algorithm) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("AlgorithmMismatchForTransform"))); } }
public byte[] TransformToDigest(object data, SignatureResourcePool resourcePool, string digestMethod, DictionaryManager dictionaryManager) { for (int i = 0; i < (this.TransformCount - 1); i++) { data = this[i].Process(data, resourcePool, dictionaryManager); } return this[this.TransformCount - 1].ProcessAndDigest(data, resourcePool, digestMethod, dictionaryManager); }
public KeyInfoSerializer( bool emitBspRequiredAttributes, DictionaryManager dictionaryManager, TrustDictionary trustDictionary, SecurityTokenSerializer innerSecurityTokenSerializer ) : this( emitBspRequiredAttributes, dictionaryManager, trustDictionary, innerSecurityTokenSerializer, null ) { }
public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager) { reader.MoveToContent(); if (XmlHelper.ReadEmptyElementAndRequiredAttribute(reader, dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace, dictionaryManager.XmlSignatureDictionary.Algorithm, out this.prefix) != this.Algorithm) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("AlgorithmMismatchForTransform"))); } }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.Transforms, dictionaryManager.XmlSignatureDictionary.Namespace); for (int i = 0; i < this.TransformCount; i++) { this[i].WriteTo(writer, dictionaryManager); } writer.WriteEndElement(); }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.Transforms, dictionaryManager.XmlSignatureDictionary.Namespace); for (int i = 0; i < this.TransformCount; i++) { this[i].WriteTo(writer, dictionaryManager); } writer.WriteEndElement(); }
public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(this.Algorithm); writer.WriteEndAttribute(); this.transformationParameters.WriteTo(writer, dictionaryManager); writer.WriteEndElement(); // Transform }
public PreDigestedSignedInfo(DictionaryManager dictionaryManager, string canonicalizationMethod, XmlDictionaryString canonicalizationMethodDictionaryString, string digestMethod, XmlDictionaryString digestMethodDictionaryString, string signatureMethod, XmlDictionaryString signatureMethodDictionaryString) : base(dictionaryManager) { this.references = new ReferenceEntry[8]; base.CanonicalizationMethod = canonicalizationMethod; base.CanonicalizationMethodDictionaryString = canonicalizationMethodDictionaryString; this.DigestMethod = digestMethod; this.digestMethodDictionaryString = digestMethodDictionaryString; base.SignatureMethod = signatureMethod; base.SignatureMethodDictionaryString = signatureMethodDictionaryString; }
public PreDigestedSignedInfo(DictionaryManager dictionaryManager, string canonicalizationMethod, XmlDictionaryString canonicalizationMethodDictionaryString, string digestMethod, XmlDictionaryString digestMethodDictionaryString, string signatureMethod, XmlDictionaryString signatureMethodDictionaryString) : base(dictionaryManager) { this.references = new ReferenceEntry[8]; base.CanonicalizationMethod = canonicalizationMethod; base.CanonicalizationMethodDictionaryString = canonicalizationMethodDictionaryString; this.DigestMethod = digestMethod; this.digestMethodDictionaryString = digestMethodDictionaryString; base.SignatureMethod = signatureMethod; base.SignatureMethodDictionaryString = signatureMethodDictionaryString; }
public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager) { reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.SignatureValue, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; this.Id = reader.GetAttribute("Id", null); reader.Read(); this.signatureText = reader.ReadString(); this.signatureValue = Convert.FromBase64String(this.signatureText.Trim()); reader.ReadEndElement(); }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(XmlSignatureStrings.SecurityJan2004Prefix, XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace); //<wsse:TransformationParameters> writer.WriteStartElement(dictionaryManager.XmlSignatureDictionary.Prefix.Value, dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod, dictionaryManager.XmlSignatureDictionary.Namespace); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n); writer.WriteEndAttribute(); writer.WriteEndElement(); // CanonicalizationMethod writer.WriteEndElement(); // TransformationParameters }
public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager) { XmlTokenStream stream = input as XmlTokenStream; if (stream == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.IdentityModel.SR.GetString("UnsupportedInputTypeForTransform", new object[] { input.GetType() }))); } stream.SetElementExclusion("Signature", "http://www.w3.org/2000/09/xmldsig#"); return stream; }
public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager) { reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.DigestValue, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; reader.Read(); reader.MoveToContent(); this.digestText = reader.ReadString(); this.digestValue = Convert.FromBase64String(this.digestText.Trim()); reader.MoveToContent(); reader.ReadEndElement(); }
public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { string prefix = ""; XmlDictionaryString namespaceUri = dictionaryManager.XmlSignatureDictionary.Namespace; writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.SignedInfo, namespaceUri); if (base.Id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, base.Id); } base.WriteCanonicalizationMethod(writer, dictionaryManager); base.WriteSignatureMethod(writer, dictionaryManager); for (int i = 0; i < this.count; i++) { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Reference, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.URI, null); writer.WriteString("#"); writer.WriteString(this.references[i].id); writer.WriteEndAttribute(); writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transforms, namespaceUri); if (this.addEnvelopedSignatureTransform) { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(dictionaryManager.XmlSignatureDictionary.EnvelopedSignature); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestMethod, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (this.digestMethodDictionaryString != null) { writer.WriteString(this.digestMethodDictionaryString); } else { writer.WriteString(this.digestMethod); } writer.WriteEndAttribute(); writer.WriteEndElement(); byte[] digest = this.references[i].digest; writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestValue, namespaceUri); writer.WriteBase64(digest, 0, digest.Length); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); }
public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { string prefix = ""; XmlDictionaryString namespaceUri = dictionaryManager.XmlSignatureDictionary.Namespace; writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.SignedInfo, namespaceUri); if (base.Id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, base.Id); } base.WriteCanonicalizationMethod(writer, dictionaryManager); base.WriteSignatureMethod(writer, dictionaryManager); for (int i = 0; i < this.count; i++) { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Reference, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.URI, null); writer.WriteString("#"); writer.WriteString(this.references[i].id); writer.WriteEndAttribute(); writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transforms, namespaceUri); if (this.addEnvelopedSignatureTransform) { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(dictionaryManager.XmlSignatureDictionary.EnvelopedSignature); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestMethod, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (this.digestMethodDictionaryString != null) { writer.WriteString(this.digestMethodDictionaryString); } else { writer.WriteString(this.digestMethod); } writer.WriteEndAttribute(); writer.WriteEndElement(); byte[] digest = this.references[i].digest; writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestValue, namespaceUri); writer.WriteBase64(digest, 0, digest.Length); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); }
public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager, bool preserveComments) { XmlDictionaryString elementName = this.isCanonicalizationMethod ? dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod : dictionaryManager.XmlSignatureDictionary.Transform; reader.MoveToStartElement(elementName, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; bool isEmptyElement = reader.IsEmptyElement; algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (string.IsNullOrEmpty(algorithm)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.ID0001, dictionaryManager.XmlSignatureDictionary.Algorithm, reader.LocalName))); } if (algorithm == dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14nWithComments.Value) { // to include comments in canonicalization, two conditions need to be met // 1. the Reference must be an xpointer. // 2. the transform must be #withComments includeComments = preserveComments && true; } else if (algorithm == dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n.Value) { includeComments = false; } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.ID6005, algorithm))); } reader.Read(); reader.MoveToContent(); if (!isEmptyElement) { if (reader.IsStartElement(dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace)) { reader.MoveToStartElement(dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace); this.inclusiveListElementPrefix = reader.Prefix; bool emptyElement = reader.IsEmptyElement; // We treat PrefixList as optional Attribute. this.InclusiveNamespacesPrefixList = reader.GetAttribute(dictionaryManager.ExclusiveC14NDictionary.PrefixList, null); reader.Read(); if (!emptyElement) { reader.ReadEndElement(); } } reader.MoveToContent(); reader.ReadEndElement(); // Transform } }
/// <summary> /// Initializes an instance of <see cref="EnvelopedSignatureWriter"/>. The returned writer can be directly used /// to write the envelope. The signature will be automatically generated when /// the envelope is completed. /// </summary> /// <param name="innerWriter">Writer to wrap/</param> /// <param name="signingCredentials">SigningCredentials to be used to generate the signature.</param> /// <param name="referenceId">The reference Id of the envelope.</param> /// <param name="securityTokenSerializer">SecurityTokenSerializer to serialize the signature KeyInfo.</param> /// <exception cref="ArgumentNullException">One of he input parameter is null.</exception> /// <exception cref="ArgumentException">The string 'referenceId' is either null or empty.</exception> public EnvelopedSignatureWriter(XmlWriter innerWriter, SigningCredentials signingCredentials, string referenceId, SecurityTokenSerializer securityTokenSerializer) { if (innerWriter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("innerWriter"); } if (signingCredentials == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("signingCredentials"); } if (string.IsNullOrEmpty(referenceId)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.ID0006), "referenceId")); } if (securityTokenSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("securityTokenSerializer"); } // Remember the user's writer here. We need to finally write out the signed XML // into this writer. _dictionaryManager = new DictionaryManager(); _innerWriter = innerWriter; _signingCreds = signingCredentials; _referenceId = referenceId; _tokenSerializer = securityTokenSerializer; _signatureFragment = new MemoryStream(); _endFragment = new MemoryStream(); _writerStream = new MemoryStream(); XmlDictionaryWriter effectiveWriter = XmlDictionaryWriter.CreateTextWriter(_writerStream, Encoding.UTF8, false); // Initialize the base writer to the newly created writer. The user should write the XML // to this. base.InitializeInnerWriter(effectiveWriter); _hashAlgorithm = CryptoHelper.CreateHashAlgorithm(_signingCreds.DigestAlgorithm); _hashStream = new HashStream(_hashAlgorithm); base.InnerWriter.StartCanonicalization(_hashStream, false, null); // // Add tracing for the un-canonicalized bytes // if (DiagnosticUtility.ShouldTraceVerbose) { _preCanonicalTracingStream = new MemoryStream(); base.InitializeTracingWriter(new XmlTextWriter(_preCanonicalTracingStream, Encoding.UTF8)); } }
/// <summary> /// Initializes an instance of <see cref="EnvelopedSignatureWriter"/>. The returned writer can be directly used /// to write the envelope. The signature will be automatically generated when /// the envelope is completed. /// </summary> /// <param name="innerWriter">Writer to wrap/</param> /// <param name="signingCredentials">SigningCredentials to be used to generate the signature.</param> /// <param name="referenceId">The reference Id of the envelope.</param> /// <param name="securityTokenSerializer">SecurityTokenSerializer to serialize the signature KeyInfo.</param> /// <exception cref="ArgumentNullException">One of he input parameter is null.</exception> /// <exception cref="ArgumentException">The string 'referenceId' is either null or empty.</exception> public EnvelopedSignatureWriter(XmlWriter innerWriter, SigningCredentials signingCredentials, string referenceId, SecurityTokenSerializer securityTokenSerializer) { if (innerWriter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("innerWriter"); } if (signingCredentials == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("signingCredentials"); } if (string.IsNullOrEmpty(referenceId)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.ID0006), "referenceId")); } if (securityTokenSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("securityTokenSerializer"); } // Remember the user's writer here. We need to finally write out the signed XML // into this writer. _dictionaryManager = new DictionaryManager(); _innerWriter = innerWriter; _signingCreds = signingCredentials; _referenceId = referenceId; _tokenSerializer = securityTokenSerializer; _signatureFragment = new MemoryStream(); _endFragment = new MemoryStream(); _writerStream = new MemoryStream(); XmlDictionaryWriter effectiveWriter = XmlDictionaryWriter.CreateTextWriter(_writerStream, Encoding.UTF8, false); // Initialize the base writer to the newly created writer. The user should write the XML // to this. base.InitializeInnerWriter(effectiveWriter); _hashAlgorithm = CryptoHelper.CreateHashAlgorithm(_signingCreds.DigestAlgorithm); _hashStream = new HashStream(_hashAlgorithm); base.InnerWriter.StartCanonicalization(_hashStream, false, null); // // Add tracing for the un-canonicalized bytes // if (DiagnosticUtility.ShouldTraceVerbose) { _preCanonicalTracingStream = new MemoryStream(); base.InitializeTracingWriter(new XmlTextWriter(_preCanonicalTracingStream, Encoding.UTF8)); } }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix ?? "", dictionaryManager.XmlSignatureDictionary.DigestValue, dictionaryManager.XmlSignatureDictionary.Namespace); if (this.digestText != null) { writer.WriteString(this.digestText); } else { writer.WriteBase64(this.digestValue, 0, this.digestValue.Length); } writer.WriteEndElement(); }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { if (this.DataReferenceCount == 0) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("ReferenceListCannotBeEmpty"))); } writer.WriteStartElement("e", ElementName, NamespaceUri); for (int i = 0; i < this.DataReferenceCount; i++) { DataReference.WriteTo(writer, this.referredIds[i]); } writer.WriteEndElement(); }
public KeyInfoSerializer( bool emitBspRequiredAttributes, DictionaryManager dictionaryManager, TrustDictionary trustDictionary, SecurityTokenSerializer innerSecurityTokenSerializer, Func<KeyInfoSerializer, IEnumerable<SerializerEntries>> additionalEntries) { this.dictionaryManager = dictionaryManager; this.emitBspRequiredAttributes = emitBspRequiredAttributes; this.innerSecurityTokenSerializer = innerSecurityTokenSerializer; this.serializerEntries = new List<SecurityTokenSerializer.SerializerEntries>(); this.serializerEntries.Add(new XmlDsigSep2000(this)); this.serializerEntries.Add(new XmlEncApr2001(this)); this.serializerEntries.Add(new System.IdentityModel.Security.WSTrust(this, trustDictionary)); if ( additionalEntries != null ) { foreach ( SerializerEntries entries in additionalEntries( this ) ) { this.serializerEntries.Add(entries); } } bool wsSecuritySerializerFound = false; foreach ( SerializerEntries entry in this.serializerEntries ) { if ( ( entry is WSSecurityXXX2005 ) || ( entry is WSSecurityJan2004 ) ) { wsSecuritySerializerFound = true; break; } } if ( !wsSecuritySerializerFound ) { this.serializerEntries.Add( new WSSecurityXXX2005( this ) ); } this.tokenEntries = new List<TokenEntry>(); this.keyIdentifierEntries = new List<SecurityTokenSerializer.KeyIdentifierEntry>(); this.keyIdentifierClauseEntries = new List<SecurityTokenSerializer.KeyIdentifierClauseEntry>(); for (int i = 0; i < this.serializerEntries.Count; ++i) { SecurityTokenSerializer.SerializerEntries serializerEntry = this.serializerEntries[i]; serializerEntry.PopulateTokenEntries(this.tokenEntries); serializerEntry.PopulateKeyIdentifierEntries(this.keyIdentifierEntries); serializerEntry.PopulateKeyIdentifierClauseEntries(this.keyIdentifierClauseEntries); } }
public Reference(DictionaryManager dictionaryManager, string uri, object resolvedXmlSource) { this.digestValueElement = new DigestValueElement(); this.prefix = ""; this.transformChain = new System.IdentityModel.TransformChain(); if (dictionaryManager == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionaryManager"); } this.dictionaryManager = dictionaryManager; this.digestMethodElement = new ElementWithAlgorithmAttribute(dictionaryManager.XmlSignatureDictionary.DigestMethod); this.uri = uri; this.resolvedXmlSource = resolvedXmlSource; }
public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager) { reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Signature, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; this.Id = reader.GetAttribute(dictionaryManager.UtilityDictionary.IdAttribute, null); reader.Read(); this.signedInfo.ReadFrom(reader, this.signedXml.TransformFactory, dictionaryManager); this.signatureValueElement.ReadFrom(reader, dictionaryManager); if (this.signedXml.SecurityTokenSerializer.CanReadKeyIdentifier(reader)) { this.keyIdentifier = this.signedXml.SecurityTokenSerializer.ReadKeyIdentifier(reader); } reader.ReadEndElement(); }
public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager) { reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Signature, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; this.Id = reader.GetAttribute(dictionaryManager.UtilityDictionary.IdAttribute, null); reader.Read(); this.signedInfo.ReadFrom(reader, this.signedXml.TransformFactory, dictionaryManager); this.signatureValueElement.ReadFrom(reader, dictionaryManager); if (this.signedXml.SecurityTokenSerializer.CanReadKeyIdentifier(reader)) { this.keyIdentifier = this.signedXml.SecurityTokenSerializer.ReadKeyIdentifier(reader); } reader.ReadEndElement(); }
public Reference(DictionaryManager dictionaryManager, string uri, object resolvedXmlSource) { this.digestValueElement = new DigestValueElement(); this.prefix = ""; this.transformChain = new System.IdentityModel.TransformChain(); if (dictionaryManager == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionaryManager"); } this.dictionaryManager = dictionaryManager; this.digestMethodElement = new ElementWithAlgorithmAttribute(dictionaryManager.XmlSignatureDictionary.DigestMethod); this.uri = uri; this.resolvedXmlSource = resolvedXmlSource; }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, this.elementName, dictionaryManager.XmlSignatureDictionary.Namespace); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (this.algorithmDictionaryString != null) { writer.WriteString(this.algorithmDictionaryString); } else { writer.WriteString(this.algorithm); } writer.WriteEndAttribute(); writer.WriteEndElement(); }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, this.elementName, dictionaryManager.XmlSignatureDictionary.Namespace); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (this.algorithmDictionaryString != null) { writer.WriteString(this.algorithmDictionaryString); } else { writer.WriteString(this.algorithm); } writer.WriteEndAttribute(); writer.WriteEndElement(); }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.Signature, dictionaryManager.XmlSignatureDictionary.Namespace); if (this.id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.id); } this.signedInfo.WriteTo(writer, dictionaryManager); this.signatureValueElement.WriteTo(writer, dictionaryManager); if (this.keyIdentifier != null) { this.signedXml.SecurityTokenSerializer.WriteKeyIdentifier(writer, this.keyIdentifier); } writer.WriteEndElement(); }
public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.SignedInfo, dictionaryManager.XmlSignatureDictionary.Namespace); if (base.Id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, base.Id); } base.WriteCanonicalizationMethod(writer, dictionaryManager); base.WriteSignatureMethod(writer, dictionaryManager); for (int i = 0; i < this.references.Count; i++) { this.references[i].WriteTo(writer, dictionaryManager); } writer.WriteEndElement(); }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.Signature, dictionaryManager.XmlSignatureDictionary.Namespace); if (this.id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.id); } this.signedInfo.WriteTo(writer, dictionaryManager); this.signatureValueElement.WriteTo(writer, dictionaryManager); if (this.keyIdentifier != null) { this.signedXml.SecurityTokenSerializer.WriteKeyIdentifier(writer, this.keyIdentifier); } writer.WriteEndElement(); }
public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager) { reader.MoveToContent(); reader.MoveToStartElement(XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace); string prefix = reader.Prefix; bool skipReadingTransformEnd = reader.IsEmptyElement; reader.ReadStartElement(); if (reader.IsStartElement(dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod, dictionaryManager.XmlSignatureDictionary.Namespace)) { string algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); // Canonicalization Method can be empty. // <elementNOTempty></elementNOTempty> // <elementEmpty/> bool skipReadingC14End = reader.IsEmptyElement; reader.ReadStartElement(); if (algorithm == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException( SR.GetString(SR.RequiredAttributeMissing, dictionaryManager.XmlSignatureDictionary.Algorithm, dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod))); } if (algorithm != this.CanonicalizationAlgorithm) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.AlgorithmMismatchForTransform))); } // ReadEndElement() called only if element was not empty if (!skipReadingC14End) { reader.MoveToContent(); reader.ReadEndElement(); } } // If it was empty, don't read endElement as it was read in ReadStartElement if (!skipReadingTransformEnd) { reader.MoveToContent(); reader.ReadEndElement(); } }
public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { XmlDictionaryString elementName = this.isCanonicalizationMethod ? dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod : dictionaryManager.XmlSignatureDictionary.Transform; writer.WriteStartElement(this.prefix, elementName, dictionaryManager.XmlSignatureDictionary.Namespace); writer.WriteAttributeString(dictionaryManager.XmlSignatureDictionary.Algorithm, null, algorithm); if (this.InclusiveNamespacesPrefixList != null) { writer.WriteStartElement(this.inclusiveListElementPrefix, dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace); writer.WriteAttributeString(dictionaryManager.ExclusiveC14NDictionary.PrefixList, null, this.InclusiveNamespacesPrefixList); writer.WriteEndElement(); // InclusiveNamespaces } writer.WriteEndElement(); // Transform }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.SignatureValue, dictionaryManager.XmlSignatureDictionary.Namespace); if (this.id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.id); } if (this.signatureText != null) { writer.WriteString(this.signatureText); } else { writer.WriteBase64(this.signatureValue, 0, this.signatureValue.Length); } writer.WriteEndElement(); }
public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager) { reader.MoveToStartElement(this.elementName, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; bool isEmptyElement = reader.IsEmptyElement; this.algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (this.algorithm == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("RequiredAttributeMissing", new object[] { dictionaryManager.XmlSignatureDictionary.Algorithm, this.elementName }))); } reader.Read(); reader.MoveToContent(); if (!isEmptyElement) { reader.MoveToContent(); reader.ReadEndElement(); } }
public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager) { reader.MoveToStartElement(this.elementName, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; bool isEmptyElement = reader.IsEmptyElement; this.algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (this.algorithm == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("RequiredAttributeMissing", new object[] { dictionaryManager.XmlSignatureDictionary.Algorithm, this.elementName }))); } reader.Read(); reader.MoveToContent(); if (!isEmptyElement) { reader.MoveToContent(); reader.ReadEndElement(); } }
public void ReadFrom(XmlDictionaryReader reader, TransformFactory transformFactory, DictionaryManager dictionaryManager) { reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Transforms, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; reader.Read(); while (reader.IsStartElement(dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace)) { string attribute = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); Transform transform = transformFactory.CreateTransform(attribute); transform.ReadFrom(reader, dictionaryManager); this.Add(transform); } reader.MoveToContent(); reader.ReadEndElement(); if (this.TransformCount == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("AtLeastOneTransformRequired"))); } }
internal SignedXml(SignedInfo signedInfo, DictionaryManager dictionaryManager, System.IdentityModel.Selectors.SecurityTokenSerializer tokenSerializer) { if (signedInfo == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("signedInfo")); } if (dictionaryManager == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionaryManager"); } if (tokenSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenSerializer"); } this.transformFactory = StandardTransformFactory.Instance; this.tokenSerializer = tokenSerializer; this.signature = new System.IdentityModel.Signature(this, signedInfo); this.dictionaryManager = dictionaryManager; }
internal SignedXml(SignedInfo signedInfo, DictionaryManager dictionaryManager, SecurityTokenSerializer tokenSerializer) { if (signedInfo == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("signedInfo")); } if (dictionaryManager == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionaryManager"); } if (tokenSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenSerializer"); } this.transformFactory = StandardTransformFactory.Instance; this.tokenSerializer = tokenSerializer; this.signature = new Signature(this, signedInfo); this.dictionaryManager = dictionaryManager; }
public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager) { if (input is XmlReader) { CanonicalizationDriver configuredDriver = this.GetConfiguredDriver(resourcePool); configuredDriver.SetInput(input as XmlReader); return configuredDriver.GetMemoryStream(); } if (!(input is ISecurityElement)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.IdentityModel.SR.GetString("UnsupportedInputTypeForTransform", new object[] { input.GetType() }))); } MemoryStream stream = new MemoryStream(); XmlDictionaryWriter writer = resourcePool.TakeUtf8Writer(); writer.StartCanonicalization(stream, false, null); (input as ISecurityElement).WriteTo(writer, dictionaryManager); writer.EndCanonicalization(); stream.Seek(0L, SeekOrigin.Begin); return stream; }
public void ProcessAndDigest(object input, SignatureResourcePool resourcePool, HashAlgorithm hash, DictionaryManager dictionaryManger) { HashStream hashStream = resourcePool.TakeHashStream(hash); XmlReader reader = input as XmlReader; if (reader != null) { this.ProcessReaderInput(reader, resourcePool, hashStream); } else { if (!(input is ISecurityElement)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.IdentityModel.SR.GetString("UnsupportedInputTypeForTransform", new object[] { input.GetType() }))); } XmlDictionaryWriter writer = resourcePool.TakeUtf8Writer(); writer.StartCanonicalization(hashStream, this.IncludeComments, this.GetInclusivePrefixes()); (input as ISecurityElement).WriteTo(writer, dictionaryManger); writer.EndCanonicalization(); } hashStream.FlushHash(); }
public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager) { if (input is XmlReader) { CanonicalizationDriver driver = GetConfiguredDriver(resourcePool); driver.SetInput(input as XmlReader); return driver.GetMemoryStream(); } else if (input is ISecurityElement) { MemoryStream stream = new MemoryStream(); XmlDictionaryWriter utf8Writer = resourcePool.TakeUtf8Writer(); utf8Writer.StartCanonicalization(stream, false, null); (input as ISecurityElement).WriteTo(utf8Writer, dictionaryManager); utf8Writer.EndCanonicalization(); stream.Seek(0, SeekOrigin.Begin); return stream; } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedInputTypeForTransform, input.GetType()))); } }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.Reference, dictionaryManager.XmlSignatureDictionary.Namespace); if (this.id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.id); } if (this.uri != null) { writer.WriteAttributeString(dictionaryManager.XmlSignatureDictionary.URI, null, this.uri); } if (this.type != null) { writer.WriteAttributeString(dictionaryManager.XmlSignatureDictionary.Type, null, this.type); } if (this.transformChain.TransformCount > 0) { this.transformChain.WriteTo(writer, dictionaryManager); } this.digestMethodElement.WriteTo(writer, dictionaryManager); this.digestValueElement.WriteTo(writer, dictionaryManager); writer.WriteEndElement(); }
/// <summary> /// Initializes an instance of <see cref="EnvelopedSignatureReader"/> /// </summary> /// <param name="reader">Reader pointing to the enveloped signed XML.</param> /// <param name="securityTokenSerializer">Token Serializer to deserialize the KeyInfo of the Signature.</param> /// <param name="signingTokenResolver">Token Resolver to resolve the signing token.</param> /// <param name="requireSignature">The value indicates whether the signature is optional.</param> /// <param name="automaticallyReadSignature">This value indicates if the Signature should be read /// when the Signature element is encountered or allow the caller to read the Signature manually.</param> /// <param name="resolveIntrinsicSigningKeys">A value indicating if intrinsic signing keys should be resolved.</param> public EnvelopedSignatureReader(XmlReader reader, SecurityTokenSerializer securityTokenSerializer, SecurityTokenResolver signingTokenResolver, bool requireSignature, bool automaticallyReadSignature, bool resolveIntrinsicSigningKeys) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } if (securityTokenSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("securityTokenSerializer"); } _automaticallyReadSignature = automaticallyReadSignature; _dictionaryManager = new DictionaryManager(); _tokenSerializer = securityTokenSerializer; _requireSignature = requireSignature; _signingTokenResolver = signingTokenResolver ?? EmptySecurityTokenResolver.Instance; _resolveIntrinsicSigningKeys = resolveIntrinsicSigningKeys; XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateDictionaryReader(reader); _wrappedReader = new WrappedReader(dictionaryReader); base.InitializeInnerReader(_wrappedReader); }
public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { XmlDictionaryString localName = this.isCanonicalizationMethod ? dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod : dictionaryManager.XmlSignatureDictionary.Transform; XmlDictionaryString str2 = this.includeComments ? dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14nWithComments : dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n; writer.WriteStartElement(this.prefix, localName, dictionaryManager.XmlSignatureDictionary.Namespace); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (str2 != null) { writer.WriteString(str2); } else { writer.WriteString(str2.Value); } writer.WriteEndAttribute(); if (this.InclusiveNamespacesPrefixList != null) { writer.WriteStartElement(this.inclusiveListElementPrefix, dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace); writer.WriteAttributeString(dictionaryManager.ExclusiveC14NDictionary.PrefixList, null, this.InclusiveNamespacesPrefixList); writer.WriteEndElement(); } writer.WriteEndElement(); }
/// <summary> /// Initializes an instance of <see cref="EnvelopedSignatureReader"/> /// </summary> /// <param name="reader">Reader pointing to the enveloped signed XML.</param> /// <param name="securityTokenSerializer">Token Serializer to deserialize the KeyInfo of the Signature.</param> /// <param name="signingTokenResolver">Token Resolver to resolve the signing token.</param> /// <param name="requireSignature">The value indicates whether the signature is optional.</param> /// <param name="automaticallyReadSignature">This value indicates if the Signature should be read /// when the Signature element is encountered or allow the caller to read the Signature manually.</param> /// <param name="resolveIntrinsicSigningKeys">A value indicating if intrinsic signing keys should be resolved.</param> public EnvelopedSignatureReader(XmlReader reader, SecurityTokenSerializer securityTokenSerializer, SecurityTokenResolver signingTokenResolver, bool requireSignature, bool automaticallyReadSignature, bool resolveIntrinsicSigningKeys) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } if (securityTokenSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("securityTokenSerializer"); } _automaticallyReadSignature = automaticallyReadSignature; _dictionaryManager = new DictionaryManager(); _tokenSerializer = securityTokenSerializer; _requireSignature = requireSignature; _signingTokenResolver = signingTokenResolver ?? EmptySecurityTokenResolver.Instance; _resolveIntrinsicSigningKeys = resolveIntrinsicSigningKeys; XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateDictionaryReader(reader); _wrappedReader = new WrappedReader(dictionaryReader); base.InitializeInnerReader(_wrappedReader); }
public PreDigestedSignedInfo(DictionaryManager dictionaryManager) : base(dictionaryManager) { this.references = new ReferenceEntry[InitialReferenceArraySize]; }
public override void ReadFrom(XmlDictionaryReader reader, TransformFactory transformFactory, DictionaryManager dictionaryManager) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); // sender side use only }
internal void WriteTo(XmlWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { if (writer == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); if ((this.signingCredentials == null) && (this.signature == null)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SamlAssertionMissingSigningCredentials))); XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer); if (this.signingCredentials != null) { using (HashAlgorithm hash = CryptoHelper.CreateHashAlgorithm(this.signingCredentials.DigestAlgorithm)) { this.hashStream = new HashStream(hash); this.keyInfoSerializer = keyInfoSerializer; this.dictionaryManager = samlSerializer.DictionaryManager; SamlDelegatingWriter delegatingWriter = new SamlDelegatingWriter(dictionaryWriter, this.hashStream, this, samlSerializer.DictionaryManager.ParentDictionary); this.WriteXml(delegatingWriter, samlSerializer, keyInfoSerializer); } } else { this.tokenStream.SetElementExclusion(null, null); this.tokenStream.WriteTo(dictionaryWriter, samlSerializer.DictionaryManager); } }
public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { string prefix = XmlSignatureStrings.Prefix; XmlDictionaryString ns = dictionaryManager.XmlSignatureDictionary.Namespace; writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.SignedInfo, ns); if (this.Id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.Id); } WriteCanonicalizationMethod(writer, dictionaryManager); WriteSignatureMethod(writer, dictionaryManager); for (int i = 0; i < this.count; i++) { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Reference, ns); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.URI, null); writer.WriteString("#"); writer.WriteString(this.references[i].id); writer.WriteEndAttribute(); writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transforms, ns); if (this.addEnvelopedSignatureTransform) { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(dictionaryManager.XmlSignatureDictionary.EnvelopedSignature); writer.WriteEndAttribute(); writer.WriteEndElement(); // Transform } if (this.references[i].useStrTransform) { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(SecurityAlgorithms.StrTransform); writer.WriteEndAttribute(); writer.WriteStartElement(XmlSignatureStrings.SecurityJan2004Prefix, XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace); //<wsse:TransformationParameters> writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod, ns); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n); writer.WriteEndAttribute(); writer.WriteEndElement(); //CanonicalizationMethod writer.WriteEndElement(); // TransformationParameters writer.WriteEndElement(); // Transform } else { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n); writer.WriteEndAttribute(); writer.WriteEndElement(); // Transform } writer.WriteEndElement(); // Transforms writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestMethod, ns); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (this.digestMethodDictionaryString != null) { writer.WriteString(this.digestMethodDictionaryString); } else { writer.WriteString(this.digestMethod); } writer.WriteEndAttribute(); writer.WriteEndElement(); // DigestMethod byte[] digest = this.references[i].digest; writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestValue, ns); writer.WriteBase64(digest, 0, digest.Length); writer.WriteEndElement(); // DigestValue writer.WriteEndElement(); // Reference } writer.WriteEndElement(); // SignedInfo }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { bool isEmptyElement; if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (!this.MoveToFirst()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.IdentityModel.SR.GetString("XmlTokenBufferIsEmpty"))); } int num = 0; int num2 = -1; bool flag = true; Label_0040: switch (this.NodeType) { case XmlNodeType.Element: isEmptyElement = this.IsEmptyElement; num++; if (flag) { if (this.excludedElementDepth.HasValue) { int? excludedElementDepth = this.excludedElementDepth; int num3 = num - 1; if (!((excludedElementDepth.GetValueOrDefault() == num3) && excludedElementDepth.HasValue)) { break; } } if ((this.LocalName == this.excludedElement) && (this.NamespaceUri == this.excludedElementNamespace)) { flag = false; num2 = num; } } break; case XmlNodeType.Text: if (flag) { writer.WriteString(this.Value); } goto Label_01AD; case XmlNodeType.CDATA: if (flag) { writer.WriteCData(this.Value); } goto Label_01AD; case XmlNodeType.Comment: if (flag) { writer.WriteComment(this.Value); } goto Label_01AD; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: if (flag) { writer.WriteWhitespace(this.Value); } goto Label_01AD; case XmlNodeType.EndElement: goto Label_0152; default: goto Label_01AD; } if (flag) { writer.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceUri); } if (this.MoveToFirstAttribute()) { do { if (flag) { writer.WriteAttributeString(this.Prefix, this.LocalName, this.NamespaceUri, this.Value); } } while (this.MoveToNextAttribute()); } if (!isEmptyElement) { goto Label_01AD; } Label_0152: if (flag) { writer.WriteEndElement(); } else if (num2 == num) { flag = true; num2 = -1; } num--; Label_01AD: if (this.MoveToNext()) { goto Label_0040; } }
public Reference(DictionaryManager dictionaryManager) : this(dictionaryManager, null) { }
public Reference(DictionaryManager dictionaryManager, string uri) : this(dictionaryManager, uri, null) { }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { this.GetWriter().WriteTo(writer, dictionaryManager); }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { throw ExceptionHelper.PlatformNotSupported(); }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (!MoveToFirst()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.XmlTokenBufferIsEmpty))); } int depth = 0; int recordedDepth = -1; bool include = true; do { switch (this.NodeType) { case XmlNodeType.Element: bool isEmpty = this.IsEmptyElement; depth++; if (include && (null == excludedElementDepth || excludedElementDepth == (depth - 1)) && this.LocalName == this.excludedElement && this.NamespaceUri == this.excludedElementNamespace) { include = false; recordedDepth = depth; } if (include) { writer.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceUri); } if (MoveToFirstAttribute()) { do { if (include) { writer.WriteAttributeString(this.Prefix, this.LocalName, this.NamespaceUri, this.Value); } } while (MoveToNextAttribute()); } if (isEmpty) { goto case XmlNodeType.EndElement; } break; case XmlNodeType.EndElement: if (include) { writer.WriteEndElement(); } else if (recordedDepth == depth) { include = true; recordedDepth = -1; } depth--; break; case XmlNodeType.CDATA: if (include) { writer.WriteCData(this.Value); } break; case XmlNodeType.Comment: if (include) { writer.WriteComment(this.Value); } break; case XmlNodeType.Text: if (include) { writer.WriteString(this.Value); } break; case XmlNodeType.SignificantWhitespace: case XmlNodeType.Whitespace: if (include) { writer.WriteWhitespace(this.Value); } break; case XmlNodeType.DocumentType: case XmlNodeType.XmlDeclaration: break; } } while (MoveToNext()); }
public void ReadFrom(XmlDictionaryReader reader, TransformFactory transformFactory, DictionaryManager dictionaryManager) { reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Reference, dictionaryManager.XmlSignatureDictionary.Namespace); this.prefix = reader.Prefix; this.Id = reader.GetAttribute("Id", null); this.Uri = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.URI, null); this.Type = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Type, null); reader.Read(); if (reader.IsStartElement(dictionaryManager.XmlSignatureDictionary.Transforms, dictionaryManager.XmlSignatureDictionary.Namespace)) { this.transformChain.ReadFrom(reader, transformFactory, dictionaryManager); } this.digestMethodElement.ReadFrom(reader, dictionaryManager); this.digestValueElement.ReadFrom(reader, dictionaryManager); reader.MoveToContent(); reader.ReadEndElement(); }