Exemple #1
0
int main(int argc, char **argv)
{ struct soap *soap = soap_new();
  const char *endpoint;
  matrix a(soap, 3); // matrix with 3 rows created in current soap env.
  // set up matrix by specifying non-zero elements only (this is optional)
  a[1].resize(1,2); // 2-element vector indexed from 1 to 2
  a[1][1] = 2;
  a[1][2] = 1;
  a[2].resize(1,3); // 3-element vector
  a[2][1] = 1;
  a[2][2] = 2;
  a[2][3] = 1;
  a[3].resize(2,3); // 2-element vector indexed from 2 to 3
  a[3][2] = 1;
  a[3][3] = 2;
  cout << "* Demonstration example *" << endl;
  cout << "Matrix:" << endl;
  a.print();
  vector b(soap, 3);
  b[1] = 1;
  b[2] = 2;
  b[3] = 3;
  cout << "Vector:" << endl;
  b.print();
  vector x(soap);
  if (argc < 2)
    endpoint = luserver;
  else
    endpoint = argv[1];
  /* solve ax=b */
  if (soap_call_ns1__lusol(soap, endpoint, "", &a, &b, &x))
  { soap_print_fault(soap, stderr);
    soap_print_fault_location(soap, stderr);
  }
  else
  { cout << "Solution vector from service:" << endl;
    x.print();
  }
  matrix a1(soap);
  if (soap_call_ns1__luinv(soap, endpoint, "", &a, &a1))
  { soap_print_fault(soap, stderr);
    soap_print_fault_location(soap, stderr);
  }
  else
  { cout << "Inverse matrix matrix from service:" << endl;
    a1.print();
  }
  soap_destroy(soap);
  soap_end(soap);
  free(soap);
  return 0;
}
int main(int argc, char **argv)
{ struct soap *soap = soap_new();
  float q;
  if (argc <= 2)
  { soap->user = soap_new(); // pass a new gSOAP environment which we need to make server-side client calls
    soap_serve(soap);	// serve request
    soap_destroy((struct soap*)soap->user);
    soap_end((struct soap*)soap->user);
    soap_done((struct soap*)soap->user);
    free(soap->user);
    soap->user = NULL;
  }
  else if (soap_call_ns3__getQuote(soap, endpoint, NULL, argv[1], argv[2], q) == 0)
    printf("\nCompany %s: %f (%s)\n", argv[1], q, argv[2]);
  else
  { soap_print_fault(soap, stderr);
    soap_print_fault_location(soap, stderr);
  }
  soap_destroy(soap);
  soap_end(soap);
  soap_done(soap);
  free(soap);
  return 0;
}
Exemple #3
0
int main(int argc, char **argv)
{ struct soap *soap;
  int server = 0;
  int text = 0;
  int port = 0;
  FILE *fd;
  double result;
  char *user;
  int runs = 1;
  /* create context */
  soap = soap_new();
  /* register wsse plugin */
  soap_register_plugin_arg(soap, soap_wsse, (void*)token_handler);
  /* options */
  if (argc >= 2)
  { if (strchr(argv[1], 'c'))
      soap_set_omode(soap, SOAP_IO_CHUNK);
    else if (strchr(argv[1], 'y'))
      soap_set_omode(soap, SOAP_IO_STORE);
    if (strchr(argv[1], 'i'))
      soap_set_omode(soap, SOAP_XML_INDENT);
    if (strchr(argv[1], 'n'))
      soap_set_omode(soap, SOAP_XML_CANONICAL);
    if (strchr(argv[1], 'a'))
      aes = 1;
    if (strchr(argv[1], 'o'))
      oaep = 1;
    if (strchr(argv[1], 'd'))
      sym = 1;
    if (strchr(argv[1], 'e'))
      enc = 1;
    if (strchr(argv[1], 'f'))
      addenc = 1;
    /* if (strchr(argv[1], 'F'))
      addenca = 1; */
    if (strchr(argv[1], 'h'))
      hmac = 1;
    if (strchr(argv[1], 'k'))
      nokey = 1;
    if (strchr(argv[1], 's'))
      server = 1;
    if (strchr(argv[1], 't'))
      text = 1;
    if (strchr(argv[1], 'g'))
      addsig = 1;
    if (strchr(argv[1], 'b'))
      nobody = 1;
    if (strchr(argv[1], 'x'))
      nohttp = 1;
    if (strchr(argv[1], 'z'))
      soap_set_mode(soap, SOAP_ENC_ZLIB);
    if (isdigit(argv[1][strlen(argv[1])-1]))
    { runs = argv[1][strlen(argv[1])-1] - '0';
      soap_set_mode(soap, SOAP_IO_KEEPALIVE);
    }
  }
  /* soap->actor = "..."; */ /* set only when required */
  user = getenv("USER");
  if (!user)
    user = "******";
  /* read RSA private key for signing */
  if ((fd = fopen("server.pem", "r")))
  { rsa_privk = PEM_read_PrivateKey(fd, NULL, NULL, (void*)"password");
    fclose(fd);
    if (!rsa_privk)
    { fprintf(stderr, "Could not read private RSA key from server.pem\n");
      exit(1);
    }
  }
  else
    fprintf(stderr, "Could not read server.pem\n");
  /* read certificate (more efficient is to keep certificate in memory)
     to obtain public key for encryption and signature verification */
  if ((fd = fopen("servercert.pem", "r")))
  { cert = PEM_read_X509(fd, NULL, NULL, NULL);
    fclose(fd);
    if (!cert)
    { fprintf(stderr, "Could not read certificate from servercert.pem\n");
      exit(1);
    }
  }
  else
    fprintf(stderr, "Could not read server.pem\n");
  rsa_pubk = X509_get_pubkey(cert);
  if (!rsa_pubk)
  { fprintf(stderr, "Could not get public key from certificate\n");
    exit(1);
  }
  /* port argument */
  if (argc >= 3)
    port = atoi(argv[2]);
  /* need cacert to verify certificates with CA (cacert.pem for testing and
     cacerts.pem for production, which contains the trusted CA certificates) */
  soap->cafile = "cacert.pem";
  /* server or client/ */
  if (server)
  { if (port)
    { /* stand-alone server serving messages over port */
      if (!soap_valid_socket(soap_bind(soap, NULL, port, 100)))
      { soap_print_fault(soap, stderr);
        exit(1);
      }
      printf("Server started at port %d\n", port);
      while (soap_valid_socket(soap_accept(soap)))
      { if (hmac)
          soap_wsse_verify_auto(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key));
        else if (nokey)
          soap_wsse_verify_auto(soap, SOAP_SMD_VRFY_RSA_SHA1, rsa_pubk, 0);
        else
          soap_wsse_verify_auto(soap, SOAP_SMD_NONE, NULL, 0);
        if (sym)
        { if (aes)
            soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_AES256_CBC, aes_key, sizeof(aes_key));
	  else
	    soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_DES_CBC, des_key, sizeof(des_key));
        }
        else if (enc)
          soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0);
        if (soap_serve(soap))
        { soap_wsse_delete_Security(soap);
          soap_print_fault(soap, stderr);
          soap_print_fault_location(soap, stderr);
        }
	soap_destroy(soap);
	soap_end(soap);
      }
      soap_print_fault(soap, stderr);
      exit(1);
    }
    else
    { /* CGI-style server serving messages over stdin/out */
      if (hmac)
        soap_wsse_verify_auto(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key));
      else if (nokey)
        soap_wsse_verify_auto(soap, SOAP_SMD_VRFY_RSA_SHA1, rsa_pubk, 0);
      else
        soap_wsse_verify_auto(soap, SOAP_SMD_NONE, NULL, 0);
      if (sym)
      { if (aes)
          soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_AES256_CBC, aes_key, sizeof(aes_key));
	else
	  soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_DES_CBC, des_key, sizeof(des_key));
      }
      else if (enc)
        soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0);
      if (soap_serve(soap))
      { soap_wsse_delete_Security(soap);
        soap_print_fault(soap, stderr);
        soap_print_fault_location(soap, stderr);
      }
      soap_destroy(soap);
      soap_end(soap);
    }
  }
  else /* client */
  { int run;
    char endpoint[80];
    /* ns1:test data */
    struct ns1__add a;
    struct ns1__sub b;
    a.a = 123;
    a.b = 456;
    b.a = 789;
    b.b = -99999;
    /* client sending messages to stdout or over port */
    if (port)
      sprintf(endpoint, "http://localhost:%d", port);
    else if (nohttp)
      strcpy(endpoint, "");
    else
      strcpy(endpoint, "http://");

    for (run = 0; run < runs; run++)
    {

    /* message lifetime of 60 seconds */
    soap_wsse_add_Timestamp(soap, "Time", 60);
    /* add user name with text or digest password */
    if (text)
      soap_wsse_add_UsernameTokenText(soap, "User", user, "userPass");
    else
      soap_wsse_add_UsernameTokenDigest(soap, "User", user, "userPass");
    if (sym)
    { if (aes)
      { /* symmetric encryption with AES */
        soap_wsse_add_EncryptedData_KeyInfo_KeyName(soap, "My AES Key");
        if (soap_wsse_encrypt_body(soap, SOAP_MEC_ENC_AES256_CBC, aes_key, sizeof(aes_key)))
          soap_print_fault(soap, stderr);
        soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_AES256_CBC, aes_key, sizeof(aes_key));
      }
      else
      { /* symmetric encryption with DES */
        soap_wsse_add_EncryptedData_KeyInfo_KeyName(soap, "My DES Key");
        if (soap_wsse_encrypt_body(soap, SOAP_MEC_ENC_DES_CBC, des_key, sizeof(des_key)))
          soap_print_fault(soap, stderr);
        soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_DES_CBC, des_key, sizeof(des_key));
      }
    }
    else if (addenc || addenca)
    { /* RSA encryption of the <ns1:add> element */
      const char *SubjectKeyId = NULL; /* set to non-NULL to use SubjectKeyIdentifier in Header rather than a full cert key */
      /* MUST set wsu:Id of the elements to encrypt */
      if (addenc) /* encrypt element <ns1:add> */
      { soap_wsse_set_wsu_id(soap, "ns1:add");
        if (soap_wsse_add_EncryptedKey_encrypt_only(soap, SOAP_MEC_ENV_ENC_DES_CBC, "Cert", cert, SubjectKeyId, NULL, NULL, "ns1:add"))
          soap_print_fault(soap, stderr);
      }
      else /* encrypt element <a> */
      { soap_wsse_set_wsu_id(soap, "a");
        if (soap_wsse_add_EncryptedKey_encrypt_only(soap, SOAP_MEC_ENV_ENC_DES_CBC, "Cert", cert, SubjectKeyId, NULL, NULL, "a"))
          soap_print_fault(soap, stderr);
      }
      soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0);
    }
    else if (enc)
    { /* RSA encryption of the SOAP Body */
      const char *SubjectKeyId = NULL; /* set to non-NULL to use SubjectKeyIdentifier in Header rather than a full cert key */
      if (oaep)
      { if (soap_wsse_add_EncryptedKey(soap, SOAP_MEC_ENV_ENC_AES256_CBC | SOAP_MEC_OAEP, "Cert", cert, SubjectKeyId, NULL, NULL))
          soap_print_fault(soap, stderr);
      }
      else if (aes)
      { if (soap_wsse_add_EncryptedKey(soap, SOAP_MEC_ENV_ENC_AES256_CBC, "Cert", cert, SubjectKeyId, NULL, NULL))
          soap_print_fault(soap, stderr);
      }
      else
      { if (soap_wsse_add_EncryptedKey(soap, SOAP_MEC_ENV_ENC_DES_CBC, "Cert", cert, SubjectKeyId, NULL, NULL))
          soap_print_fault(soap, stderr);
      }
      soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0);
    }
    if (hmac)
    { /* symmetric signature */
      if (nobody)
        soap_wsse_sign(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key));
      else
        soap_wsse_sign_body(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key));
      /* WS-SecureConversation contect token */
      soap_wsse_add_SecurityContextToken(soap, "SCT", contextId);
    }
    else
    { if (nokey)
        soap_wsse_add_KeyInfo_KeyName(soap, "MyKey");
      else
      { soap_wsse_add_BinarySecurityTokenX509(soap, "X509Token", cert);
        soap_wsse_add_KeyInfo_SecurityTokenReferenceX509(soap, "#X509Token");
      }
      if (nobody || addsig) /* do not sign body */
        soap_wsse_sign(soap, SOAP_SMD_SIGN_RSA_SHA1, rsa_privk, 0);
      else
        soap_wsse_sign_body(soap, SOAP_SMD_SIGN_RSA_SHA256, rsa_privk, 0);
    }
    /* enable automatic signature verification of server responses */
    if (hmac)
      soap_wsse_verify_auto(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key));
    else if (nokey)
      soap_wsse_verify_auto(soap, SOAP_SMD_VRFY_RSA_SHA1, rsa_pubk, 0);
    else
      soap_wsse_verify_auto(soap, SOAP_SMD_NONE, NULL, 0);
    /* sign the response message in unsigned body? If so, set wsu:Id */
    if (addsig)
    { soap_wsse_set_wsu_id(soap, "ns1:add");
      soap_wsse_sign_only(soap, "User ns1:add");
    }
    /* invoke the server. You can choose add, sub, mul, or div operations
     * that show different security aspects (intentional message rejections)
     * for demonstration purposes (see server operations below) */
    if (!soap_call_ns1__add(soap, endpoint, NULL, 1.0, 2.0, &result))
    { if (!soap_wsse_verify_Timestamp(soap))
      { const char *servername = soap_wsse_get_Username(soap);
        if (servername
	 && !strcmp(servername, "server")
         && !soap_wsse_verify_Password(soap, "serverPass"))
          printf("Result = %g\n", result);
        else
	{ fprintf(stderr, "Server authentication failed\n");
          soap_print_fault(soap, stderr);
        }
      }
      else
      { fprintf(stderr, "Server response expired\n");
        soap_print_fault(soap, stderr);
      }
    }
    else
    { soap_print_fault(soap, stderr);
      soap_print_fault_location(soap, stderr);
    }
    /* clean up security header */
    soap_wsse_delete_Security(soap);
    /* disable soap_wsse_verify_auto */
    soap_wsse_verify_done(soap);

  } /* run */

  }
  /* clean up keys */
  if (rsa_privk)
    EVP_PKEY_free(rsa_privk);
  if (rsa_pubk)
    EVP_PKEY_free(rsa_pubk);
  if (cert)
    X509_free(cert);
  /* clean up gSOAP engine */
  soap_destroy(soap);
  soap_end(soap);
  soap_done(soap);
  free(soap);
  /* done */
  return 0;
}
Exemple #4
0
int main(int argc, char **argv)
{
  struct soap *soap = soap_new1(SOAP_XML_INDENT);

  soap_register_plugin(soap, soap_wsa);

  if (argc < 2)
  { /* no args: act as CGI service over stdin/out */
    if (soap_serve(soap))
    { soap_print_fault(soap, stderr);
      soap_print_fault_location(soap, stderr);
    }
  }
  else
  {
    int port = atoi(argv[1]);

    if (port)
    { /* stand-alone server serving messages over port */
      soap->bind_flags = SO_REUSEADDR;
      if (!soap_valid_socket(soap_bind(soap, NULL, port, 100)))
      { soap_print_fault(soap, stderr);
        exit(1);
      }
      printf("Server is running\n");
      while (soap_valid_socket(soap_accept(soap)))
      { if (soap_serve(soap))
        { soap_print_fault(soap, stderr);
          soap_print_fault_location(soap, stderr);
        }
        printf("Request served\n");
        soap_destroy(soap);
        soap_end(soap);
      }
    }
    else
    { /* client */
      struct ns__wsademoResult res;

      soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction);
      if (argc >= 3)
      { if (strchr(argv[2], 'f'))
          soap_wsa_add_From(soap, FromAddress);
        if (strchr(argv[2], 'r'))
          soap_wsa_add_ReplyTo(soap, ReplyToAddress);
        if (strchr(argv[2], 'n'))
        {
#ifdef SOAP_WSA_2005
          soap_wsa_add_NoReply(soap);
#else
          printf("'NoReply' feature not available with WS-Addressing 2003/2004\n");
#endif
        }
        if (strchr(argv[2], 'e'))
          soap_wsa_add_FaultTo(soap, FaultToAddress);
      }
      if (soap_call_ns__wsademo(soap, ToAddress, NULL, argv[1], &res))
      {
#ifdef SOAP_WSA_2005
        wsa5__FaultCodesType fault;
	const char *info;

        if (soap->error == 202)	/* HTTP ACCEPTED */
          printf("Request was accepted\n");
        else if (soap_wsa_check_fault(soap, &fault, &info))
	{ switch (fault)
	  { case wsa5__EndpointUnavailable:
	      fprintf(stderr, "Server %s is currently not available.\n", info?info:"");
	      break;
            default:
	      fprintf(stderr, "A wsa fault %d occurred:\n", (int)fault);
	      soap_print_fault(soap, stderr);
	      break;
	  }
	}
        else
	  soap_print_fault(soap, stderr);
#else
        if (soap->error == 202)	/* HTTP ACCEPTED */
          printf("Request was accepted\n");
        else
	  soap_print_fault(soap, stderr);
#endif
      }
      else if (res.out)
        printf("Result = %s\n", res.out);
    }
  }
  soap_destroy(soap);
  soap_end(soap);
  soap_done(soap);
  free(soap);
  return 0;
}
Exemple #5
0
int main(int argc, char **argv)
{ struct soap *soap;
  xsd__string s;
  xsd__boolean b;
  struct ArrayOfString a;
  if (argc < 4)
  { fprintf(stderr, "Usage:\tuddi find <business> <service>\n\tuddi list <business> <service>\n\tuddi query <business> <service> <query>\n\tuddi add <business> <service> <desc> <accesspoint> <acpdesc> <login> <passwd>\n\tuddi remove <business> <service> <login> <passwd>\n\tuddi delete <business> <service> <accesspoint> <login> <passwd>\n");
    fprintf(stderr, "For more info: http://erwin.dstc.edu.au/UDDIProxyService");
    return 0;
  }
  soap = soap_new();
  switch (tolower(*argv[1]))
  { case 'f':
      if (!soap_call_ns__FindServiceAccessPoint(soap, "http://erwin.dstc.edu.au/UDDIProxyService/UDDIProxy.asmx", "http://dstc.edu.au/FindServiceAccessPoint", argv[1], argv[2], UDDITest, s))
        printf("Access point = %s\n", s);
      break;
    case 'l':
      if (!soap_call_ns__FindServiceAccessPoints(soap, "http://erwin.dstc.edu.au/UDDIProxyService/UDDIProxy.asmx", "http://dstc.edu.au/FindServiceAccessPoints", argv[1], argv[2], UDDITest, a))
        for (int i = 0; i < a.__size; i++)
	  printf("Access point = %s\n", a.__ptr[i]);
      break;
    case 'q':
      if (argc < 5)
      { fprintf(stderr, "uddi query: missing argument\n");
        return -1;
      }
      if (!soap_call_ns__FindServiceAccessPointsQuery(soap, "http://erwin.dstc.edu.au/UDDIProxyService/UDDIProxy.asmx", "http://dstc.edu.au/FindServiceAccessPointsQuery", argv[1], argv[2], argv[3], UDDITest, a))
        for (int i = 0; i < a.__size; i++)
	  printf("Access point = %s\n", a.__ptr[i]);
      break;
    case 'a':
      if (argc < 9)
      { fprintf(stderr, "uddi add: missing argument(s)\n");
        return -1;
      }
      if (!soap_call_ns__AddService(soap, "http://erwin.dstc.edu.au/UDDIProxyService/UDDIProxy.asmx", "http://dstc.edu.au/AddService", argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], UDDITest, b))
        if (b)
	  printf("Service added\n");
        else
	  printf("Service could not be added\n");
      break;
    case 'r':
      if (argc < 6)
      { fprintf(stderr, "uddi remove: missing argument(s)\n");
        return -1;
      }
      if (!soap_call_ns__RemoveService(soap, "http://erwin.dstc.edu.au/UDDIProxyService/UDDIProxy.asmx", "http://dstc.edu.au/RemoveService", argv[1], argv[2], argv[3], argv[4], UDDITest, b))
        if (b)
	  printf("Service removed\n");
        else
	  printf("Service could not be removed\n");
      break;
    case 'd':
      if (argc < 7)
      { fprintf(stderr, "uddi delete: missing argument(s)\n");
        return -1;
      }
      if (!soap_call_ns__RemoveServiceAccessPoint(soap, "http://erwin.dstc.edu.au/UDDIProxyService/UDDIProxy.asmx", "http://dstc.edu.au/RemoveAccessPointService", argv[1], argv[2], argv[3], argv[4], argv[5], UDDITest, b))
        if (b)
	  printf("Service access point deleted\n");
        else
	  printf("Service access point could not be deleted\n");
      break;
    default:
      fprintf(stderr, "uddi: unknown command '%s'\n", argv[1]);
      return -1;
  }
  if (soap->error)
  { soap_print_fault(soap, stderr);
    soap_print_fault_location(soap, stderr);
  }
  soap_end(soap);
  free(soap);
}