Add support for just integrity protecting. Implement and use
`gss_krb5_getsomekey'. Fix bug in checking of pad. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4655 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997 Kungliga Tekniska H<>gskolan
|
* Copyright (c) 1997, 1998 Kungliga Tekniska H<>gskolan
|
||||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -40,6 +40,30 @@
|
|||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
OM_uint32
|
||||||
|
gss_krb5_getsomekey(const gss_ctx_id_t context_handle,
|
||||||
|
des_cblock *key)
|
||||||
|
{
|
||||||
|
/* XXX this is ugly, and probably incorrect... */
|
||||||
|
krb5_keyblock *skey;
|
||||||
|
krb5_auth_con_getlocalsubkey(gssapi_krb5_context,
|
||||||
|
context_handle->auth_context,
|
||||||
|
&skey);
|
||||||
|
if(skey == NULL)
|
||||||
|
krb5_auth_con_getremotesubkey(gssapi_krb5_context,
|
||||||
|
context_handle->auth_context,
|
||||||
|
&skey);
|
||||||
|
if(skey == NULL)
|
||||||
|
krb5_auth_con_getkey(gssapi_krb5_context,
|
||||||
|
context_handle->auth_context,
|
||||||
|
&skey);
|
||||||
|
if(skey == NULL)
|
||||||
|
return GSS_S_FAILURE;
|
||||||
|
memcpy(key, skey->keyvalue.data, sizeof(*key));
|
||||||
|
krb5_free_keyblock(gssapi_krb5_context, skey);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
OM_uint32 gss_unwrap
|
OM_uint32 gss_unwrap
|
||||||
(OM_uint32 * minor_status,
|
(OM_uint32 * minor_status,
|
||||||
const gss_ctx_id_t context_handle,
|
const gss_ctx_id_t context_handle,
|
||||||
@@ -60,6 +84,7 @@ OM_uint32 gss_unwrap
|
|||||||
int32_t seq_number;
|
int32_t seq_number;
|
||||||
size_t padlength;
|
size_t padlength;
|
||||||
OM_uint32 ret;
|
OM_uint32 ret;
|
||||||
|
int cstate;
|
||||||
|
|
||||||
p = input_message_buffer->value;
|
p = input_message_buffer->value;
|
||||||
ret = gssapi_krb5_verify_header (&p,
|
ret = gssapi_krb5_verify_header (&p,
|
||||||
@@ -71,9 +96,15 @@ OM_uint32 gss_unwrap
|
|||||||
if (memcmp (p, "\x00\x00", 2) != 0)
|
if (memcmp (p, "\x00\x00", 2) != 0)
|
||||||
return GSS_S_BAD_SIG;
|
return GSS_S_BAD_SIG;
|
||||||
p += 2;
|
p += 2;
|
||||||
if (memcmp (p, "\x00\x00", 2) != 0)
|
if (memcmp (p, "\x00\x00", 2) == 0) {
|
||||||
return GSS_S_BAD_MIC;
|
cstate = 1;
|
||||||
|
} else if (memcmp (p, "\xFF\xFF", 2) == 0) {
|
||||||
|
cstate = 0;
|
||||||
|
} else
|
||||||
|
return GSS_S_BAD_MIC;
|
||||||
p += 2;
|
p += 2;
|
||||||
|
if(conf_state != NULL)
|
||||||
|
*conf_state = cstate;
|
||||||
if (memcmp (p, "\xff\xff", 2) != 0)
|
if (memcmp (p, "\xff\xff", 2) != 0)
|
||||||
return GSS_S_DEFECTIVE_TOKEN;
|
return GSS_S_DEFECTIVE_TOKEN;
|
||||||
p += 2;
|
p += 2;
|
||||||
@@ -81,34 +112,29 @@ OM_uint32 gss_unwrap
|
|||||||
|
|
||||||
len = p - (u_char *)input_message_buffer->value;
|
len = p - (u_char *)input_message_buffer->value;
|
||||||
|
|
||||||
/* decrypt data */
|
if(cstate) {
|
||||||
|
/* decrypt data */
|
||||||
memset (&zero, 0, sizeof(zero));
|
gss_krb5_getsomekey(context_handle, &key);
|
||||||
#if 0
|
for (i = 0; i < sizeof(key); ++i)
|
||||||
memcpy (&key, context_handle->auth_context->key.keyvalue.data,
|
key[i] ^= 0xf0;
|
||||||
sizeof(key));
|
des_set_key (&key, schedule);
|
||||||
#endif
|
memset (&zero, 0, sizeof(zero));
|
||||||
memcpy (&key, context_handle->auth_context->remote_subkey->keyvalue.data,
|
des_cbc_encrypt ((des_cblock *)p,
|
||||||
sizeof(key));
|
(des_cblock *)p,
|
||||||
for (i = 0; i < sizeof(key); ++i)
|
input_message_buffer->length - len,
|
||||||
key[i] ^= 0xf0;
|
schedule,
|
||||||
des_set_key (&key, schedule);
|
&zero,
|
||||||
des_cbc_encrypt ((des_cblock *)p,
|
DES_DECRYPT);
|
||||||
(des_cblock *)p,
|
|
||||||
input_message_buffer->length - len,
|
|
||||||
schedule,
|
|
||||||
&zero,
|
|
||||||
DES_DECRYPT);
|
|
||||||
|
|
||||||
memset (key, 0, sizeof(key));
|
|
||||||
memset (schedule, 0, sizeof(schedule));
|
|
||||||
|
|
||||||
|
memset (key, 0, sizeof(key));
|
||||||
|
memset (schedule, 0, sizeof(schedule));
|
||||||
|
}
|
||||||
/* check pad */
|
/* check pad */
|
||||||
|
|
||||||
pad = (u_char *)input_message_buffer->value + input_message_buffer->length - 1;
|
pad = (u_char *)input_message_buffer->value + input_message_buffer->length - 1;
|
||||||
padlength = *pad;
|
padlength = *pad;
|
||||||
|
|
||||||
for (i = padlength; i >= 0 && *pad == padlength; i--, pad--)
|
for (i = padlength; i > 0 && *pad == padlength; i--, pad--)
|
||||||
;
|
;
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
return GSS_S_BAD_MIC;
|
return GSS_S_BAD_MIC;
|
||||||
@@ -119,12 +145,7 @@ OM_uint32 gss_unwrap
|
|||||||
md5_finito (&md5, hash);
|
md5_finito (&md5, hash);
|
||||||
|
|
||||||
memset (&zero, 0, sizeof(zero));
|
memset (&zero, 0, sizeof(zero));
|
||||||
#if 0
|
gss_krb5_getsomekey(context_handle, &key);
|
||||||
memcpy (&key, context_handle->auth_context->key.keyvalue.data,
|
|
||||||
sizeof(key));
|
|
||||||
#endif
|
|
||||||
memcpy (&key, context_handle->auth_context->remote_subkey->keyvalue.data,
|
|
||||||
sizeof(key));
|
|
||||||
des_set_key (&key, schedule);
|
des_set_key (&key, schedule);
|
||||||
des_cbc_cksum ((des_cblock *)hash,
|
des_cbc_cksum ((des_cblock *)hash,
|
||||||
(des_cblock *)hash, sizeof(hash), schedule, &zero);
|
(des_cblock *)hash, sizeof(hash), schedule, &zero);
|
||||||
@@ -165,8 +186,8 @@ OM_uint32 gss_unwrap
|
|||||||
output_message_buffer->length = input_message_buffer->length
|
output_message_buffer->length = input_message_buffer->length
|
||||||
- len - 8 - padlength;
|
- len - 8 - padlength;
|
||||||
output_message_buffer->value = malloc(output_message_buffer->length);
|
output_message_buffer->value = malloc(output_message_buffer->length);
|
||||||
if(output_message_buffer->value == NULL)
|
if(output_message_buffer->length != 0 && output_message_buffer->value == NULL)
|
||||||
return GSS_S_FAILURE;
|
return GSS_S_FAILURE;
|
||||||
memcpy (output_message_buffer->value,
|
memcpy (output_message_buffer->value,
|
||||||
p + 24,
|
p + 24,
|
||||||
output_message_buffer->length);
|
output_message_buffer->length);
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997 Kungliga Tekniska H<>gskolan
|
* Copyright (c) 1997, 1998 Kungliga Tekniska H<>gskolan
|
||||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -40,6 +40,30 @@
|
|||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
OM_uint32
|
||||||
|
gss_krb5_getsomekey(const gss_ctx_id_t context_handle,
|
||||||
|
des_cblock *key)
|
||||||
|
{
|
||||||
|
/* XXX this is ugly, and probably incorrect... */
|
||||||
|
krb5_keyblock *skey;
|
||||||
|
krb5_auth_con_getlocalsubkey(gssapi_krb5_context,
|
||||||
|
context_handle->auth_context,
|
||||||
|
&skey);
|
||||||
|
if(skey == NULL)
|
||||||
|
krb5_auth_con_getremotesubkey(gssapi_krb5_context,
|
||||||
|
context_handle->auth_context,
|
||||||
|
&skey);
|
||||||
|
if(skey == NULL)
|
||||||
|
krb5_auth_con_getkey(gssapi_krb5_context,
|
||||||
|
context_handle->auth_context,
|
||||||
|
&skey);
|
||||||
|
if(skey == NULL)
|
||||||
|
return GSS_S_FAILURE;
|
||||||
|
memcpy(key, skey->keyvalue.data, sizeof(*key));
|
||||||
|
krb5_free_keyblock(gssapi_krb5_context, skey);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
OM_uint32 gss_unwrap
|
OM_uint32 gss_unwrap
|
||||||
(OM_uint32 * minor_status,
|
(OM_uint32 * minor_status,
|
||||||
const gss_ctx_id_t context_handle,
|
const gss_ctx_id_t context_handle,
|
||||||
@@ -60,6 +84,7 @@ OM_uint32 gss_unwrap
|
|||||||
int32_t seq_number;
|
int32_t seq_number;
|
||||||
size_t padlength;
|
size_t padlength;
|
||||||
OM_uint32 ret;
|
OM_uint32 ret;
|
||||||
|
int cstate;
|
||||||
|
|
||||||
p = input_message_buffer->value;
|
p = input_message_buffer->value;
|
||||||
ret = gssapi_krb5_verify_header (&p,
|
ret = gssapi_krb5_verify_header (&p,
|
||||||
@@ -71,9 +96,15 @@ OM_uint32 gss_unwrap
|
|||||||
if (memcmp (p, "\x00\x00", 2) != 0)
|
if (memcmp (p, "\x00\x00", 2) != 0)
|
||||||
return GSS_S_BAD_SIG;
|
return GSS_S_BAD_SIG;
|
||||||
p += 2;
|
p += 2;
|
||||||
if (memcmp (p, "\x00\x00", 2) != 0)
|
if (memcmp (p, "\x00\x00", 2) == 0) {
|
||||||
return GSS_S_BAD_MIC;
|
cstate = 1;
|
||||||
|
} else if (memcmp (p, "\xFF\xFF", 2) == 0) {
|
||||||
|
cstate = 0;
|
||||||
|
} else
|
||||||
|
return GSS_S_BAD_MIC;
|
||||||
p += 2;
|
p += 2;
|
||||||
|
if(conf_state != NULL)
|
||||||
|
*conf_state = cstate;
|
||||||
if (memcmp (p, "\xff\xff", 2) != 0)
|
if (memcmp (p, "\xff\xff", 2) != 0)
|
||||||
return GSS_S_DEFECTIVE_TOKEN;
|
return GSS_S_DEFECTIVE_TOKEN;
|
||||||
p += 2;
|
p += 2;
|
||||||
@@ -81,34 +112,29 @@ OM_uint32 gss_unwrap
|
|||||||
|
|
||||||
len = p - (u_char *)input_message_buffer->value;
|
len = p - (u_char *)input_message_buffer->value;
|
||||||
|
|
||||||
/* decrypt data */
|
if(cstate) {
|
||||||
|
/* decrypt data */
|
||||||
memset (&zero, 0, sizeof(zero));
|
gss_krb5_getsomekey(context_handle, &key);
|
||||||
#if 0
|
for (i = 0; i < sizeof(key); ++i)
|
||||||
memcpy (&key, context_handle->auth_context->key.keyvalue.data,
|
key[i] ^= 0xf0;
|
||||||
sizeof(key));
|
des_set_key (&key, schedule);
|
||||||
#endif
|
memset (&zero, 0, sizeof(zero));
|
||||||
memcpy (&key, context_handle->auth_context->remote_subkey->keyvalue.data,
|
des_cbc_encrypt ((des_cblock *)p,
|
||||||
sizeof(key));
|
(des_cblock *)p,
|
||||||
for (i = 0; i < sizeof(key); ++i)
|
input_message_buffer->length - len,
|
||||||
key[i] ^= 0xf0;
|
schedule,
|
||||||
des_set_key (&key, schedule);
|
&zero,
|
||||||
des_cbc_encrypt ((des_cblock *)p,
|
DES_DECRYPT);
|
||||||
(des_cblock *)p,
|
|
||||||
input_message_buffer->length - len,
|
|
||||||
schedule,
|
|
||||||
&zero,
|
|
||||||
DES_DECRYPT);
|
|
||||||
|
|
||||||
memset (key, 0, sizeof(key));
|
|
||||||
memset (schedule, 0, sizeof(schedule));
|
|
||||||
|
|
||||||
|
memset (key, 0, sizeof(key));
|
||||||
|
memset (schedule, 0, sizeof(schedule));
|
||||||
|
}
|
||||||
/* check pad */
|
/* check pad */
|
||||||
|
|
||||||
pad = (u_char *)input_message_buffer->value + input_message_buffer->length - 1;
|
pad = (u_char *)input_message_buffer->value + input_message_buffer->length - 1;
|
||||||
padlength = *pad;
|
padlength = *pad;
|
||||||
|
|
||||||
for (i = padlength; i >= 0 && *pad == padlength; i--, pad--)
|
for (i = padlength; i > 0 && *pad == padlength; i--, pad--)
|
||||||
;
|
;
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
return GSS_S_BAD_MIC;
|
return GSS_S_BAD_MIC;
|
||||||
@@ -119,12 +145,7 @@ OM_uint32 gss_unwrap
|
|||||||
md5_finito (&md5, hash);
|
md5_finito (&md5, hash);
|
||||||
|
|
||||||
memset (&zero, 0, sizeof(zero));
|
memset (&zero, 0, sizeof(zero));
|
||||||
#if 0
|
gss_krb5_getsomekey(context_handle, &key);
|
||||||
memcpy (&key, context_handle->auth_context->key.keyvalue.data,
|
|
||||||
sizeof(key));
|
|
||||||
#endif
|
|
||||||
memcpy (&key, context_handle->auth_context->remote_subkey->keyvalue.data,
|
|
||||||
sizeof(key));
|
|
||||||
des_set_key (&key, schedule);
|
des_set_key (&key, schedule);
|
||||||
des_cbc_cksum ((des_cblock *)hash,
|
des_cbc_cksum ((des_cblock *)hash,
|
||||||
(des_cblock *)hash, sizeof(hash), schedule, &zero);
|
(des_cblock *)hash, sizeof(hash), schedule, &zero);
|
||||||
@@ -165,8 +186,8 @@ OM_uint32 gss_unwrap
|
|||||||
output_message_buffer->length = input_message_buffer->length
|
output_message_buffer->length = input_message_buffer->length
|
||||||
- len - 8 - padlength;
|
- len - 8 - padlength;
|
||||||
output_message_buffer->value = malloc(output_message_buffer->length);
|
output_message_buffer->value = malloc(output_message_buffer->length);
|
||||||
if(output_message_buffer->value == NULL)
|
if(output_message_buffer->length != 0 && output_message_buffer->value == NULL)
|
||||||
return GSS_S_FAILURE;
|
return GSS_S_FAILURE;
|
||||||
memcpy (output_message_buffer->value,
|
memcpy (output_message_buffer->value,
|
||||||
p + 24,
|
p + 24,
|
||||||
output_message_buffer->length);
|
output_message_buffer->length);
|
||||||
|
Reference in New Issue
Block a user