Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / X509CertificateEndpointIdentity.cs / 1 / X509CertificateEndpointIdentity.cs
//----------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel
{
using System;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
using System.Xml.Serialization;
public class X509CertificateEndpointIdentity : EndpointIdentity
{
X509Certificate2Collection certificateCollection = new X509Certificate2Collection();
public X509CertificateEndpointIdentity(X509Certificate2 certificate)
{
if (certificate == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("certificate");
base.Initialize(new Claim(ClaimTypes.Thumbprint, certificate.GetCertHash(), Rights.PossessProperty));
this.certificateCollection.Add(certificate);
}
public X509CertificateEndpointIdentity(X509Certificate2 primaryCertificate, X509Certificate2Collection supportingCertificates)
{
if (primaryCertificate == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("primaryCertificate");
if (supportingCertificates == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("supportingCertificates");
base.Initialize(new Claim(ClaimTypes.Thumbprint, primaryCertificate.GetCertHash(), Rights.PossessProperty));
this.certificateCollection.Add(primaryCertificate);
for (int i = 0; i < supportingCertificates.Count; ++i)
{
this.certificateCollection.Add(supportingCertificates[i]);
}
}
internal X509CertificateEndpointIdentity(XmlDictionaryReader reader)
{
if (reader == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
reader.MoveToContent();
if (reader.IsEmptyElement)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.UnexpectedEmptyElementExpectingClaim, XD.AddressingDictionary.X509v3Certificate.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value)));
reader.ReadStartElement(XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace);
while (reader.IsStartElement(XD.XmlSignatureDictionary.X509Certificate, XD.XmlSignatureDictionary.Namespace))
{
X509Certificate2 certificate = new X509Certificate2(Convert.FromBase64String(reader.ReadElementString()));
if (this.certificateCollection.Count == 0)
{
// This is the first certificate. We assume this as the primary
// certificate and initialize the base class.
base.Initialize(new Claim(ClaimTypes.Thumbprint, certificate.GetCertHash(), Rights.PossessProperty));
}
this.certificateCollection.Add(certificate);
}
reader.ReadEndElement();
if (this.certificateCollection.Count == 0)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.UnexpectedEmptyElementExpectingClaim, XD.AddressingDictionary.X509v3Certificate.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value)));
}
public X509Certificate2Collection Certificates
{
get { return this.certificateCollection; }
}
internal override void WriteContentsTo(XmlDictionaryWriter writer)
{
if (writer == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.KeyInfo, XD.XmlSignatureDictionary.Namespace);
writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace);
for (int i = 0; i < certificateCollection.Count; ++i)
{
writer.WriteElementString(XD.XmlSignatureDictionary.X509Certificate, XD.XmlSignatureDictionary.Namespace, Convert.ToBase64String(certificateCollection[i].RawData));
}
writer.WriteEndElement();
writer.WriteEndElement();
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TimeStampChecker.cs
- WebBrowserNavigatingEventHandler.cs
- WinHttpWebProxyFinder.cs
- BinHexEncoder.cs
- FormView.cs
- Certificate.cs
- TextBreakpoint.cs
- ConnectionManagementElementCollection.cs
- RsaElement.cs
- HTMLTagNameToTypeMapper.cs
- RawTextInputReport.cs
- DispatcherTimer.cs
- UnsafeNativeMethods.cs
- HScrollBar.cs
- ChangeConflicts.cs
- SoapProtocolReflector.cs
- TransactionScope.cs
- RegexBoyerMoore.cs
- RewritingProcessor.cs
- ChangeBlockUndoRecord.cs
- DecimalAnimation.cs
- DBBindings.cs
- HealthMonitoringSection.cs
- SoapFault.cs
- EventSinkActivityDesigner.cs
- TypeElementCollection.cs
- FixUpCollection.cs
- _ChunkParse.cs
- WindowsSpinner.cs
- ProtocolsConfigurationHandler.cs
- BindableAttribute.cs
- ActivityBuilderHelper.cs
- BrushValueSerializer.cs
- QueryOperationResponseOfT.cs
- _BasicClient.cs
- TextMetrics.cs
- GridItemProviderWrapper.cs
- RemotingConfiguration.cs
- XmlUtf8RawTextWriter.cs
- ResourceExpressionBuilder.cs
- OleDbEnumerator.cs
- PeerTransportCredentialType.cs
- MaskedTextBoxTextEditor.cs
- X509Extension.cs
- XmlCDATASection.cs
- PolicyManager.cs
- XmlSchemaExporter.cs
- ReflectEventDescriptor.cs
- DataBindingHandlerAttribute.cs
- AccessKeyManager.cs
- SqlCommandBuilder.cs
- FontNamesConverter.cs
- AlphabeticalEnumConverter.cs
- CheckBoxStandardAdapter.cs
- UiaCoreApi.cs
- XPathSelectionIterator.cs
- StringHelper.cs
- TrackingProfileCache.cs
- Native.cs
- XmlSiteMapProvider.cs
- EdmPropertyAttribute.cs
- BasicExpandProvider.cs
- WSUtilitySpecificationVersion.cs
- DebugInfo.cs
- ContextMenu.cs
- ListenerElementsCollection.cs
- GeometryGroup.cs
- Emitter.cs
- ExceptionRoutedEventArgs.cs
- _LoggingObject.cs
- InternalTypeHelper.cs
- FlowDocumentPaginator.cs
- SafePipeHandle.cs
- BevelBitmapEffect.cs
- BulletedListDesigner.cs
- SessionStateSection.cs
- CollectionView.cs
- PersonalizationStateQuery.cs
- ETagAttribute.cs
- SqlAliaser.cs
- WebServiceMethodData.cs
- DescendantBaseQuery.cs
- TypeSystemProvider.cs
- AttributeData.cs
- RunInstallerAttribute.cs
- UnsafeNativeMethods.cs
- SapiGrammar.cs
- Baml2006KnownTypes.cs
- CurrentTimeZone.cs
- Lease.cs
- DependencyPropertyAttribute.cs
- WindowsGraphicsWrapper.cs
- ActionMismatchAddressingException.cs
- EpmContentDeSerializerBase.cs
- WindowsSysHeader.cs
- PackUriHelper.cs
- TableRow.cs
- DataRowCollection.cs
- ProfileBuildProvider.cs
- CompositeFontFamily.cs