server_basic128rsa15.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <open62541/server.h>
  4. #include <open62541/server_config_default.h>
  5. #include <open62541/plugin/log_stdout.h>
  6. #include <open62541/plugin/securitypolicy.h>
  7. #include <open62541/client_highlevel.h>
  8. #include "common.h"
  9. #include <signal.h>
  10. #include <stdlib.h>
  11. UA_Boolean running = true;
  12. static void stopHandler(int sig) {
  13. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "received ctrl-c");
  14. running = false;
  15. }
  16. int main(int argc, char* argv[]) {
  17. signal(SIGINT, stopHandler);
  18. signal(SIGTERM, stopHandler);
  19. if(argc < 3) {
  20. UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
  21. "Missing arguments. Arguments are "
  22. "<server-certificate.der> <private-key.der> "
  23. "[<trustlist1.crl>, ...]");
  24. return EXIT_FAILURE;
  25. }
  26. /* Load certificate and private key */
  27. UA_ByteString certificate = loadFile(argv[1]);
  28. UA_ByteString privateKey = loadFile(argv[2]);
  29. /* Load the trustlist */
  30. size_t trustListSize = 0;
  31. if(argc > 3)
  32. trustListSize = (size_t)argc-3;
  33. UA_STACKARRAY(UA_ByteString, trustList, trustListSize);
  34. for(size_t i = 0; i < trustListSize; i++)
  35. trustList[i] = loadFile(argv[i+3]);
  36. /* Loading of a revocation list currently unsupported */
  37. UA_ByteString *revocationList = NULL;
  38. size_t revocationListSize = 0;
  39. UA_ServerConfig *config =
  40. UA_ServerConfig_new_basic128rsa15(4840, &certificate, &privateKey,
  41. trustList, trustListSize,
  42. revocationList, revocationListSize);
  43. UA_ByteString_clear(&certificate);
  44. UA_ByteString_clear(&privateKey);
  45. for(size_t i = 0; i < trustListSize; i++)
  46. UA_ByteString_clear(&trustList[i]);
  47. if(!config) {
  48. UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
  49. "Could not create the server config");
  50. return EXIT_FAILURE;
  51. }
  52. UA_Server *server = UA_Server_new(config);
  53. UA_StatusCode retval = UA_Server_run(server, &running);
  54. UA_Server_delete(server);
  55. UA_ServerConfig_delete(config);
  56. return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
  57. }