使用 Spnego 解密 kerberos 票证
我在 JBoss 下使用 spnego ( http://spnego.sourceforge.net ) 进行 kerberos 身份验证。
我需要解密 kerberos 票证才能访问包含 PAC 数据的授权数据。需要 PAC 数据来决定向用户授予哪些角色。
如何访问和解密kerberos票证?我已经在网上搜索了示例,但没有费力。
I'm using spnego ( http://spnego.sourceforge.net ) for kerberos authentication under JBoss.
I need to decrypt kerberos ticket to access the authorization-data which will containt PAC data. The PAC data is needed to decide which roles are to be granted to user.
How to access and decrypt kerberos ticket? I've searched net for examples, but without effort.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这些人有一个完整的 PAC 解码实现:
http://jaaslounge.sourceforge.net/
您可以像这样使用令牌解析器
:如果您想解密底层的 Kerberos 票证,则需要跳过一些步骤。不确定你是否需要那个。
授予
These guys have a full PAC decoding implementation:
http://jaaslounge.sourceforge.net/
You can use the token parser like this:
You're going to need to jump though some hoops if you want to decrypt the underlying Kerberos ticket. Not sure if you need that.
Grant
我已经成功地将 http://spnego.sourceforge.net 中的 servlet 过滤器与 < a href="http://jaaslounge.sourceforge.net/" rel="noreferrer">http://jaaslounge.sourceforge.net/ 无需使用 DER/ASN.1 解析器显式执行某些操作:
我还编写了一个新的 HttpFilter(从 spnego.sf.net 派生):spnego-pac,它通过 getUserPrincipal() 公开 LogonInfo。
可以在此处找到完整演示上述代码的示例项目:
https://github.com/EleotleCram /jetty-spnego-demo
spnego-pac 过滤器(在上面的示例中使用)可以在这里找到:
https://github.com/EleotleCram/spnego.sf.net-fork
希望这对任何人都有帮助。
__
马塞尔
I have successfully used the servlet filter from http://spnego.sourceforge.net in combination with the PAC parser from http://jaaslounge.sourceforge.net/ without the need to do something explicitly with DER/ASN.1 parsers :
I've also written a new HttpFilter (forked from spnego.sf.net): spnego-pac, that discloses the LogonInfo through the getUserPrincipal().
An example project demonstrating the above code in full can be found here:
https://github.com/EleotleCram/jetty-spnego-demo
The spnego-pac filter (used in the above example) can be found here:
https://github.com/EleotleCram/spnego.sf.net-fork
Hope this is helpful to anyone.
__
Marcel
如果您从
spnegoToken
获取机制令牌,如下所示:机制令牌通常是
KerberosApRequest
。有一个KerberosToken
构造函数,它接受KerberosApRequest
。只需传入mechanismToken
字节数组以及解密内容的密钥即可。If you get the mechanism token from the
spnegoToken
like this:The mechanism token is usually a
KerberosApRequest
. There is aKerberosToken
constructor which takes aKerberosApRequest
. Simply pass in themechanismToken
byte array along with the key to decrypt the contents.我提供了自己的解决方案:
我的解决方案基于 BouncyCastle 库(用于解析令牌的部分)和 JaasLounge(用于解密令牌的加密部分)。不幸的是,从 JaasLounge 解码整个 spnego 令牌的代码未能满足我的要求。我必须自己写。
我已经部分地解码了票据,首先从 byte[] 数组构造 DERObjects:
untag() 是我的辅助函数,用于删除 DERTaggedObject 包装
为了从给定的 DERObject 中提取 DERObject 序列,我编写了另一个辅助函数:
最后,当我得到包含加密部分的 DEROctetStream 时,我刚刚使用了 KerberosEncData:
我们从客户端浏览器接收到的字节序列将被解析为单个 DERApplicationSpecific
这是票证根 - 级别 0。
根包含:
级别 1 包含:
级别 2 包含:
0x01 0x00
,解析为布尔值 (false)级别 3 包含:
票证部分 - 第 4 级包含:
服务器名称和实例名称
加密部分序列(级别 5)包含:
17 - ETYPE-AES128-CTS-HMAC-SHA1-96
18 - ETYPE-AES256-CTS-HMAC-SHA1-96
问题出在 DERBoolean 构造函数上,当找到序列 0x01 0x00 时,它会抛出 ArrayIndexOutOfBoundException。我必须更改该构造函数:
I provide my own solution to the problem:
I've based my solution on BouncyCastle library (for parsing parts of token) and JaasLounge (for decrypting encrypted part of token). Unfortunatelly, the code for decoding whole spnego token from JaasLounge failed for my requirements. I had to write it myself.
I've decoded ticket part by part, firstly constructing DERObjects from byte[] array:
The untag() is my helper function, to remove DERTaggedObject wrapping
For extracting sequence of DERObject from given DERObject I've written another helper function:
At the end, when I've got DEROctetStream, that contained encrypted part, I've just used KerberosEncData:
The byte sequence we receive from client browser will be parsed into single DERApplicationSpecific
which is ticket root - level 0.
The root contains:
Level 1 contains:
Level 2 contains:
0x01 0x00
, parsed as boolean (false)Level 3 contains:
Ticket part - level 4 contains:
server name and instance name
Encrypted part sequence (level 5) contains:
The problem was with DERBoolean constructor, that throw ArrayIndexOutOfBoundException, when sequence 0x01 0x00 was found. I had to change that constructor:
哇,自从我使用 spnego 以来已经有一段时间了(将近一年)......你问了一个非常酷的问题。
我做了一些挖掘,打算尝试运行一些我不久前使用 MS-AD 的代码,但今天感觉不到:-/
无论如何,我通过谷歌找到了这个链接:
http://www.google .com/url?sa=t&source=web&cd=1&sqi=2&ved=0CBMQFjAA&url=http%3A%2F%2Fbofriis.dk%2Ffiles%2Fms_kerberos_pac.pdf&rct=j&q=java %20kerberos%20privilege%20attribute%20certificate&ei=2FASTbaLGcP38Abk07iQDg&usg=AFQjCNHcIfQRUTxkQUvLRcgOaQksCALTHA&sig2=g8yn7ie1PbzSkE2Mfv41Bw&cad=rja
Hopefully that can give you some insight.
Wow been a while since I've used spnego (nearly a year) ... You're asking a very cool question.
I did a little digging and was going to try and run up some code I had from a while back that was working with MS-AD but just not feeling it today :-/
Anyway, I found this link through google:
http://www.google.com/url?sa=t&source=web&cd=1&sqi=2&ved=0CBMQFjAA&url=http%3A%2F%2Fbofriis.dk%2Ffiles%2Fms_kerberos_pac.pdf&rct=j&q=java%20kerberos%20privilege%20attribute%20certificate&ei=2FASTbaLGcP38Abk07iQDg&usg=AFQjCNHcIfQRUTxkQUvLRcgOaQksCALTHA&sig2=g8yn7ie1PbzSkE2Mfv41Bw&cad=rja
Hopefully that can give you some insight.