Path: blob/main/crypto/krb5/src/kdc/kdc_preauth_encts.c
34869 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* kdc/kdc_preauth_encts.c - Encrypted timestamp kdcpreauth module */2/*3* Copyright (C) 1995, 2003, 2007, 2011 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Export of this software from the United States of America may7* require a specific license from the United States Government.8* It is the responsibility of any person or organization contemplating9* export to obtain such a license before exporting.10*11* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and12* distribute this software and its documentation for any purpose and13* without fee is hereby granted, provided that the above copyright14* notice appear in all copies and that both that copyright notice and15* this permission notice appear in supporting documentation, and that16* the name of M.I.T. not be used in advertising or publicity pertaining17* to distribution of the software without specific, written prior18* permission. Furthermore if you modify this software you must label19* your software as modified software and not distribute it in such a20* fashion that it might be confused with the original M.I.T. software.21* M.I.T. makes no representations about the suitability of22* this software for any purpose. It is provided "as is" without express23* or implied warranty.24*/2526#include <k5-int.h>27#include <krb5/kdcpreauth_plugin.h>28#include "kdc_util.h"2930static void31enc_ts_get(krb5_context context, krb5_kdc_req *request,32krb5_kdcpreauth_callbacks cb, krb5_kdcpreauth_rock rock,33krb5_kdcpreauth_moddata moddata, krb5_preauthtype pa_type,34krb5_kdcpreauth_edata_respond_fn respond, void *arg)35{36krb5_keyblock *armor_key = cb->fast_armor(context, rock);3738/* Encrypted timestamp must not be used with FAST, and requires a key. */39if (armor_key != NULL || !cb->have_client_keys(context, rock))40(*respond)(arg, ENOENT, NULL);41else42(*respond)(arg, 0, NULL);43}4445static void46enc_ts_verify(krb5_context context, krb5_data *req_pkt, krb5_kdc_req *request,47krb5_enc_tkt_part *enc_tkt_reply, krb5_pa_data *pa,48krb5_kdcpreauth_callbacks cb, krb5_kdcpreauth_rock rock,49krb5_kdcpreauth_moddata moddata,50krb5_kdcpreauth_verify_respond_fn respond, void *arg)51{52krb5_pa_enc_ts * pa_enc = 0;53krb5_error_code retval;54krb5_data scratch;55krb5_data enc_ts_data;56krb5_enc_data *enc_data = 0;57krb5_keyblock key;58krb5_key_data * client_key;59krb5_int32 start;6061scratch.data = (char *)pa->contents;62scratch.length = pa->length;6364enc_ts_data.data = 0;6566if ((retval = decode_krb5_enc_data(&scratch, &enc_data)) != 0)67goto cleanup;6869enc_ts_data.length = enc_data->ciphertext.length;70if ((enc_ts_data.data = (char *) malloc(enc_ts_data.length)) == NULL)71goto cleanup;7273start = 0;74while (1) {75if ((retval = krb5_dbe_search_enctype(context, rock->client,76&start, enc_data->enctype,77-1, 0, &client_key)))78goto cleanup;7980if ((retval = krb5_dbe_decrypt_key_data(context, NULL, client_key,81&key, NULL)))82goto cleanup;8384key.enctype = enc_data->enctype;8586retval = krb5_c_decrypt(context, &key, KRB5_KEYUSAGE_AS_REQ_PA_ENC_TS,870, enc_data, &enc_ts_data);88krb5_free_keyblock_contents(context, &key);89if (retval == 0)90break;91}9293if ((retval = decode_krb5_pa_enc_ts(&enc_ts_data, &pa_enc)) != 0)94goto cleanup;9596retval = krb5_check_clockskew(context, pa_enc->patimestamp);97if (retval)98goto cleanup;99100setflag(enc_tkt_reply->flags, TKT_FLG_PRE_AUTH);101102retval = 0;103104cleanup:105if (enc_data) {106krb5_free_data_contents(context, &enc_data->ciphertext);107free(enc_data);108}109krb5_free_data_contents(context, &enc_ts_data);110if (pa_enc)111free(pa_enc);112/* If we get NO_MATCHING_KEY, it probably means that the password was113* incorrect. */114if (retval == KRB5_KDB_NO_MATCHING_KEY)115retval = KRB5KDC_ERR_PREAUTH_FAILED;116117(*respond)(arg, retval, NULL, NULL, NULL);118}119120static krb5_preauthtype enc_ts_types[] = {121KRB5_PADATA_ENC_TIMESTAMP, 0 };122123krb5_error_code124kdcpreauth_encrypted_timestamp_initvt(krb5_context context, int maj_ver,125int min_ver, krb5_plugin_vtable vtable)126{127krb5_kdcpreauth_vtable vt;128129if (maj_ver != 1)130return KRB5_PLUGIN_VER_NOTSUPP;131vt = (krb5_kdcpreauth_vtable)vtable;132vt->name = "encrypted_timestamp";133vt->pa_type_list = enc_ts_types;134vt->edata = enc_ts_get;135vt->verify = enc_ts_verify;136return 0;137}138139140