检查缓存中是否存在 Kerberos 票证

发布于 2024-12-04 06:57:18 字数 248 浏览 1 评论 0 原文

我编写了一些 C 代码来连接到 Kerberized LDAP 服务器。这一切都工作正常,但目前,它每次连接时都会生成一个新的 TGT,而不是使用默认凭据缓存中的 TGT(假设它已经存在)。

我已经研究过使用 krb5_cc_resolve 和 krb5_initialize 之类的方法来获取对缓存的引用,但这似乎会破坏缓存(如果它已经存在)及其持有的任何票证。

基本上,我想知道的是:是否有任何方法可以检查现有 TGT 的默认凭据缓存而不破坏它?

I have written some C code to connect to a Kerberized LDAP server. This all works fine, but at present, it currently generates a new TGT every time it connects, rather than using the one (assuming it already exists) in the default credentials cache.

I have looked into using the likes of krb5_cc_resolve and krb5_initialize to get a reference to the cache, but this seems to destroy the cache if it already exists, along with any tickets it holds.

Basically, what I want to know is: is there any way of checking the default credentials cache for existing TGTs without destroying it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬﹪忆之殇 2024-12-11 06:57:18

krb5_cc_initialize 清除缓存,如文档所述。如果您想访问现有缓存,请不要这样做

文档

任何现有凭据都将被丢弃,缓存的主体名称将设置为指定的值

krb5_cc_initialize clears the cache, as the documentation says. Just don't do that if you want to access an existing cache

From the docs:

Any existing credentials are discarded and the principal name for the cache is set to the value specified

人间☆小暴躁 2024-12-11 06:57:18

查看 kstart 的代码,其中实现了 -H 选项。

http://git.eyrie.org/?p=kerberos/kstart.git;a=blob;f=framework.c;h=66e851413a9b4d71fa4d61ded2f3c0d71cd03b0c;hb=HEAD

基本上,你需要检查票据中主体的过期时间。

 /* Obtain the ticket. */
 memset(&increds, 0, sizeof(increds));
 code = krb5_cc_resolve(ctx, config->cache, &ccache);
 if (code != 0)
     goto done;
     increds.client = config->client;
 else {
     code = krb5_cc_get_principal(ctx, ccache, &increds.client);
    if (code != 0)
        goto done;
 }
 code = get_krbtgt_princ(ctx, increds.client, &increds.server);
if (code != 0)
     goto done;
 code = krb5_get_credentials(ctx, 0, ccache, &increds, &outcreds);
 if (code != 0)
    goto done;
 increds_valid = true;

 /* Check the expiration time and renewal limit. */
if (code == 0) {
    now = time(NULL);
   then = outcreds->times.endtime;
     if (config->happy_ticket > 0)
        offset = 60 * config->happy_ticket;
   else
        offset = 60 * config->keep_ticket + EXPIRE_FUDGE;
    if (then < now + offset)
       code = KRB5KRB_AP_ERR_TKT_EXPIRED;

Look in the code for kstart where it implements the -H option.

http://git.eyrie.org/?p=kerberos/kstart.git;a=blob;f=framework.c;h=66e851413a9b4d71fa4d61ded2f3c0d71cd03b0c;hb=HEAD

Basically, you need to check the expire time for the principal in the ticket.

 /* Obtain the ticket. */
 memset(&increds, 0, sizeof(increds));
 code = krb5_cc_resolve(ctx, config->cache, &ccache);
 if (code != 0)
     goto done;
     increds.client = config->client;
 else {
     code = krb5_cc_get_principal(ctx, ccache, &increds.client);
    if (code != 0)
        goto done;
 }
 code = get_krbtgt_princ(ctx, increds.client, &increds.server);
if (code != 0)
     goto done;
 code = krb5_get_credentials(ctx, 0, ccache, &increds, &outcreds);
 if (code != 0)
    goto done;
 increds_valid = true;

 /* Check the expiration time and renewal limit. */
if (code == 0) {
    now = time(NULL);
   then = outcreds->times.endtime;
     if (config->happy_ticket > 0)
        offset = 60 * config->happy_ticket;
   else
        offset = 60 * config->keep_ticket + EXPIRE_FUDGE;
    if (then < now + offset)
       code = KRB5KRB_AP_ERR_TKT_EXPIRED;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文