server_basic128rsa15.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. #include <ua_server.h>
  4. #include <ua_config_default.h>
  5. #include <ua_log_stdout.h>
  6. #include <ua_securitypolicies.h>
  7. #include <ua_client_highlevel.h>
  8. #include "common.h"
  9. #include <signal.h>
  10. UA_Boolean running = true;
  11. static void stopHandler(int sig) {
  12. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "received ctrl-c");
  13. running = false;
  14. }
  15. int main(int argc, char* argv[]) {
  16. signal(SIGINT, stopHandler);
  17. signal(SIGTERM, stopHandler);
  18. if(argc < 3) {
  19. UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
  20. "Missing arguments. Arguments are "
  21. "<server-certificate.der> <private-key.der> "
  22. "[<trustlist1.crl>, ...]");
  23. return 1;
  24. }
  25. /* Load certificate and private key */
  26. UA_ByteString certificate = loadFile(argv[1]);
  27. UA_ByteString privateKey = loadFile(argv[2]);
  28. /* Load the trustlist */
  29. size_t trustListSize = 0;
  30. if(argc > 3)
  31. trustListSize = (size_t)argc-3;
  32. UA_STACKARRAY(UA_ByteString, trustList, trustListSize);
  33. for(size_t i = 0; i < trustListSize; i++)
  34. trustList[i] = loadFile(argv[i+3]);
  35. /* Loading of a revocation list currently unsupported */
  36. UA_ByteString *revocationList = NULL;
  37. size_t revocationListSize = 0;
  38. UA_ServerConfig *config =
  39. UA_ServerConfig_new_basic128rsa15(4840, &certificate, &privateKey,
  40. trustList, trustListSize,
  41. revocationList, revocationListSize);
  42. UA_ByteString_clear(&certificate);
  43. UA_ByteString_clear(&privateKey);
  44. for(size_t i = 0; i < trustListSize; i++)
  45. UA_ByteString_clear(&trustList[i]);
  46. if(!config) {
  47. UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
  48. "Could not create the server config");
  49. return 1;
  50. }
  51. UA_Server *server = UA_Server_new(config);
  52. UA_StatusCode retval = UA_Server_run(server, &running);
  53. UA_Server_delete(server);
  54. UA_ServerConfig_delete(config);
  55. return (int)retval;
  56. }