mod_auth_tkt - java implementation

415 Views Asked by At

Has anyone implemented a mod_auth_tkt cookie generation using Java?

I'm stuck on how to generate the iptstamp (can be done in PHP using the pack function) and hextimestamp in Java.

The algorithm for generating the cookie is below:

cookie := digest + hextimestamp + user_id + '!' + token_list + '!' + user_data

digest := MD5(digest0 + key)

digest0 := MD5(iptstamp + key + user_id + '\0' + token_list + '\0' + user_data)
  • iptstamp is a 8 bytes long byte array, bytes 0-3 are filled with client's IP address as a binary number in network byte order, bytes 4-7 are filled with timestamp as a binary number in network byte order.

  • hextimestamp is 8 character long hexadecimal number expressing timestamp used in iptstamp.

  • token_list is an optional comma-separated list of access tokens for this user.
    This list is checked if TKTAuthToken is set for a particular area.

  • user_data is optional

1

There are 1 best solutions below

0
On

Simply convert the IP Address to 4 bytes and append the timestamp.

iptstamp = ip_chars + ts_chars

http://code.cmlenz.net/diva/changeset/173/branches http://www.mail-archive.com/[email protected]/msg00003.html

Using the following to get network byte order.

ByteBuffer bb = ByteBuffer.allocate(4096);
bb.order(ByteOrder.BIG_ENDIAN);

See

Network Order short (Java)