Active Directory and use of SSPI EncryptMessage/DecryptMessage
(Resposting on platformsdk.security, was originally on
windows.server.active_directory).
I'm using Java JNDI to talk to ADAM / LDS. I wanted to use pass-through
authentication so I wrote a custom SASL client for JNDI that implements
GSS-SPNEGO, using native SSPI calls.
I've been able to avoid the need for encrypting messages by requesting no
context attributes during the SSPI bind process, so that the completed
context does not have the ISC_RET_INTEGRITY flag - and hence communication
proceeds using plain LDAPv3, which JNDI can do just fine. So far, things are
working great.
However, I've discovered that when my client code runs on Server 2008, the
resulting context contains ISC_RET_INTEGRITY, ISC_RET_REPLAY_DETECT and
ISC_RET_SEQUENCE_DETECT even though I did not requested them. As a result,
messages must undergo GSS wrap/unwrap when communicating with the server to
satisfy the integrity requirement.
I presume this means calling EncryptMessage / DecryptMessage on the bytes,
so I do this in GSSAPI style following the reference code at
http://msdn.microsoft.com/en-us/library/ms995352.aspx
My EncryptMessage call succeeds (and interestingly SecPkgSizes.cbBlockSize,
and consequently the the third buffer (SECBUFFER_PADDING) size is always
zero). I then concatenate the three buffers in the same order and send it
over the wire. However, AD does not seem to like this, and returns a message
which contains (after calling DecryptMessage on it):
LdapErr: DSID-0C06042B, comment: Error decrypting ldap message, data 0,
v1771.Å .1.3.6.1.4.1.1466.20036
So:
1. Is there any way to avoid Vista / Server 2008 setting the
ISC_RET_INTEGRITY flag when I use InitializeSecurityContext when running on
that platform? I know the server is not requiring this, since when I run the
same client code on XP talking to LDS on Server 2008, the flags are not set.
So it must be the SSPI client code on Vista that is forcing it.
2. If not, is there any more complete reference code for the correct way to
invoke EncryptMessage / DecryptMessage, and how to format the resulting
message from the buffers when talking to AD after a GSS-SPNEGO bind? Is it
GSS style messages and I'm screwing it up somehow, or does it expect messages
of a somewhat different format?
Thanks in advance for any pointers...
Doug
date: Thu, 5 Jun 2008 13:03:02 -0700
author: clarkd4