Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / SelfIssuedAuthProofToken.cs / 1 / SelfIssuedAuthProofToken.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace Microsoft.InfoCards { using System; using System.IdentityModel.Selectors; using System.IdentityModel.Tokens; using System.ServiceModel; using System.ServiceModel.Security; using System.ServiceModel.Security.Tokens; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.IdentityModel; using System.Security.Cryptography.Xml; using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace; using System.Collections.ObjectModel; using System.Collections.Generic; // // Summary: // This class implements a proof token that we can hand to indigo // for purposes of signing (instead of passing for example the raw unencrypted // Saml token) // internal class SelfIssuedAuthProofToken : SecurityToken, IDisposable { string m_id; DateTime m_expiration; ReadOnlyCollectionm_securityKeys; SecurityKey m_securityKey; bool m_isSymmetric; RSACryptoServiceProvider m_publicKey; public SelfIssuedAuthProofToken( RSACryptoServiceProvider rsa, DateTime expiration ) : this( expiration ) { m_publicKey = new RSACryptoServiceProvider(); // // Get the public key from the passed in public/private key pair. This is used strictly for // creating an RsaKeyIdentifierClause // m_publicKey.ImportCspBlob( rsa.ExportCspBlob( false ) ); InitCrypto( new SelfIssuedAuthAsymmetricKey( rsa ) ); } public SelfIssuedAuthProofToken( InMemorySymmetricSecurityKey symKey, DateTime expiration ) : this( expiration ) { m_isSymmetric = true; InitCrypto( symKey ); } private SelfIssuedAuthProofToken( DateTime expiration ) : base() { m_id = Guid.NewGuid().ToString(); m_expiration = expiration.ToUniversalTime(); } public override string Id { get { return m_id; } } public override ReadOnlyCollection SecurityKeys { get { return m_securityKeys; } } public override DateTime ValidTo { get { return m_expiration; } } public override DateTime ValidFrom { get { return DateTime.UtcNow; } } private void InitCrypto( SecurityKey securityKey ) { m_securityKey = securityKey; List securityKeys = new List ( 1 ); securityKeys.Add( securityKey ); m_securityKeys = securityKeys.AsReadOnly(); } public override bool CanCreateKeyIdentifierClause () { return typeof(T) == typeof(RsaKeyIdentifierClause); } public override T CreateKeyIdentifierClause () { if ( typeof( T ) == typeof( RsaKeyIdentifierClause ) ) { return (T)( (object)new RsaKeyIdentifierClause( m_publicKey ) ); } return base.CreateKeyIdentifierClause (); } public override bool MatchesKeyIdentifierClause( SecurityKeyIdentifierClause keyIdentifierClause ) { RsaKeyIdentifierClause rsaKeyIdentifierClause = keyIdentifierClause as RsaKeyIdentifierClause; if (rsaKeyIdentifierClause != null) return rsaKeyIdentifierClause.Matches( m_publicKey ); return false; } public void Dispose() { // // SymmetricKey is NOT IDisposable but RSACryptoServiceProvider is // if ( null != m_securityKey && !m_isSymmetric ) { ( ( IDisposable )m_securityKey ).Dispose(); m_securityKey = null; m_securityKeys = null; } if( null != m_publicKey ) { ( ( IDisposable )m_publicKey ).Dispose(); m_publicKey = null; } } } } // 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
- Stacktrace.cs
- UnsafeNativeMethodsMilCoreApi.cs
- ContextStaticAttribute.cs
- TextComposition.cs
- JournalNavigationScope.cs
- CompositeFontParser.cs
- ColumnReorderedEventArgs.cs
- sitestring.cs
- DisplayInformation.cs
- Brushes.cs
- CategoryState.cs
- SafeRegistryKey.cs
- InstancePersistenceCommandException.cs
- RemotingConfiguration.cs
- Models.cs
- DerivedKeyCachingSecurityTokenSerializer.cs
- MenuItemCollection.cs
- VisemeEventArgs.cs
- SplitterPanel.cs
- EasingQuaternionKeyFrame.cs
- LoginViewDesigner.cs
- VectorAnimationUsingKeyFrames.cs
- ApplicationFileCodeDomTreeGenerator.cs
- ConfigXmlAttribute.cs
- ToolStripMenuItemCodeDomSerializer.cs
- HwndMouseInputProvider.cs
- NonBatchDirectoryCompiler.cs
- HtmlUtf8RawTextWriter.cs
- TokenBasedSet.cs
- ProfileService.cs
- MarkupCompiler.cs
- FormattedTextSymbols.cs
- BinHexEncoder.cs
- ExtendedPropertyCollection.cs
- RegexCompiler.cs
- LinkedResource.cs
- XDRSchema.cs
- AsyncCompletedEventArgs.cs
- DataGridRelationshipRow.cs
- SelectionItemProviderWrapper.cs
- Clause.cs
- ManagementScope.cs
- InstanceCreationEditor.cs
- EncryptedData.cs
- FixedTextBuilder.cs
- CorePropertiesFilter.cs
- ColorBuilder.cs
- Control.cs
- XmlSchemaInfo.cs
- MetadataItemCollectionFactory.cs
- GridItemProviderWrapper.cs
- Random.cs
- MultipartIdentifier.cs
- ModelService.cs
- LambdaCompiler.Unary.cs
- HtmlControlPersistable.cs
- Util.cs
- ObjectKeyFrameCollection.cs
- SaveFileDialog.cs
- ExceptionValidationRule.cs
- ReadOnlyPropertyMetadata.cs
- APCustomTypeDescriptor.cs
- ChangeBlockUndoRecord.cs
- XmlNamespaceMappingCollection.cs
- OdbcPermission.cs
- XPathAncestorQuery.cs
- Authorization.cs
- WebPartConnection.cs
- ConfigurationManagerHelper.cs
- MissingFieldException.cs
- CultureTable.cs
- GeneratedView.cs
- JumpPath.cs
- GC.cs
- AccessorTable.cs
- ChannelManager.cs
- TimeSpanConverter.cs
- PaperSize.cs
- WSTrustFeb2005.cs
- MethodImplAttribute.cs
- UTF8Encoding.cs
- DetailsViewRowCollection.cs
- XhtmlBasicListAdapter.cs
- Buffer.cs
- QilTernary.cs
- DesignerSelectionListAdapter.cs
- XslTransform.cs
- CodeTypeDeclarationCollection.cs
- RecordsAffectedEventArgs.cs
- MemberProjectionIndex.cs
- ExpandableObjectConverter.cs
- ProfileSection.cs
- EntitySetBase.cs
- Exception.cs
- GrammarBuilderRuleRef.cs
- cache.cs
- Context.cs
- SecurityContextSecurityTokenAuthenticator.cs
- DependentList.cs
- DesignTimeData.cs