Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Security / Cryptography / ManifestSignatureInformation.cs / 1305376 / ManifestSignatureInformation.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Deployment.Internal; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices.ComTypes; using System.Security; using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.Xml; using System.Xml; namespace System.Security.Cryptography { ////// Wrapper for information about the various signatures that can be applied to a manifest /// [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)] public sealed class ManifestSignatureInformation { private ManifestKinds m_manifest; private StrongNameSignatureInformation m_strongNameSignature; private AuthenticodeSignatureInformation m_authenticodeSignature; internal ManifestSignatureInformation(ManifestKinds manifest, StrongNameSignatureInformation strongNameSignature, AuthenticodeSignatureInformation authenticodeSignature) { Debug.Assert(manifest == ManifestKinds.Application || manifest == ManifestKinds.Deployment, "Invalid manifest for signature information"); m_manifest = manifest; m_strongNameSignature = strongNameSignature; m_authenticodeSignature = authenticodeSignature; } ////// Authenticode signature of the manifest /// public AuthenticodeSignatureInformation AuthenticodeSignature { get { return m_authenticodeSignature; } } ////// Manifest the signature information is for /// public ManifestKinds Manifest { get { return m_manifest; } } ////// Details about the strong name signature of the manifest /// public StrongNameSignatureInformation StrongNameSignature { get { return m_strongNameSignature; } } ////// Load the XML from the specified manifest into an XmlDocument /// //// [System.Security.SecurityCritical] private static XmlDocument GetManifestXml(ActivationContext application, ManifestKinds manifest) { Debug.Assert(application != null, "application != null"); IStream manifestStream = null; if (manifest == ManifestKinds.Application) { manifestStream = InternalActivationContextHelper.GetApplicationComponentManifest(application) as IStream; } else if (manifest == ManifestKinds.Deployment) { manifestStream = InternalActivationContextHelper.GetDeploymentComponentManifest(application) as IStream; } Debug.Assert(manifestStream != null, "Cannot get stream for manifest"); using (MemoryStream manifestContent = new MemoryStream()) { byte[] buffer = new byte[4096]; int bytesRead = 0; do { unsafe { manifestStream.Read(buffer, buffer.Length, new IntPtr(&bytesRead)); } manifestContent.Write(buffer, 0, bytesRead); } while (bytesRead == buffer.Length); manifestContent.Position = 0; XmlDocument manifestXml = new XmlDocument(); manifestXml.PreserveWhitespace = true; manifestXml.Load(manifestContent); return manifestXml; } } ///// /// Verify and gather information about the signatures of the specified manifests /// public static ManifestSignatureInformationCollection VerifySignature(ActivationContext application) { return VerifySignature(application, ManifestKinds.ApplicationAndDeployment); } ////// Verify and gather information about the signatures of the specified manifests /// public static ManifestSignatureInformationCollection VerifySignature(ActivationContext application, ManifestKinds manifests) { return VerifySignature(application, manifests, X509RevocationFlag.ExcludeRoot, X509RevocationMode.Online); } ////// Verify and gather information about the signatures of the specified manifests /// //// [System.Security.SecurityCritical] public static ManifestSignatureInformationCollection VerifySignature(ActivationContext application, ManifestKinds manifests, X509RevocationFlag revocationFlag, X509RevocationMode revocationMode) { if (application == null) { throw new ArgumentNullException("application"); } if (revocationFlag < X509RevocationFlag.EndCertificateOnly || X509RevocationFlag.ExcludeRoot < revocationFlag) { throw new ArgumentOutOfRangeException("revocationFlag"); } if (revocationMode < X509RevocationMode.NoCheck || X509RevocationMode.Offline < revocationMode) { throw new ArgumentOutOfRangeException("revocationMode"); } List// signatures = new List (); if ((manifests & ManifestKinds.Deployment) == ManifestKinds.Deployment) { XmlDocument deploymentManifest = GetManifestXml(application, ManifestKinds.Deployment); ManifestSignedXml deploymentSignature = new ManifestSignedXml(deploymentManifest, ManifestKinds.Deployment); signatures.Add(deploymentSignature.VerifySignature(revocationFlag, revocationMode)); } if ((manifests & ManifestKinds.Application) == ManifestKinds.Application) { XmlDocument applicationManifest = GetManifestXml(application, ManifestKinds.Application); ManifestSignedXml applicationSignature = new ManifestSignedXml(applicationManifest, ManifestKinds.Application); signatures.Add(applicationSignature.VerifySignature(revocationFlag, revocationMode)); } return new ManifestSignatureInformationCollection(signatures); } } [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)] public sealed class ManifestSignatureInformationCollection : ReadOnlyCollection { internal ManifestSignatureInformationCollection(IList signatureInformation) : base(signatureInformation) { return; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Deployment.Internal; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices.ComTypes; using System.Security; using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.Xml; using System.Xml; namespace System.Security.Cryptography { /// /// Wrapper for information about the various signatures that can be applied to a manifest /// [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)] public sealed class ManifestSignatureInformation { private ManifestKinds m_manifest; private StrongNameSignatureInformation m_strongNameSignature; private AuthenticodeSignatureInformation m_authenticodeSignature; internal ManifestSignatureInformation(ManifestKinds manifest, StrongNameSignatureInformation strongNameSignature, AuthenticodeSignatureInformation authenticodeSignature) { Debug.Assert(manifest == ManifestKinds.Application || manifest == ManifestKinds.Deployment, "Invalid manifest for signature information"); m_manifest = manifest; m_strongNameSignature = strongNameSignature; m_authenticodeSignature = authenticodeSignature; } ////// Authenticode signature of the manifest /// public AuthenticodeSignatureInformation AuthenticodeSignature { get { return m_authenticodeSignature; } } ////// Manifest the signature information is for /// public ManifestKinds Manifest { get { return m_manifest; } } ////// Details about the strong name signature of the manifest /// public StrongNameSignatureInformation StrongNameSignature { get { return m_strongNameSignature; } } ////// Load the XML from the specified manifest into an XmlDocument /// //// [System.Security.SecurityCritical] private static XmlDocument GetManifestXml(ActivationContext application, ManifestKinds manifest) { Debug.Assert(application != null, "application != null"); IStream manifestStream = null; if (manifest == ManifestKinds.Application) { manifestStream = InternalActivationContextHelper.GetApplicationComponentManifest(application) as IStream; } else if (manifest == ManifestKinds.Deployment) { manifestStream = InternalActivationContextHelper.GetDeploymentComponentManifest(application) as IStream; } Debug.Assert(manifestStream != null, "Cannot get stream for manifest"); using (MemoryStream manifestContent = new MemoryStream()) { byte[] buffer = new byte[4096]; int bytesRead = 0; do { unsafe { manifestStream.Read(buffer, buffer.Length, new IntPtr(&bytesRead)); } manifestContent.Write(buffer, 0, bytesRead); } while (bytesRead == buffer.Length); manifestContent.Position = 0; XmlDocument manifestXml = new XmlDocument(); manifestXml.PreserveWhitespace = true; manifestXml.Load(manifestContent); return manifestXml; } } ///// /// Verify and gather information about the signatures of the specified manifests /// public static ManifestSignatureInformationCollection VerifySignature(ActivationContext application) { return VerifySignature(application, ManifestKinds.ApplicationAndDeployment); } ////// Verify and gather information about the signatures of the specified manifests /// public static ManifestSignatureInformationCollection VerifySignature(ActivationContext application, ManifestKinds manifests) { return VerifySignature(application, manifests, X509RevocationFlag.ExcludeRoot, X509RevocationMode.Online); } ////// Verify and gather information about the signatures of the specified manifests /// //// [System.Security.SecurityCritical] public static ManifestSignatureInformationCollection VerifySignature(ActivationContext application, ManifestKinds manifests, X509RevocationFlag revocationFlag, X509RevocationMode revocationMode) { if (application == null) { throw new ArgumentNullException("application"); } if (revocationFlag < X509RevocationFlag.EndCertificateOnly || X509RevocationFlag.ExcludeRoot < revocationFlag) { throw new ArgumentOutOfRangeException("revocationFlag"); } if (revocationMode < X509RevocationMode.NoCheck || X509RevocationMode.Offline < revocationMode) { throw new ArgumentOutOfRangeException("revocationMode"); } List// signatures = new List (); if ((manifests & ManifestKinds.Deployment) == ManifestKinds.Deployment) { XmlDocument deploymentManifest = GetManifestXml(application, ManifestKinds.Deployment); ManifestSignedXml deploymentSignature = new ManifestSignedXml(deploymentManifest, ManifestKinds.Deployment); signatures.Add(deploymentSignature.VerifySignature(revocationFlag, revocationMode)); } if ((manifests & ManifestKinds.Application) == ManifestKinds.Application) { XmlDocument applicationManifest = GetManifestXml(application, ManifestKinds.Application); ManifestSignedXml applicationSignature = new ManifestSignedXml(applicationManifest, ManifestKinds.Application); signatures.Add(applicationSignature.VerifySignature(revocationFlag, revocationMode)); } return new ManifestSignatureInformationCollection(signatures); } } [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)] public sealed class ManifestSignatureInformationCollection : ReadOnlyCollection { internal ManifestSignatureInformationCollection(IList signatureInformation) : base(signatureInformation) { return; } } } // 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
- controlskin.cs
- UnsafeNativeMethods.cs
- PasswordPropertyTextAttribute.cs
- DoubleAnimationBase.cs
- OpenTypeLayout.cs
- ColorInterpolationModeValidation.cs
- EntityDataSourceWizardForm.cs
- IBuiltInEvidence.cs
- DesignerDeviceConfig.cs
- SudsParser.cs
- RegexWriter.cs
- Types.cs
- DrawingAttributesDefaultValueFactory.cs
- PieceNameHelper.cs
- GlyphRunDrawing.cs
- TabControl.cs
- HtmlContainerControl.cs
- EventEntry.cs
- UInt64Converter.cs
- ByteKeyFrameCollection.cs
- ProxyManager.cs
- EdmTypeAttribute.cs
- Win32PrintDialog.cs
- SimpleApplicationHost.cs
- ByteStream.cs
- HebrewCalendar.cs
- XmlQueryCardinality.cs
- MbpInfo.cs
- QilGeneratorEnv.cs
- PackageProperties.cs
- HMACSHA512.cs
- input.cs
- TextDecorationLocationValidation.cs
- OptimalBreakSession.cs
- TextSelectionHelper.cs
- CompilerInfo.cs
- ElementsClipboardData.cs
- SaveFileDialog.cs
- GridItemCollection.cs
- WebPartManagerInternals.cs
- WebBrowserUriTypeConverter.cs
- FormViewPagerRow.cs
- RegisteredScript.cs
- TableRow.cs
- HandleRef.cs
- CachedTypeface.cs
- XPathArrayIterator.cs
- ImageUrlEditor.cs
- WsdlImporterElement.cs
- ResolveMatchesMessage11.cs
- GeneralTransform.cs
- ParagraphResult.cs
- SchemaImporterExtensionElement.cs
- OdbcConnectionFactory.cs
- HwndSourceKeyboardInputSite.cs
- EdgeModeValidation.cs
- ListMarkerSourceInfo.cs
- MailAddress.cs
- InvalidCastException.cs
- KnownIds.cs
- HostProtectionException.cs
- NullEntityWrapper.cs
- sqlmetadatafactory.cs
- ApplicationServicesHostFactory.cs
- SafeNativeMethodsOther.cs
- MetadataCacheItem.cs
- EntityDescriptor.cs
- SelectedCellsCollection.cs
- FontEditor.cs
- DefaultValidator.cs
- NameTable.cs
- DataGridViewSelectedRowCollection.cs
- HtmlMeta.cs
- HttpException.cs
- AppendHelper.cs
- SiteMapSection.cs
- DataRecordInternal.cs
- CompilationUnit.cs
- SearchForVirtualItemEventArgs.cs
- XmlQueryRuntime.cs
- BuildProviderCollection.cs
- TTSVoice.cs
- MatrixConverter.cs
- CodeObject.cs
- HandoffBehavior.cs
- WebScriptEndpoint.cs
- FixedHighlight.cs
- RawStylusInputCustomData.cs
- SqlExpressionNullability.cs
- StyleXamlTreeBuilder.cs
- HostedTransportConfigurationManager.cs
- DesignerOptionService.cs
- BamlMapTable.cs
- IImplicitResourceProvider.cs
- _SingleItemRequestCache.cs
- ClusterUtils.cs
- Dictionary.cs
- ThemeDictionaryExtension.cs
- LayoutEditorPart.cs
- StylusPointProperty.cs