ua_services_securechannel.c 3.0 KB

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