(krb5_build_authenticator): if the local sequence number is non-zero,

don't generate a new one


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@12143 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2003-04-25 18:10:29 +00:00
parent 0b41135c1f
commit 10617940f1

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997 - 2002 Kungliga Tekniska H<>gskolan * Copyright (c) 1997 - 2003 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden). * (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved. * All rights reserved.
* *
@@ -45,86 +45,86 @@ krb5_build_authenticator (krb5_context context,
krb5_data *result, krb5_data *result,
krb5_key_usage usage) krb5_key_usage usage)
{ {
Authenticator *auth; Authenticator *auth;
u_char *buf = NULL; u_char *buf = NULL;
size_t buf_size; size_t buf_size;
size_t len; size_t len;
krb5_error_code ret; krb5_error_code ret;
krb5_crypto crypto; krb5_crypto crypto;
auth = malloc(sizeof(*auth)); auth = malloc(sizeof(*auth));
if (auth == NULL) { if (auth == NULL) {
krb5_set_error_string(context, "malloc: out of memory"); krb5_set_error_string(context, "malloc: out of memory");
return ENOMEM; return ENOMEM;
} }
memset (auth, 0, sizeof(*auth)); memset (auth, 0, sizeof(*auth));
auth->authenticator_vno = 5; auth->authenticator_vno = 5;
copy_Realm(&cred->client->realm, &auth->crealm); copy_Realm(&cred->client->realm, &auth->crealm);
copy_PrincipalName(&cred->client->name, &auth->cname); copy_PrincipalName(&cred->client->name, &auth->cname);
{ krb5_us_timeofday (context, &auth->ctime, &auth->cusec);
int32_t sec, usec;
krb5_us_timeofday (context, &sec, &usec); ret = krb5_auth_con_getlocalsubkey(context, auth_context, &auth->subkey);
auth->ctime = sec; if(ret)
auth->cusec = usec; goto fail;
}
ret = krb5_auth_con_getlocalsubkey(context, auth_context, &auth->subkey);
if(ret)
goto fail;
if (auth_context->flags & KRB5_AUTH_CONTEXT_DO_SEQUENCE) { if (auth_context->flags & KRB5_AUTH_CONTEXT_DO_SEQUENCE) {
krb5_generate_seq_number (context, if(auth_context->local_seqnumber == 0)
&cred->session, krb5_generate_seq_number (context,
&auth_context->local_seqnumber); &cred->session,
ALLOC(auth->seq_number, 1); &auth_context->local_seqnumber);
*auth->seq_number = auth_context->local_seqnumber; ALLOC(auth->seq_number, 1);
} else if(auth->seq_number == NULL) {
auth->seq_number = NULL; ret = ENOMEM;
auth->authorization_data = NULL; goto fail;
auth->cksum = cksum; }
*auth->seq_number = auth_context->local_seqnumber;
} else
auth->seq_number = NULL;
auth->authorization_data = NULL;
auth->cksum = cksum;
/* XXX - Copy more to auth_context? */ /* XXX - Copy more to auth_context? */
if (auth_context) { if (auth_context) {
auth_context->authenticator->ctime = auth->ctime; auth_context->authenticator->ctime = auth->ctime;
auth_context->authenticator->cusec = auth->cusec; auth_context->authenticator->cusec = auth->cusec;
} }
ASN1_MALLOC_ENCODE(Authenticator, buf, buf_size, auth, &len, ret); ASN1_MALLOC_ENCODE(Authenticator, buf, buf_size, auth, &len, ret);
if (ret) if (ret)
goto fail; goto fail;
ret = krb5_crypto_init(context, &cred->session, enctype, &crypto); ret = krb5_crypto_init(context, &cred->session, enctype, &crypto);
if (ret) if (ret)
goto fail; goto fail;
ret = krb5_encrypt (context, ret = krb5_encrypt (context,
crypto, crypto,
usage /* KRB5_KU_AP_REQ_AUTH */, usage /* KRB5_KU_AP_REQ_AUTH */,
buf + buf_size - len, buf + buf_size - len,
len, len,
result); result);
krb5_crypto_destroy(context, crypto); krb5_crypto_destroy(context, crypto);
if (ret) if (ret)
goto fail; goto fail;
free (buf); free (buf);
if (auth_result) if (auth_result)
*auth_result = auth; *auth_result = auth;
else { else {
/* Don't free the `cksum', it's allocated by the caller */ /* Don't free the `cksum', it's allocated by the caller */
auth->cksum = NULL; auth->cksum = NULL;
free_Authenticator (auth);
free (auth);
}
return ret;
fail:
free_Authenticator (auth); free_Authenticator (auth);
free (auth); free (auth);
} free (buf);
return ret; return ret;
fail:
free_Authenticator (auth);
free (auth);
free (buf);
return ret;
} }