ua_services_securechannel.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "ua_server_internal.h"
  5. #include "ua_services.h"
  6. #include "ua_securechannel_manager.h"
  7. void
  8. Service_OpenSecureChannel(UA_Server *server, UA_SecureChannel *channel,
  9. const UA_OpenSecureChannelRequest *request,
  10. UA_OpenSecureChannelResponse *response) {
  11. if(request->requestType == UA_SECURITYTOKENREQUESTTYPE_RENEW) {
  12. /* Renew the channel */
  13. response->responseHeader.serviceResult =
  14. UA_SecureChannelManager_renew(&server->secureChannelManager,
  15. channel, request, response);
  16. /* Logging */
  17. if(response->responseHeader.serviceResult == UA_STATUSCODE_GOOD) {
  18. UA_LOG_DEBUG_CHANNEL(server->config.logger, channel,
  19. "SecureChannel renewed");
  20. } else {
  21. UA_LOG_DEBUG_CHANNEL(server->config.logger, channel,
  22. "Renewing SecureChannel failed");
  23. }
  24. return;
  25. }
  26. /* Must be ISSUE or RENEW */
  27. if(request->requestType != UA_SECURITYTOKENREQUESTTYPE_ISSUE) {
  28. response->responseHeader.serviceResult = UA_STATUSCODE_BADINTERNALERROR;
  29. return;
  30. }
  31. /* Open the channel */
  32. response->responseHeader.serviceResult =
  33. UA_SecureChannelManager_open(&server->secureChannelManager, channel,
  34. request, response);
  35. /* Logging */
  36. if(response->responseHeader.serviceResult == UA_STATUSCODE_GOOD) {
  37. UA_LOG_INFO_CHANNEL(server->config.logger, channel,
  38. "Opened SecureChannel");
  39. } else {
  40. UA_LOG_INFO_CHANNEL(server->config.logger, channel,
  41. "Opening a SecureChannel failed");
  42. }
  43. }
  44. /* The server does not send a CloseSecureChannel response */
  45. void
  46. Service_CloseSecureChannel(UA_Server *server, UA_SecureChannel *channel) {
  47. UA_LOG_INFO_CHANNEL(server->config.logger, channel, "CloseSecureChannel");
  48. UA_SecureChannelManager_close(&server->secureChannelManager,
  49. channel->securityToken.channelId);
  50. }