server_basic128rsa15.c 2.1 KB

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