// Gsoap_t.cxx #include #include #include "dataset_util/Text.h" #include "dataset_util/FileStatus.h" #include "dataset_credential/Gsoap.h" #include "gsoap_gsi/gsi.h" #define WITH_GSI using std::string; using std::cout; using std::cerr; using std::endl; using dset::GssCredential; using dset::Gsoap; void msg(string txt) { cout << "*** "; cout << txt; cout << " ***" << endl; } #ifdef WITH_GSI int client_authorization(struct soap* psoap, char* dn) { struct gsi_plugin_data* pgsiplug = (struct gsi_plugin_data *) soap_lookup_plugin(psoap, GSI_PLUGIN_ID); //string client_identity = pgsiplug->client_identity; string service_identity = pgsiplug->server_identity; //cout << "GSI Client ID: " << client_identity << endl; cout << "GSI Service ID: " << service_identity << endl; return 0; } #endif int Gsoap_t() { #ifdef WITH_GSI msg("Initialize GSI"); // Create auth file. string globus_version = "3"; string gcom = "rm -f authorized_dn"; gcom += "; "; if ( globus_version == "2" ) { gcom += "grid-proxy-info -subject"; gcom += " | sed 's#/CN=proxy##g'"; } else { gcom += "grid-proxy-info -identity"; } gcom += " > authorized_dn"; system(gcom.c_str()); Text aufile("authorized_dn"); string dn = aufile.line(0); cout << "DN: " << dn << endl; msg("Create GSI soap struct"); struct soap soap; soap_init(&soap); //soap_set_namespaces(&soap, dial_ws_base_namespaces); // Register the GSI plugin. if ( soap_register_plugin(&soap, globus_gsi) ) { cerr << "Unable to register GSI plugin" << endl; assert(false); } // Set authorization callback. struct gsi_plugin_data* pgsiplug = (struct gsi_plugin_data*) soap_lookup_plugin(&soap, GSI_PLUGIN_ID); assert( pgsiplug != 0 ); pgsiplug->gsi_authorization_callback = client_authorization; // Acquire credential. if ( gsi_acquire_credential(&soap) < 0 ) { cerr << "Unable to acquire credential" << endl; assert(false); } // Setup GSI channel. //gsi_set_delegation(&soap, GLOBUS_TRUE, (char*) dn.c_str()); gsi_set_replay(&soap, GLOBUS_TRUE); gsi_set_sequence(&soap, GLOBUS_TRUE); gsi_set_confidentiality(&soap, GLOBUS_TRUE); gsi_set_integrity(&soap, GLOBUS_TRUE); // Copy credential to delegated credential for test purposes. msg("Creating dummy delegated credential"); assert( pgsiplug->proxy_filename == 0 ); assert( pgsiplug->credential != 0 ); OM_uint32 miner; gss_buffer_desc cred_buffer; assert( gss_export_cred(&miner, pgsiplug->credential, NULL, 0, &cred_buffer) == GSS_S_COMPLETE); assert( gss_import_cred(&miner, &pgsiplug->delegated_credential, NULL, 0, &cred_buffer, 0, 0) == GSS_S_COMPLETE); assert( gss_release_buffer(&miner, &cred_buffer) == GSS_S_COMPLETE); assert( pgsiplug->delegated_credential != 0 ); gss_cred_id_t gssmain = pgsiplug->credential; gss_cred_id_t gssdele = pgsiplug->delegated_credential; msg("Create soap wrapper"); Gsoap wsoap(soap); cout << wsoap << endl; assert( wsoap.is_valid() ); assert( wsoap.credential().is_valid() ); assert( wsoap.credential().gss_handle() == gssmain ); assert( wsoap.delegated_credential().is_valid() ); assert( wsoap.delegated_credential().gss_handle() == gssdele ); msg("Unset credential"); assert( wsoap.release_credential() == 0 ); cout << wsoap << endl; assert( ! wsoap.credential().is_valid() ); assert( wsoap.credential().gss_handle() == 0 ); msg("Reset credential"); GssCredential newcred; assert( newcred.is_valid() ); assert( wsoap.set_credential(newcred) == 0 ); cout << wsoap << endl; assert( wsoap.credential().is_valid() ); assert( wsoap.credential().gss_handle() != 0 ); assert( wsoap.credential().gss_handle() != newcred.gss_handle() ); #endif return 0; } #ifdef CTEST_MAIN int main() { return Gsoap_t(); } #endif