Exemplo n.º 1
0
        protected override SecurityKeyIdentifier ReadKeyIdentifierCore(XmlReader reader)
        {
            XmlDictionaryReader localReader = XmlDictionaryReader.CreateDictionaryReader(reader);

            localReader.ReadStartElement(CoreWCF.XD.XmlSignatureDictionary.KeyInfo, CoreWCF.XD.XmlSignatureDictionary.Namespace);
            SecurityKeyIdentifier keyIdentifier = new SecurityKeyIdentifier();

            while (localReader.IsStartElement())
            {
                SecurityKeyIdentifierClause clause = InnerSecurityTokenSerializer.ReadKeyIdentifierClause(localReader);
                if (clause == null)
                {
                    localReader.Skip();
                }
                else
                {
                    keyIdentifier.Add(clause);
                }
            }
            if (keyIdentifier.Count == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format("ErrorDeserializingKeyIdentifierClause")));
            }
            localReader.ReadEndElement();

            return(keyIdentifier);
        }
Exemplo n.º 2
0
 internal EncryptedKeyIdentifierClause(byte[] encryptedKey, string encryptionMethod, SecurityKeyIdentifier encryptingKeyIdentifier, string carriedKeyName, bool cloneBuffer, byte[] derivationNonce, int derivationLength)
     : base("http://www.w3.org/2001/04/xmlenc#EncryptedKey", encryptedKey, cloneBuffer, derivationNonce, derivationLength)
 {
     CarriedKeyName          = carriedKeyName;
     _encryptionMethod       = encryptionMethod ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(encryptionMethod));
     EncryptingKeyIdentifier = encryptingKeyIdentifier;
 }
Exemplo n.º 3
0
 protected override bool CanWriteKeyIdentifierCore(SecurityKeyIdentifier keyIdentifier)
 {
     for (int i = 0; i < _keyIdentifierEntries.Count; ++i)
     {
         KeyIdentifierEntry keyIdentifierEntry = _keyIdentifierEntries[i];
         if (keyIdentifierEntry.SupportsCore(keyIdentifier))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 4
0
            public override void WriteKeyIdentifierCore(XmlDictionaryWriter writer, SecurityKeyIdentifier keyIdentifier)
            {
                writer.WriteStartElement(CoreWCF.XD.XmlSignatureDictionary.Prefix.Value, LocalName, NamespaceUri);
                bool clauseWritten = false;

                foreach (SecurityKeyIdentifierClause clause in keyIdentifier)
                {
                    _securityTokenSerializer.InnerSecurityTokenSerializer.WriteKeyIdentifierClause(writer, clause);
                    clauseWritten = true;
                }
                writer.WriteEndElement(); // KeyInfo
                if (!clauseWritten)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityMessageSerializationException(SR.NoKeyInfoClausesToWrite));
                }
            }
Exemplo n.º 5
0
        /// <summary>
        /// Override of the base class. Resolves the given SecurityKeyIdentifier to a 
        /// SecurityToken.
        /// </summary>
        /// <param name="keyIdentifier">The KeyIdentifier to be resolved.</param>
        /// <param name="token">The resolved SecurityToken</param>
        /// <returns>True if successfully resolved.</returns>
        /// <exception cref="ArgumentNullException">Input argument 'keyIdentifier' is null.</exception>
        protected override bool TryResolveTokenCore(SecurityKeyIdentifier keyIdentifier, out SecurityToken token)
        {
            if (keyIdentifier == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(keyIdentifier));
            }

            token = null;
            foreach (SecurityTokenResolver tokenResolver in _tokenResolvers)
            {
                if (tokenResolver.TryResolveToken(keyIdentifier, out token))
                {
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 6
0
        protected override void WriteKeyIdentifierCore(XmlWriter writer, SecurityKeyIdentifier keyIdentifier)
        {
            bool wroteKeyIdentifier         = false;
            XmlDictionaryWriter localWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer);

            for (int i = 0; i < _keyIdentifierEntries.Count; ++i)
            {
                KeyIdentifierEntry keyIdentifierEntry = _keyIdentifierEntries[i];
                if (keyIdentifierEntry.SupportsCore(keyIdentifier))
                {
                    try
                    {
                        keyIdentifierEntry.WriteKeyIdentifierCore(localWriter, keyIdentifier);
                    }
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        if (!ShouldWrapException(e))
                        {
                            throw;
                        }

                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format("ErrorSerializingKeyIdentifier"), e));
                    }
                    wroteKeyIdentifier = true;
                    break;
                }
            }

            if (!wroteKeyIdentifier)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.StandardsManagerCannotWriteObject, keyIdentifier.GetType())));
            }

            localWriter.Flush();
        }
Exemplo n.º 7
0
            public override SecurityKeyIdentifier ReadKeyIdentifierCore(XmlDictionaryReader reader)
            {
                reader.ReadStartElement(LocalName, NamespaceUri);
                SecurityKeyIdentifier keyIdentifier = new SecurityKeyIdentifier();

                while (reader.IsStartElement())
                {
                    SecurityKeyIdentifierClause clause = _securityTokenSerializer.ReadKeyIdentifierClause(reader);
                    if (clause == null)
                    {
                        reader.Skip();
                    }
                    else
                    {
                        keyIdentifier.Add(clause);
                    }
                }
                if (keyIdentifier.Count == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.ErrorDeserializingKeyIdentifierClause));
                }
                reader.ReadEndElement();
                return(keyIdentifier);
            }
Exemplo n.º 8
0
 public EncryptedKeyIdentifierClause(byte[] encryptedKey, string encryptionMethod, SecurityKeyIdentifier encryptingKeyIdentifier, string carriedKeyName, byte[] derivationNonce, int derivationLength)
     : this(encryptedKey, encryptionMethod, encryptingKeyIdentifier, carriedKeyName, true, derivationNonce, derivationLength)
 {
 }
Exemplo n.º 9
0
 public EncryptedKeyIdentifierClause(byte[] encryptedKey, string encryptionMethod, SecurityKeyIdentifier encryptingKeyIdentifier, string carriedKeyName)
     : this(encryptedKey, encryptionMethod, encryptingKeyIdentifier, carriedKeyName, true, null, 0)
 {
 }
Exemplo n.º 10
0
 public EncryptedKeyIdentifierClause(byte[] encryptedKey, string encryptionMethod, SecurityKeyIdentifier encryptingKeyIdentifier)
     : this(encryptedKey, encryptionMethod, encryptingKeyIdentifier, null)
 {
 }
Exemplo n.º 11
0
 public override bool SupportsCore(SecurityKeyIdentifier keyIdentifier)
 {
     return(true);
 }