Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > Proxy auth with default credentials

Reply
Thread Tools

Proxy auth with default credentials

 
 
kristan.mcdonald@googlemail.com
Guest
Posts: n/a
 
      02-23-2006
Ok, I've managed to get authenticated on my proxy by doing :

System.Net.WebRequest req;
req = System.Net.WebRequest.Create("http://www.mywebsite.com/");
System.Net.WebProxy prx = new
System.Net.WebProxy("http://myproxyserver",true);
System.Net.CredentialCache cache = new System.Net.CredentialCache();
cache.Add( new Uri( "http://myproxyserver" ), "NTLM", new
System.Net.NetworkCredential("username", "password", "domain") );

I want this to be an app on the intranet and use the impersonated users
details. I've setup IIS to auth using integrated authentication, the
..net app is set to impersonate=true and windows authentication. The box
is set to be trusted for delegation etc.

But I can't figure out how in code to create the cache entry for the
proxy server for the impersonated user. I don't want to hardcode a
un/pw for obvious reasons but I can't see any other way. I've tried to
use the System.Net.CredentialCache.DefaultCredential but I just get a
proxy auth required message if I try it.

BTW, for some reason setting the proxies credential to the
DefaultCredential doesn't seem to work, if I look at a packet trace it
tries to negotiate authentication with the proxy server but it does it
under "Negotiate" rather than "NTLM" - this seems to make a difference.

Help!

 
Reply With Quote
 
 
 
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      02-23-2006
I'm pretty sure I read that .NET can't do proxy server authentication using
Kerberos authentication. You would need that in your scenario as you would
be delegating the user's login credentials to the proxy server.

I think there is a kbase article that covers this.
http://support.microsoft.com/kb/321728/

That Kbase mentions it in terms of IE, but System.Net uses WinInet under the
covers, so I would not be surprised if the same rules apply.

Joe K.

<> wrote in message
news: oups.com...
> Ok, I've managed to get authenticated on my proxy by doing :
>
> System.Net.WebRequest req;
> req = System.Net.WebRequest.Create("http://www.mywebsite.com/");
> System.Net.WebProxy prx = new
> System.Net.WebProxy("http://myproxyserver",true);
> System.Net.CredentialCache cache = new System.Net.CredentialCache();
> cache.Add( new Uri( "http://myproxyserver" ), "NTLM", new
> System.Net.NetworkCredential("username", "password", "domain") );
>
> I want this to be an app on the intranet and use the impersonated users
> details. I've setup IIS to auth using integrated authentication, the
> .net app is set to impersonate=true and windows authentication. The box
> is set to be trusted for delegation etc.
>
> But I can't figure out how in code to create the cache entry for the
> proxy server for the impersonated user. I don't want to hardcode a
> un/pw for obvious reasons but I can't see any other way. I've tried to
> use the System.Net.CredentialCache.DefaultCredential but I just get a
> proxy auth required message if I try it.
>
> BTW, for some reason setting the proxies credential to the
> DefaultCredential doesn't seem to work, if I look at a packet trace it
> tries to negotiate authentication with the proxy server but it does it
> under "Negotiate" rather than "NTLM" - this seems to make a difference.
>
> Help!
>



 
Reply With Quote
 
 
 
 
kristan.mcdonald@googlemail.com
Guest
Posts: n/a
 
      02-27-2006
Ok, I'm still getting my head around the whole windows security setup,
but from what you've said my understanding is:
I can't auth with kerberos to the proxy, impersonation is a function of
kerberos, so I won't be able to authenticate against the proxy with an
impersonated user.

I'm happy I can't do that, but seeing as I'm impersonating the user on
the IIS box, I've therefore got a thread running as mydomain\myuser on
the IIS box. Why can't I use that users credentials to create something
I can assign to the proxy object so I can use with NTLM authentication
(which does work against the proxy)?

Basically I'm trying to get a way of creating a
System.Net.NetworkCredential with the details of the user IIS is
impersonating - I just can't see how to do it?

 
Reply With Quote
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      02-27-2006
It is actually delegation that is a function of Kerberos. Impersonation can
be done with most types of Windows authentication. The issue is that you
are impersonating a user who was authenticated from a remote browser via
IWA, so in order to pass their credentials on to another network node (the
proxy server in this case), you must use delegation.

If you authenticated with Basic authentication, then you could capture the
user's plaintext credentials and use that to build a NetworkCredential or
you might be able to simply impersonate the user and authenticate via NTLM
to the proxy server. That depends a little on how IIS did the Basic
authentication.

I'm not sure there is another good solution for you though if you need to
use the authenticated user's credentials to access the web resource and the
proxy requires authentication.

Joe K.

<> wrote in message
news: ups.com...
> Ok, I'm still getting my head around the whole windows security setup,
> but from what you've said my understanding is:
> I can't auth with kerberos to the proxy, impersonation is a function of
> kerberos, so I won't be able to authenticate against the proxy with an
> impersonated user.
>
> I'm happy I can't do that, but seeing as I'm impersonating the user on
> the IIS box, I've therefore got a thread running as mydomain\myuser on
> the IIS box. Why can't I use that users credentials to create something
> I can assign to the proxy object so I can use with NTLM authentication
> (which does work against the proxy)?
>
> Basically I'm trying to get a way of creating a
> System.Net.NetworkCredential with the details of the user IIS is
> impersonating - I just can't see how to do it?
>



 
Reply With Quote
 
kristan.mcdonald@googlemail.com
Guest
Posts: n/a
 
      02-27-2006
What I thought I could do was just impersonate the user on IIS,
configure the proxy's credentials to DefaultCredentials (which should
be that of the logged on user) and then everything should work. It
didn't though and I a 407 proxy authentication required so I assumed it
wasn't passing anything. However when I captured the conversation
between IIS and the proxy, it was trying to authentication using
"Negotiate" rather than "NTLM" which appears to be what is needed. This
failing is probably because of the restrictions in the article you
mentioned.

The only way I seemed to be able to force the IIS to send NTLM was to
create the credentials myself, hence me now needing a way to get from
the impersonated user to a NetworkCredential object I can use. The only
other thing I can think of is if there is someway to force the WebProxy
object to only use NTLM and not Negotiate - any ideas??

Thanks

 
Reply With Quote
 
kristan.mcdonald@googlemail.com
Guest
Posts: n/a
 
      02-27-2006
Done a bit more digging and it may not be the auth type that's the
problem, I've tried doing:

System.Net.NetworkCredential myCred =
System.Net.CredentialCache.DefaultCredentials.GetC redential(new Uri(
"http://myproxyserver" ), "NTLM");

and if I examine the contents of myCred, everything is blank - no
matter what URI I specify, it comes back with blank username, blank
domain etc. If I look at User.Identity it's got it running as the right
person, am I being really thick as to what DefaultCredentials should
allow me to do? Is it maybe just not populated when you're
impersonating and I have to do something extra to make it work?

 
Reply With Quote
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      02-27-2006
I don't think DefaultCredentials ever shows you who the person is. It is
just some kind of a wrapper around an internal handle. I could be wrong
about that.

The issue is that you can't get the right kind of NTLM credentials for the
user if you authenticated them with IWA on the front end. You would need to
prompt the user for their plaintext credentials.

Is it possible for you to use a service account's credentials to get through
the proxy server authentication? You would be building a NetworkCredential
with explicit credentials, but it would not require getting the user's
plaintext credentials.

Joe K.

<> wrote in message
news: oups.com...
> Done a bit more digging and it may not be the auth type that's the
> problem, I've tried doing:
>
> System.Net.NetworkCredential myCred =
> System.Net.CredentialCache.DefaultCredentials.GetC redential(new Uri(
> "http://myproxyserver" ), "NTLM");
>
> and if I examine the contents of myCred, everything is blank - no
> matter what URI I specify, it comes back with blank username, blank
> domain etc. If I look at User.Identity it's got it running as the right
> person, am I being really thick as to what DefaultCredentials should
> allow me to do? Is it maybe just not populated when you're
> impersonating and I have to do something extra to make it work?
>



 
Reply With Quote
 
kristan.mcdonald@googlemail.com
Guest
Posts: n/a
 
      02-27-2006
I've tried a slightly different tack now and I'm still getting nowhere.
I've created a c# console app and pasted in the following :

System.Net.WebRequest req;
req = System.Net.WebRequest.Create("http://test.com");
System.Net.WebProxy prx = new
System.Net.WebProxy("http://myproxy",true);
prx.Credentials = System.Net.CredentialCache.DefaultCredentials;

//comment out to switch between default proxy and proxy specified above
//req.Proxy = prx;
req.Proxy = System.Net.WebProxy.GetDefaultProxy();

System.Net.WebResponse resp = req.GetResponse();


In both cases (using GetDefaultProxy and DefaultCredentials) I get a
407 error. This is running on my PC, logged in as me - if I open IE I
can connect fine - I'm getting confused now! I don't really want to
have to hard code credentials in (or pull them from registry/config or
something) but I can't see any way around it at the moment. I must be
doing something really basic wrong. Incidentially, if I create my own
NetworkCredential object and specify them that way, it works.

 
Reply With Quote
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      02-27-2006
This I can't tell you. I'd suggest sniffing the network traffic with a tool
like Ethereal and seeing what is different between IE and your code.
However, you should be able to make this work with the right combo of
parameters.

Joe K.

<> wrote in message
news: oups.com...
> I've tried a slightly different tack now and I'm still getting nowhere.
> I've created a c# console app and pasted in the following :
>
> System.Net.WebRequest req;
> req = System.Net.WebRequest.Create("http://test.com");
> System.Net.WebProxy prx = new
> System.Net.WebProxy("http://myproxy",true);
> prx.Credentials = System.Net.CredentialCache.DefaultCredentials;
>
> //comment out to switch between default proxy and proxy specified above
> //req.Proxy = prx;
> req.Proxy = System.Net.WebProxy.GetDefaultProxy();
>
> System.Net.WebResponse resp = req.GetResponse();
>
>
> In both cases (using GetDefaultProxy and DefaultCredentials) I get a
> 407 error. This is running on my PC, logged in as me - if I open IE I
> can connect fine - I'm getting confused now! I don't really want to
> have to hard code credentials in (or pull them from registry/config or
> something) but I can't see any way around it at the moment. I must be
> doing something really basic wrong. Incidentially, if I create my own
> NetworkCredential object and specify them that way, it works.
>



 
Reply With Quote
 
kristan.mcdonald@googlemail.com
Guest
Posts: n/a
 
      02-28-2006
Well I've got it working in the console app, basically it looks like
you have to request the credential for the URI you're trying to request
from DefaultCredentials instead of just assigning the lot, this has the
effect of forcing it to use NTLM instead of Negoitate which seems to
work, basically swapping:

prx.Credentials = System.Net.CredentialCache.DefaultCredentials;

for

System.Net.CredentialCache cache = new System.Net.CredentialCache();
cache.Add(new
Uri("http://proxyserver"),"NTLM",System.Net.CredentialCache.De faultCredentials.GetCredential(new
Uri("http://proxyserver"),"NTLM"));
prx.Credentials = cache;

However this doesn't work when I put it in an asp.net app and try it
with impersonation. I'm going to give up with impersonation for now and
do the whole thing a different way. Thanks for all your help with this
Joe!

Kristan

 
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
"The credentials supplied conflict with an existing set of credentials" -=rjh=- NZ Computing 2 07-15-2006 11:09 PM
credentials/auth in Ruby SOAP libs? Chris McMahon Ruby 0 03-25-2006 08:43 PM
Re: Pass Basic Auth. credentials to remote site? Craig Deelsnyder ASP .Net 2 07-21-2004 06:00 PM
Configuring Windows Auth & Forms Auth in Asp.Net =?Utf-8?B?Q2hyaXMgTW9oYW4=?= ASP .Net 0 04-28-2004 06:11 PM
Can I pass ASP Basic Auth Credentials to an APS.NET Forms Authentication site? Douglas J. Badin ASP .Net Security 4 01-29-2004 02:13 AM



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