ua_services_securechannel.c 2.9 KB

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