Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > implementing ICertificatePolicy causes security exception under hosted environment

Reply
Thread Tools

implementing ICertificatePolicy causes security exception under hosted environment

 
 
C.W.
Guest
Posts: n/a
 
      12-19-2005
I need to establish an SSL connection with another in my application.
However, I have run into a security exception when I run my code under
hosted environment.

In particular, I have the following class:

Class AcceptAllCertificatesPolicy

Implements ICertificatePolicy



Public Function CheckValidationResult(ByVal srvPoint As
System.Net.ServicePoint, ByVal certificate As
System.Security.Cryptography.X509Certificates.X509 Certificate, ByVal request
As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean
Implements System.Net.ICertificatePolicy.CheckValidationResul t

Return True

End Function

End Class



When I call this class using

ServicePointManager.CertificatePolicy = New AcceptAllCertificatesPolicy

I get a security exception

Description: The application attempted to perform an operation not allowed
by the security policy. To grant this application the required permission
please contact your system administrator or change the application's trust
level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the
permission of type System.Security.Permissions.SecurityPermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.


Line 418: req.ClientCertificates.Add(X509Cert)
Line 419:
Line 420: ServicePointManager.CertificatePolicy = New
AcceptAllCertificatesPolicy
Line 421:
Line 422: Dim reqWriter As StreamWriter = New
StreamWriter(req.GetRequestStream())



Stack Trace:
[SecurityException: Request for the permission of type
System.Security.Permissions.SecurityPermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
failed.]
System.Security.CodeAccessSecurityEngine.CheckHelp er(PermissionSet
grantedSet, PermissionSet deniedSet, CodeAccessPermission demand,
PermissionToken permToken) +666
System.Security.CodeAccessSecurityEngine.Check(Per missionToken permToken,
CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames,
Int32 unrestrictedOverride) +0
System.Security.CodeAccessSecurityEngine.Check(Cod eAccessPermission cap,
StackCrawlMark& stackMark) +88
System.Security.CodeAccessPermission.Demand() +62
System.Net.ServicePointManager.set_CertificatePoli cy(ICertificatePolicy
value) +45



I gather this must be due to security restrictions set up by the webhost.
Can I change my code to somehow get around this or only the web host can fix
this issue?

Thanks in advance


 
Reply With Quote
 
 
 
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      12-19-2005
The SDK docs indicate that accessing the
ServicePointManager.CertificatePolicy requires SecurityPermission with the
UnmanagedCode flag. If you are running your code under partial trust
(sounds like you are), you must have that permission.

The alternative might be to fix the SSL issues that are causing you to want
to override certificate errors.

Joe K.

"C.W." <c.w@nospam_com> wrote in message
news:...
>I need to establish an SSL connection with another in my application.
>However, I have run into a security exception when I run my code under
>hosted environment.
>
> In particular, I have the following class:
>
> Class AcceptAllCertificatesPolicy
>
> Implements ICertificatePolicy
>
>
>
> Public Function CheckValidationResult(ByVal srvPoint As
> System.Net.ServicePoint, ByVal certificate As
> System.Security.Cryptography.X509Certificates.X509 Certificate, ByVal
> request As System.Net.WebRequest, ByVal certificateProblem As Integer) As
> Boolean Implements System.Net.ICertificatePolicy.CheckValidationResul t
>
> Return True
>
> End Function
>
> End Class
>
>
>
> When I call this class using
>
> ServicePointManager.CertificatePolicy = New AcceptAllCertificatesPolicy
>
> I get a security exception
>
> Description: The application attempted to perform an operation not allowed
> by the security policy. To grant this application the required permission
> please contact your system administrator or change the application's trust
> level in the configuration file.
>
> Exception Details: System.Security.SecurityException: Request for the
> permission of type System.Security.Permissions.SecurityPermission,
> mscorlib, Version=1.0.5000.0, Culture=neutral,
> PublicKeyToken=b77a5c561934e089 failed.
>
>
> Line 418: req.ClientCertificates.Add(X509Cert)
> Line 419:
> Line 420: ServicePointManager.CertificatePolicy = New
> AcceptAllCertificatesPolicy
> Line 421:
> Line 422: Dim reqWriter As StreamWriter = New
> StreamWriter(req.GetRequestStream())
>
>
>
> Stack Trace:
> [SecurityException: Request for the permission of type
> System.Security.Permissions.SecurityPermission, mscorlib,
> Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
> failed.]
> System.Security.CodeAccessSecurityEngine.CheckHelp er(PermissionSet
> grantedSet, PermissionSet deniedSet, CodeAccessPermission demand,
> PermissionToken permToken) +666
> System.Security.CodeAccessSecurityEngine.Check(Per missionToken
> permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32
> checkFrames, Int32 unrestrictedOverride) +0
> System.Security.CodeAccessSecurityEngine.Check(Cod eAccessPermission cap,
> StackCrawlMark& stackMark) +88
> System.Security.CodeAccessPermission.Demand() +62
> System.Net.ServicePointManager.set_CertificatePoli cy(ICertificatePolicy
> value) +45
>
>
>
> I gather this must be due to security restrictions set up by the webhost.
> Can I change my code to somehow get around this or only the web host can
> fix this issue?
>
> Thanks in advance
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best practices for using forms authentication and security in a hosted env (was: Re: Using a Forms authentication in a shared hosting environment) JEFF ASP .Net 1 11-12-2007 07:00 PM
Need a secure ICertificatePolicy... Rob Edwards ASP .Net Web Services 0 11-17-2005 02:39 PM
ASP.NET calling COM DLL under SP1 (2003) or SP2 (XP) causes exception markd@peloton.com ASP .Net Security 0 08-03-2005 02:48 PM
winform control hosted in IE, FileIO security exception. Please he =?Utf-8?B?TW9l?= ASP .Net 1 05-12-2005 08:11 PM
Security Exception - Winform usercontrol hosted in ASP.NET Scott Leonard ASP .Net Security 2 12-22-2004 06:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57