ua_securechannel.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef UA_SECURECHANNEL_H_
  2. #define UA_SECURECHANNEL_H_
  3. #include "queue.h"
  4. #include "ua_types.h"
  5. #include "ua_transport_generated.h"
  6. #include "ua_connection_internal.h"
  7. struct UA_Session;
  8. typedef struct UA_Session UA_Session;
  9. struct SessionEntry {
  10. LIST_ENTRY(SessionEntry) pointers;
  11. UA_Session *session; // Just a pointer. The session is held in the session manager or the client
  12. };
  13. /* For chunked requests */
  14. struct ChunkEntry {
  15. LIST_ENTRY(ChunkEntry) pointers;
  16. UA_UInt32 requestId;
  17. UA_ByteString bytes;
  18. };
  19. /* For chunked responses */
  20. typedef struct {
  21. UA_SecureChannel *channel;
  22. UA_UInt32 requestId;
  23. UA_UInt32 messageType;
  24. UA_UInt16 chunksSoFar;
  25. size_t messageSizeSoFar;
  26. UA_Boolean final;
  27. UA_StatusCode errorCode;
  28. } UA_ChunkInfo;
  29. struct UA_SecureChannel {
  30. UA_MessageSecurityMode securityMode;
  31. UA_ChannelSecurityToken securityToken; // the channelId is contained in the securityToken
  32. UA_ChannelSecurityToken nextSecurityToken; // the channelId is contained in the securityToken
  33. UA_AsymmetricAlgorithmSecurityHeader clientAsymAlgSettings;
  34. UA_AsymmetricAlgorithmSecurityHeader serverAsymAlgSettings;
  35. UA_ByteString clientNonce;
  36. UA_ByteString serverNonce;
  37. UA_UInt32 receiveSequenceNumber;
  38. UA_UInt32 sendSequenceNumber;
  39. UA_Connection *connection;
  40. LIST_HEAD(session_pointerlist, SessionEntry) sessions;
  41. LIST_HEAD(chunk_pointerlist, ChunkEntry) chunks;
  42. };
  43. void UA_SecureChannel_init(UA_SecureChannel *channel);
  44. void UA_SecureChannel_deleteMembersCleanup(UA_SecureChannel *channel);
  45. UA_StatusCode UA_SecureChannel_generateNonce(UA_ByteString *nonce);
  46. void UA_SecureChannel_attachSession(UA_SecureChannel *channel, UA_Session *session);
  47. void UA_SecureChannel_detachSession(UA_SecureChannel *channel, UA_Session *session);
  48. UA_Session * UA_SecureChannel_getSession(UA_SecureChannel *channel, UA_NodeId *token);
  49. UA_StatusCode UA_SecureChannel_sendBinaryMessage(UA_SecureChannel *channel, UA_UInt32 requestId,
  50. const void *content, const UA_DataType *contentType);
  51. void UA_SecureChannel_revolveTokens(UA_SecureChannel *channel);
  52. /**
  53. * Chunking
  54. * -------- */
  55. typedef void
  56. (UA_ProcessMessageCallback)(void *application, UA_SecureChannel *channel,
  57. UA_MessageType messageType, UA_UInt32 requestId,
  58. const UA_ByteString *message);
  59. UA_StatusCode
  60. UA_SecureChannel_processChunks(UA_SecureChannel *channel, const UA_ByteString *chunks,
  61. UA_ProcessMessageCallback callback, void *application);
  62. /**
  63. * Log Helper
  64. * ---------- */
  65. #define UA_LOG_TRACE_CHANNEL(LOGGER, CHANNEL, MSG, ...) \
  66. UA_LOG_TRACE(LOGGER, UA_LOGCATEGORY_SECURECHANNEL, "Connection %i | SecureChannel %i | " MSG, \
  67. ((CHANNEL)->connection ? CHANNEL->connection->sockfd : 0), \
  68. (CHANNEL)->securityToken.channelId, ##__VA_ARGS__);
  69. #define UA_LOG_DEBUG_CHANNEL(LOGGER, CHANNEL, MSG, ...) \
  70. UA_LOG_DEBUG(LOGGER, UA_LOGCATEGORY_SECURECHANNEL, "Connection %i | SecureChannel %i | " MSG, \
  71. ((CHANNEL)->connection ? (CHANNEL)->connection->sockfd : 0), \
  72. (CHANNEL)->securityToken.channelId, ##__VA_ARGS__);
  73. #define UA_LOG_INFO_CHANNEL(LOGGER, CHANNEL, MSG, ...) \
  74. UA_LOG_INFO(LOGGER, UA_LOGCATEGORY_SECURECHANNEL, "Connection %i | SecureChannel %i | " MSG, \
  75. ((CHANNEL)->connection ? (CHANNEL)->connection->sockfd : 0), \
  76. (CHANNEL)->securityToken.channelId, ##__VA_ARGS__);
  77. #define UA_LOG_WARNING_CHANNEL(LOGGER, CHANNEL, MSG, ...) \
  78. UA_LOG_WARNING(LOGGER, UA_LOGCATEGORY_SECURECHANNEL, "Connection %i | SecureChannel %i | " MSG, \
  79. ((CHANNEL)->connection ? (CHANNEL)->connection->sockfd : 0), \
  80. (CHANNEL)->securityToken.channelId, ##__VA_ARGS__);
  81. #define UA_LOG_ERROR_CHANNEL(LOGGER, CHANNEL, MSG, ...) \
  82. UA_LOG_ERROR(LOGGER, UA_LOGCATEGORY_SECURECHANNEL, "Connection %i | SecureChannel %i | " MSG, \
  83. ((CHANNEL)->connection ? (CHANNEL)->connection->sockfd : 0), \
  84. (CHANNEL)->securityToken.channelId, ##__VA_ARGS__);
  85. #define UA_LOG_FATAL_CHANNEL(LOGGER, CHANNEL, MSG, ...) \
  86. UA_LOG_FATAL(LOGGER, UA_LOGCATEGORY_SECURECHANNEL, "Connection %i | SecureChannel %i | " MSG, \
  87. ((CHANNEL)->connection ? (CHANNEL)->connection->sockfd : 0), \
  88. (CHANNEL)->securityToken.channelId, ##__VA_ARGS__);
  89. #endif /* UA_SECURECHANNEL_H_ */