2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * lib/krb5/krb/mk_rep.c
2N/A *
2N/A * Copyright 1990 by the Massachusetts Institute of Technology.
2N/A * All Rights Reserved.
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
2N/A * distribute this software and its documentation for any purpose and
2N/A * without fee is hereby granted, provided that the above copyright
2N/A * notice appear in all copies and that both that copyright notice and
2N/A * this permission notice appear in supporting documentation, and that
2N/A * the name of M.I.T. not be used in advertising or publicity pertaining
2N/A * to distribution of the software without specific, written prior
2N/A * permission. Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A * M.I.T. makes no representations about the suitability of
2N/A * this software for any purpose. It is provided "as is" without express
2N/A * or implied warranty.
2N/A */
2N/A/*
2N/A * Copyright (c) 2006-2008, Novell, Inc.
2N/A * All rights reserved.
2N/A *
2N/A * Redistribution and use in source and binary forms, with or without
2N/A * modification, are permitted provided that the following conditions are met:
2N/A *
2N/A * * Redistributions of source code must retain the above copyright notice,
2N/A * this list of conditions and the following disclaimer.
2N/A * * Redistributions in binary form must reproduce the above copyright
2N/A * notice, this list of conditions and the following disclaimer in the
2N/A * documentation and/or other materials provided with the distribution.
2N/A * * The copyright holder's name is not used to endorse or promote products
2N/A * derived from this software without specific prior written permission.
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2N/A * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2N/A * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2N/A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2N/A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2N/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2N/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2N/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2N/A * POSSIBILITY OF SUCH DAMAGE.
2N/A */
2N/A/*
2N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A/*
2N/A * krb5_mk_rep()
2N/A */
2N/A
2N/A#include "k5-int.h"
2N/A#include "auth_con.h"
2N/A
2N/A/* Solaris Kerberos */
2N/A#include "kerberos_dtrace.h"
2N/A
2N/A/*
2N/A Formats a KRB_AP_REP message into outbuf.
2N/A
2N/A The outbuf buffer storage is allocated, and should be freed by the
2N/A caller when finished.
2N/A
2N/A returns system errors
2N/A*/
2N/A
2N/Astatic krb5_error_code
2N/Ak5_mk_rep(krb5_context context, krb5_auth_context auth_context,
2N/A krb5_data *outbuf, int dce_style)
2N/A{
2N/A krb5_error_code retval;
2N/A krb5_ap_rep_enc_part repl;
2N/A krb5_ap_rep reply;
2N/A krb5_data * scratch;
2N/A krb5_data * toutbuf;
2N/A
2N/A /* Make the reply */
2N/A if (((auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_DO_SEQUENCE) ||
2N/A (auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_RET_SEQUENCE)) &&
2N/A (auth_context->local_seq_number == 0)) {
2N/A if ((retval = krb5_generate_seq_number(context,
2N/A &auth_context->key->keyblock,
2N/A &auth_context->local_seq_number)))
2N/A return(retval);
2N/A }
2N/A
2N/A if (dce_style) {
2N/A krb5_us_timeofday(context, &repl.ctime, &repl.cusec);
2N/A } else {
2N/A repl.ctime = auth_context->authentp->ctime;
2N/A repl.cusec = auth_context->authentp->cusec;
2N/A }
2N/A
2N/A if (dce_style)
2N/A repl.subkey = NULL;
2N/A else if (auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_USE_SUBKEY) {
2N/A assert(auth_context->negotiated_etype != ENCTYPE_NULL);
2N/A
2N/A retval = krb5int_generate_and_save_subkey (context, auth_context,
2N/A &auth_context->key->keyblock,
2N/A auth_context->negotiated_etype);
2N/A if (retval)
2N/A return retval;
2N/A repl.subkey = &auth_context->send_subkey->keyblock;
2N/A } else
2N/A repl.subkey = auth_context->authentp->subkey;
2N/A
2N/A if (dce_style)
2N/A repl.seq_number = auth_context->remote_seq_number;
2N/A else
2N/A repl.seq_number = auth_context->local_seq_number;
2N/A
2N/A /* encode it before encrypting */
2N/A if ((retval = encode_krb5_ap_rep_enc_part(&repl, &scratch)))
2N/A return retval;
2N/A
2N/A if ((retval = krb5_encrypt_keyhelper(context, auth_context->key,
2N/A KRB5_KEYUSAGE_AP_REP_ENCPART,
2N/A scratch, &reply.enc_part)))
2N/A goto cleanup_scratch;
2N/A
2N/A if (!(retval = encode_krb5_ap_rep(&reply, &toutbuf))) {
2N/A /* Solaris Kerberos */
2N/A KERBEROS_PROBE_KRB_AP_REP(MAKE, toutbuf, &reply, &repl);
2N/A *outbuf = *toutbuf;
2N/A free(toutbuf);
2N/A }
2N/A
2N/A memset(reply.enc_part.ciphertext.data, 0, reply.enc_part.ciphertext.length);
2N/A free(reply.enc_part.ciphertext.data);
2N/A reply.enc_part.ciphertext.length = 0;
2N/A reply.enc_part.ciphertext.data = 0;
2N/A
2N/Acleanup_scratch:
2N/A memset(scratch->data, 0, scratch->length);
2N/A krb5_free_data(context, scratch);
2N/A
2N/A return retval;
2N/A}
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_mk_rep(krb5_context context, krb5_auth_context auth_context, krb5_data *outbuf)
2N/A{
2N/A return k5_mk_rep(context, auth_context, outbuf, 0);
2N/A}
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_mk_rep_dce(krb5_context context, krb5_auth_context auth_context, krb5_data *outbuf)
2N/A{
2N/A return k5_mk_rep(context, auth_context, outbuf, 1);
2N/A}