opcua_secureChannelLayer.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * opcua_secureChannelLayer.h
  3. *
  4. * Created on: Dec 19, 2013
  5. * Author: opcua
  6. */
  7. #ifndef OPCUA_SECURECHANNELLAYER_H_
  8. #define OPCUA_SECURECHANNELLAYER_H_
  9. #include "opcua.h"
  10. #include "UA_connection.h"
  11. #include "../include/UA_config.h"
  12. static const UA_Int32 SL_HEADER_LENGTH = 0;
  13. /* Enums */
  14. typedef enum
  15. {
  16. UA_SECURITYTOKEN_ISSUE = 0,
  17. UA_SECURITYTOKEN_RENEW = 1
  18. }SecurityTokenRequestType;
  19. typedef enum
  20. {
  21. UA_SECURITYMODE_INVALID = 0,
  22. UA_SECURITYMODE_SIGN = 1,
  23. UA_SECURITYMODE_SIGNANDENCRYPT = 2
  24. } securityMode;
  25. /* Structures */
  26. typedef struct T_SL_Response
  27. {
  28. UA_UInt32 serverProtocolVersion;
  29. SL_ChannelSecurityToken securityToken;
  30. UA_String serverNonce;
  31. }UA_SL_Response;
  32. UA_TYPE_METHOD_PROTOTYPES(UA_SL_Response)
  33. /*** UA_OPCUATcpMessageHeader ***/
  34. /* TCP Header */
  35. typedef struct T_UA_OPCUATcpMessageHeader {
  36. UA_UInt32 messageType;
  37. UA_Byte isFinal;
  38. UA_UInt32 messageSize;
  39. } UA_OPCUATcpMessageHeader;
  40. UA_Int32 UA_OPCUATcpMessageHeader_calcSize(UA_OPCUATcpMessageHeader const * ptr);
  41. UA_Int32 UA_OPCUATcpMessageHeader_encode(UA_OPCUATcpMessageHeader const * src, UA_Int32* pos, char* dst);
  42. UA_Int32 UA_OPCUATcpMessageHeader_decode(char const * src, UA_Int32* pos, UA_OPCUATcpMessageHeader* dst);
  43. /*** UA_OPCUATcpHelloMessage ***/
  44. /* Hello Message */
  45. typedef struct T_UA_OPCUATcpHelloMessage {
  46. UA_UInt32 protocolVersion;
  47. UA_UInt32 receiveBufferSize;
  48. UA_UInt32 sendBufferSize;
  49. UA_UInt32 maxMessageSize;
  50. UA_UInt32 maxChunkCount;
  51. UA_String endpointUrl;
  52. } UA_OPCUATcpHelloMessage;
  53. UA_Int32 UA_OPCUATcpHelloMessage_calcSize(UA_OPCUATcpHelloMessage const * ptr);
  54. UA_Int32 UA_OPCUATcpHelloMessage_encode(UA_OPCUATcpHelloMessage const * src, UA_Int32* pos, char* dst);
  55. UA_Int32 UA_OPCUATcpHelloMessage_decode(char const * src, UA_Int32* pos, UA_OPCUATcpHelloMessage* dst);
  56. /*** UA_OPCUATcpAcknowledgeMessage ***/
  57. /* Acknowledge Message */
  58. typedef struct T_UA_OPCUATcpAcknowledgeMessage {
  59. UA_UInt32 protocolVersion;
  60. UA_UInt32 receiveBufferSize;
  61. UA_UInt32 sendBufferSize;
  62. UA_UInt32 maxMessageSize;
  63. UA_UInt32 maxChunkCount;
  64. } UA_OPCUATcpAcknowledgeMessage;
  65. UA_Int32 UA_OPCUATcpAcknowledgeMessage_calcSize(UA_OPCUATcpAcknowledgeMessage const * ptr);
  66. UA_Int32 UA_OPCUATcpAcknowledgeMessage_encode(UA_OPCUATcpAcknowledgeMessage const * src, UA_Int32* pos, char* dst);
  67. UA_Int32 UA_OPCUATcpAcknowledgeMessage_decode(char const * src, UA_Int32* pos, UA_OPCUATcpAcknowledgeMessage* dst);
  68. /*** UA_SecureConversationMessageHeader ***/
  69. /* Secure Layer Sequence Header */
  70. typedef struct T_UA_SecureConversationMessageHeader {
  71. UA_UInt32 messageType;
  72. UA_Byte isFinal;
  73. UA_UInt32 messageSize;
  74. UA_UInt32 secureChannelId;
  75. } UA_SecureConversationMessageHeader;
  76. UA_Int32 UA_SecureConversationMessageHeader_calcSize(UA_SecureConversationMessageHeader const * ptr);
  77. UA_Int32 UA_SecureConversationMessageHeader_encode(UA_SecureConversationMessageHeader const * src, UA_Int32* pos, char* dst);
  78. UA_Int32 UA_SecureConversationMessageHeader_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageHeader* dst);
  79. /*** UA_AsymmetricAlgorithmSecurityHeader ***/
  80. /* Security Header> */
  81. typedef struct T_UA_AsymmetricAlgorithmSecurityHeader {
  82. UA_ByteString securityPolicyUri;
  83. UA_ByteString senderCertificate;
  84. UA_ByteString receiverCertificateThumbprint;
  85. UA_UInt32 requestId;
  86. } UA_AsymmetricAlgorithmSecurityHeader;
  87. UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_calcSize(UA_AsymmetricAlgorithmSecurityHeader const * ptr);
  88. UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_encode(UA_AsymmetricAlgorithmSecurityHeader const * src, UA_Int32* pos, char* dst);
  89. UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_decode(char const * src, UA_Int32* pos, UA_AsymmetricAlgorithmSecurityHeader* dst);
  90. /*** UA_SymmetricAlgorithmSecurityHeader ***/
  91. /* Secure Layer Symmetric Algorithm Header */
  92. typedef struct T_UA_SymmetricAlgorithmSecurityHeader {
  93. UA_UInt32 tokenId;
  94. } UA_SymmetricAlgorithmSecurityHeader;
  95. UA_Int32 UA_SymmetricAlgorithmSecurityHeader_calcSize(UA_SymmetricAlgorithmSecurityHeader const * ptr);
  96. UA_Int32 UA_SymmetricAlgorithmSecurityHeader_encode(UA_SymmetricAlgorithmSecurityHeader const * src, UA_Int32* pos, char* dst);
  97. UA_Int32 UA_SymmetricAlgorithmSecurityHeader_decode(char const * src, UA_Int32* pos, UA_SymmetricAlgorithmSecurityHeader* dst);
  98. /*** UA_SequenceHeader ***/
  99. /* Secure Layer Sequence Header */
  100. typedef struct T_UA_SequenceHeader {
  101. UA_UInt32 sequenceNumber;
  102. UA_UInt32 requestId;
  103. } UA_SequenceHeader;
  104. UA_Int32 UA_SequenceHeader_calcSize(UA_SequenceHeader const * ptr);
  105. UA_Int32 UA_SequenceHeader_encode(UA_SequenceHeader const * src, UA_Int32* pos, char* dst);
  106. UA_Int32 UA_SequenceHeader_decode(char const * src, UA_Int32* pos, UA_SequenceHeader* dst);
  107. /*** UA_SecureConversationMessageFooter ***/
  108. /* Secure Conversation Message Footer */
  109. typedef struct T_UA_SecureConversationMessageFooter {
  110. UA_Int32 paddingSize;
  111. UA_Byte** padding;
  112. UA_Byte signature;
  113. } UA_SecureConversationMessageFooter;
  114. UA_Int32 UA_SecureConversationMessageFooter_calcSize(UA_SecureConversationMessageFooter const * ptr);
  115. UA_Int32 UA_SecureConversationMessageFooter_encode(UA_SecureConversationMessageFooter const * src, UA_Int32* pos, char* dst);
  116. UA_Int32 UA_SecureConversationMessageFooter_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageFooter* dst);
  117. /*** UA_SecureConversationMessageAbortBody ***/
  118. /* Secure Conversation Message Abort Body */
  119. typedef struct T_UA_SecureConversationMessageAbortBody {
  120. UA_UInt32 error;
  121. UA_String reason;
  122. } UA_SecureConversationMessageAbortBody;
  123. UA_Int32 UA_SecureConversationMessageAbortBody_calcSize(UA_SecureConversationMessageAbortBody const * ptr);
  124. UA_Int32 UA_SecureConversationMessageAbortBody_encode(UA_SecureConversationMessageAbortBody const * src, UA_Int32* pos, char* dst);
  125. UA_Int32 UA_SecureConversationMessageAbortBody_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageAbortBody* dst);
  126. /**
  127. *
  128. * @param connection
  129. * @return
  130. */
  131. UA_Int32 SL_initConnectionObject(UA_connection *connection);
  132. /**
  133. *
  134. * @param connection
  135. * @param response
  136. * @param sizeInOut
  137. * @return
  138. */
  139. UA_Int32 SL_openSecureChannel_responseMessage_get(UA_connection *connection,
  140. UA_SL_Response *response, UA_Int32* sizeInOut);
  141. void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage);
  142. #endif /* OPCUA_SECURECHANNELLAYER_H_ */