2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * lib/krb5/rcache/rc_conv.c
2N/A *
2N/A * This file of the Kerberos V5 software is derived from public-domain code
2N/A * contributed by Daniel J. Bernstein, <brnstnd@acf10.nyu.edu>.
2N/A *
2N/A */
2N/A
2N/A/*
2N/A * An implementation for the default replay cache type.
2N/A */
2N/A
2N/A#include "rc_base.h"
2N/A
2N/A/*
2N/A Local stuff:
2N/A krb5_auth_to_replay(context, krb5_tkt_authent *auth,krb5_donot_replay *rep)
2N/A given auth, take important information and make rep; return -1 if failed
2N/A*/
2N/A
2N/Akrb5_error_code
2N/Akrb5_auth_to_rep(krb5_context context, krb5_tkt_authent *auth, krb5_donot_replay *rep)
2N/A{
2N/A krb5_error_code retval;
2N/A rep->cusec = auth->authenticator->cusec;
2N/A rep->ctime = auth->authenticator->ctime;
2N/A if ((retval = krb5_unparse_name(context, auth->ticket->server, &rep->server)))
2N/A return retval; /* shouldn't happen */
2N/A if ((retval = krb5_unparse_name(context, auth->authenticator->client,
2N/A &rep->client))) {
2N/A free(rep->server);
2N/A return retval; /* shouldn't happen. */
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/A/*
2N/A * Generate a printable hash value for a message for use in a replay
2N/A * record. It is not necessary for this hash function to be
2N/A * collision-proof (the only thing you can do with a second preimage
2N/A * is produce a false replay error) but it is necessary for the
2N/A * function to be consistent across implementations. We do an unkeyed
2N/A * MD5 hash of the message and convert it into uppercase hex
2N/A * representation.
2N/A */
2N/Akrb5_error_code
2N/Akrb5_rc_hash_message(krb5_context context, const krb5_data *message,
2N/A char **out)
2N/A{
2N/A krb5_error_code retval;
2N/A krb5_checksum cksum;
2N/A char *hash, *ptr;
2N/A unsigned int i;
2N/A
2N/A *out = NULL;
2N/A
2N/A /* Calculate the binary checksum. */
2N/A retval = krb5_c_make_checksum(context, CKSUMTYPE_RSA_MD5, 0, 0,
2N/A message, &cksum);
2N/A if (retval)
2N/A return retval;
2N/A
2N/A /* Convert the checksum into printable form. */
2N/A hash = malloc(cksum.length * 2 + 1);
2N/A if (!hash) {
2N/A krb5_free_checksum_contents(context, &cksum);
2N/A return KRB5_RC_MALLOC;
2N/A }
2N/A
2N/A for (i = 0, ptr = hash; i < cksum.length; i++, ptr += 2)
2N/A snprintf(ptr, 3, "%02X", cksum.contents[i]);
2N/A *ptr = '\0';
2N/A *out = hash;
2N/A krb5_free_checksum_contents(context, &cksum);
2N/A return 0;
2N/A}