Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Security / Cryptography / X509Certificates / AuthenticodeSignatureInformation.cs / 1305376 / AuthenticodeSignatureInformation.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Security.Permissions; namespace System.Security.Cryptography.X509Certificates { ////// Details about the Authenticode signature of a manifest /// [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)] public sealed class AuthenticodeSignatureInformation { private string m_description; private Uri m_descriptionUrl; private CapiNative.AlgorithmId m_hashAlgorithmId; private X509Chain m_signatureChain; private TimestampInformation m_timestamp; private SignatureVerificationResult m_verificationResult; private X509Certificate2 m_signingCertificate; internal AuthenticodeSignatureInformation(X509Native.AXL_AUTHENTICODE_SIGNER_INFO signer, X509Chain signatureChain, TimestampInformation timestamp) { m_verificationResult = (SignatureVerificationResult)signer.dwError; m_hashAlgorithmId = signer.algHash; if (signer.pwszDescription != IntPtr.Zero) { m_description = Marshal.PtrToStringUni(signer.pwszDescription); } if (signer.pwszDescriptionUrl != IntPtr.Zero) { string descriptionUrl = Marshal.PtrToStringUni(signer.pwszDescriptionUrl); Uri.TryCreate(descriptionUrl, UriKind.RelativeOrAbsolute, out m_descriptionUrl); } m_signatureChain = signatureChain; // If there was a timestamp, and it was not valid we need to invalidate the entire Authenticode // signature as well, since we cannot assume that the signature would have verified without // the timestamp. if (timestamp != null && timestamp.VerificationResult != SignatureVerificationResult.MissingSignature) { if (timestamp.IsValid) { m_timestamp = timestamp; } else { m_verificationResult = SignatureVerificationResult.InvalidTimestamp; } } else { m_timestamp = null; } } ////// Create an Authenticode signature information for a signature which is not valid /// internal AuthenticodeSignatureInformation(SignatureVerificationResult error) { Debug.Assert(error != SignatureVerificationResult.Valid); m_verificationResult = error; } ////// Description of the signing certificate /// public string Description { get { return m_description; } } ////// Description URL of the signing certificate /// public Uri DescriptionUrl { get { return m_descriptionUrl; } } ////// Hash algorithm the signature was computed with /// public string HashAlgorithm { get { return CapiNative.GetAlgorithmName(m_hashAlgorithmId); } } ////// HRESULT from verifying the signature /// public int HResult { get { return CapiNative.HResultForVerificationResult(m_verificationResult); } } ////// X509 chain used to verify the Authenticode signature /// public X509Chain SignatureChain { [StorePermission(SecurityAction.Demand, OpenStore = true, EnumerateCertificates = true)] get { return m_signatureChain; } } ////// Certificate the manifest was signed with /// public X509Certificate2 SigningCertificate { [StorePermission(SecurityAction.Demand, OpenStore = true, EnumerateCertificates = true)] get { if (m_signingCertificate == null && SignatureChain != null) { Debug.Assert(SignatureChain.ChainElements.Count > 0, "SignatureChain.ChainElements.Count > 0"); m_signingCertificate = SignatureChain.ChainElements[0].Certificate; } return m_signingCertificate; } } ////// Timestamp, if any, applied to the Authenticode signature /// ////// Note that this is only available in the trusted publisher case /// public TimestampInformation Timestamp { get { return m_timestamp; } } ////// Trustworthiness of the Authenticode signature /// public TrustStatus TrustStatus { get { switch (VerificationResult) { case SignatureVerificationResult.Valid: return TrustStatus.Trusted; case SignatureVerificationResult.CertificateNotExplicitlyTrusted: return TrustStatus.KnownIdentity; case SignatureVerificationResult.CertificateExplicitlyDistrusted: return TrustStatus.Untrusted; default: return TrustStatus.UnknownIdentity; } } } ////// Result of verifying the Authenticode signature /// public SignatureVerificationResult VerificationResult { get { return m_verificationResult; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Security.Permissions; namespace System.Security.Cryptography.X509Certificates { ////// Details about the Authenticode signature of a manifest /// [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)] public sealed class AuthenticodeSignatureInformation { private string m_description; private Uri m_descriptionUrl; private CapiNative.AlgorithmId m_hashAlgorithmId; private X509Chain m_signatureChain; private TimestampInformation m_timestamp; private SignatureVerificationResult m_verificationResult; private X509Certificate2 m_signingCertificate; internal AuthenticodeSignatureInformation(X509Native.AXL_AUTHENTICODE_SIGNER_INFO signer, X509Chain signatureChain, TimestampInformation timestamp) { m_verificationResult = (SignatureVerificationResult)signer.dwError; m_hashAlgorithmId = signer.algHash; if (signer.pwszDescription != IntPtr.Zero) { m_description = Marshal.PtrToStringUni(signer.pwszDescription); } if (signer.pwszDescriptionUrl != IntPtr.Zero) { string descriptionUrl = Marshal.PtrToStringUni(signer.pwszDescriptionUrl); Uri.TryCreate(descriptionUrl, UriKind.RelativeOrAbsolute, out m_descriptionUrl); } m_signatureChain = signatureChain; // If there was a timestamp, and it was not valid we need to invalidate the entire Authenticode // signature as well, since we cannot assume that the signature would have verified without // the timestamp. if (timestamp != null && timestamp.VerificationResult != SignatureVerificationResult.MissingSignature) { if (timestamp.IsValid) { m_timestamp = timestamp; } else { m_verificationResult = SignatureVerificationResult.InvalidTimestamp; } } else { m_timestamp = null; } } ////// Create an Authenticode signature information for a signature which is not valid /// internal AuthenticodeSignatureInformation(SignatureVerificationResult error) { Debug.Assert(error != SignatureVerificationResult.Valid); m_verificationResult = error; } ////// Description of the signing certificate /// public string Description { get { return m_description; } } ////// Description URL of the signing certificate /// public Uri DescriptionUrl { get { return m_descriptionUrl; } } ////// Hash algorithm the signature was computed with /// public string HashAlgorithm { get { return CapiNative.GetAlgorithmName(m_hashAlgorithmId); } } ////// HRESULT from verifying the signature /// public int HResult { get { return CapiNative.HResultForVerificationResult(m_verificationResult); } } ////// X509 chain used to verify the Authenticode signature /// public X509Chain SignatureChain { [StorePermission(SecurityAction.Demand, OpenStore = true, EnumerateCertificates = true)] get { return m_signatureChain; } } ////// Certificate the manifest was signed with /// public X509Certificate2 SigningCertificate { [StorePermission(SecurityAction.Demand, OpenStore = true, EnumerateCertificates = true)] get { if (m_signingCertificate == null && SignatureChain != null) { Debug.Assert(SignatureChain.ChainElements.Count > 0, "SignatureChain.ChainElements.Count > 0"); m_signingCertificate = SignatureChain.ChainElements[0].Certificate; } return m_signingCertificate; } } ////// Timestamp, if any, applied to the Authenticode signature /// ////// Note that this is only available in the trusted publisher case /// public TimestampInformation Timestamp { get { return m_timestamp; } } ////// Trustworthiness of the Authenticode signature /// public TrustStatus TrustStatus { get { switch (VerificationResult) { case SignatureVerificationResult.Valid: return TrustStatus.Trusted; case SignatureVerificationResult.CertificateNotExplicitlyTrusted: return TrustStatus.KnownIdentity; case SignatureVerificationResult.CertificateExplicitlyDistrusted: return TrustStatus.Untrusted; default: return TrustStatus.UnknownIdentity; } } } ////// Result of verifying the Authenticode signature /// public SignatureVerificationResult VerificationResult { get { return m_verificationResult; } } } } // 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
- DataServiceExpressionVisitor.cs
- DelegateHelpers.Generated.cs
- cookiecontainer.cs
- WindowExtensionMethods.cs
- X509CertificateValidationMode.cs
- TabControlAutomationPeer.cs
- ProtocolsSection.cs
- XmlSchemaCompilationSettings.cs
- ToolStripComboBox.cs
- MessageFilterTable.cs
- XmlSchemaIdentityConstraint.cs
- HideDisabledControlAdapter.cs
- ImageListImage.cs
- Geometry.cs
- CharConverter.cs
- PanningMessageFilter.cs
- ObjectDataSourceView.cs
- ToolStripDropDown.cs
- MaterializeFromAtom.cs
- DefaultProxySection.cs
- CodePrimitiveExpression.cs
- X509WindowsSecurityToken.cs
- _SslSessionsCache.cs
- XhtmlConformanceSection.cs
- StackOverflowException.cs
- __Error.cs
- Calendar.cs
- autovalidator.cs
- UnsafeNativeMethods.cs
- CalendarDesigner.cs
- WindowsTooltip.cs
- IgnoreFlushAndCloseStream.cs
- GridViewEditEventArgs.cs
- ConfigurationManagerHelper.cs
- ConsoleKeyInfo.cs
- UserNamePasswordClientCredential.cs
- WindowProviderWrapper.cs
- FontStyle.cs
- securitycriticaldataClass.cs
- MessageRpc.cs
- FormViewPagerRow.cs
- SoapIgnoreAttribute.cs
- Rect3D.cs
- TextElementEnumerator.cs
- TextDecoration.cs
- XmlSchemaSimpleContentRestriction.cs
- LoginStatusDesigner.cs
- CodeCompileUnit.cs
- RemoteWebConfigurationHost.cs
- ResolveMatchesApril2005.cs
- RuntimeResourceSet.cs
- DesignTimeVisibleAttribute.cs
- LassoHelper.cs
- RSAOAEPKeyExchangeFormatter.cs
- IEnumerable.cs
- EnumMember.cs
- OrderByBuilder.cs
- ToolStripItem.cs
- WebSysDisplayNameAttribute.cs
- recordstatescratchpad.cs
- SynchronizationFilter.cs
- QilFunction.cs
- PersonalizableAttribute.cs
- StateManagedCollection.cs
- EntityContainerAssociationSet.cs
- Environment.cs
- Literal.cs
- MetafileHeaderEmf.cs
- StringBuilder.cs
- XmlObjectSerializerWriteContextComplexJson.cs
- ClientApiGenerator.cs
- NodeFunctions.cs
- DataGridRow.cs
- BufferedWebEventProvider.cs
- UnmanagedMemoryStream.cs
- ClientEndpointLoader.cs
- TextElement.cs
- EventListener.cs
- ThrowHelper.cs
- _LazyAsyncResult.cs
- SingleSelectRootGridEntry.cs
- SystemUdpStatistics.cs
- DbLambda.cs
- ParallelDesigner.cs
- ActivityValidator.cs
- SiblingIterators.cs
- BuildManagerHost.cs
- BackgroundWorker.cs
- RoutedEvent.cs
- ButtonFieldBase.cs
- ObjectPersistData.cs
- TextChange.cs
- CalendarAutomationPeer.cs
- SizeAnimationBase.cs
- OpacityConverter.cs
- RangeEnumerable.cs
- CachedPathData.cs
- ServiceRouteHandler.cs
- FormsAuthenticationConfiguration.cs
- entityreference_tresulttype.cs