示例#1
0
void grisu_auth_header(void)
{
/* CURRENT - fixing crappy windows soap failure */
/* WINDOWS seems to require a reinit EVERY time - or it forgets stuff and soap calls fail */
/* TODO - test if this bollocks up linux or not ... */
soap_init1(&soap, SOAP_ENC_MTOM);

if (soap_ssl_client_context(&soap, SOAP_SSL_SKIP_HOST_CHECK, NULL, NULL, NULL, grisu_cert_path, NULL))
  printf("grisu_auth_header(): SSL init failed.\n");

/* allocate if necessary */
if (!grisu_soap_header)
  grisu_soap_header = g_malloc(sizeof(struct SOAP_ENV__Header));

/* fill out the header with current values */
grisu_soap_header->username = grisu_username;
grisu_soap_header->password = grisu_password;
grisu_soap_header->myproxyserver = grisu_server;
grisu_soap_header->myproxyport = grisu_port;

#if DEBUG_GRISU_AUTH_HEADER
printf("SOAP Header:      ptr = %p\n", grisu_soap_header);
printf("SOAP Header: username = %s\n", grisu_soap_header->username);
printf("SOAP Header: password = %s\n", grisu_soap_header->password);
printf("SOAP Header:   server = %s\n", grisu_soap_header->myproxyserver);
printf("SOAP Header:     port = %s\n", grisu_soap_header->myproxyport);
#endif

/* use the header if auth is turned on */
if (grisu_auth)
  soap.header = grisu_soap_header;
else
  soap.header = NULL;
}
示例#2
0
int
bes_security(struct bes_context *context, 
             char *x509cert, 
             char *x509pass, 
             char *capath, 
             char *user, 
             char *pass)
{
    struct soap *soap;
    
    if (context == NULL) {
        return BESE_BAD_ARG;
    }
    
    soap = context->soap;
    
    if (soap_ssl_client_context(soap, SOAP_SSL_DEFAULT|SOAP_SSL_SKIP_HOST_CHECK,
                                x509cert, x509pass, NULL, capath, NULL)) {
        setErrorString(context, context->soap, BESE_SOAP_ERR);
        return BESE_SOAP_ERR;
    }
    
    if (user) {
        if (soap_wsse_add_UsernameTokenText(soap, NULL, user, pass)) {
            setErrorString(context, context->soap, BESE_SOAP_ERR);
            return BESE_SOAP_ERR;
        }
        if (soap_wsse_add_Timestamp(soap, NULL, 60)) {
            setErrorString(context, context->soap, BESE_SOAP_ERR);
            return BESE_SOAP_ERR;
        }
    }
    
    if (x509cert) {
        if (context->x509cert) free(context->x509cert);
        context->x509cert = strdup(x509cert);
    }
    
    if (x509pass) {
        if (context->x509pass) free(context->x509pass);
        context->x509pass = strdup(x509pass);
    }
    
    if (capath) {
        if (context->capath) free(context->capath);
        context->capath = strdup(capath);
    }

    if (user) {
        if (context->user) free(context->user);
        context->user = strdup(user);
    }
    
    if (pass) {
        if (context->pass) free(context->pass);
        context->pass = strdup(pass);
    }
    
    return BESE_OK;
}
示例#3
0
int main()
{ struct soap soap;
  double a, b, result;
  /* Init SSL */
  soap_ssl_init();
  if (CRYPTO_thread_setup())
  { fprintf(stderr, "Cannot setup thread mutex for OpenSSL\n");
    exit(1);
  }
  a = 10.0;
  b = 20.0;
  /* Init gSOAP context */
  soap_init(&soap);
  /* The supplied server certificate "server.pem" assumes that the server is
    running on 'localhost', so clients can only connect from the same host when
    verifying the server's certificate. Use SOAP_SSL_NO_AUTHENTICATION to omit
    the authentication of the server and use encryption directly from any site.
    To verify the certificates of third-party services, they must provide a
    certificate issued by Verisign or another trusted CA. At the client-side,
    the capath parameter should point to a directory that contains these
    trusted (root) certificates or the cafile parameter should refer to one
    file will all certificates. To help you out, the supplied "cacerts.pem"
    file contains the certificates issued by various CAs. You should use this
    file for the cafile parameter instead of "cacert.pem" to connect to trusted
    servers.  Note that the client may fail to connect if the server's
    credentials have problems (e.g. expired). Use SOAP_SSL_NO_AUTHENTICATION
    and set cacert to NULL to encrypt messages if you don't care about the
    trustworthyness of the server.  Note: setting capath may not work on
    Windows.
  */
  if (soap_ssl_client_context(&soap,
    /* SOAP_SSL_NO_AUTHENTICATION, */ /* for encryption w/o authentication */
    /* SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK, */	/* if we don't want the host name checks since these will change from machine to machine */
    SOAP_SSL_DEFAULT,	/* use SOAP_SSL_DEFAULT in production code */
    NULL, 		/* keyfile (cert+key): required only when client must authenticate to server (see SSL docs to create this file) */
    NULL, 		/* password to read the keyfile */
    "cacert.pem",	/* optional cacert file to store trusted certificates, use cacerts.pem for all public certificates issued by common CAs */
    NULL,		/* optional capath to directory with trusted certificates */
    NULL		/* if randfile!=NULL: use a file with random data to seed randomness */ 
  ))
  { soap_print_fault(&soap, stderr);
    exit(1);
  }
  soap.connect_timeout = 60;	/* try to connect for 1 minute */
  soap.send_timeout = soap.recv_timeout = 30;	/* if I/O stalls, then timeout after 30 seconds */
  if (soap_call_ns__add(&soap, server, "", a, b, &result) == SOAP_OK)
    fprintf(stdout, "Result: %f + %f = %f\n", a, b, result);
  else
    soap_print_fault(&soap, stderr);
  soap_destroy(&soap); /* C++ */
  soap_end(&soap);
  soap_done(&soap);
  CRYPTO_thread_cleanup();
  return 0;
}
示例#4
0
/**
 * Defines the SSL authentication scheme.
 * @param icat :: ICATPortBindingProxy object.
 */
void ICat4Catalog::setSSLContext(ICATPortBindingProxy &icat) {
  if (soap_ssl_client_context(
          &icat, SOAP_SSL_CLIENT, /* use SOAP_SSL_DEFAULT in production code */
          nullptr, /* keyfile: required only when client must authenticate to
        server (see SSL docs on how to obtain this file) */
          nullptr, /* password to read the keyfile */
          nullptr, /* optional cacert file to store trusted certificates */
          nullptr, /* optional capath to directory with trusted certificates */
          nullptr  /* if randfile!=NULL: use a file with random data to seed
                   randomness */
          )) {
    throwErrorMessage(icat);
  }
}
示例#5
0
void send(const std::string& message)
{
	struct soap account_info_soap;
	

	soap_init(&account_info_soap);

	if (soap_ssl_client_context(&account_info_soap,
		SOAP_SSL_DEFAULT | SOAP_SSL_ALLOW_EXPIRED_CERTIFICATE,
		"client.key", /* keyfile: required only when client must authenticate to server (see SSL docs on how to obtain this file) */
		NULL, /* password to read the key file (not used with GNUTLS) */
		"server.crt", /* cacert file to store trusted certificates (needed to verify server) */
		NULL, /* capath to directory with trusted certificates */
		NULL /* if randfile!=NULL: use a file with random data to seed randomness */
	))
	{
		printf("Init soap ssl client context error \n");
		return;
	}


	std::string server = "https://172.18.15.7/pmec/mid/trade/";
	std::string result;
	account_info_soap.userid = "1";
	account_info_soap.passwd = "cpp";
	account_info_soap.connect_timeout = 60;	/* try to connect for 1 minute */
	account_info_soap.send_timeout = account_info_soap.recv_timeout = 30;	/* if I/O stalls, then timeout after 30 seconds */

	if (soap_call_ns__trade(&account_info_soap, server.c_str(), NULL, message, &result) == SOAP_OK)
	{
		printf("result is %s, thread id = %lu\n", result.c_str(), pthread_self());
	}
	else
	{
		soap_print_fault(&account_info_soap, stderr);
	}

	soap_destroy(&account_info_soap); /* C++ */
	soap_end(&account_info_soap);
	soap_done(&account_info_soap);
	
	//soap_free(&account_info_soap);
	
	usleep(1);
}
示例#6
0
文件: try_01.cpp 项目: roger918/Gsoap
int main()
{
wsHttpWellthServiceProxy service;
//char request[64];
std::string request = "*****@*****.**";
char response[64];
_ns3__GetNameByEmailID soapRequest;
_ns3__GetNameByEmailIDResponse soapResponse;
struct soap *pSoap = NULL;


pSoap = soap_new();
soap_set_namespaces(pSoap,namespaces);
soap_ssl_init();
if (soap_ssl_client_context(pSoap, SOAP_SSL_NO_AUTHENTICATION, NULL,NULL,NULL,NULL,NULL) == SOAP_OK)
  std::cout << "Client COntext set OK " << std::endl;

/**
strcpy(request,"*****@*****.**");
soapRequest.emailID = (std::string *)&request;
**/
pSoap->ssl_flags = SOAP_SSL_NO_AUTHENTICATION | SOAP_SSL_NO_DEFAULT_CA_PATH;
soapRequest.emailID = &request;
soapRequest.soap = pSoap;



// if (service.GetNameByEmailID((_ns3__GetNameByEmailID*)request,(_ns3__GetNameByEmailIDResponse*)response) == SOAP_OK)
//soap_call___ns1__GetNameByEmailID(pSoap,NULL,NULL,&soapRequest,&soapResponse);

if (service.GetNameByEmailID(&soapRequest,&soapResponse) == SOAP_OK)
  std::cout << "The response is " << response << std::endl;
else
  service.soap_stream_fault(std::cerr); 
  service.destroy(); // delete data and release memory 


}
AmazonSimpleStorageService::AmazonSimpleStorageService()

{
    initializeService();

    m_service = new AmazonS3SoapBindingProxy;
    m_service->soap_stream_fault(std::cout);
    
    soap_ssl_client_context(m_service->soap,
           SOAP_SSL_NO_AUTHENTICATION,
           NULL,
           NULL,
           NULL,
           NULL,
           NULL);

    /* Wenn Sie im Hochschulnetz arbeiten...
        client.proxy_host="proxy.hft-stuttgart.de"; // proxy hostname
        client.proxy_port=80;
        client.proxy_userid=NULL;  // user pass if proxy
        client.proxy_passwd=NULL;  // requires authentication
        client.proxy_http_version="1.1"; // http version
    */
}
示例#8
0
// 测试事件 ...
void test_event(const zonekey__ZonekeyDMServiceType *service)
{
	return;
	int rc;
	fprintf(stdout, "\n\n%s: url=%s\n", __FUNCTION__, service->url.c_str());

	PullPointSubscriptionBindingProxy pps, pps_p;	// pps 用于 CreatePullPointSubscription, pps_p 用于 PullMessage, ...

	// 使用 WS-usernameToken,参考 wsseapi.h 

#ifdef WITH_OPENSSL
	soap_wsse_add_UsernameTokenDigest(pps.soap, "id", "zonekey", "yekenoz");
	// 使用 tls ..
	KVConfig cfg("client.config");

	// ca-certs 的文件中,保存着签署 server 证书的 ca ...
	rc = soap_ssl_client_context(pps.soap, SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK, 0, 0, cfg.get_value("cacerts", "cacerts.pem"), 0, 0);
	if (rc != SOAP_OK) {
		log(LOG_FAULT, "%s: soap_ssl_client_context faulure, code=%d, using cacerts='%s'\n", __func__, rc, cfg.get_value("cacerts", "cacerts.pem"));
		soap_print_fault(pps.soap, stderr);
		exit(-1);
	}

	log(LOG_DEBUG, "%s: soap_ssl_client_context ok, using cacerts='%s'\n", __func__, cfg.get_value("cacerts", "cacerts.pem"));
#endif

	{
		log(LOG_DEBUG, "===> try GetServiceCapabilities ...\n");

		/// GetServiceCapabilities
		_tev__GetServiceCapabilities req;
		_tev__GetServiceCapabilitiesResponse res;
		rc = pps.GetServiceCapabilities(service->url.c_str(), 0, &req, &res);
		if (rc != SOAP_OK) {
			log(LOG_ERROR, "%s: GetServiceCapablities err, code=%d\n", __func__, rc);
			soap_print_fault(pps.soap, stderr);
		}
		else {
			log(LOG_DEBUG, "%s: GetServiceCapablities ok\n", __func__);
		}
	}

	{
		log(LOG_DEBUG, "===> try CreatePullPointSubscription ...\n");

		/// CreatePullPointSubscription
		_tev__CreatePullPointSubscription req;
		_tev__CreatePullPointSubscriptionResponse res;

		rc = pps.CreatePullPointSubscription(service->url.c_str(), 0, &req, &res);
		if (rc != SOAP_OK) {
			log(LOG_ERROR, "%s: CreatePullPointSubscription err, code=%d\n", __func__, rc);
			soap_print_fault(pps.soap, stderr);
		}
		else {
			log(LOG_DEBUG, "%s: CreatePullPointSubscription ok\n", __func__);

			struct tm *ptm = localtime(&res.wsnt__CurrentTime);
			log(LOG_DEBUG, "\t CurrentTime=%04d-%02d-%02d %02d:%02d:%02d\n",
				ptm->tm_year + 1900, ptm->tm_min + 1, ptm->tm_mday,
				ptm->tm_hour, ptm->tm_min, ptm->tm_sec);

			ptm = localtime(&res.wsnt__TerminationTime);
			log(LOG_DEBUG, "\t TerminateTime=%04d-%02d-%02d %02d:%02d:%02d\n",
				ptm->tm_year + 1900, ptm->tm_min + 1, ptm->tm_mday,
				ptm->tm_hour, ptm->tm_min, ptm->tm_sec);

			log(LOG_DEBUG, "\t pullpoint url='%s'\n", res.SubscriptionReference.Address);

			const char *endpoint = res.SubscriptionReference.Address;
			{
				log(LOG_DEBUG, "===> try PullMessage ...\n");

				/// PullMessage
				_tev__PullMessages req;
				_tev__PullMessagesResponse res;

				req.MessageLimit = 0;
				req.Timeout = 10;	// 10 秒超时 ??? .

				rc = pps_p.PullMessages(endpoint, 0, &req, &res);
				if (rc != SOAP_OK) {
					log(LOG_ERROR, "%s: PullMessage for '%s' err, code=%d\n", __func__, endpoint, rc);
				}
				else {
					log(LOG_DEBUG, "%s: PullMessage for '%s' ok\n", __func__, endpoint);
					log(LOG_DEBUG, "\t en there are %u messages\n", res.wsnt__NotificationMessage.size());
					std::vector<class wsnt__NotificationMessageHolderType * >::const_iterator it;
					for (it = res.wsnt__NotificationMessage.begin(); it != res.wsnt__NotificationMessage.end(); ++it) {
						log(LOG_DEBUG, "\t\t: %s/%s: code=%d, info=%s\n", (*it)->Message.Message->ns.c_str(),
							(*it)->Message.Message->sid.c_str(), (int)(*it)->Message.Message->code, (*it)->Message.Message->info.c_str());
					}
				}
			}

			{
				log(LOG_DEBUG, "===> try Unsubscribe ...\n");

				/// UnSubscribe
				_wsnt__Unsubscribe req;
				_wsnt__UnsubscribeResponse res;

				rc = pps_p.Unsubscribe(endpoint, 0, &req, &res);
				if (rc != SOAP_OK) {
					log(LOG_ERROR, "%s: Unsubecribe for '%s' err, code=%d\n", __func__, endpoint, rc);
				}
				else {
					log(LOG_DEBUG, "%s: Unsubscribe for '%s' ok\n", __func__, endpoint);
				}
			}
		}
	}

	log(LOG_INFO, "%s: end \n\n", __func__);
}
示例#9
0
int main(int argc, char *argv[])
{
  char  *delegation_id = "", *reqtxt, *certtxt, *valid = NULL, 
        *cert = NULL, *key = NULL, *capath = NULL, *keycert, timestr[81],
        *vomsdir = "/etc/grid-security/vomsdir",
        *executable, *keytxt, *proxychain, *ptr, *p;
  struct ns__putProxyResponse *unused = NULL;
  struct tm *finish_tm;
  int    option_index, c, noverify = 0, i, ret,
         method = HTPROXY_PUT, verbose = 0, fd, minutes;
  struct soap soap_get, soap_put;
  struct ns__getNewProxyReqResponse     getNewProxyReqResponse;
  struct ns__renewProxyReqResponse      renewProxyReqResponse;
  struct ns__destroyResponse            destroyResponse;
  struct ns__getTerminationTimeResponse getTerminationTimeResponse;
  FILE   *ifp, *ofp;
  STACK_OF(X509) *x509_certstack;
  X509   *x509_cert;
  BIO    *certmem;
  GRSTx509Chain *grst_chain = NULL;
  GRSTx509Cert  *grst_cert = NULL;
  long   ptrlen;
  struct stat statbuf;
  struct passwd *userpasswd; 
  struct option long_options[] = {      {"verbose",     0, 0, 'v'},
                                        {"cert",        1, 0, 0},
                                        {"key",         1, 0, 0},
                                        {"capath",      1, 0, 0},
                                        {"destroy",     0, 0, 0},
                                        {"time",        0, 0, 0},
                                        {"no-verify",   0, 0, 0},
                                        {"valid",       1, 0, 0},
                                        {"delegation-id",1, 0, 0},
                                        {"put",         0, 0, 0},
                                        {"renew",       0, 0, 0},
                                        {"unixtime",	0, 0, 0},
                                        {"make",	0, 0, 0},
                                        {"info",	0, 0, 0},
                                        {0, 0, 0, 0}  };

  if (argc == 1)
    {
      printsyntax(argv[0]);
      return 0;
    }

  while (1)
       {
         option_index = 0;
                                                                                
         c = getopt_long(argc, argv, "v", long_options, &option_index);

         if      (c == -1) break;
         else if (c == 0)
           {
             if      (option_index ==  1) cert            = optarg;
             else if (option_index ==  2) key             = optarg;
             else if (option_index ==  3) capath          = optarg;
             else if (option_index ==  4) method          = HTPROXY_DESTROY;
             else if (option_index ==  5) method          = HTPROXY_TIME;
             else if (option_index ==  6) noverify        = 1;
             else if (option_index ==  7) valid           = optarg;
             else if (option_index ==  8) delegation_id   = optarg;
             else if (option_index ==  9) method          = HTPROXY_PUT;
             else if (option_index == 10) method          = HTPROXY_RENEW;
             else if (option_index == 11) method          = HTPROXY_UNIXTIME;
             else if (option_index == 12) method          = HTPROXY_MAKE;
             else if (option_index == 13) method          = HTPROXY_INFO;
           }
         else if (c == 'v') 
                {
                  GRSTerrorLogFunc = htproxy_logfunc;
                  ++verbose;
                }
       }

  executable = rindex(argv[0], '/');
  if (executable != NULL) executable++;
  else                    executable = argv[0];
  
  if    (strcmp(executable, "htproxydestroy") == 0) method = HTPROXY_DESTROY;
  else if (strcmp(executable, "htproxyrenew") == 0) method = HTPROXY_RENEW;
  else if (strcmp(executable, "htproxytime") == 0)  method = HTPROXY_TIME;
  else if (strcmp(executable, "htproxyunixtime") == 0) 
                                                    method = HTPROXY_UNIXTIME;
  else if (strcmp(executable, "htproxymake") == 0)  method = HTPROXY_MAKE;
  else if (strcmp(executable, "htproxyinfo") == 0)  method = HTPROXY_INFO;

  if ((method != HTPROXY_MAKE) && 
      (method != HTPROXY_INFO) && (optind + 1 != argc))
    {
      fprintf(stderr, "Must specify a delegation service URL!\n");
      return 1;
    }

  if ((method == HTPROXY_RENEW) && (delegation_id[0] == '\0'))
    {
      fprintf(stderr, "Must give a Delegation ID when renewing\n");
      return 1;
    }
    
  if (valid == NULL) minutes = 60 * 12;
  else minutes = atoi(valid);
  
  if (verbose) fprintf(stderr, "Proxy valid for %d minutes\n", minutes);
 
  ERR_load_crypto_strings ();
  OpenSSL_add_all_algorithms();

  if      ((cert == NULL) && (key != NULL)) cert = key;
  else if ((cert != NULL) && (key == NULL)) key = cert;
  else if ((cert == NULL) && (key == NULL))
    {
      if (method != HTPROXY_MAKE) cert = getenv("X509_USER_PROXY");

      if (cert != NULL) key = cert;
      else
        {
          if (method != HTPROXY_MAKE) 
               asprintf(&(cert), "/tmp/x509up_u%d", geteuid());

          /* one fine day, we will check the proxy file for 
             expiry too to avoid suprises when we try to use it ... */

          if (stat(cert, &statbuf) == 0) key = cert;
          else if (method != HTPROXY_INFO)
            {
              cert = getenv("X509_USER_CERT");
              key  = getenv("X509_USER_KEY");
                                                                                
              userpasswd = getpwuid(geteuid());
                                                                                
              if ((cert == NULL) &&
                  (userpasswd != NULL) &&
                  (userpasswd->pw_dir != NULL))
                asprintf(&(cert), "%s/.globus/usercert.pem",
                                                    userpasswd->pw_dir);
                                                                                
              if ((key == NULL) &&
                  (userpasswd != NULL) &&
                  (userpasswd->pw_dir != NULL))
                asprintf(&(key), "%s/.globus/userkey.pem",
                                                    userpasswd->pw_dir);
                                                                                
            }
        }
    }
                                                                                
  if (capath == NULL) capath = getenv("X509_CERT_DIR");
  if (capath == NULL) capath = "/etc/grid-security/certificates";

  if (verbose) fprintf(stderr, "key=%s\ncert=%s\ncapath=%s\n",
                       key, cert, capath);

  if ((key != NULL) && (cert != NULL) &&
      (strcmp(key, cert) != 0)) /* we have to concatenate for gSOAP */
    {
      keycert = strdup("/tmp/.XXXXXX");
        
      fd = mkstemp(keycert);
      ofp = fdopen(fd, "w");
      if (!ofp)
      {
          fprintf(stderr, "Cannot open tmp file for the key\n");
          return 1;
      }
          
      ifp = fopen(key, "r");          
      {
          fprintf(stderr, "Cannot open the file with the key\n");
          return 1;
      }
      while ((c = fgetc(ifp)) != EOF) fputc(c, ofp);          
      fclose(ifp);
          
      ifp = fopen(cert, "r");          
      {
          fprintf(stderr, "Cannot open the file with the cert\n");
          return 1;
      }
      while ((c = fgetc(ifp)) != EOF) fputc(c, ofp);          
      fclose(ifp);
          
      fclose(ofp);       
          
      if (verbose) fprintf(stderr, "Created %s key/cert file\n", keycert);
    }
  else keycert = key;

  if ((method == HTPROXY_PUT) || (method == HTPROXY_RENEW))
    {
      if (verbose) 
        {
          fprintf(stderr, "Using SOAP delegation protocol\n");
          fprintf(stderr, "Delegation-ID: %s\n", delegation_id);
        }

      soap_init(&soap_get);
  
      if (soap_ssl_client_context(&soap_get,
                                  SOAP_SSL_DEFAULT,
                                  keycert, 
                                  "",
                                  NULL,
                                  capath,
                                  NULL))
        {
          soap_print_fault(&soap_get, stderr);
          return 1;
        } 

      if ((method == HTPROXY_RENEW) && (delegation_id[0] != '\0'))
        {
          if (verbose) fprintf(stderr, "Send renewProxyReq to service\n");

          soap_call_ns__renewProxyReq(&soap_get, 
                                argv[optind],	/* HTTPS url of service */
                                "http://www.gridsite.org/namespaces/delegation-1",
                                delegation_id, 
                                &renewProxyReqResponse);
      
          if (soap_get.error)
            {
              soap_print_fault(&soap_get, stderr);
              return 1;        
            }
       
          reqtxt = renewProxyReqResponse._renewProxyReqReturn;
        }
      else
        {
          if (verbose) fprintf(stderr, "Send getNewProxyReq to service\n");

          soap_call_ns__getNewProxyReq(&soap_get,
                            argv[optind],	/* HTTPS url of service */
                            "http://www.gridsite.org/namespaces/delegation-1",
                            &getNewProxyReqResponse);

          if (soap_get.error)
            {
              soap_print_fault(&soap_get, stderr);
              return 1;        
            }

          if (!getNewProxyReqResponse.getNewProxyReqReturn)
            {
              fprintf(stderr, "Empty response from getNewProxyReq\n");
              return 1;
            }

          reqtxt = getNewProxyReqResponse.getNewProxyReqReturn->proxyRequest;
          delegation_id = 
                   getNewProxyReqResponse.getNewProxyReqReturn->delegationID;
        }
 
      if (verbose) fprintf(stderr, "reqtxt:\n%s", reqtxt);
      
      if (GRSTx509MakeProxyCert(&certtxt, stderr, reqtxt, cert, key, minutes) 
          != GRST_RET_OK)
        {
          return 1;
        }

      soap_init(&soap_put);
  
      if (verbose) fprintf(stderr, "Send putProxy to service:\n%s\n", certtxt);

      if (soap_ssl_client_context(&soap_put,
                                  SOAP_SSL_DEFAULT,
                                  keycert, 
                                  "",
                                  NULL,
                                  capath,
                                  NULL))
        {
          soap_print_fault(&soap_put, stderr);
          return 1;
        } 

      soap_call_ns__putProxy(&soap_put, argv[optind],
                             "http://www.gridsite.org/namespaces/delegation-1",
                             delegation_id, 
                             certtxt, unused);      
      if (soap_put.error)
        {
          soap_print_fault(&soap_put, stderr);
          return 1;        
        }

      puts(delegation_id);

      return 0;
    }  
  else if (method == HTPROXY_DESTROY)
    {
      if (verbose) 
        {
          fprintf(stderr, "Using SOAP proxy destroy protocol\n");
          fprintf(stderr, "Delegation-ID: %s\n", delegation_id);
        }

      soap_init(&soap_put);
  
      if (verbose) fprintf(stderr, "Send destroy to service:\n");

      if (soap_ssl_client_context(&soap_put,
                                  SOAP_SSL_DEFAULT,
                                  keycert, 
                                  "",
                                  NULL,
                                  capath,
                                  NULL))
        {
          soap_print_fault(&soap_put, stderr);
          return 1;
        } 

      soap_call_ns__destroy(&soap_put, argv[optind],
                             "http://www.gridsite.org/namespaces/delegation-1",
                             delegation_id, 
                             &destroyResponse);
      if (soap_put.error)
        {
          soap_print_fault(&soap_put, stderr);
          return 1;        
        }

      return 0;
    }  
  else if ((method == HTPROXY_TIME) || (method == HTPROXY_UNIXTIME))
    {
      if (verbose) 
        {
          fprintf(stderr, "Using SOAP proxy get expiration time protocol\n");
          fprintf(stderr, "Delegation-ID: %s\n", delegation_id);
        }

      soap_init(&soap_put);
  
      if (verbose) fprintf(stderr, "Send get time to service:\n");

      if (soap_ssl_client_context(&soap_put,
                                  SOAP_SSL_DEFAULT,
                                  keycert, 
                                  "",
                                  NULL,
                                  capath,
                                  NULL))
        {
          soap_print_fault(&soap_put, stderr);
          return 1;
        } 

      soap_call_ns__getTerminationTime(&soap_put, argv[optind],
                             "http://www.gridsite.org/namespaces/delegation-1",
                             delegation_id, 
                             &getTerminationTimeResponse);
      if (soap_put.error)
        {
          soap_print_fault(&soap_put, stderr);
          return 1;        
        }


      if (method == HTPROXY_UNIXTIME)
       printf("%ld\n", getTerminationTimeResponse._getTerminationTimeReturn);
      else
        {
          finish_tm = 
           localtime(&(getTerminationTimeResponse._getTerminationTimeReturn));

          strftime(timestr, sizeof(timestr),
                       "%a %b %e %H:%M:%S %Z %Y\n", finish_tm);
                       
          fputs(timestr, stdout);
        }
        
      return 0;
    }  
  else if (method == HTPROXY_MAKE)
#ifdef HT_LEAK_TEST
    {
    int ii;
    FILE *ffpp;
    char lineline[80];
    for (ii=0; ii < 1000; ++ii)
#endif
    {
      if (GRSTx509CreateProxyRequestKS(&reqtxt, &keytxt, NULL, 0) != GRST_RET_OK)
        {
          fprintf(stderr, "Failed to create internal proxy cert request\n");
          return 1;
        }
      
#ifdef HT_LEAK_TEST      
     ffpp = fopen("/proc/self/statm", "r");
     fgets(lineline, sizeof(lineline), ffpp);
     fprintf(stderr, "%d a %s", ii, lineline);
     fclose(ffpp);
#endif
      if (GRSTx509MakeProxyCert(&proxychain, NULL, reqtxt, cert, key, minutes)
            != GRST_RET_OK)
        {
          fprintf(stderr, "Failed to sign internal proxy cert request\n");
          return 2;
        }
        
#ifdef HT_LEAK_TEST      
     ffpp = fopen("/proc/self/statm", "r");
     fgets(lineline, sizeof(lineline), ffpp);
     fprintf(stderr, "%d b %s", ii, lineline);
     fclose(ffpp);
#endif

      /* convert back to cert stack so can output in the right order */
      if (GRSTx509StringToChain(&x509_certstack, proxychain) != GRST_RET_OK)
        {
          fprintf(stderr, "Failed to convert internal proxy chain\n");
          return 3;
        }
        
#ifdef HT_LEAK_TEST      
     ffpp = fopen("/proc/self/statm", "r");
     fgets(lineline, sizeof(lineline), ffpp);
     fprintf(stderr, "%d c %s", ii, lineline);
     fclose(ffpp);
#endif

      /* just the proxy certificate we have created */
      if ((x509_cert = sk_X509_value(x509_certstack, 0)))
        {
          certmem = BIO_new(BIO_s_mem());
          if (PEM_write_bio_X509(certmem, x509_cert) == 1)
            {
              ptrlen = BIO_get_mem_data(certmem, &ptr);
              fwrite(ptr, 1, ptrlen, stdout);
            }
                                                          
          BIO_free(certmem);
        }
                                                                    
#ifdef HT_LEAK_TEST      
     ffpp = fopen("/proc/self/statm", "r");
     fgets(lineline, sizeof(lineline), ffpp);
     fprintf(stderr, "%d d %s", ii, lineline);
     fclose(ffpp);
#endif
      /* then the private key */ 
      fputs(keytxt, stdout);
      
      /* and only now the rest of the certificates */
      for (i=1; i <= sk_X509_num(x509_certstack) - 1; ++i)
        /* loop through the proxy chain starting at 2nd most recent proxy */
         {
           if ((x509_cert = sk_X509_value(x509_certstack, i)))
             {
               certmem = BIO_new(BIO_s_mem());
               if (PEM_write_bio_X509(certmem, x509_cert) == 1)
                 {
                   ptrlen = BIO_get_mem_data(certmem, &ptr);
                   fwrite(ptr, 1, ptrlen, stdout);
                 }

               BIO_free(certmem);
             }
         }

 
#ifdef HT_LEAK_TEST      
     ffpp = fopen("/proc/self/statm", "r");
     fgets(lineline, sizeof(lineline), ffpp);
     fprintf(stderr, "%d e %s", ii, lineline);
     fclose(ffpp);
#endif
      free(proxychain);
      free(keytxt);
      free(reqtxt);
      sk_X509_free(x509_certstack);
      
#ifdef HT_LEAK_TEST      
     ffpp = fopen("/proc/self/statm", "r");
     fgets(lineline, sizeof(lineline), ffpp);
     fprintf(stderr, "%d f %s", ii, lineline);
     fclose(ffpp);
    }
#endif
      return 0;
    }
  else if (method == HTPROXY_INFO)
    {
      if (cert != NULL) 
        {
          if (verbose) fprintf(stderr, "Getting proxy info from %s\n", cert);
    
          ifp = fopen(cert, "r");
          if (ifp == NULL)
            {
              fprintf(stderr, "Failed to open proxy file\n");
              return 2;              
            }
        }
      else  
        {
          if (verbose) fprintf(stderr, "Getting proxy info from stdin\n");
          ifp = stdin;
        }
      
      ptrlen = 4096;
      ptr = malloc(ptrlen);
      i = 0;
      
      while ((c = fgetc(ifp)) != EOF)
           {
             ptr[i] = c;
             ++i;
             
             if (i >= ptrlen) 
               {
                 ptrlen += 4096;
                 ptr = realloc(ptr, ptrlen);
               }
           }
           
      ptr[i] = '\0';
      if (cert != NULL) fclose(ifp);
      
      if ((GRSTx509StringToChain(&x509_certstack, ptr) != GRST_RET_OK) ||
          (x509_certstack == NULL))
        {
          fprintf(stderr, "Failed to parse proxy file for certificate chain\n");
          free(ptr);
          return 2;
        }

      free(ptr);

      if (verbose) fprintf(stderr, "Parsing certificate chain\n");
      
      ret = GRSTx509ChainLoadCheck(&grst_chain, x509_certstack, NULL,  
                                   capath, vomsdir);
      
      if ((ret != GRST_RET_OK) || 
          (grst_chain == NULL) || (grst_chain->firstcert == NULL))
        {
          fprintf(stderr, "Failed parsing certificate chain\n");
          return 3;
        }
      
      grst_cert = grst_chain->firstcert;

      for (i=0; grst_cert != NULL; grst_cert = grst_cert->next, ++i)
         {
           if      (grst_cert->type == GRST_CERT_TYPE_CA)    p = "(CA) ";
           else if (grst_cert->type == GRST_CERT_TYPE_EEC)   p = "(EEC) ";
           else if (grst_cert->type == GRST_CERT_TYPE_PROXY) p = "(PC) ";
           else if (grst_cert->type == GRST_CERT_TYPE_VOMS)  p = "(AC) ";
           else p = "";
                              
           printf("%d %s%s\n", i, p,
                  (grst_cert->type == GRST_CERT_TYPE_VOMS) 
                    ? grst_cert->value : grst_cert->dn);
 
           printf(" Status     : %d ( %s%s%s%s%s%s)\n", grst_cert->errors,
                 (grst_cert->errors == 0) ? "OK " : "",
                 (grst_cert->errors & GRST_CERT_BAD_FORMAT) ? "BAD_FORMAT ":"",
                 (grst_cert->errors & GRST_CERT_BAD_CHAIN)  ? "BAD_CHAIN ":"",
                 (grst_cert->errors & GRST_CERT_BAD_SIG)    ? "BAD_SIG ":"",
                 (grst_cert->errors & GRST_CERT_BAD_TIME)   ? "BAD_TIME ":"",
                 (grst_cert->errors & GRST_CERT_BAD_OCSP)   ? "BAD_OCSP ":"");

           printf(" Start      : %s",   ctime(&(grst_cert->notbefore)));
           printf(" Finish     : %s",   ctime(&(grst_cert->notafter)));
           printf(" Delegation : %d\n", grst_cert->delegation);

           if (grst_cert->type == GRST_CERT_TYPE_VOMS)
             {
               printf(" User DN    : %s\n", grst_cert->dn);
               printf(" VOMS DN    : %s\n\n", grst_cert->issuer);
             }
           else
             {
               printf(" Serial     : %s\n", grst_cert->serial);
               printf(" Issuer     : %s\n\n", grst_cert->issuer);              
             }
         }
      
      GRSTx509ChainFree(grst_chain);
    }
  /* weirdness */
}
示例#10
0
/**
 *
 * @param argc
 * @param argv[]
 * @return
 */
int main(int argc, char* argv[])
{
    bool fSSL = false;
    const char *pcszArgEndpoint = "http://localhost:18083/";

    int ap;
    for (ap = 1; ap < argc; ap++)
    {
        if (argv[ap][0] == '-')
        {
            if (!strcmp(argv[ap], "-h"))
                usage(0);
            else if (!strcmp(argv[ap], "-c"))
            {
                ap++;
                if (ap >= argc)
                    usage(1);
                pcszArgEndpoint = argv[ap];
                fSSL = !strncmp(pcszArgEndpoint, "https://", 8);
            }
            else
                usage(1);
        }
        else
            break;
    }

    if (argc < 1 + ap)
        usage(1);

#ifdef WITH_OPENSSL
    if (fSSL)
        soap_ssl_init();
#endif /* WITH_OPENSSL */

    struct soap soap; // gSOAP runtime environment
    soap_init(&soap); // initialize runtime environment (only once)
#ifdef WITH_OPENSSL
    // Use SOAP_SSL_NO_AUTHENTICATION here to accept broken server configs.
    // In a real world setup please use at least SOAP_SSL_DEFAULT and provide
    // the necessary CA certificate for validating the server's certificate.
    if (fSSL && soap_ssl_client_context(&soap, SOAP_SSL_NO_AUTHENTICATION,
                                        NULL /*clientkey*/, NULL /*password*/,
                                        NULL /*cacert*/, NULL /*capath*/,
                                        NULL /*randfile*/))
    {
        soap_print_fault(&soap, stderr);
        exit(1);
    }
#endif /* WITH_OPENSSL */

    const char *pcszMode = argv[ap];
    int soaprc = SOAP_SVR_FAULT;

    if (!strcmp(pcszMode, "logon"))
    {
        if (argc < 3 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IWebsessionManager_USCORElogon req;
            req.username = argv[ap + 1];
            req.password = argv[ap + 2];
            _vbox__IWebsessionManager_USCORElogonResponse resp;

            if (!(soaprc = soap_call___vbox__IWebsessionManager_USCORElogon(&soap,
                                                            pcszArgEndpoint,
                                                            NULL,
                                                            &req,
                                                            &resp)))
                std::cout << "VirtualBox objref: \"" << resp.returnval << "\"\n";
        }
    }
    else if (!strcmp(pcszMode, "getsession"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IWebsessionManager_USCOREgetSessionObject req;
            req.refIVirtualBox = argv[ap + 1];
            _vbox__IWebsessionManager_USCOREgetSessionObjectResponse resp;

            if (!(soaprc = soap_call___vbox__IWebsessionManager_USCOREgetSessionObject(&soap,
                                                            pcszArgEndpoint,
                                                            NULL,
                                                            &req,
                                                            &resp)))
                std::cout << "session: \"" << resp.returnval << "\"\n";
        }
    }
    else if (!strcmp(pcszMode, "logoff"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IWebsessionManager_USCORElogoff req;
            req.refIVirtualBox = argv[ap + 1];
            _vbox__IWebsessionManager_USCORElogoffResponse resp;

            if (!(soaprc = soap_call___vbox__IWebsessionManager_USCORElogoff(&soap,
                                                            pcszArgEndpoint,
                                                            NULL,
                                                            &req,
                                                            &resp)))
            {
                ;
            }
        }
    }
    else if (!strcmp(pcszMode, "version"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IVirtualBox_USCOREgetVersion req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IVirtualBox_USCOREgetVersionResponse resp;

            if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetVersion(&soap,
                                                            pcszArgEndpoint,
                                                            NULL,
                                                            &req,
                                                            &resp)))
                std::cout << "version: \"" << resp.returnval << "\"\n";
        }
    }
    else if (!strcmp(pcszMode, "gethost"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IVirtualBox_USCOREgetHost req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IVirtualBox_USCOREgetHostResponse resp;

            if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetHost(&soap,
                                                            pcszArgEndpoint,
                                                            NULL,
                                                            &req,
                                                            &resp)))
            {
                std::cout << "Host objref " << resp.returnval << "\n";
            }
        }
    }
    else if (!strcmp(pcszMode, "getpc"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IVirtualBox_USCOREgetPerformanceCollector req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IVirtualBox_USCOREgetPerformanceCollectorResponse resp;

            if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetPerformanceCollector(&soap,
                                                            pcszArgEndpoint,
                                                            NULL,
                                                            &req,
                                                            &resp)))
            {
                std::cout << "Performance collector objref " << resp.returnval << "\n";
            }
        }
    }
    else if (!strcmp(pcszMode, "getmachines"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IVirtualBox_USCOREgetMachines req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IVirtualBox_USCOREgetMachinesResponse resp;

            if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetMachines(&soap,
                                                                pcszArgEndpoint,
                                                                NULL,
                                                                &req,
                                                                &resp)))
            {
                size_t c = resp.returnval.size();
                for (size_t i = 0;
                     i < c;
                     ++i)
                {
                    std::cout << "Machine " << i << ": objref " << resp.returnval[i] << "\n";
                }
            }
        }
    }
    else if (!strcmp(pcszMode, "createmachine"))
    {
        if (argc < 4 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IVirtualBox_USCOREcreateMachine req;
            req._USCOREthis = argv[ap + 1];
            req.settingsFile = argv[ap + 2];
            req.name = argv[ap + 3];
            std::cout << "createmachine: settingsFile = \"" << req.settingsFile << "\", name = \"" << req.name << "\"\n";
            _vbox__IVirtualBox_USCOREcreateMachineResponse resp;

            if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREcreateMachine(&soap,
                                                                  pcszArgEndpoint,
                                                                  NULL,
                                                                  &req,
                                                                  &resp)))
                std::cout << "Machine created: managed object reference ID is " << resp.returnval << "\n";
        }
    }
    else if (!strcmp(pcszMode, "registermachine"))
    {
        if (argc < 3 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IVirtualBox_USCOREregisterMachine req;
            req._USCOREthis = argv[ap + 1];
            req.machine = argv[ap + 2];
            _vbox__IVirtualBox_USCOREregisterMachineResponse resp;
            if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREregisterMachine(&soap,
                                                                    pcszArgEndpoint,
                                                                    NULL,
                                                                    &req,
                                                                    &resp)))
                std::cout << "Machine registered.\n";
        }
    }
    else if (!strcmp(pcszMode, "getdvddrives"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IHost_USCOREgetDVDDrives req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IHost_USCOREgetDVDDrivesResponse resp;
            if (!(soaprc = soap_call___vbox__IHost_USCOREgetDVDDrives(&soap,
                                                           pcszArgEndpoint,
                                                           NULL,
                                                           &req,
                                                           &resp)))
            {
                size_t c = resp.returnval.size();
                for (size_t i = 0;
                    i < c;
                    ++i)
                {
                    std::cout << "DVD drive " << i << ": objref " << resp.returnval[i] << "\n";
                }
            }
        }
    }
    else if (!strcmp(pcszMode, "getname"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IMachine_USCOREgetName req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IMachine_USCOREgetNameResponse resp;
            if (!(soaprc = soap_call___vbox__IMachine_USCOREgetName(&soap,
                                                         pcszArgEndpoint,
                                                         NULL,
                                                         &req,
                                                         &resp)))
                printf("Name is: %s\n", resp.returnval.c_str());
        }
    }
    else if (!strcmp(pcszMode, "getid"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IMachine_USCOREgetId req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IMachine_USCOREgetIdResponse resp;
            if (!(soaprc = soap_call___vbox__IMachine_USCOREgetId(&soap,
                                                       pcszArgEndpoint,
                                                       NULL,
                                                       &req,
                                                       &resp)))
                std::cout << "UUID is: " << resp.returnval << "\n";;
        }
    }
    else if (!strcmp(pcszMode, "getostypeid"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IMachine_USCOREgetOSTypeId req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IMachine_USCOREgetOSTypeIdResponse resp;
            if (!(soaprc = soap_call___vbox__IMachine_USCOREgetOSTypeId(&soap,
                                                             pcszArgEndpoint,
                                                             NULL,
                                                             &req,
                                                             &resp)))
                std::cout << "Guest OS type is: " << resp.returnval << "\n";
        }
    }
    else if (!strcmp(pcszMode, "savesettings"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IMachine_USCOREsaveSettings req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IMachine_USCOREsaveSettingsResponse resp;
            if (!(soaprc = soap_call___vbox__IMachine_USCOREsaveSettings(&soap,
                                                              pcszArgEndpoint,
                                                              NULL,
                                                              &req,
                                                              &resp)))
                std::cout << "Settings saved\n";
        }
    }
    else if (!strcmp(pcszMode, "setupmetrics"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IPerformanceCollector_USCOREsetupMetrics req;
            req._USCOREthis = argv[ap + 1];
//             req.metricNames[0] = "*";
//             req.objects
            req.period = 1;     // seconds
            req.count = 100;
            _vbox__IPerformanceCollector_USCOREsetupMetricsResponse resp;
            if (!(soaprc = soap_call___vbox__IPerformanceCollector_USCOREsetupMetrics(&soap,
                                                              pcszArgEndpoint,
                                                              NULL,
                                                              &req,
                                                              &resp)))
            {
                size_t c = resp.returnval.size();
                for (size_t i = 0;
                     i < c;
                     ++i)
                {
                    std::cout << "Metric " << i << ": objref " << resp.returnval[i] << "\n";
                }
            }
        }
    }
    else if (!strcmp(pcszMode, "querymetricsdata"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IPerformanceCollector_USCOREqueryMetricsData req;
            req._USCOREthis = argv[ap + 1];
//             req.metricNames[0] = "*";
//             req.objects
            _vbox__IPerformanceCollector_USCOREqueryMetricsDataResponse resp;
            if (!(soaprc = soap_call___vbox__IPerformanceCollector_USCOREqueryMetricsData(&soap,
                                                              pcszArgEndpoint,
                                                              NULL,
                                                              &req,
                                                              &resp)))
            {
                size_t c = resp.returnval.size();
                for (size_t i = 0;
                     i < c;
                     ++i)
                {
                    std::cout << "long " << i << ": " << resp.returnval[i] << "\n";
                }
            }
        }
    }
    else if (!strcmp(pcszMode, "errorinfo"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IVirtualBoxErrorInfo_USCOREgetResultCode req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IVirtualBoxErrorInfo_USCOREgetResultCodeResponse resp;
            if (!(soaprc = soap_call___vbox__IVirtualBoxErrorInfo_USCOREgetResultCode(&soap,
                                                                                      pcszArgEndpoint,
                                                                                      NULL,
                                                                                      &req,
                                                                                      &resp)))
            {
                std::cout << "ErrorInfo ResultCode: " << std::hex << resp.returnval << "\n";

                _vbox__IVirtualBoxErrorInfo_USCOREgetText req2;
                req2._USCOREthis = argv[ap + 1];
                _vbox__IVirtualBoxErrorInfo_USCOREgetTextResponse resp2;
                if (!(soaprc = soap_call___vbox__IVirtualBoxErrorInfo_USCOREgetText(&soap,
                                                                                    pcszArgEndpoint,
                                                                                    NULL,
                                                                                    &req2,
                                                                                    &resp2)))
                {
                    std::cout << "ErrorInfo Text:       " << resp2.returnval << "\n";

                    _vbox__IVirtualBoxErrorInfo_USCOREgetNext req3;
                    req3._USCOREthis = argv[ap + 1];
                    _vbox__IVirtualBoxErrorInfo_USCOREgetNextResponse resp3;
                    if (!(soaprc = soap_call___vbox__IVirtualBoxErrorInfo_USCOREgetNext(&soap,
                                                                                        pcszArgEndpoint,
                                                                                        NULL,
                                                                                        &req3,
                                                                                        &resp3)))
                        std::cout << "Next ErrorInfo:       " << resp3.returnval << "\n";
                }
            }
        }
    }
    else if (!strcmp(pcszMode, "release"))
    {
        if (argc < 2 + ap)
            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
        else
        {
            _vbox__IManagedObjectRef_USCORErelease req;
            req._USCOREthis = argv[ap + 1];
            _vbox__IManagedObjectRef_USCOREreleaseResponse resp;
            if (!(soaprc = soap_call___vbox__IManagedObjectRef_USCORErelease(&soap,
                                                                  pcszArgEndpoint,
                                                                  NULL,
                                                                  &req,
                                                                  &resp)))
                std::cout << "Managed object reference " << req._USCOREthis << " released.\n";
        }
    }
    else
        std::cout << "Unknown mode parameter \"" << pcszMode << "\".\n";

    if (soaprc)
    {
        if (    (soap.fault)
             && (soap.fault->detail)
           )
        {
            // generic fault message whether the fault is known or not
            std::cerr << "Generic fault message:\n";
            soap_print_fault(&soap, stderr); // display the SOAP fault message on the stderr stream

            if (soap.fault->detail->vbox__InvalidObjectFault)
            {
                std::cerr << "Bad object ID: " << soap.fault->detail->vbox__InvalidObjectFault->badObjectID << "\n";
            }
            else if (soap.fault->detail->vbox__RuntimeFault)
            {
                std::cerr << "Result code:   0x" << std::hex << soap.fault->detail->vbox__RuntimeFault->resultCode << "\n";
                std::cerr << "ErrorInfo:     " << soap.fault->detail->vbox__RuntimeFault->returnval << "\n";
            }
        }
        else
        {
            std::cerr << "Invalid fault data, fault message:\n";
            soap_print_fault(&soap, stderr); // display the SOAP fault message on the stderr stream
        }
    }

    soap_destroy(&soap); // delete deserialized class instances (for C++ only)
    soap_end(&soap); // remove deserialized data and clean up
    soap_done(&soap); // detach the gSOAP environment

    return soaprc;
}
示例#11
0
/**
 * Do the delegation
 * @param handle     The handle
 * @param url        The delegation endpoint
 * @param err_buffer Used to build the error string
 * @return NULL on failure, or an allocated string with the delegation ID
 */
static char *htext_delegate(htext_handle *handle, char *url, char *err_buffer)
{
  char                               *delegation_id = NULL;
  char                               *reqtxt  = NULL, *certtxt = NULL;
  char                               *keycert = NULL;
  struct soap                        *soap_get = NULL, *soap_put = NULL;
  struct tns__getNewProxyReqResponse  getNewProxyReqResponse;
  char                               *ucert = NULL, *ukey = NULL, *capath = NULL;
  int                                 lifetime;

  /* Get from the handle */
  ucert    = GETSTR(handle, HTEXTOP_USERCERTIFICATE);
  ukey     = GETSTR(handle, HTEXTOP_USERPRIVKEY);
  capath   = GETSTR(handle, HTEXTOP_CAPATH);
  lifetime = GETINT(handle, HTEXTOP_PROXYLIFE);

  /* Only one is needed if they are the same */
  if (ucert && !ukey) ukey  = ucert;
  if (!ucert && ukey) ucert = ukey;

  /* Cert and key need to be in the same file */
  if (strcmp(ucert, ukey) == 0) {
    keycert = strdup(ucert);
  }
  else {
    FILE *ifp, *ofp;
    int   fd;
    char  c;

    keycert = strdup("/tmp/.XXXXXX");

    fd = mkstemp(keycert);
    ofp = fdopen(fd, "w");

    ifp = fopen(ukey, "r");
    while ((c = fgetc(ifp)) != EOF) fputc(c, ofp);
    fclose(ifp);

    ifp = fopen(ukey, "r");
    while ((c = fgetc(ifp)) != EOF) fputc(c, ofp);
    fclose(ifp);

    fclose(ofp);
  }

  /* Initialize SSL */
  ERR_load_crypto_strings ();
  OpenSSL_add_all_algorithms();

  /* Request a new delegation ID */
  soap_get = soap_new();

  if (soap_ssl_client_context(soap_get, SOAP_SSL_DEFAULT, keycert, "",
                              NULL, capath, NULL) == 0) {
    soap_call_tns__getNewProxyReq(soap_get,
                                  url,
                                  "http://www.gridsite.org/namespaces/delegation-1",
                                  &getNewProxyReqResponse);

    if(soap_get->error == 0) {
      reqtxt        = getNewProxyReqResponse.getNewProxyReqReturn->proxyRequest;
      delegation_id = strdup(getNewProxyReqResponse.getNewProxyReqReturn->delegationID);

      /* Generate proxy */
      if (GRSTx509MakeProxyCert(&certtxt, stderr, reqtxt,
                                ucert, ukey, lifetime) == GRST_RET_OK) {
        /* Submit the proxy */
        soap_put = soap_new();

        if (soap_ssl_client_context(soap_put, SOAP_SSL_DEFAULT, keycert, "",
                              NULL, capath, NULL) == 0) {
            soap_call_tns__putProxy(soap_put,
                          url,
                          "http://www.gridsite.org/namespaces/delegation-1",
                          delegation_id, certtxt, NULL);
            if (soap_put->error) {
              /* Could not PUT */
#ifndef NO_SOAP_SPRINT
              soap_sprint_fault(soap_put, err_buffer, sizeof(err_buffer));
              htext_error(handle, err_buffer);
#else
              soap_print_fault(soap_put, stderr);
              handle->status = HTEXTS_FAILED;
#endif
            }
        }
        else { /* soap_put ssl error */
#ifndef NO_SOAP_SPRINT
          soap_sprint_fault(soap_put, err_buffer, sizeof(err_buffer));
          htext_error(handle, err_buffer);
#else
          soap_print_fault(soap_put, stderr);
          handle->status = HTEXTS_FAILED;
#endif
        }

        soap_free(soap_put);
      }
      else {
        htext_error(handle, "Could not generate the proxy");
      }
    }
    else { /* Could not get ID */
#ifndef NO_SOAP_SPRINT
      soap_sprint_fault(soap_get, err_buffer, sizeof(err_buffer));
      htext_error(handle, err_buffer);
#else
      soap_print_fault(soap_get, stderr);
      handle->status = HTEXTS_FAILED;
#endif
    }
  }
  else { /* soap_get ssl error */
#ifndef NO_SOAP_SPRINT
    soap_sprint_fault(soap_get, err_buffer, sizeof(err_buffer));
    htext_error(handle, err_buffer);
#else
    soap_print_fault(soap_put, stderr);
    handle->status = HTEXTS_FAILED;
#endif
  }

  /* Clean soap_get */
  soap_free(soap_get);
  free(keycert);
  free(certtxt);
  
  /* Return delegation ID */
  return delegation_id;
}
示例#12
0
int main(int argc, char **argv)
{
	if (argc < 4)
	{ fprintf(stderr, "Usage: [add|sub|mul|div|pow] num num\n");
		exit(0);
	}


	double a, b, result;
	a = strtod(argv[2], NULL);
	b = strtod(argv[3], NULL);


	calcProxy calc;
	calc.soap_endpoint = server;

#ifdef WITH_OPENSSL

	soap_ssl_init();

	if (soap_ssl_client_context(&calc,
								//SOAP_SSL_DEFAULT,	/* use SOAP_SSL_DEFAULT in production code, we don't want the host name checks since these will change from machine to machine */
								SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK,	/* use SOAP_SSL_DEFAULT in production code, we don't want the host name checks since these will change from machine to machine */
								NULL, 		/* keyfile: required only when client must authenticate to server (see SSL docs on how to obtain this file) */
								NULL, 		/* password to read the keyfile */
								"cacert.pem",	/* optional cacert file to store trusted certificates, use cacerts.pem for all public certificates issued by common CAs */
								NULL,		/* optional capath to directory with trusted certificates */
								NULL		/* if randfile!=NULL: use a file with random data to seed randomness */
								))
	{
		soap_print_fault(&calc, stderr);
		exit(1);
	}

	calc.connect_timeout = 60;	/* try to connect for 1 minute */
	calc.send_timeout = calc.recv_timeout = 30;	/* if I/O stalls, then timeout after 30 seconds */

#endif



	switch (*argv[1])
	{
	case 'a':
		printf("start add \n");
		calc.add(a, b, &result);
		printf("stop add \n");
		break;
	case 's':
		calc.sub(a, b, &result);
		break;
	case 'm':
		calc.mul(a, b, &result);
		break;
	case 'd':
		calc.div(a, b, &result);
		break;
	case 'p':
		calc.pow(a, b, &result);
		break;
	default:
		fprintf(stderr, "Unknown command\n");
		exit(0);
	}


	if (calc.error){
		printf("soap_stream_fault \n", result);
		calc.soap_stream_fault(std::cerr);
	}
	else{
		printf("result = %g\n", result);
	}


	return 0;
}