2004-07-12 04:26:50 +00:00
/*
Unix SMB / CIFS implementation .
simple GSSAPI wrappers
Copyright ( C ) Andrew Tridgell 2001
Copyright ( C ) Jim McDonough < jmcd @ us . ibm . com > 2002
Copyright ( C ) Luke Howard 2003
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2004-07-12 04:26:50 +00:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2004-07-12 04:26:50 +00:00
*/
# include "includes.h"
2006-01-03 15:40:05 +00:00
# include "libcli/util/asn_1.h"
2005-03-29 08:24:03 +00:00
# include "auth/gensec/gensec.h"
2004-07-12 04:26:50 +00:00
/*
generate a krb5 GSS - API wrapper packet given a ticket
*/
2005-01-31 16:02:58 +00:00
DATA_BLOB gensec_gssapi_gen_krb5_wrap ( TALLOC_CTX * mem_ctx , const DATA_BLOB * ticket , const uint8_t tok_id [ 2 ] )
2004-07-12 04:26:50 +00:00
{
2007-05-21 12:47:18 +00:00
struct asn1_data * data ;
2006-12-20 12:49:11 +00:00
DATA_BLOB ret ;
2004-12-06 15:14:42 +00:00
2007-05-21 06:12:06 +00:00
if ( ! data | | ! ticket - > data ) {
2006-12-20 12:49:11 +00:00
return data_blob ( NULL , 0 ) ;
2004-12-06 15:14:42 +00:00
}
2004-07-12 04:26:50 +00:00
2007-05-21 12:47:18 +00:00
data = asn1_init ( mem_ctx ) ;
if ( data = = NULL ) {
return data_blob ( NULL , 0 ) ;
}
2007-05-21 06:12:06 +00:00
asn1_push_tag ( data , ASN1_APPLICATION ( 0 ) ) ;
asn1_write_OID ( data , GENSEC_OID_KERBEROS5 ) ;
2004-07-12 04:26:50 +00:00
2007-05-21 06:12:06 +00:00
asn1_write ( data , tok_id , 2 ) ;
asn1_write ( data , ticket - > data , ticket - > length ) ;
asn1_pop_tag ( data ) ;
2004-07-12 04:26:50 +00:00
2007-05-21 06:12:06 +00:00
if ( data - > has_error ) {
DEBUG ( 1 , ( " Failed to build krb5 wrapper at offset %d \n " , ( int ) data - > ofs ) ) ;
asn1_free ( data ) ;
2006-12-20 12:49:11 +00:00
return data_blob ( NULL , 0 ) ;
2004-07-12 04:26:50 +00:00
}
2007-05-21 06:12:06 +00:00
ret = data_blob_talloc ( mem_ctx , data - > data , data - > length ) ;
asn1_free ( data ) ;
2004-07-12 04:26:50 +00:00
return ret ;
}
/*
parse a krb5 GSS - API wrapper packet giving a ticket
*/
2005-01-31 16:02:58 +00:00
BOOL gensec_gssapi_parse_krb5_wrap ( TALLOC_CTX * mem_ctx , const DATA_BLOB * blob , DATA_BLOB * ticket , uint8_t tok_id [ 2 ] )
2004-07-12 04:26:50 +00:00
{
BOOL ret ;
2007-05-21 06:12:06 +00:00
struct asn1_data * data = asn1_init ( mem_ctx ) ;
2004-07-12 04:26:50 +00:00
int data_remaining ;
2007-05-21 12:47:18 +00:00
if ( ! data ) {
return False ;
}
2007-05-21 06:12:06 +00:00
asn1_load ( data , * blob ) ;
asn1_start_tag ( data , ASN1_APPLICATION ( 0 ) ) ;
asn1_check_OID ( data , GENSEC_OID_KERBEROS5 ) ;
2004-07-12 04:26:50 +00:00
2007-05-21 06:12:06 +00:00
data_remaining = asn1_tag_remaining ( data ) ;
2004-07-12 04:26:50 +00:00
if ( data_remaining < 3 ) {
2007-05-21 06:12:06 +00:00
data - > has_error = True ;
2004-07-12 04:26:50 +00:00
} else {
2007-05-21 06:12:06 +00:00
asn1_read ( data , tok_id , 2 ) ;
2004-07-12 04:26:50 +00:00
data_remaining - = 2 ;
* ticket = data_blob_talloc ( mem_ctx , NULL , data_remaining ) ;
2007-05-21 06:12:06 +00:00
asn1_read ( data , ticket - > data , ticket - > length ) ;
2004-07-12 04:26:50 +00:00
}
2007-05-21 06:12:06 +00:00
asn1_end_tag ( data ) ;
2004-07-12 04:26:50 +00:00
2007-05-21 06:12:06 +00:00
ret = ! data - > has_error ;
2004-07-12 04:26:50 +00:00
2007-05-21 06:12:06 +00:00
asn1_free ( data ) ;
2004-07-12 04:26:50 +00:00
return ret ;
}
2005-06-22 02:12:26 +00:00
/*
check a GSS - API wrapper packet givin an expected OID
*/
BOOL gensec_gssapi_check_oid ( const DATA_BLOB * blob , const char * oid )
{
BOOL ret ;
2007-05-21 06:12:06 +00:00
struct asn1_data * data = asn1_init ( NULL ) ;
2005-06-22 02:12:26 +00:00
2007-05-21 12:47:18 +00:00
if ( ! data ) return False ;
2007-05-21 06:12:06 +00:00
asn1_load ( data , * blob ) ;
asn1_start_tag ( data , ASN1_APPLICATION ( 0 ) ) ;
asn1_check_OID ( data , oid ) ;
2005-06-22 02:12:26 +00:00
2007-05-21 06:12:06 +00:00
ret = ! data - > has_error ;
2005-06-22 02:12:26 +00:00
2007-05-21 06:12:06 +00:00
asn1_free ( data ) ;
2005-06-22 02:12:26 +00:00
return ret ;
}