server_basic128rsa15.c 2.1 KB

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