00001 /* 00002 * Copyright (c) 2001 EU DataGrid. 00003 * For license conditions see http://www.eu-datagrid.org/license.html 00004 * 00005 * Copyright (c) 2001, 2002 by 00006 * Martijn Steenbakkers <martijn@nikhef.nl>, 00007 * David Groep <davidg@nikhef.nl>, 00008 * NIKHEF Amsterdam, the Netherlands 00009 */ 00010 00021 /***************************************************************************** 00022 Include header files 00023 ******************************************************************************/ 00024 #include <stdlib.h> 00025 #include <stdio.h> 00026 #include <errno.h> 00027 #include "lcas_defines.h" 00028 #include "lcas_types.h" 00029 #include "lcas_log.h" 00030 00031 /* For X509 and STACK_OF(X509) structs (output) */ 00032 #include <openssl/x509.h> 00033 00034 /* For the gss_cred_id_t struct (input) */ 00035 #include <gssapi.h> 00036 00037 /* Internal globus header: 00038 * defines gss_cred_id_desc (= internal structure of gss_cred_id_t) 00039 */ 00040 #include "gssapi_openssl.h" 00041 00042 00043 /* Defines globus_gsi_cred_handle_t (GSI (globus) credential, 00044 * part of gss_cred_id_desc) 00045 * and interface functions to globus_gsi_cred_handle_t: 00046 * globus_gsi_cred_get_cert() and globus_gsi_cred_get_cert_chain() 00047 */ 00048 #include "globus_gsi_credential.h" 00049 00050 /* Internal globus header: 00051 * describes internal structure of globus_gsi_cred_get_cert 00052 * not needed if interface functions to globus_gsi_cred_handle_t are used 00053 */ 00054 //#include "globus_i_gsi_credential.h" 00055 00056 /****************************************************************************** 00057 Define constants 00058 ******************************************************************************/ 00059 00060 /****************************************************************************** 00061 Module specific prototypes 00062 ******************************************************************************/ 00063 00064 00065 /****************************************************************************** 00066 Function: lcas_cred_to_x509() 00067 Description: Return the pointer to X509 structure from gss credential 00068 Parameters: 00069 cred: globus credential 00070 Returns: pointer to X509 struct or NULL 00071 ******************************************************************************/ 00085 X509 * lcas_cred_to_x509( 00086 gss_cred_id_t cred 00087 ) 00088 { 00089 /* Internally a gss_cred_id_t type is a pointer to a gss_cred_id_desc */ 00090 gss_cred_id_desc * cred_desc = NULL; 00091 globus_gsi_cred_handle_t gsi_cred_handle; 00092 X509 * px509=NULL; 00093 00094 /* cast to gss_cred_id_desc */ 00095 if (cred != GSS_C_NO_CREDENTIAL) 00096 { 00097 cred_desc = (gss_cred_id_desc *) cred; 00098 if (globus_module_activate(GLOBUS_GSI_CREDENTIAL_MODULE) ==GLOBUS_SUCCESS) 00099 { 00100 gsi_cred_handle = cred_desc->cred_handle; 00101 if (globus_gsi_cred_get_cert(gsi_cred_handle, &px509) == GLOBUS_SUCCESS) 00102 { 00103 globus_module_deactivate(GLOBUS_GSI_CREDENTIAL_MODULE); 00104 return px509; 00105 } 00106 else 00107 { 00108 globus_module_deactivate(GLOBUS_GSI_CREDENTIAL_MODULE); 00109 return NULL; 00110 } 00111 } 00112 else 00113 { 00114 globus_module_deactivate(GLOBUS_GSI_CREDENTIAL_MODULE); 00115 return NULL; 00116 } 00117 } 00118 else 00119 { 00120 return NULL; 00121 } 00122 } 00123 00124 00125 /****************************************************************************** 00126 Function: lcas_cred_to_x509_chain() 00127 Description: Return the pointer to X509 chain from gss credential 00128 Parameters: 00129 cred: globus credential 00130 Returns: pointer to X509 chain or NULL 00131 ******************************************************************************/ 00145 STACK_OF(X509) * lcas_cred_to_x509_chain( 00146 gss_cred_id_t cred 00147 ) 00148 { 00149 /* Internally a gss_cred_id_t type is a pointer to a gss_cred_id_desc */ 00150 gss_cred_id_desc * cred_desc = NULL; 00151 globus_gsi_cred_handle_t gsi_cred_handle; 00152 STACK_OF(X509) * px509_chain=NULL; 00153 00154 /* cast to gss_cred_id_desc */ 00155 if (cred != GSS_C_NO_CREDENTIAL) 00156 { 00157 cred_desc = (gss_cred_id_desc *) cred; 00158 if (globus_module_activate(GLOBUS_GSI_CREDENTIAL_MODULE) ==GLOBUS_SUCCESS) 00159 { 00160 gsi_cred_handle = cred_desc->cred_handle; 00161 if (globus_gsi_cred_get_cert_chain(gsi_cred_handle, &px509_chain) == GLOBUS_SUCCESS) 00162 { 00163 globus_module_deactivate(GLOBUS_GSI_CREDENTIAL_MODULE); 00164 return px509_chain; 00165 } 00166 else 00167 { 00168 globus_module_deactivate(GLOBUS_GSI_CREDENTIAL_MODULE); 00169 return NULL; 00170 } 00171 } 00172 else 00173 { 00174 globus_module_deactivate(GLOBUS_GSI_CREDENTIAL_MODULE); 00175 return NULL; 00176 } 00177 } 00178 else 00179 { 00180 return NULL; 00181 } 00182 } 00183 00184 /****************************************************************************** 00185 CVS Information: 00186 $Source: /cvs/fabric_mgt/gridification/lcas/modules/voms/lcas_voms_utils.c,v $ 00187 $Date: 2003/08/08 16:20:25 $ 00188 $Revision: 1.1 $ 00189 $Author: martijn $ 00190 ******************************************************************************/