ua_services_securechannel.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 Service_OpenSecureChannel(UA_Server *server, UA_Connection *connection,
  8. const UA_OpenSecureChannelRequest *request,
  9. UA_OpenSecureChannelResponse *response) {
  10. // todo: if(request->clientProtocolVersion != protocolVersion)
  11. if(request->requestType == UA_SECURITYTOKENREQUESTTYPE_ISSUE) {
  12. response->responseHeader.serviceResult =
  13. UA_SecureChannelManager_open(&server->secureChannelManager, connection, request, response);
  14. if(response->responseHeader.serviceResult == UA_STATUSCODE_GOOD) {
  15. UA_LOG_INFO(server->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
  16. "Connection %i | SecureChannel %i | OpenSecureChannel: Opened SecureChannel",
  17. connection->sockfd, response->securityToken.channelId);
  18. } else {
  19. UA_LOG_DEBUG(server->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
  20. "Connection %i | OpenSecureChannel: Opening a SecureChannel failed",
  21. connection->sockfd);
  22. }
  23. } else {
  24. response->responseHeader.serviceResult =
  25. UA_SecureChannelManager_renew(&server->secureChannelManager, connection, request, response);
  26. if(response->responseHeader.serviceResult == UA_STATUSCODE_GOOD) {
  27. UA_LOG_DEBUG(server->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
  28. "Connection %i | SecureChannel %i | OpenSecureChannel: SecureChannel renewed",
  29. connection->sockfd, response->securityToken.channelId);
  30. } else {
  31. UA_LOG_DEBUG(server->config.logger, UA_LOGCATEGORY_SECURECHANNEL,
  32. "Connection %i | OpenSecureChannel: Renewing SecureChannel failed",
  33. connection->sockfd);
  34. }
  35. }
  36. }
  37. /* The server does not send a CloseSecureChannel response */
  38. void Service_CloseSecureChannel(UA_Server *server, UA_SecureChannel *channel) {
  39. UA_LOG_INFO_CHANNEL(server->config.logger, channel, "CloseSecureChannel");
  40. UA_SecureChannelManager_close(&server->secureChannelManager, channel->securityToken.channelId);
  41. }