Add lucid interface.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18412 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -202,3 +202,187 @@ gsskrb5_register_acceptor_identity(const char *identity)
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
set_key(krb5_keyblock *keyblock, gss_krb5_lucid_key_t *key)
|
||||
{
|
||||
key->type = keyblock->keytype;
|
||||
key->length = keyblock->keyvalue.length;
|
||||
key->data = malloc(key->length);
|
||||
if (key->data == NULL && key->length != 0)
|
||||
return ENOMEM;
|
||||
memcpy(key->data, keyblock->keyvalue.data, key->length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
free_key(gss_krb5_lucid_key_t *key)
|
||||
{
|
||||
memset(key->data, 0, key->length);
|
||||
free(key->data);
|
||||
memset(key, 0, sizeof(*key));
|
||||
}
|
||||
|
||||
|
||||
OM_uint32
|
||||
gss_krb5_export_lucid_sec_context(OM_uint32 *minor_status,
|
||||
gss_ctx_id_t *context_handle,
|
||||
OM_uint32 version,
|
||||
void **rctx)
|
||||
{
|
||||
krb5_context context = NULL;
|
||||
krb5_error_code ret;
|
||||
gss_buffer_set_t data_set = GSS_C_NO_BUFFER_SET;
|
||||
OM_uint32 major_status;
|
||||
gss_krb5_lucid_context_v1_t *ctx = NULL;
|
||||
krb5_storage *sp = NULL;
|
||||
uint32_t num;
|
||||
|
||||
if (context_handle == NULL || *context_handle == GSS_C_NO_CONTEXT) {
|
||||
ret = EINVAL;
|
||||
return GSS_S_FAILURE;
|
||||
}
|
||||
|
||||
major_status =
|
||||
gss_inquire_sec_context_by_oid (minor_status,
|
||||
*context_handle,
|
||||
GSS_KRB5_EXPORT_LUCID_CONTEXT_X,
|
||||
&data_set);
|
||||
if (major_status)
|
||||
return major_status;
|
||||
|
||||
if (data_set == GSS_C_NO_BUFFER_SET || data_set->count != 1) {
|
||||
gss_release_buffer_set(minor_status, &data_set);
|
||||
*minor_status = EINVAL;
|
||||
return GSS_S_FAILURE;
|
||||
}
|
||||
|
||||
ret = krb5_init_context(&context);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
ctx = calloc(1, sizeof(*ctx));
|
||||
if (ctx) {
|
||||
ret = ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
sp = krb5_storage_from_mem(data_set->elements[0].value,
|
||||
data_set->elements[0].length);
|
||||
if (sp == NULL) {
|
||||
ret = ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = krb5_ret_uint32(sp, &num);
|
||||
if (ret) goto out;
|
||||
if (num != 1) {
|
||||
ret = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
ctx->version = 1;
|
||||
/* initiator */
|
||||
ret = krb5_ret_uint32(sp, &ctx->initiate);
|
||||
if (ret) goto out;
|
||||
/* endtime */
|
||||
ret = krb5_ret_uint32(sp, &ctx->endtime);
|
||||
if (ret) goto out;
|
||||
/* send_seq */
|
||||
ret = krb5_ret_uint32(sp, &num);
|
||||
if (ret) goto out;
|
||||
ctx->send_seq = ((uint64_t)num) << 32;
|
||||
ret = krb5_ret_uint32(sp, &num);
|
||||
if (ret) goto out;
|
||||
ctx->send_seq |= num;
|
||||
/* recv_seq */
|
||||
ret = krb5_ret_uint32(sp, &num);
|
||||
if (ret) goto out;
|
||||
ctx->recv_seq = ((uint64_t)num) << 32;
|
||||
ret = krb5_ret_uint32(sp, &num);
|
||||
if (ret) goto out;
|
||||
ctx->recv_seq |= num;
|
||||
/* protocol */
|
||||
ret = krb5_ret_uint32(sp, &ctx->protocol);
|
||||
if (ret) goto out;
|
||||
if (ctx->protocol == 0) {
|
||||
krb5_keyblock key;
|
||||
|
||||
/* sign_alg */
|
||||
ret = krb5_ret_uint32(sp, &ctx->rfc1964_kd.sign_alg);
|
||||
if (ret) goto out;
|
||||
/* seal_alg */
|
||||
ret = krb5_ret_uint32(sp, &ctx->rfc1964_kd.seal_alg);
|
||||
if (ret) goto out;
|
||||
/* ctx_key */
|
||||
ret = krb5_ret_keyblock(sp, &key);
|
||||
if (ret) goto out;
|
||||
ret = set_key(&key, &ctx->rfc1964_kd.ctx_key);
|
||||
krb5_free_keyblock_contents(context, &key);
|
||||
if (ret) goto out;
|
||||
} else if (ctx->protocol == 1) {
|
||||
krb5_keyblock key;
|
||||
|
||||
/* acceptor_subkey */
|
||||
ret = krb5_ret_uint32(sp, &ctx->cfx_kd.have_acceptor_subkey);
|
||||
if (ret) goto out;
|
||||
/* ctx_key */
|
||||
ret = krb5_ret_keyblock(sp, &key);
|
||||
if (ret) goto out;
|
||||
ret = set_key(&key, &ctx->cfx_kd.ctx_key);
|
||||
krb5_free_keyblock_contents(context, &key);
|
||||
if (ret) goto out;
|
||||
/* acceptor_subkey */
|
||||
if (ctx->cfx_kd.have_acceptor_subkey) {
|
||||
ret = krb5_ret_keyblock(sp, &key);
|
||||
if (ret) goto out;
|
||||
ret = set_key(&key, &ctx->cfx_kd.acceptor_subkey);
|
||||
krb5_free_keyblock_contents(context, &key);
|
||||
if (ret) goto out;
|
||||
}
|
||||
} else {
|
||||
ret = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*rctx = ctx;
|
||||
|
||||
out:
|
||||
gss_release_buffer_set(minor_status, &data_set);
|
||||
if (sp)
|
||||
krb5_storage_free(sp);
|
||||
if (context)
|
||||
krb5_free_context(context);
|
||||
|
||||
if (ret) {
|
||||
if (ctx)
|
||||
gss_krb5_free_lucid_sec_context(NULL, ctx);
|
||||
|
||||
*minor_status = ret;
|
||||
return GSS_S_FAILURE;
|
||||
}
|
||||
*minor_status = 0;
|
||||
return GSS_S_COMPLETE;
|
||||
}
|
||||
|
||||
OM_uint32
|
||||
gss_krb5_free_lucid_sec_context(OM_uint32 *minor_status, void *c)
|
||||
{
|
||||
gss_krb5_lucid_context_v1_t *ctx = c;
|
||||
|
||||
if (ctx->version != 1) {
|
||||
*minor_status = 0;
|
||||
return GSS_S_FAILURE;
|
||||
}
|
||||
|
||||
if (ctx->protocol == 0) {
|
||||
free_key(&ctx->rfc1964_kd.ctx_key);
|
||||
} else if (ctx->protocol == 1) {
|
||||
free_key(&ctx->cfx_kd.ctx_key);
|
||||
if (ctx->cfx_kd.have_acceptor_subkey)
|
||||
free_key(&ctx->cfx_kd.acceptor_subkey);
|
||||
}
|
||||
free(ctx);
|
||||
if (minor_status)
|
||||
*minor_status = 0;
|
||||
return GSS_S_COMPLETE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user