<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Windows Authentication Blog : Negotiate</title><link>http://blogs.technet.com/authentication/archive/tags/Negotiate/default.aspx</link><description>Tags: Negotiate</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Migrating from NTLM to Negotiate in a nutshell</title><link>http://blogs.technet.com/authentication/archive/2006/04/27/migrating-from-ntlm-to-negotiate-in-a-nutshell.aspx</link><pubDate>Fri, 28 Apr 2006 03:51:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:426628</guid><dc:creator>Authentication</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.technet.com/authentication/comments/426628.aspx</comments><wfw:commentRss>http://blogs.technet.com/authentication/commentrss.aspx?PostID=426628</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;&lt;BR&gt;Migrating to Negotiate from NTLM is quite simple in most cases.&amp;nbsp; It breaks down into these four simple steps:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I&gt;&lt;BR&gt;First, build an SPN for your Service&lt;/I&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;When I talk to people about using Negotiate, there’s often this moment of terror when they realize they’re going to have to build an SPN.&amp;nbsp; I’ve got my theories about why that might be, but suffice it to say you can hold back the terrors.&amp;nbsp; It’s not difficult, and it corresponds to about 90% of the work here.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;The first thing you have to do is pick an &lt;B&gt;SPN prefix&lt;/B&gt;.&amp;nbsp; This should be something unique to your application protocol.&amp;nbsp; For example, if I have an application called “Flying Authentication Thing”, then FlyingAuthenticationThing would be a useful (if not particularly short) SPN prefix.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;The prefix is half the work of building an SPN.&amp;nbsp; The other half is literally putting that prefix in front of your server’s hostname (DNS preferred, netbios if necessary).&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;For example, &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;FlyingAuthenticationThing/my-dev-machine.ntdev.corp.microsoft.com &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;would denote the FlyingAuthenticationThing service on my current development machine.&amp;nbsp; You can do this with the explicitly-blessed DsMakeSpn (see &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/dsmakespn.asp"&gt;&lt;FONT face=Calibri color=#0000ff size=3&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/dsmakespn.asp&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt;), or a simple sprintf.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B&gt;&lt;I&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I&gt;Second, have your Service register the SPN&lt;/I&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;The SPN needs to be associated with the account your server is running as.&amp;nbsp; If this is NetworkService or LocalSystem, that would be the host computer’s account (usually netbios computername$) in the Directory.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Register your SPN when the service gets installed.&amp;nbsp; You only have to do it once.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;You can use &lt;B&gt;DsWriteAccountSpn&lt;/B&gt; (see &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/dswriteaccountspn.asp?frame=true"&gt;&lt;FONT face=Calibri color=#0000ff size=3&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/dswriteaccountspn.asp?frame=true&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt;) to register that SPN.&amp;nbsp; There should already be SPNs on the machine account already.&amp;nbsp; Don’t disturb them… just add yours to the mix.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;The cool thing about registering your SPN is that it’s generally fire-and-forget.&amp;nbsp; If your computer changes names for some reason, most of the SPNs will automatically change with it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Alternatively, you can use &lt;I&gt;setspn&lt;/I&gt; (a reskit tool, see &lt;/FONT&gt;&lt;A href="http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/setspn-o.asp"&gt;&lt;FONT face=Calibri color=#0000ff size=3&gt;http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/setspn-o.asp&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt;) to write the SPN manually, since you only have to do it at installation time.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I&gt;Third, have your client use the Service’s SPN.&lt;/I&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;This may seem obvious, but to get Mutual Auth, you have to actually provide the server name to the client authentication mechanism.&amp;nbsp; It can’t just guess J&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;So, when you’re going to connect to a server (netbios name or dns name), build an SPN out of it the same way your server did above.&amp;nbsp; That is, slap your SPN prefix onto the front of it with a slash in the middle.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Pass the newly-built SPN to your authentication function.&amp;nbsp; In SSPI terms, this would be InitializeSecurityContext’s pszTargetName parameter.&amp;nbsp; Wrappers around SSPI have their own parameters—consult your API documentation.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I&gt;Fourth, have your Client and Server call Negotiate instead of NTLM&lt;/I&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Whatever your client or server calls with NTLM, have it call it with Negotiate instead.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;In SSPI terms, this means changing the call to AcquireCredentialsHandle to have “Negotiate” instead of “NTLM”.&amp;nbsp; For RPC, DCOM, or other callers, it will be different, but usually just as simple – swapping, say, RPC_C_AUTHN_WINNT with RPC_C_AUTHN_GSS_SPNEGO.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Consult your API documentation for more on this if you don't use SSPI directly, since there are lots of functions that wrap SSPI in some way.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;…and that’s it!&amp;nbsp; You’re done!&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;One of the cool things about Negotiate is that it tends to know when it's necessary (and safe) to downgrade to NTLM.&amp;nbsp; One of those cases is when no SPN is registered on a server's account.&amp;nbsp; In those cases, the server is obviously downlevel (that is, it hasn't registered an SPN yet), so NTLM will be used.&amp;nbsp; So uplevel clients can talk to downlevel servers.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;Also, because Negotiate is smart enough to accept raw (non-gss-framed) NTLM, the reverse is also true: a downlevel client can talk to an uplevel server.&amp;nbsp; This makes migration far less painful than one might expect from changing authentication protocols.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 11pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-fareast-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 11pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-fareast-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;-Dave Christiansen&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=426628" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/authentication/archive/tags/NTLM/default.aspx">NTLM</category><category domain="http://blogs.technet.com/authentication/archive/tags/Negotiate/default.aspx">Negotiate</category></item></channel></rss>