ua_services_securechannel.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "ua_services.h"
  2. UA_Int32 Service_OpenSecureChannel(SL_Channel *channel, const UA_OpenSecureChannelRequest* request, UA_OpenSecureChannelResponse* response) {
  3. if (request->clientProtocolVersion != channel->tlConnection->remoteConf.protocolVersion) {
  4. printf("SL_processMessage - error protocol version \n");
  5. //TODO ERROR_Bad_ProtocolVersionUnsupported
  6. }
  7. UA_UInt32 retval = UA_SUCCESS;
  8. switch (request->requestType) {
  9. case UA_SECURITYTOKEN_ISSUE:
  10. if (channel->connectionState == connectionState_ESTABLISHED) {
  11. printf("SL_processMessage - multiple security token request");
  12. //TODO return ERROR
  13. retval = UA_ERROR;
  14. break;
  15. }
  16. printf("SL_processMessage - TODO: create new token for a new SecureChannel\n");
  17. // SL_createNewToken(connection);
  18. break;
  19. case UA_SECURITYTOKEN_RENEW:
  20. if (channel->connectionState == connectionState_CLOSED) {
  21. printf("SL_processMessage - renew token request received, but no secureChannel was established before");
  22. //TODO return ERROR
  23. retval = UA_ERROR;
  24. break;
  25. }
  26. printf("TODO: create new token for an existing SecureChannel\n");
  27. break;
  28. }
  29. switch (request->securityMode) {
  30. case UA_SECURITYMODE_INVALID:
  31. channel->remoteNonce.data = UA_NULL;
  32. channel->remoteNonce.length = -1;
  33. printf("SL_processMessage - client demands no security \n");
  34. break;
  35. case UA_SECURITYMODE_SIGN:
  36. printf("SL_processMessage - client demands signed \n");
  37. //TODO check if senderCertificate and ReceiverCertificateThumbprint are present
  38. break;
  39. case UA_SECURITYMODE_SIGNANDENCRYPT:
  40. printf("SL_processMessage - client demands signed & encrypted \n");
  41. //TODO check if senderCertificate and ReceiverCertificateThumbprint are present
  42. break;
  43. }
  44. channel->connectionState = connectionState_ESTABLISHED;
  45. if (request->requestHeader.returnDiagnostics != 0) {
  46. printf("SL_openSecureChannel - diagnostics demanded by the client\n");
  47. printf("SL_openSecureChannel - retrieving diagnostics not implemented!\n");
  48. //TODO fill with demanded information part 4, 7.8 - Table 123
  49. response->responseHeader.serviceDiagnostics.encodingMask = 0;
  50. } else {
  51. response->responseHeader.serviceDiagnostics.encodingMask = 0;
  52. }
  53. response->serverProtocolVersion = channel->tlConnection->localConf.protocolVersion;
  54. response->securityToken.channelId = channel->securityToken.secureChannelId;
  55. response->securityToken.tokenId = channel->securityToken.tokenId;
  56. response->securityToken.revisedLifetime = channel->securityToken.revisedLifetime;
  57. UA_ByteString_copy(&(channel->localNonce), &(response->serverNonce));
  58. return retval;
  59. }
  60. UA_Int32 Service_CloseSecureChannel(SL_Channel *channel, const UA_CloseSecureChannelRequest *request, UA_CloseSecureChannelResponse *response) {
  61. // 62451 Part 6 Chapter 7.1.4 - The server does not send a CloseSecureChannel response
  62. channel->connectionState = connectionState_CLOSE;
  63. return UA_SUCCESS;
  64. }