Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / Tokens / WrappedKeySecurityToken.cs / 1 / WrappedKeySecurityToken.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Security.Tokens { using System.Collections; using System.ServiceModel; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.IdentityModel.Selectors; using System.IdentityModel.Tokens; using System.Security.Cryptography; using System.Text; using System.Xml; // temporary til we get rid of EncryptedKey public class WrappedKeySecurityToken : SecurityToken { string id; DateTime effectiveTime; EncryptedKey encryptedKey; ReadOnlyCollectionsecurityKey; byte[] wrappedKey; string wrappingAlgorithm; ISspiNegotiation wrappingSspiContext; SecurityToken wrappingToken; SecurityKey wrappingSecurityKey; SecurityKeyIdentifier wrappingTokenReference; bool serializeCarriedKeyName; byte[] wrappedKeyHash; XmlDictionaryString wrappingAlgorithmDictionaryString; // sender use internal WrappedKeySecurityToken(string id, byte[] keyToWrap, ISspiNegotiation wrappingSspiContext) : this(id, keyToWrap, (wrappingSspiContext != null) ? (wrappingSspiContext.KeyEncryptionAlgorithm) : null, wrappingSspiContext, null) { } // sender use public WrappedKeySecurityToken(string id, byte[] keyToWrap, string wrappingAlgorithm, SecurityToken wrappingToken, SecurityKeyIdentifier wrappingTokenReference) : this(id, keyToWrap, wrappingAlgorithm, null, wrappingToken, wrappingTokenReference) { } internal WrappedKeySecurityToken(string id, byte[] keyToWrap, string wrappingAlgorithm, XmlDictionaryString wrappingAlgorithmDictionaryString, SecurityToken wrappingToken, SecurityKeyIdentifier wrappingTokenReference) : this(id, keyToWrap, wrappingAlgorithm, wrappingAlgorithmDictionaryString, wrappingToken, wrappingTokenReference, null, null) { } // direct receiver use, chained sender use internal WrappedKeySecurityToken(string id, byte[] keyToWrap, string wrappingAlgorithm, ISspiNegotiation wrappingSspiContext, byte[] wrappedKey) : this(id, keyToWrap, wrappingAlgorithm, null) { if (wrappingSspiContext == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("wrappingSspiContext"); } this.wrappingSspiContext = wrappingSspiContext; if (wrappedKey == null) { this.wrappedKey = wrappingSspiContext.Encrypt(keyToWrap); } else { this.wrappedKey = wrappedKey; } this.serializeCarriedKeyName = false; } // receiver use internal WrappedKeySecurityToken(string id, byte[] keyToWrap, string wrappingAlgorithm, SecurityToken wrappingToken, SecurityKeyIdentifier wrappingTokenReference, byte[] wrappedKey, SecurityKey wrappingSecurityKey) : this(id, keyToWrap, wrappingAlgorithm, null, wrappingToken, wrappingTokenReference, wrappedKey, wrappingSecurityKey) { } WrappedKeySecurityToken(string id, byte[] keyToWrap, string wrappingAlgorithm, XmlDictionaryString wrappingAlgorithmDictionaryString, SecurityToken wrappingToken, SecurityKeyIdentifier wrappingTokenReference, byte[] wrappedKey, SecurityKey wrappingSecurityKey) : this(id, keyToWrap, wrappingAlgorithm, wrappingAlgorithmDictionaryString) { if (wrappingToken == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("wrappingToken"); } this.wrappingToken = wrappingToken; this.wrappingTokenReference = wrappingTokenReference; if (wrappedKey == null) { this.wrappedKey = SecurityUtils.EncryptKey(wrappingToken, wrappingAlgorithm, keyToWrap); } else { this.wrappedKey = wrappedKey; } this.wrappingSecurityKey = wrappingSecurityKey; this.serializeCarriedKeyName = true; } WrappedKeySecurityToken(string id, byte[] keyToWrap, string wrappingAlgorithm, XmlDictionaryString wrappingAlgorithmDictionaryString) { if (id == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("id"); if (wrappingAlgorithm == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("wrappingAlgorithm"); if (keyToWrap == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("securityKeyToWrap"); this.id = id; this.effectiveTime = DateTime.UtcNow; this.securityKey = SecurityUtils.CreateSymmetricSecurityKeys(keyToWrap); this.wrappingAlgorithm = wrappingAlgorithm; this.wrappingAlgorithmDictionaryString = wrappingAlgorithmDictionaryString; } public override string Id { get { return this.id; } } public override DateTime ValidFrom { get { return this.effectiveTime; } } public override DateTime ValidTo { // Never expire get { return DateTime.MaxValue; } } internal EncryptedKey EncryptedKey { get { return this.encryptedKey; } set { this.encryptedKey = value; } } internal ReferenceList ReferenceList { get { return this.encryptedKey == null ? null : this.encryptedKey.ReferenceList; } } public string WrappingAlgorithm { get { return this.wrappingAlgorithm; } } internal SecurityKey WrappingSecurityKey { get { return this.wrappingSecurityKey; } } public SecurityToken WrappingToken { get { return this.wrappingToken; } } public SecurityKeyIdentifier WrappingTokenReference { get { return this.wrappingTokenReference; } } internal string CarriedKeyName { get { return null; } } public override ReadOnlyCollection SecurityKeys { get { return this.securityKey; } } internal byte[] GetHash() { if (this.wrappedKeyHash == null) { EnsureEncryptedKeySetUp(); using (HashAlgorithm hash = CryptoHelper.NewSha1HashAlgorithm()) { this.wrappedKeyHash = hash.ComputeHash(this.encryptedKey.GetWrappedKey()); } } return wrappedKeyHash; } public byte[] GetWrappedKey() { return SecurityUtils.CloneBuffer(this.wrappedKey); } internal void EnsureEncryptedKeySetUp() { if (this.encryptedKey == null) { EncryptedKey ek = new EncryptedKey(); ek.Id = this.Id; if (this.serializeCarriedKeyName) { ek.CarriedKeyName = this.CarriedKeyName; } else { ek.CarriedKeyName = null; } ek.EncryptionMethod = this.WrappingAlgorithm; ek.EncryptionMethodDictionaryString = this.wrappingAlgorithmDictionaryString; ek.SetUpKeyWrap(this.wrappedKey); if (this.WrappingTokenReference != null) { ek.KeyIdentifier = this.WrappingTokenReference; } this.encryptedKey = ek; } } public override bool CanCreateKeyIdentifierClause () { if (typeof(T) == typeof(EncryptedKeyHashIdentifierClause)) return true; return base.CanCreateKeyIdentifierClause (); } public override T CreateKeyIdentifierClause () { if (typeof(T) == typeof(EncryptedKeyHashIdentifierClause)) return new EncryptedKeyHashIdentifierClause(GetHash()) as T; return base.CreateKeyIdentifierClause (); } public override bool MatchesKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause) { EncryptedKeyHashIdentifierClause encKeyIdentifierClause = keyIdentifierClause as EncryptedKeyHashIdentifierClause; if (encKeyIdentifierClause != null) return encKeyIdentifierClause.Matches(GetHash()); return base.MatchesKeyIdentifierClause(keyIdentifierClause); } } } // 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
- Vector3DIndependentAnimationStorage.cs
- NotificationContext.cs
- RoleGroup.cs
- ClientUrlResolverWrapper.cs
- UpWmlMobileTextWriter.cs
- EdmSchemaError.cs
- OdbcEnvironment.cs
- AssemblyNameUtility.cs
- TextCompositionManager.cs
- EntityDataSourceWizardForm.cs
- OrderedHashRepartitionEnumerator.cs
- _StreamFramer.cs
- WebPartCloseVerb.cs
- SupportedAddressingMode.cs
- Line.cs
- StatusBar.cs
- FrameDimension.cs
- WebException.cs
- XPathParser.cs
- DataSourceCache.cs
- ConstNode.cs
- Propagator.JoinPropagator.cs
- columnmapkeybuilder.cs
- PresentationSource.cs
- InputReferenceExpression.cs
- PresentationAppDomainManager.cs
- DictionarySurrogate.cs
- XmlCDATASection.cs
- SafeSecurityHandles.cs
- RemotingConfiguration.cs
- QueryResponse.cs
- EDesignUtil.cs
- ZipIOExtraFieldPaddingElement.cs
- PanelDesigner.cs
- ManualWorkflowSchedulerService.cs
- SctClaimDictionary.cs
- SequentialUshortCollection.cs
- CodeAttributeDeclarationCollection.cs
- IntegerValidator.cs
- TreeViewHitTestInfo.cs
- SiteMapNodeItem.cs
- EditorBrowsableAttribute.cs
- PropertyMapper.cs
- WCFServiceClientProxyGenerator.cs
- NodeInfo.cs
- SHA1CryptoServiceProvider.cs
- SamlAdvice.cs
- SoapInteropTypes.cs
- _DomainName.cs
- TransformationRules.cs
- KeyboardEventArgs.cs
- DurableInstanceContextProvider.cs
- CqlParserHelpers.cs
- TransformValueSerializer.cs
- ThreadStartException.cs
- Soap.cs
- GPRECT.cs
- WebBrowserNavigatingEventHandler.cs
- ToolboxItemSnapLineBehavior.cs
- WinEventHandler.cs
- CancelEventArgs.cs
- WmlTextBoxAdapter.cs
- UrlAuthorizationModule.cs
- RelationshipManager.cs
- _AutoWebProxyScriptEngine.cs
- XPathParser.cs
- XmlQueryOutput.cs
- OdbcUtils.cs
- DataBindingsDialog.cs
- Types.cs
- HttpListenerRequestUriBuilder.cs
- DiscreteKeyFrames.cs
- HtmlInputSubmit.cs
- XmlSchemaFacet.cs
- Setter.cs
- precedingsibling.cs
- DateTimeFormatInfoScanner.cs
- TemplateApplicationHelper.cs
- DataColumnMapping.cs
- HyperLinkColumn.cs
- TextModifierScope.cs
- Serializer.cs
- IconBitmapDecoder.cs
- DataControlFieldTypeEditor.cs
- HttpProfileBase.cs
- SelectionRangeConverter.cs
- keycontainerpermission.cs
- ContextBase.cs
- RawStylusInputReport.cs
- HttpCachePolicyWrapper.cs
- LayoutEditorPart.cs
- ProviderCollection.cs
- XmlIlTypeHelper.cs
- HtmlInputText.cs
- ToolStripItemRenderEventArgs.cs
- GeneralTransform2DTo3DTo2D.cs
- ParseChildrenAsPropertiesAttribute.cs
- HostProtectionException.cs
- SoapSchemaMember.cs
- Win32MouseDevice.cs