1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.IdentityModel
{
using System.Collections.Generic;
using System.IdentityModel.Diagnostics;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Xml;
/// <summary>
/// This class implements a deserialization for: EncryptedType as defined in section 3.5.1 of http://www.w3.org/TR/2002/REC-xmlenc-core-2002120
/// </summary>
internal class EncryptedKeyElement : EncryptedTypeElement
{
string _carriedName;
string _recipient;
List<string> _keyReferences;
List<string> _dataReferences;
public EncryptedKeyElement( SecurityTokenSerializer keyInfoSerializer )
: base( keyInfoSerializer )
{
_keyReferences = new List<string>();
_dataReferences = new List<string>();
}
public string CarriedName
{
get { return _carriedName; }
}
public IList<string> DataReferences
{
get { return _dataReferences; }
}
public IList<string> KeyReferences
{
get { return _keyReferences; }
}
public override void ReadExtensions( XmlDictionaryReader reader )
{
reader.MoveToContent();
if ( reader.IsStartElement( XmlEncryptionConstants.Elements.ReferenceList, XmlEncryptionConstants.Namespace ) )
{
reader.ReadStartElement();
// could have data or key references. these are the only two possible elements sec 3.6 xml enc.
// 3.6 The ReferenceList Element specifies there is a choice. Once one is chosen, it is fixed.
if ( reader.IsStartElement( XmlEncryptionConstants.Elements.DataReference, XmlEncryptionConstants.Namespace ) )
{
while ( reader.IsStartElement() )
{
if ( reader.IsStartElement( XmlEncryptionConstants.Elements.DataReference, XmlEncryptionConstants.Namespace ) )
{
string dataRef = reader.GetAttribute( XmlEncryptionConstants.Attributes.Uri );
if ( !string.IsNullOrEmpty( dataRef ) )
{
_dataReferences.Add( dataRef );
}
reader.Skip();
}
else if ( reader.IsStartElement( XmlEncryptionConstants.Elements.KeyReference, XmlEncryptionConstants.Namespace ) )
{
throw DiagnosticUtility.ThrowHelperXml( reader, SR.GetString( SR.ID4189 ) );
}
else
{
string xml = reader.ReadOuterXml();
if ( DiagnosticUtility.ShouldTraceWarning )
{
TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.GetString( SR.ID8024, reader.Name, reader.NamespaceURI, xml ) );
}
}
}
}
else if ( reader.IsStartElement( XmlEncryptionConstants.Elements.KeyReference, XmlEncryptionConstants.Namespace ) )
{
while ( reader.IsStartElement() )
{
if ( reader.IsStartElement( XmlEncryptionConstants.Elements.KeyReference, XmlEncryptionConstants.Namespace ) )
{
string keyRef = reader.GetAttribute( XmlEncryptionConstants.Attributes.Uri );
if ( !string.IsNullOrEmpty( keyRef ) )
{
_keyReferences.Add( keyRef );
}
reader.Skip();
}
else if ( reader.IsStartElement( XmlEncryptionConstants.Elements.DataReference, XmlEncryptionConstants.Namespace ) )
{
throw DiagnosticUtility.ThrowHelperXml( reader, SR.GetString( SR.ID4190 ) );
}
else
{
string xml = reader.ReadOuterXml();
if ( DiagnosticUtility.ShouldTraceWarning )
{
TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.GetString( SR.ID8024, reader.Name, reader.NamespaceURI, xml ) );
}
}
}
}
else
{
// there must be at least one reference.
throw DiagnosticUtility.ThrowHelperXml( reader, SR.GetString( SR.ID4191 ) );
}
reader.MoveToContent();
if ( reader.IsStartElement( XmlEncryptionConstants.Elements.CarriedKeyName, XmlEncryptionConstants.Namespace ) )
{
reader.ReadStartElement();
_carriedName = reader.ReadString();
reader.ReadEndElement();
}
// </ReferenceList>
reader.ReadEndElement();
}
}
public override void ReadXml( XmlDictionaryReader reader )
{
if ( reader == null )
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "reader" );
}
reader.MoveToContent();
if ( !reader.IsStartElement( XmlEncryptionConstants.Elements.EncryptedKey, XmlEncryptionConstants.Namespace ) )
{
throw DiagnosticUtility.ThrowHelperXml( reader, SR.GetString( SR.ID4187 ) );
}
_recipient = reader.GetAttribute( XmlEncryptionConstants.Attributes.Recipient, null );
//<EncryptedKey> extends <EncryptedType>
// base will read the start element and end elements
base.ReadXml( reader );
}
public EncryptedKeyIdentifierClause GetClause()
{
return new EncryptedKeyIdentifierClause( CipherData.CipherValue, Algorithm, KeyIdentifier );
}
}
}
|