ua_services_securechannel.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. *
  5. * Copyright 2014-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  6. * Copyright 2014, 2017 (c) Florian Palm
  7. * Copyright 2015 (c) Oleksiy Vasylyev
  8. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  9. * Copyright 2017 (c) Mark Giraud, Fraunhofer IOSB
  10. */
  11. #include "ua_server_internal.h"
  12. #include "ua_services.h"
  13. #include "ua_securechannel_manager.h"
  14. void
  15. Service_OpenSecureChannel(UA_Server *server, UA_SecureChannel *channel,
  16. const UA_OpenSecureChannelRequest *request,
  17. UA_OpenSecureChannelResponse *response) {
  18. if(request->requestType == UA_SECURITYTOKENREQUESTTYPE_RENEW) {
  19. /* Renew the channel */
  20. response->responseHeader.serviceResult =
  21. UA_SecureChannelManager_renew(&server->secureChannelManager,
  22. channel, request, response);
  23. /* Logging */
  24. if(response->responseHeader.serviceResult == UA_STATUSCODE_GOOD) {
  25. UA_LOG_DEBUG_CHANNEL(server->config.logger, channel,
  26. "SecureChannel renewed");
  27. } else {
  28. UA_LOG_DEBUG_CHANNEL(server->config.logger, channel,
  29. "Renewing SecureChannel failed");
  30. }
  31. return;
  32. }
  33. /* Must be ISSUE or RENEW */
  34. if(request->requestType != UA_SECURITYTOKENREQUESTTYPE_ISSUE) {
  35. response->responseHeader.serviceResult = UA_STATUSCODE_BADINTERNALERROR;
  36. return;
  37. }
  38. /* Open the channel */
  39. response->responseHeader.serviceResult =
  40. UA_SecureChannelManager_open(&server->secureChannelManager, channel,
  41. request, response);
  42. /* Logging */
  43. if(response->responseHeader.serviceResult == UA_STATUSCODE_GOOD) {
  44. UA_LOG_INFO_CHANNEL(server->config.logger, channel,
  45. "Opened SecureChannel");
  46. } else {
  47. UA_LOG_INFO_CHANNEL(server->config.logger, channel,
  48. "Opening a SecureChannel failed");
  49. }
  50. }
  51. /* The server does not send a CloseSecureChannel response */
  52. void
  53. Service_CloseSecureChannel(UA_Server *server, UA_SecureChannel *channel) {
  54. UA_LOG_INFO_CHANNEL(server->config.logger, channel, "CloseSecureChannel");
  55. UA_SecureChannelManager_close(&server->secureChannelManager,
  56. channel->securityToken.channelId);
  57. }