Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Security / Cryptography / SafeCryptoHandles.cs / 1305376 / SafeCryptoHandles.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //[....] // // // SafeCryptoHandles.cs // namespace System.Security.Cryptography { using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.Versioning; using Microsoft.Win32.SafeHandles; ////// Safe handle representing a mscorwks!CRYPT_PROV_CTX /// ////// Since we need sometimes to delete the key container created in the context of the CSP, the handle /// used in this class is actually a pointer to a CRYPT_PROV_CTX unmanaged structure defined in /// COMCryptography.h /// [System.Security.SecurityCritical] // auto-generated internal sealed class SafeProvHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeProvHandle() : base(true) { SetHandle(IntPtr.Zero); } private SafeProvHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeProvHandle InvalidHandle { get { return new SafeProvHandle(); } } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [ResourceExposure(ResourceScope.None)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [SuppressUnmanagedCodeSecurity] private static extern void FreeCsp(IntPtr pProviderContext); [System.Security.SecurityCritical] protected override bool ReleaseHandle() { FreeCsp(handle); return true; } } #if FEATURE_CRYPTO ////// Safe handle representing a mscorkws!CRYPT_KEY_CTX /// ////// Since we need to delete the key handle before the provider is released we need to actually hold a /// pointer to a CRYPT_KEY_CTX unmanaged structure whose destructor decrements a refCount. Only when /// the provider refCount is 0 it is deleted. This way, we loose a ---- in the critical finalization /// of the key handle and provider handle. This also applies to hash handles, which point to a /// CRYPT_HASH_CTX. Those strucutres are defined in COMCryptography.h /// [System.Security.SecurityCritical] // auto-generated internal sealed class SafeKeyHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeKeyHandle() : base(true) { SetHandle(IntPtr.Zero); } private SafeKeyHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeKeyHandle InvalidHandle { get { return new SafeKeyHandle(); } } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [ResourceExposure(ResourceScope.None)] [SuppressUnmanagedCodeSecurity] private static extern void FreeKey(IntPtr pKeyCotext); [System.Security.SecurityCritical] protected override bool ReleaseHandle() { FreeKey(handle); return true; } } ////// SafeHandle representing a mscorwks!CRYPT_HASH_CTX /// ////// See code:System.Security.Cryptography.SafeKeyHandle for information about the release process /// for a CRYPT_HASH_CTX. /// [System.Security.SecurityCritical] // auto-generated internal sealed class SafeHashHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeHashHandle() : base(true) { SetHandle(IntPtr.Zero); } private SafeHashHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeHashHandle InvalidHandle { get { return new SafeHashHandle(); } } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [ResourceExposure(ResourceScope.None)] [SuppressUnmanagedCodeSecurity] private static extern void FreeHash(IntPtr pHashContext); [System.Security.SecurityCritical] protected override bool ReleaseHandle() { FreeHash(handle); return true; } } #endif // #if FEATURE_CRYPTO } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //[....] // // // SafeCryptoHandles.cs // namespace System.Security.Cryptography { using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.Versioning; using Microsoft.Win32.SafeHandles; ////// Safe handle representing a mscorwks!CRYPT_PROV_CTX /// ////// Since we need sometimes to delete the key container created in the context of the CSP, the handle /// used in this class is actually a pointer to a CRYPT_PROV_CTX unmanaged structure defined in /// COMCryptography.h /// [System.Security.SecurityCritical] // auto-generated internal sealed class SafeProvHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeProvHandle() : base(true) { SetHandle(IntPtr.Zero); } private SafeProvHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeProvHandle InvalidHandle { get { return new SafeProvHandle(); } } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [ResourceExposure(ResourceScope.None)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [SuppressUnmanagedCodeSecurity] private static extern void FreeCsp(IntPtr pProviderContext); [System.Security.SecurityCritical] protected override bool ReleaseHandle() { FreeCsp(handle); return true; } } #if FEATURE_CRYPTO ////// Safe handle representing a mscorkws!CRYPT_KEY_CTX /// ////// Since we need to delete the key handle before the provider is released we need to actually hold a /// pointer to a CRYPT_KEY_CTX unmanaged structure whose destructor decrements a refCount. Only when /// the provider refCount is 0 it is deleted. This way, we loose a ---- in the critical finalization /// of the key handle and provider handle. This also applies to hash handles, which point to a /// CRYPT_HASH_CTX. Those strucutres are defined in COMCryptography.h /// [System.Security.SecurityCritical] // auto-generated internal sealed class SafeKeyHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeKeyHandle() : base(true) { SetHandle(IntPtr.Zero); } private SafeKeyHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeKeyHandle InvalidHandle { get { return new SafeKeyHandle(); } } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [ResourceExposure(ResourceScope.None)] [SuppressUnmanagedCodeSecurity] private static extern void FreeKey(IntPtr pKeyCotext); [System.Security.SecurityCritical] protected override bool ReleaseHandle() { FreeKey(handle); return true; } } ////// SafeHandle representing a mscorwks!CRYPT_HASH_CTX /// ////// See code:System.Security.Cryptography.SafeKeyHandle for information about the release process /// for a CRYPT_HASH_CTX. /// [System.Security.SecurityCritical] // auto-generated internal sealed class SafeHashHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeHashHandle() : base(true) { SetHandle(IntPtr.Zero); } private SafeHashHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeHashHandle InvalidHandle { get { return new SafeHashHandle(); } } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [ResourceExposure(ResourceScope.None)] [SuppressUnmanagedCodeSecurity] private static extern void FreeHash(IntPtr pHashContext); [System.Security.SecurityCritical] protected override bool ReleaseHandle() { FreeHash(handle); return true; } } #endif // #if FEATURE_CRYPTO } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TypefaceMetricsCache.cs
- OleDbEnumerator.cs
- ListSurrogate.cs
- ProcessModelSection.cs
- ValidationUtility.cs
- LocalValueEnumerator.cs
- RegexReplacement.cs
- RelatedImageListAttribute.cs
- DrawingContext.cs
- TrackingServices.cs
- ExpressionParser.cs
- MediaScriptCommandRoutedEventArgs.cs
- selecteditemcollection.cs
- SoapSchemaExporter.cs
- BindingUtils.cs
- BasePattern.cs
- SessionParameter.cs
- DataFormats.cs
- XPathBinder.cs
- WebPartConnectionsConfigureVerb.cs
- NonClientArea.cs
- RepeaterItemCollection.cs
- DeflateEmulationStream.cs
- TransformGroup.cs
- AssemblyCache.cs
- EntityException.cs
- CompilerErrorCollection.cs
- ValueSerializerAttribute.cs
- Keyboard.cs
- SafeCertificateStore.cs
- Formatter.cs
- NativeConfigurationLoader.cs
- DatagridviewDisplayedBandsData.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- UserInitiatedNavigationPermission.cs
- CultureSpecificStringDictionary.cs
- BrushMappingModeValidation.cs
- RealizationDrawingContextWalker.cs
- WorkflowApplication.cs
- DataGridCommandEventArgs.cs
- DashStyles.cs
- EdgeProfileValidation.cs
- SqlInfoMessageEvent.cs
- listitem.cs
- ServiceEndpointAssociationProvider.cs
- MessageDroppedTraceRecord.cs
- WebPartCatalogCloseVerb.cs
- Fault.cs
- CodeTypeReferenceExpression.cs
- EventSinkActivityDesigner.cs
- CapacityStreamGeometryContext.cs
- BaseCodePageEncoding.cs
- ConfigurationManagerInternal.cs
- Selection.cs
- JournalEntryListConverter.cs
- ISAPIApplicationHost.cs
- XmlEntityReference.cs
- HttpServerUtilityBase.cs
- XPathAncestorIterator.cs
- ImpersonationOption.cs
- ValueType.cs
- ColorAnimationUsingKeyFrames.cs
- BoundingRectTracker.cs
- OutputCacheSection.cs
- LocatorGroup.cs
- TextRangeEditTables.cs
- ThrowHelper.cs
- CacheMemory.cs
- CustomAttributeBuilder.cs
- arc.cs
- LambdaCompiler.Binary.cs
- SafeCoTaskMem.cs
- InvalidFilterCriteriaException.cs
- UserNameSecurityTokenAuthenticator.cs
- securitycriticaldata.cs
- TextParagraphCache.cs
- SignerInfo.cs
- DataGridViewTextBoxEditingControl.cs
- UidManager.cs
- EventDescriptor.cs
- Registry.cs
- PreProcessInputEventArgs.cs
- ControllableStoryboardAction.cs
- DataGridParentRows.cs
- CategoryNameCollection.cs
- RelOps.cs
- SQLGuidStorage.cs
- Selection.cs
- NonDualMessageSecurityOverHttp.cs
- ColorInterpolationModeValidation.cs
- XDeferredAxisSource.cs
- EventDescriptor.cs
- TabPage.cs
- RowParagraph.cs
- RtfControlWordInfo.cs
- Splitter.cs
- Logging.cs
- NodeLabelEditEvent.cs
- PingReply.cs
- SqlBuffer.cs