HighTechTalks DotNet Forums  

WindowsIdentity - Invalid token; it cannot be duplicated

Dotnet Security microsoft.public.dotnet.security


Discuss WindowsIdentity - Invalid token; it cannot be duplicated in the Dotnet Security forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Kamal
 
Posts: n/a

Default WindowsIdentity - Invalid token; it cannot be duplicated - 03-14-2007 , 09:39 AM






I am having invalid token, it cannot be duplicated error 70% of the time on
one machine. We are creating and validating the current user. The following
line of code raise exception.

System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

Exception:
String Message = "LoginWI() Invalid token; it cannot be duplicated. at
RtReports.Security.LocalAuthentication.CheckUserGr oups(IntPtr iToken,
StringCollection strGroupsCollection)


Any help is really appreciated.

Thanks,
Kamal

Reply With Quote
  #2  
Old   
Dominick Baier
 
Posts: n/a

Default Re: WindowsIdentity - Invalid token; it cannot be duplicated - 03-14-2007 , 10:00 AM






Where do you get the token from?


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

Quote:
I am having invalid token, it cannot be duplicated error 70% of the
time on one machine. We are creating and validating the current user.
The following line of code raise exception.

System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

Exception:
String Message = "LoginWI() Invalid token; it cannot be duplicated.
at
RtReports.Security.LocalAuthentication.CheckUserGr oups(IntPtr iToken,
StringCollection strGroupsCollection)

Any help is really appreciated.

Thanks,
Kamal



Reply With Quote
  #3  
Old   
Kamal
 
Posts: n/a

Default Re: WindowsIdentity - Invalid token; it cannot be duplicated - 03-14-2007 , 11:49 AM



Hi Domnic,

Thanks for your response. Here the code from Login() webmethod and the same
token will be passed to another method which has the actual problem.

WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr iToken = wi.Token;
string domainName="";
string userName="";
if (wi.Name != null)
{
string curUser = wi.Name;
if (curUser.Length>0)
{
int sepIndex = curUser.IndexOf(@"\");
if (sepIndex>-1)
{
domainName = curUser.Substring(0,sepIndex);
int len = curUser.Length-domainName.Length;
if (len>0)
{
userName = curUser.Substring(sepIndex+1,len-1);
}
}
else //just in case , no domain
userName=curUser;
}
}

Thanks,
Kamal.

"Dominick Baier" wrote:

Quote:
Where do you get the token from?


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

I am having invalid token, it cannot be duplicated error 70% of the
time on one machine. We are creating and validating the current user.
The following line of code raise exception.

System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

Exception:
String Message = "LoginWI() Invalid token; it cannot be duplicated.
at
RtReports.Security.LocalAuthentication.CheckUserGr oups(IntPtr iToken,
StringCollection strGroupsCollection)

Any help is really appreciated.

Thanks,
Kamal




Reply With Quote
  #4  
Old   
Dominick Baier
 
Posts: n/a

Default Re: WindowsIdentity - Invalid token; it cannot be duplicated - 03-14-2007 , 12:07 PM



Hi,

well - frankly, i don't understand what you are doing...

and why do you have to pass tokens around??


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

Quote:
Hi Domnic,

Thanks for your response. Here the code from Login() webmethod and
the same token will be passed to another method which has the actual
problem.

WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr iToken = wi.Token;
string domainName="";
string userName="";
if (wi.Name != null)
{
string curUser = wi.Name;
if (curUser.Length>0)
{
int sepIndex = curUser.IndexOf(@"\");
if (sepIndex>-1)
{
domainName = curUser.Substring(0,sepIndex);
int len = curUser.Length-domainName.Length;
if (len>0)
{
userName = curUser.Substring(sepIndex+1,len-1);
}
}
else //just in case , no domain
userName=curUser;
}
}
Thanks,
Kamal.
"Dominick Baier" wrote:

Where do you get the token from?

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

I am having invalid token, it cannot be duplicated error 70% of the
time on one machine. We are creating and validating the current
user. The following line of code raise exception.

System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

Exception:
String Message = "LoginWI() Invalid token; it cannot be duplicated.
at
RtReports.Security.LocalAuthentication.CheckUserGr oups(IntPtr
iToken,
StringCollection strGroupsCollection)
Any help is really appreciated.

Thanks,
Kamal



Reply With Quote
  #5  
Old   
Kamal
 
Posts: n/a

Default Re: WindowsIdentity - Invalid token; it cannot be duplicated - 03-14-2007 , 01:39 PM



Dominik,
Because the login method will be used by asp.net application and also used
by sharepoint webpart to access some webservice calls, we splited into two.

So, the login method is common and before that we received the Token, we are
passing the token to Login method and it tries to get the Priniciple.

Sequence is:

1. SharepointLogin() using
WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr iToken = wi.Token;
and passing this token to LogInUser() method fo Global.ascx.

2. static internal void LogInUser(System.Web.HttpApplication appState,
IntPtr iToken, string domainName, string userName)

which internally calls another method to retreive valid groups list by
passing the iToken again.

3. public string CheckUserGroups(IntPtr iToken, StringCollection
strGroupsCollection)

which uses the following.
System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

This is where the "Invalid token" problem happens.

I can create a sample application if you like.

Please let me know if there is any best way to accomblish this one.

Thanks
Kamal

"Dominick Baier" wrote:

Quote:
Hi,

well - frankly, i don't understand what you are doing...

and why do you have to pass tokens around??


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

Hi Domnic,

Thanks for your response. Here the code from Login() webmethod and
the same token will be passed to another method which has the actual
problem.

WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr iToken = wi.Token;
string domainName="";
string userName="";
if (wi.Name != null)
{
string curUser = wi.Name;
if (curUser.Length>0)
{
int sepIndex = curUser.IndexOf(@"\");
if (sepIndex>-1)
{
domainName = curUser.Substring(0,sepIndex);
int len = curUser.Length-domainName.Length;
if (len>0)
{
userName = curUser.Substring(sepIndex+1,len-1);
}
}
else //just in case , no domain
userName=curUser;
}
}
Thanks,
Kamal.
"Dominick Baier" wrote:

Where do you get the token from?

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

I am having invalid token, it cannot be duplicated error 70% of the
time on one machine. We are creating and validating the current
user. The following line of code raise exception.

System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

Exception:
String Message = "LoginWI() Invalid token; it cannot be duplicated.
at
RtReports.Security.LocalAuthentication.CheckUserGr oups(IntPtr
iToken,
StringCollection strGroupsCollection)
Any help is really appreciated.

Thanks,
Kamal




Reply With Quote
  #6  
Old   
Joe Kaplan
 
Posts: n/a

Default Re: WindowsIdentity - Invalid token; it cannot be duplicated - 03-15-2007 , 02:28 AM



Are you passing the pointer across process boundaries or something? You
can't do that.

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
"Kamal" <Kamal (AT) discussions (DOT) microsoft.com> wrote

Quote:
Dominik,
Because the login method will be used by asp.net application and also used
by sharepoint webpart to access some webservice calls, we splited into
two.

So, the login method is common and before that we received the Token, we
are
passing the token to Login method and it tries to get the Priniciple.

Sequence is:

1. SharepointLogin() using
WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr iToken = wi.Token;
and passing this token to LogInUser() method fo Global.ascx.

2. static internal void LogInUser(System.Web.HttpApplication appState,
IntPtr iToken, string domainName, string userName)

which internally calls another method to retreive valid groups list by
passing the iToken again.

3. public string CheckUserGroups(IntPtr iToken, StringCollection
strGroupsCollection)

which uses the following.
System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

This is where the "Invalid token" problem happens.

I can create a sample application if you like.

Please let me know if there is any best way to accomblish this one.

Thanks
Kamal

"Dominick Baier" wrote:

Hi,

well - frankly, i don't understand what you are doing...

and why do you have to pass tokens around??


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

Hi Domnic,

Thanks for your response. Here the code from Login() webmethod and
the same token will be passed to another method which has the actual
problem.

WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr iToken = wi.Token;
string domainName="";
string userName="";
if (wi.Name != null)
{
string curUser = wi.Name;
if (curUser.Length>0)
{
int sepIndex = curUser.IndexOf(@"\");
if (sepIndex>-1)
{
domainName = curUser.Substring(0,sepIndex);
int len = curUser.Length-domainName.Length;
if (len>0)
{
userName = curUser.Substring(sepIndex+1,len-1);
}
}
else //just in case , no domain
userName=curUser;
}
}
Thanks,
Kamal.
"Dominick Baier" wrote:

Where do you get the token from?

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

I am having invalid token, it cannot be duplicated error 70% of the
time on one machine. We are creating and validating the current
user. The following line of code raise exception.

System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

Exception:
String Message = "LoginWI() Invalid token; it cannot be duplicated.
at
RtReports.Security.LocalAuthentication.CheckUserGr oups(IntPtr
iToken,
StringCollection strGroupsCollection)
Any help is really appreciated.

Thanks,
Kamal






Reply With Quote
  #7  
Old   
Dominick Baier
 
Posts: n/a

Default Re: WindowsIdentity - Invalid token; it cannot be duplicated - 03-15-2007 , 08:22 AM



Some things strike me odd...

First - you are using WindowsIdentity.GetCurrent() - this implies you are
using client impersonation (and also that your code will only work with that
setting) - you can always get to the authenticated client name by using Context.User.Identity.Name.

This also means - why do you have to factor that out? The client information
is always available..


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

Quote:
Dominik,
Because the login method will be used by asp.net application and also
used
by sharepoint webpart to access some webservice calls, we splited into
two.
So, the login method is common and before that we received the Token,
we are passing the token to Login method and it tries to get the
Priniciple.

Sequence is:

1. SharepointLogin() using
WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr iToken = wi.Token;
and passing this token to LogInUser() method fo Global.ascx.
2. static internal void LogInUser(System.Web.HttpApplication appState,
IntPtr iToken, string domainName, string userName)

which internally calls another method to retreive valid groups list
by passing the iToken again.

3. public string CheckUserGroups(IntPtr iToken, StringCollection
strGroupsCollection)

which uses the following.
System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);
This is where the "Invalid token" problem happens.

I can create a sample application if you like.

Please let me know if there is any best way to accomblish this one.

Thanks
Kamal
"Dominick Baier" wrote:

Hi,

well - frankly, i don't understand what you are doing...

and why do you have to pass tokens around??

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

Hi Domnic,

Thanks for your response. Here the code from Login() webmethod and
the same token will be passed to another method which has the actual
problem.

WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr iToken = wi.Token;
string domainName="";
string userName="";
if (wi.Name != null)
{
string curUser = wi.Name;
if (curUser.Length>0)
{
int sepIndex = curUser.IndexOf(@"\");
if (sepIndex>-1)
{
domainName = curUser.Substring(0,sepIndex);
int len = curUser.Length-domainName.Length;
if (len>0)
{
userName = curUser.Substring(sepIndex+1,len-1);
}
}
else //just in case , no domain
userName=curUser;
}
}
Thanks,
Kamal.
"Dominick Baier" wrote:
Where do you get the token from?

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)
I am having invalid token, it cannot be duplicated error 70% of
the time on one machine. We are creating and validating the
current user. The following line of code raise exception.

System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

Exception:
String Message = "LoginWI() Invalid token; it cannot be
duplicated.
at
RtReports.Security.LocalAuthentication.CheckUserGr oups(IntPtr
iToken,
StringCollection strGroupsCollection)
Any help is really appreciated.
Thanks,
Kamal



Reply With Quote
  #8  
Old   
Kamal
 
Posts: n/a

Default Re: WindowsIdentity - Invalid token; it cannot be duplicated - 03-16-2007 , 09:14 AM



Dominic,

Thank you so much. Reallized after your comment that the following line of
code is not right way of doing it.

System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

Replaced with

System.Security.Principal.WindowsIdentity winIden
=(WindowsIdentity)this.Context.User.Identity;

Problem is resolved now.

This helps lot to resolve few other security related questions.

http://www.leastprivilege.com/ASPNET...otingTool.aspx

Thanks for your Help.

-Kamal.


"Dominick Baier" wrote:

Quote:
Some things strike me odd...

First - you are using WindowsIdentity.GetCurrent() - this implies you are
using client impersonation (and also that your code will only work with that
setting) - you can always get to the authenticated client name by using Context.User.Identity.Name.

This also means - why do you have to factor that out? The client information
is always available..


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

Dominik,
Because the login method will be used by asp.net application and also
used
by sharepoint webpart to access some webservice calls, we splited into
two.
So, the login method is common and before that we received the Token,
we are passing the token to Login method and it tries to get the
Priniciple.

Sequence is:

1. SharepointLogin() using
WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr iToken = wi.Token;
and passing this token to LogInUser() method fo Global.ascx.
2. static internal void LogInUser(System.Web.HttpApplication appState,
IntPtr iToken, string domainName, string userName)

which internally calls another method to retreive valid groups list
by passing the iToken again.

3. public string CheckUserGroups(IntPtr iToken, StringCollection
strGroupsCollection)

which uses the following.
System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);
This is where the "Invalid token" problem happens.

I can create a sample application if you like.

Please let me know if there is any best way to accomblish this one.

Thanks
Kamal
"Dominick Baier" wrote:

Hi,

well - frankly, i don't understand what you are doing...

and why do you have to pass tokens around??

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

Hi Domnic,

Thanks for your response. Here the code from Login() webmethod and
the same token will be passed to another method which has the actual
problem.

WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr iToken = wi.Token;
string domainName="";
string userName="";
if (wi.Name != null)
{
string curUser = wi.Name;
if (curUser.Length>0)
{
int sepIndex = curUser.IndexOf(@"\");
if (sepIndex>-1)
{
domainName = curUser.Substring(0,sepIndex);
int len = curUser.Length-domainName.Length;
if (len>0)
{
userName = curUser.Substring(sepIndex+1,len-1);
}
}
else //just in case , no domain
userName=curUser;
}
}
Thanks,
Kamal.
"Dominick Baier" wrote:
Where do you get the token from?

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)
I am having invalid token, it cannot be duplicated error 70% of
the time on one machine. We are creating and validating the
current user. The following line of code raise exception.

System.Security.Principal.WindowsIdentity winIden=new
System.Security.Principal.WindowsIdentity(iToken);

Exception:
String Message = "LoginWI() Invalid token; it cannot be
duplicated.
at
RtReports.Security.LocalAuthentication.CheckUserGr oups(IntPtr
iToken,
StringCollection strGroupsCollection)
Any help is really appreciated.
Thanks,
Kamal




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.